Question

I'm trying to record 3-4 streams of audio and write them to separate wav files. I'm using NAudio's asioOut to capture the audio. At first I was just writing a 3 or 4 channel wav file. So I searched questions here and thought I founded an answer, but I still can't figure it out. Now I can write the separate wav files but they have multiple channels in each file.

channel_1.wav --------> has channel 1 and 2

channel_2.wav --------> has channel 1 and 3

channel_3.wav --------> has channel 2 and 3

I think there is a problem when I try to parse the GetAsInterleavedSamples().

This is my asioOut_AudioAvailable()

    void asioOut_AudioAvailable(object sender, AsioAudioAvailableEventArgs e)
    {     

        float[] samples = new float[2 * 44100 * GetUserSpecifiedChannelCount()];

        samples = e.GetAsInterleavedSamples();

        int offset = 0;
        while (offset < samples.Length)
        {
            for (int n = 0; n < this.writers.Length; n++)
            {
                this.writers[n].WriteSamples(samples, offset, 2);
                offset += 2;
            }
        }

    }

I'm new at this so I'm just learning as a go, any help would be greatly appreciated.

Thanks.

Was it helpful?

Solution

If I understand you correctly, you only want to write one sample to each writer, so the third parameter for WriteSamples should be 1, and offset should be incremented by 1. You've probably copied the +=2 from an example that is dealing with 16 bit audio in a byte array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top