Use this code to read the wave file:
static double bytesToDouble(byte firstByte, byte secondByte) {
short s = (secondByte << 8) | firstByte;
return s / 32768.0;
}
public void openWav(string filename, out double[] left, out double[] right)
{
byte[] wav = File.ReadAllBytes(filename);
int channels = wav[22];
int pos = 12;
while(!(wav[pos]==100 && wav[pos+1]==97 && wav[pos+2]==116 && wav[pos+3]==97)) {
pos += 4;
int chunkSize = wav[pos] + wav[pos + 1] * 256 + wav[pos + 2] * 65536 + wav[pos + 3] * 16777216;
pos += 4 + chunkSize;
}
pos += 8;
int samples = (wav.Length - pos)/2;
if (channels == 2) samples /= 2;
left = new double[samples];
if (channels == 2) right = new double[samples];
else right = null;
int i=0;
while (pos < length) {
left[i] = bytesToDouble(wav[pos], wav[pos + 1]);
pos += 2;
if (channels == 2) {
right[i] = bytesToDouble(wav[pos], wav[pos + 1]);
pos += 2;
}
i++;
}
}
Make the modifications to the c# array in memory:
Changing pitch means re-sampling the array at a lower or higher sample rate, in effect stretching or shrinking the waveform to adjust the frequency.
Write out the array into a new Wave file;
Useful Link: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/