I have an app where users can play around with the pitch of an AudioSource. The next thing i want is the users to save the AudioClip to load it later and continue with the sounds. Without the pitch this is not a problem and i can now save an AudioClip as a .wav file in storage (code below). What it does is just save the data of the AudioClip, so it does not take the pitch in consideration (there is some more code but i think this is the most important stuff).
How can i manipulate the data to make sure it is being stored together with pitch?
//TODO: static void ConvertAndWrite(FileStream fileStream, AudioClip clip, float pitch) {
static void ConvertAndWrite(FileStream fileStream, AudioClip clip) {
var samples = new float[clip.samples];
clip.GetData(samples, 0);
Int16[] intData = new Int16[samples.Length];
//converting in 2 float[] steps to Int16[], //then Int16[] to Byte[]
Byte[] bytesData = new Byte[samples.Length * 2];
//bytesData array is twice the size of
//dataSource array because a float converted in Int16 is 2 bytes.
int rescaleFactor = 32767; //to convert float to Int16
for (int i = 0; i
↧