Home > Mobile >  Getting raw data from Microphone using DirectShow WinApi
Getting raw data from Microphone using DirectShow WinApi

Time:11-11

I am trying to write a small DirectShow application using C . My main issue is grabbing the raw data from the microphone and saving it as BYTES.

Is this possible using a DirectShow filter? What interface am I supposed to use in order to get the data?

Right now, I am able to achieve writing a recorded AVI file using the following Graph Filter:

Microphone->Avi Mux->File writer

This graph works fine.

I have tried to use the SampleGrabber (which is deprecated by Microsoft) and I have a lack of knowledge regarding what to do with this BaseFilter type.

CodePudding user response:

By design DirectShow topology needs to be complete, starting with source (microphone) and terminating with renderer filter, and data exchange in DirectShow pipelines is private to connected filters, without data exposure to controlling application.

This makes you confused because you apparently want to export content from the pipeline, into outer world. It is not exactly the way DirectShow is designed to work.

The "intended", "DirectShow way" is to develop a custom renderer filter which would connect to the microphone filter and receive its data. More often than not developers prefer to not take this path since developing a custom filter is a sort of complicated.

The popular solution is to build a pipeline Microphone --> Sample Grabber --> Null Renderer. Sample Grabber is a filter which exposes data, which is passed through, using SampleCB callback. Even though it's getting harder with time, you can still find tons of code which do the job. Most developers prefer this path: to build pipeline using ready to use blocks and forget about DirectShow API.

And then one another option would be to not use DirectShow at all. Given its state this API choice is unlucky, you should rather be looking at WASAPI capture instead.

  • Related