How can I mix two different audio signals and write the ouput into one stream during recording? Currently, I record two signals from different devices and write them in two seperate files. After ending the recording, I mix the two files using a WaveMixerStream32:
// Loading first MP3 file
using (var fileReader1 = new Mp3FileReader(intputFile1))
{
// Converting into 32 floating point format for mixing
using (WaveStream convertedStream1 = new WaveChannel32(fileReader1))
{
// Loading second file
using (var fileReader2 = new Mp3FileReader(intputFile2))
{
using (WaveStream convertedStream2 = new WaveChannel32(fileReader2))
{
// Mixing both streams
using (var mixer = new WaveMixerStream32())
{
mixer.AddInputStream(convertedStream1);
mixer.AddInputStream(convertedStream2);
// Converting back to integer sample format
using (WaveStream intOutput = new Wave32To16Stream(mixer))
{
// Converting into user-defined output format
using (WaveStream convertedOutput = new WaveFormatConversionStream(OutputWaveFormat, intOutput))
{
// Writing to output file
using (LameMP3FileWriter outputWriter = new LameMP3FileWriter(outputFile, convertedOutput.WaveFormat, mp3AudioQualityPreset))
{
convertedOutput.CopyTo(outputWriter);
}
}
}
}
}
}
}
}
But I need to mix both audio signals on-the-fly to process the mixed-down stream in realtime during the recording. I figured that I need to use a BufferedWaveProvider but I don't understand how this could be achived. Is there an example that shows how to use the BufferedWaveProvider for this purpose? Or is there another way to achive this by using NAudio?