Acoustic Echo Cancellation (AEC) with Speex and DirectSound

I am trying to cancel Acoustic Echo Cancellation (AEC) using Speex codec library. According to Speex documentation, I need to make two calls:

speex_echo_playback(echo_state, echo_frame); 

every time a sound frame is played, and

  speex_echo_capture(echo_state, input_frame, output_frame); 

for each captured frame.

Since I use DirectSound, I thought I could use the main DirectSound buffer as an echo_frame in a speex_echo_playback call, e.g.

  DWORD offset = 0; DWORD length = 0; LPVOID block1, block2; DWORD length1, length2; DWORD flags = DSBLOCK_ENTIREBUFFER; HRESULT hr = primary_buffer->Lock( offset , length , &block1 , &length1 , &block2 , &length2 , flags ); // Would like to convert the buffer into a form that // speex_echo_capture() can use. // Why does length1 == length2 == 0 always? hr = primary_buffer->Unlock( block1, length1, block2, length2 ); 

The documentation says that these are pointers for writing only, but is it necessary to use the buffer data at all?

This is basically how I create the buffer:

  CComPtr< IDirectSoundBuffer > primary_buffer; DSBUFFERDESC primarydesc = { sizeof( DSBUFFERDESC ), DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRL3D | DSBCAPS_LOCHARDWARE, 0, 0, NULL, DS3DALG_HRTF_LIGHT }; HRESULT hr = directsound_->CreateSoundBuffer( &primarydesc, &primary_buffer, NULL ); 

An alternative, apparently, to use the DirectSound buffer itself is to use speex_decode () output and inject my own software.

Any pointers or suggestions for getting Speex and DirectSound to work together? Thanks for any help.

+7
c ++ echo audio speex directsound
source share
1 answer

I did it once. But my approach was as follows:

I have never used the primary buffer directly. Instead, I only worked with one secondary buffer. I had two streams - a playback stream and a capture stream. In addition, I used another speex function - speex_echo_cancellation .

Thus, in my playback stream, I saved the current playback frame in the global buffer and in the capture stream, called the speex_echo_cancellation function, with a fixed capture frame and a previously saved playback frame.

DMO is not applicable for me because I also had to support Windows XP.

You can also look throug - speex mailing list archive or better even subscribe here to get more interesting information.

Good luck

Anthony

+3
source share

All Articles