Reputation: 13
I am using NAudio to split a 2 channel wav file which is also generated by recording using Wasapi included in NAudio. I have used this as an example to split the 2 channel wav file. The following is my code:
WaveFileReader reader = new WaveFileReader(outputFileName + "ORIGINAL.WAV");
var buffer = new byte[2 * reader.WaveFormat.SampleRate * reader.WaveFormat.Channels];
var format = new WaveFormat(reader.WaveFormat.SampleRate, 32, 1);
for (int i = 0; i < writers.Length; i++)
{
writers[i] = new WaveFileWriter(String.Format(outputFileName + "{0}.wav", i), format);
logevent.writeToLog(Convert.ToString(newWaveIn.WaveFormat.Channels));
}
int bytesRead;
while ((bytesRead = reader.Read(buffer, 0, buffer.Length)) > 0)
{
int offset = 0;
while (offset < bytesRead)
{
for (int i = 0; i < writers.Length; i++)
{
writers[i].Write(buffer, offset, 2);
offset += 2;
}
}
}
The bit rate for the recorded audio is 2822kbps. The two output wav files are 1058kbps each and the sound becomes jitter or a very loud white noise when played.
Upvotes: 1
Views: 814
Reputation: 49522
If it's 32 bit audio you're dealing with, then you need to write four bytes at a time, not two in your loop
Upvotes: 2