This project has moved. For the latest updates, please go here.

Input Driven Resampling Wasapi Loopback

Oct 16, 2015 at 3:33 AM
Hi,

I am recording some audio data using wasapi loopback. And now I want to do input driven resampling (resampling before writing it into file) in order to change sample rate and bit depth.
I know that there is an example on the internet using ACM Resampler, but as wasapi loopback is producing 32bit IeeeFloat samples I cannot use ACM (as far as I know).
Does anyone know how to do this using the WDL resampler or has a code example for me? I have really no idea about that and I can't find any examples...

Tha aim is to reduce the amount of data. I think for this purpose it would be even better to do a real-time mp3-conversion, but I am not sure whether this is possible in general. When you have some ideas or code snippets about that, would be very nice :)

I would be very grateful for any ideas helping me to implement one of both
Oct 17, 2015 at 3:40 AM
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