Reputation: 466
What I'm trying to do is convert a WaveIn
microphone input to a different WaveFormat, and add that to a MixingSampleProvider.
WaveIn waveIn = new WaveIn(this.Handle);
waveIn.BufferMilliseconds = 25;
waveIn.DataAvailable += waveIn_DataAvailable;
// create wave provider
WaveProvider waveProvider = new BufferedWaveProvider(waveIn.WaveFormat);
WaveFormat commonWaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(44100, 2);
MixingSampleProvider msp = new MixingSampleProvider(commonWaveFormat);
WaveFormatConversionStream wfcs = new WaveFormatConversionStream(commonWaveFormat,new WaveProviderToWaveStream(waveProvider));
msp.AddMixerInput(wfcs);
// create wave output to speakers
waveOut = new WaveOut();
waveOut.DesiredLatency = 100;
waveOut.Init(msp);
where WaveProviderToWaveStream
is a class from this answer.
However, that gives me the following exception at WaveFormatConversionStream
.
NAudio.MmException:AcmNotPossible calling acmStreamOpen
I tried
msp.addMixerInput(MediaFoundationResampler(waveProvider, commonWaveFormat).toSampleProvider());
which worked but produced a too large delay between talking into the microphone and hearing the output.
Upvotes: 1
Views: 1762
Reputation: 49482
It will be much easier for you simply to specify the format you want to record in on the to WaveIn
object itself. (Just set the WaveFormat
property before starting to record. It should still be 16 bit PCM, but specify the sample rate and channel count you want)
Then you can turn your BufferedWaveProvider
into an ISampleProvider
by using the ToSampleProvider
extension method which will let you add it to the MixingSampleProvider
Upvotes: 2