0
votes

I have a task for work, I need to convert a local .wav file into 2 separate PCM files.

I have managed to read the file into a WavStream or into a Byte[] but have no knowledge on how to convert each channel to a separate file, without losing the headers.

Sample Code will be highly appreciated.

Thanks,

Nokky.

P.S

This is the code I used.

public void WavToPcmConvert(string filePath)
{
    string fileName = Path.GetFileNameWithoutExtension(filePath);

    using (var reader = new WaveFileReader(filePath))
    {
        using (var converter = WaveFormatConversionStream.CreatePcmStream(reader))
        {
              WaveFileWriter.CreateWaveFile(, converter);
        }
    }
}
1

1 Answers

0
votes

In a PCM file, samples are interleaved left, right. Assuming you have 16 bit samples, this means you get two bytes left channel, two bytes right, and so on.

So create two WaveFileWriters, then read a second's worth of audio from converter, loop through the bytes you've read, and write alternating pairs into each WaveFileWriter. Keep going until you get to the end of your input stream (converter.Read returns 0).