Answered by:

Converting sampling rate for microphone input

Question

I'm trying to record audio from the microphone in wave PCM format at 16bit, 16KHz . However using WASAPI for wave capture, it does not automatically convert the sampling rate of the audio, and continues to record at CD Quality. I remembered sampling
rate conversion was really easy with legacy waveIn APIs, DirectSound, or DirectShow.

Then I attempted to use the Resampler MFT, but could not find a way to insert the MFT using Media Foundation or Windows.Media.Capture APIs. Windows Store app certification seems to block all necessary APIs like MFEnum.To use media extensions
through ApplyAudioEffect, it's seems that I have to encode audio to Mp3/WMA first.

Has someone figured this out? Is there a way for a Windows Store app to access the built in audio sampling rate converter?

What about other custom audio dsps, what is the best way to implement them in a Windows Store app? I prefer to apply dsps to streaming audio.

I found a way around this. With the audio captured from WASAPI, transfer it into XAudio audio graph with input format set to WASAPI's mixing format. Then, set the masteringvoice format to 16kHz or expected output format. Play the audio, and
the output will be converted to expected sampling rate. I've created an XAPO inserted to the masteringvoice, to collect the converted audio. I did have to manually convert 32bit floats to 16bit pcm in the XAPO. The application can also mute the volume
if the audio shouldn't be played.

Not an ideal solution, but it's a workable solution for converting wav audio formats, when APIs are unavailable.