class in Clatter.Core
Write audio samples to a .wav file. Instantiate a WavWriter to begin writing audio. Call Write(data) to continuously write chunks of audio data to the file. Call End() to stop writing and append the wav header data to the file.
public WavWriter(string path, bool overwrite=true, int channels=1)
Name | Type | Description |
---|---|---|
path | string | The path to the output file. |
overwrite | bool | If true, overwrite an existing file. |
channels | int | The number of audio channels. |
public void Write(byte[] audio)
Write audio samples to the .wav file.
Name | Type | Description |
---|---|---|
audio | byte[] | The audio data as an int16 byte array. |
public void End()
End the wav file. Open the file and set metadata about data size. Source:
using System;
using Clatter.Core;
public class ScrapeAudioExample
{
private static void Main(string[] args)
{
// Load the materials.
ImpactMaterial primaryMaterial = ImpactMaterial.glass_1;
ImpactMaterial secondaryMaterial = ImpactMaterial.stone_4;
ScrapeMaterial scrapeMaterial = ScrapeMaterial.ceramic;
ImpactMaterialData.Load(primaryMaterial);
ImpactMaterialData.Load(secondaryMaterial);
ScrapeMaterialData.Load(scrapeMaterial);
// Set the objects.
ClatterObjectData primary = new ClatterObjectData(0, primaryMaterial, 0.2, 0.2, 1);
ClatterObjectData secondary = new ClatterObjectData(1, secondaryMaterial, 0.5, 0.1, 100, scrapeMaterial);
// Initialize the scrape.
Scrape scrape = new Scrape(scrapeMaterial, primary, secondary, new Random());
// Start writing audio.
WavWriter writer = new WavWriter("out.wav", overwrite: true);
// Generate the scrape.
int count = Scrape.GetNumScrapeEvents(0.5);
for (int i = 0; i < count; i++)
{
scrape.GetAudio(1);
writer.Write(scrape.samples.ToInt16Bytes());
}
writer.End();
}
}