1

I'm trying to resample the WasapiLoopbackCapture's output from my soundcards 44100Hz, 16bit, 2 channel waveformat to a 16000Hz, 16bit, 1 channel format for later use in a System.Net.Sockets.NetworkStream (I want to write the converted bytes to the network stream)

But I have no idea how to start even! I'm really new to signal processing and I've tried searching for tutorials but I just can't wrap my head around how to do this.

Here's what I got so far:

void StartRecording()
{
   capture = new WasapiLoopbackCapture(device); //  device is an audiodevice picked from the user. speaker, headphones etc
   capture.ShareMode = NAudio.CoreAudioApi.AudioClientShareMode.Shared;
   capture.DataAvailable += capture_DataAvailable;
   capture.RecordingStopped += capture_RecordingStopped;
   capture.StartRecording();
}

void capture_DataAvailable(object sender, WaveInEventArgs e)
{
   outputStream.Write(e.Buffer, 0, e.BytesRecorded); // here I want to output audio to the NetworkStream.
   // But I have to resample it first, which brings me to my question.
}

What I basically want to know is how I can get a byte-array which has been resampled and ready to be shipped off to the other side of the networkstream! Any suggestions are really appreciated! Thank you in advance.

Tokfrans
  • 1,939
  • 2
  • 24
  • 56

1 Answers1

4

NAudio includes several different resamplers - one that uses ACM (WaveFormatConversionStream), one that uses Media Foundation (MediaFoundationResampler) and one written entirely in managed code (WdlResamplingSampleProvider). I discuss each of these in this post.

For your case, you want to do "input driven" resampling, where you know how many input samples you have and just want to pass them into the resampler. This can be a bit trickier than output driven resampling in NAudio. I've written another post about how to do input driven resampling using AcmStream. A similar technique can be used with the Media Foundation resampler transform or the WDL Resampling Provider but I'm afraid I don't have a code sample of that available yet.

Mark Heath
  • 48,273
  • 29
  • 137
  • 194
  • I added the AcmStream to my project, and followed every step. But when I run the program I get an exception saying AcmNotPossible calling acmStreamOpen when initializing the AcmStream-object. Any ideas why this is happening? – Tokfrans Feb 11 '15 at 11:47
  • Nevermind that, I got it working. Apparently the loopback gave me 32 bit data instead of 16. Added some simple lines of code to convert it before putting it in the resampler! Thank you for your help – Tokfrans Feb 11 '15 at 22:44