Reputation: 76
I would like to know how can I split the channels of a WAV file into two byte arrays with the PCM data.
I've been trying to do this with NAudio, but I can't get it.
Upvotes: 0
Views: 480
Reputation: 5986
You can try the following to split wav file into two byte arrays
.
using (WaveFileReader pcm = new WaveFileReader(@"E:\\test.wav"))
{
int samplesDesired = 5000;
byte[] buffer = new byte[samplesDesired * 4];
short[] left = new short[samplesDesired];
short[] right = new short[samplesDesired];
int bytesRead = pcm.Read(buffer, 0, 10000);
int index = 0;
for (int sample = 0; sample < bytesRead / 4; sample++)
{
left[sample] = BitConverter.ToInt16(buffer, index);
index += 2;
right[sample] = BitConverter.ToInt16(buffer, index);
index += 2;
}
MessageBox.Show("success");
}
Upvotes: 1