Now I am trying to do it with the Media Foundation Resampler (although I am not sure whether this is the "rigth one" :D). I am trying this one:
byte[] converted = new byte[38400];
BufferedWaveProvider rs = new BufferedWaveProvider(loopbackRecorder.WaveFormat);
MediaFoundationResampler mfr = new MediaFoundationResampler(rs, new WaveFormat(44100,32,2));
public void waveIn_DataAvailable(object sender, WaveInEventArgs e)
{
// ...
rs.AddSamples(e.Buffer, 0, e.BytesRecorded);
int count = mfr.Read(converted, 0, rs.BufferedBytes);
//...
}
When I am debugging this, it seems to run correctly when data is available the first time. Then something is written in to the converted-Array and the BufferedWaveProvider is cleared because it was read.
But the next times, the samples are stored in the BufferedWaveProvider but are not read out. And nothing is written into my converted-Array. Finally, this causes a crash because there is soon to much stored in the buffer, more bytes than my converted-Array is long.
I am not sure whether this is a good approach and I have no clue why this seems to run only the first time - the code is obviously the same for each time :P