Store AudioClip with pitch

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<samples.Length; i++) {
			intData <em>= (short) (samples _* rescaleFactor);_</em>

* Byte[] byteArr = new Byte[2];*
_ byteArr = BitConverter.GetBytes(intData*);
byteArr.CopyTo(bytesData, i * 2);

* fileStream.Write(bytesData, 0, bytesData.Length);*
* }*

Dunno on saving the audio stream that’s playing, but how about making a class that holds a sound file name and a pitch float, and the user saving that instead of recording and saving a whole audio file?
Unless the whole point is for the user to export any funny clips they made.

I think i have found the solution, for ppl getting this issue in the future.

The only thing you have to do is expand or shrink the data array you can get from an AudioClip (Interpolating in case of shrinking (pitch > 1), Extrapolating in case of expansion (Pitch < 1))

Google a bit for those kind of stuff and you should be able to figure it out :slight_smile: