Mixing two microphone inputs to one wav file
See original GitHub issueHi,
I am trying to mix two microphone inputs and save them to one wav file. To this end I have been experimenting with the RecordingPanel from the NAudio demo trying to get the microphone input in and out of a MixingWaveProvider32.
I think I am missing a step to write the MixingWaveProvider into the WaveFileWriter I have open. Could someone give me a hand please.
Please see the code snippets below.
Regards,
Darren
` private void CreateWaveInDevice() { if (radioButtonWaveIn.Checked) { waveIn = new WaveIn(); waveIn.WaveFormat = new WaveFormat(8000, 1); } else if (radioButtonWaveInEvent.Checked) { waveIn = new WaveInEvent(); waveIn.WaveFormat = new WaveFormat(8000, 1); } else if (radioButtonWasapi.Checked) { // can’t set WaveFormat as WASAPI doesn’t support SRC var device = (MMDevice) comboWasapiDevices.SelectedItem; waveIn = new WasapiCapture(device); } else { // can’t set WaveFormat as WASAPI doesn’t support SRC waveIn = new WasapiLoopbackCapture(); }
WaveFormat OutputFormat = new WaveFormat(8000, 16, 1);
bufferedWaveProvider = new BufferedWaveProvider(OutputFormat);
MediaFoundationResampler MFR = new MediaFoundationResampler(bufferedWaveProvider, WaveFormat.CreateIeeeFloatWaveFormat(8000, 1));
mixer = new MixingWaveProvider32();
mixer.AddInputStream(MFR);
WFW = new WaveFileWriter("D:\\a\\DJS.wav", waveIn.WaveFormat);
waveIn.DataAvailable += OnDataAvailable;
waveIn.RecordingStopped += OnRecordingStopped;
}
`
` void OnDataAvailable(object sender, WaveInEventArgs e) { if (this.InvokeRequired) { //Debug.WriteLine(“Data Available”); this.BeginInvoke(new EventHandler<WaveInEventArgs>(OnDataAvailable), sender, e); } else { //Debug.WriteLine(“Flushing Data Available”); //writer.Write(e.Buffer, 0, e.BytesRecorded);
bufferedWaveProvider.AddSamples(e.Buffer, 0, e.BytesRecorded);
int secondsRecorded = (int)(writer.Length / writer.WaveFormat.AverageBytesPerSecond);
if (secondsRecorded >= 30)
{
StopRecording();
}
else
{
progressBar1.Value = secondsRecorded;
}
}
}
`
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
we are a few years later. Is there a way now?
Still waiting))