Mam aplikację Delphi 6 Pro, która wykorzystuje bibliotekę komponentów DSPACK do przesyłania dźwięku do Skype z preferowanego urządzenia audio systemu. Używam składnika TSampleGrabber, aby wejść do łańcucha Graph Filter, a następnie wysłać bufory audio do Skype. Problem polega na tym, że dostaję dźwięk tylko raz na sekundę. Innymi słowy, zdarzenie OnBuffer() dla instancji TSampleGrabber uruchamia się tylko raz na sekundę z wartościami pełnej sekundy w parametrze Buffer. Muszę wiedzieć, jak zmodyfikować mój łańcuch Graph Filter, aby pobierać dane z urządzenia wejściowego w szybszym czasie niż raz na sekundę. Jeśli to możliwe, chciałbym to zrobić tak szybko, jak co 50 ms lub co najmniej co 100 ms.Jak wyeliminować 1 sekundowe opóźnienie w łańcuchu filtrów DirectShow? (Używanie Delphi i DSPACK)
Łańcuch z filtrem My Filter składa się z TFiltera, który jest mapowany na preferowane systemowe urządzenie wejściowe audio na górze. Piny wyjściowe tego filtra podłączam do pinów wejściowych urządzenia docelowego "WAV Dest" przypisanego do TFiltera, aby pobrać próbki w formacie PCM WAV. Następnie podłączam kołki wyjściowe filtra "WAV Dest" do szpilek wejściowych instancji TSampleGrabber. Co muszę zmienić, aby wydarzenie TSampleGrabber OnBuffer() zostało uruchomione w krótszym czasie?
UPDATE: Na podstawie odpowiedzi Roman R za udało mi się wdrożyć rozwiązanie, które przytaczam poniżej. Jedna uwaga. Jego związek doprowadził mnie do następnego blogu, który był pomocny w roztworze:
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;
Dzięki @Roman R. Zaktualizowałem mój oryginalny wpis, aby uwzględnić rozwiązanie, które znalazłem po oryginalnym łączu. –