[Speex-dev] Speex and DS

Thorvald Natvig speex at natvig.com
Thu Jun 23 02:36:38 PDT 2005

For any kind of capture with computation, you need to use the DS concept 
of read and capture positions.

Basically, allocate a DS capture buffer of at least 2 * framesize * 
sizeof(short), preferably 4 * framesize or so.

Keep calling
pDSCaptureBuffer->GetCurrentPosition(&dwCapturePosition, &dwReadPosition)

When dwReadPosition has changed enough since the last processed frame that 
there's a whole frame ready, lock the region from dwLastFrameReadPosition 
to dwReadPosition. Never lock the entire buffer, that will halt capture 
while you compress.

Copy the locked region into a buffer, update dwLastFrameReadPosition = 
dwReadPosition, and unlock the buffer again.

Compress the buffer you copied to.


If you want to avoid the rather gross overhead of GetCurrentPosision, you 
can estimate the time until the next frame is ready and then just sleep 
that long, or use IDirectSoundNotify, setting a marker in the buffer for 
each multiple of framesize, and then wait for the notification event 
(which you can also plug into your main event loop if you don't want to 
dedicate a thread to audio capture).

> Hello everyone
> I've a following problem with the speex codec. I'm developing application 
> that is supposed to read
> sounds from the microphone with DirectSoundCapture. Unfortunately when I want 
> to compress and decompress
> the sound buffer from DirectSound I only have jitter. Maybe you have some 
> code samples how to compress
> standard DS buffers:

More information about the Speex-dev mailing list