c++audio-streamingdirectshow

Directshow audio capture filter generates only 1 sample per second


I'm making an small real-time audio-video application using Directshow. I use SampleGrabber to grab samples from Audio Capture filter. The SampleGrabber's callback is called every second and each sample's size is 88200 bytes. I printed the WAVEFORMATEX:
WAVE_FORMAT_PCM: true
nChannels: 2
nSamplesPerSec: 44100
nAvgBytesPerSec: 176400
nBlockAlign: 4
wBitsPerSample: 16
cbSize: 0

so I have 2 questions:

  1. Is 'sample' in Directshow's aspect is different from 'sample' in audio recording? Because as I know, there are 44100 samples per second (each costs 16 bits) while directshow's SampleGrabber only grab 1 sample per second (each costs 88200 bytes). Look like lots of sample are aggregated and put into a 'buffer' ?

  2. If lots of audio sample are put into a buffer so the buffer's size should be 176400 bytes per sec. Why it is only 88200 bytes per buffer? Is only 1 channel used?


Solution

  • Directshow "sample" is a term for buffer with data:

    When a pin delivers media data to another pin, it does not pass a direct pointer to the memory buffer. Instead, it delivers a pointer to a COM object that manages the memory. This object, called a media sample, exposes the IMediaSample interface.

    Then

    ... size should be 176400 bytes per sec. Why it is only 88200 bytes per buffer?

    No it should not. You're seeing the default behavior of capture filter to produce 500 ms buffers. You can use IAMBufferNegotiation interface (related questions and search for other) to override this behavior.