Question

I have a Delphi 6 Pro app that uses the DSPACK component library to send audio to Skype from the system's preferred audio input device. I am using a TSampleGrabber component to tap into the Filter Graph chain and then send the audio buffers to Skype. The problem is that I am only getting audio once a second. In other words, the OnBuffer() event for the TSampleGrabber instance only fires once a second with a full second's worth of data in the Buffer parameter. I need to know how to modify my Filter Graph chain so it grabs data from the input device at a faster interval than once a second. If possible, I'd like to do it as fast as every 50 ms or at least every 100ms.

My Filter Graph chain consists of a TFilter that is mapped to the system's preferred audio input device at the top. I attach the output pins of that filter to the input pins of a 'WAV Dest' assigned TFilter so I can get the samples in PCM WAV format. I then attach the output pins of the 'WAV Dest' filter to the input pins of the TSampleGrabber instance. What do I need to change to get the TSampleGrabber OnBuffer() event to fire at a faster interval?


UPDATE: Based on Roman R's answer I was able to implement a solution that I am showing below. One note. His link led me to the following blog post that was helpful in solution:

http://sid6581.wordpress.com/2006/10/09/minimizing-audio-capture-latency-in-directshow/

// Variable declaration for output pin to manipulate.
var
    intfCapturePin: IPin;

...............


    // Put this code after you have initialized your audio capture device
    //  TFilter instance *and* set it's wave audio format.  My variable for
    //  this is FFiltAudCap.  I believe you need to set the buffer size before
    //  connecting up the pins of the Filters.  The media type was
    //  retrieved earlier (theMediaType) when I initialized the audio
    //  input device Filter so you will need to do similarly.

    // Get a reference to the desired output pin for the audio capture device.
    with FFiltAudCap as IBaseFilter do
        CheckDSError(findPin(StringToOleStr('Capture'), intfCapturePin));

    if not Assigned(intfCapturePin) then
        raise Exception.Create('Unable to find the audio input device''s Capture output pin.');

    // Set the capture device buffer to 50 ms worth of audio data to
    //  reduce latency.  NOTE: This will fail if the device does not
    //  support the latency you desire so make sure you watch out for that.
    setBufferLatency(intfCapturePin as IAMBufferNegotiation, 50, theMediaType);

..................

// The setBufferLatency() procedure.
procedure setBufferLatency(
                // A buffer negotiation interface pointer.
                intfBufNegotiate: IAMBufferNegotiation;
                // The desired latency in milliseconds.
                bufLatencyMS: WORD;
                // The media type the audio stream is set to.
                theMediaType: TMediaType);
var
    allocProp: _AllocatorProperties;
    wfex: TWaveFormatEx;
begin
    if not Assigned(intfBufNegotiate) then
        raise Exception.Create('The buffer negotiation interface object is unassigned.');

    // Calculate the number of bytes per second using the wave
    // format belonging to the given Media Type.
    wfex := getWaveFormat(theMediaType);

    if wfex.nAvgBytesPerSec = 0 then
        raise Exception.Create('The average bytes per second value for the given Media Type is 0.');

    allocProp.cbAlign := -1;  // -1 means "no preference".
    // Calculate the size of the buffer needed to get the desired
    //  latency in milliseconds given the average bytes per second
    //  of the Media Type's audio format.
    allocProp.cbBuffer := Trunc(wfex.nAvgBytesPerSec * (bufLatencyMS / 1000));
    allocProp.cbPrefix := -1;
    allocProp.cBuffers := -1;

    // Try to set the buffer size to the desired.
    CheckDSError(intfBufNegotiate.SuggestAllocatorProperties(allocProp));
end;
Was it helpful?

Solution

I suppose you need to fine tune Audio Capture filter to capture in buffers of the size you want, i.e. short enough to make overall latency small.

Audio capture filters expose IAMBufferNegotiation interface on output pins and SuggestAllocatorProperties lets you specify buffer configuration.

See for more info: Configuring Windows Media Audio Encoder DMO to reduce delay.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top