<p class="MsoNormal"><span style="" lang="EN-GB">Hello,</span></p><p class="MsoNormal"><br><span style="" lang="EN-GB"></span></p><p class="MsoNormal"><span style="" lang="EN-GB">I&#39;m new on DSP and i want to implant speex echo canceller on the Blackfin DSK version of speex to work on the BF533 EZ-KIT LITE
</span></p><p class="MsoNormal"><span style="" lang="EN-GB">But i can perform the echo canceller to work</span></p><p class="MsoNormal"><br><span style="" lang="EN-GB"></span></p><p class="MsoNormal"><span style="" lang="EN-GB">
This is my code, so if somebody can tell me where i&#39;m wrong<br><br></span></p><p class="MsoNormal"><span style="" lang="EN-GB">//-----------------------------------------------------------------------------</span></p>


<p class="MsoNormal"><span style="" lang="EN-GB">//
CallBackFunction() - Gets called by the audio pseudo-driver when a new audio</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">//<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>block is ready to be
played.</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">//-----------------------------------------------------------------------------</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">int
CallBackFunction(PVOID inputBuffer, PVOID outputBuffer, PVOID userData)</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">{</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>ezTurnOnLED(LED_CALLBACK);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>CYCLES_START(g_CycleStats);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span></span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>int<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>i;</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>volatile ARTYP_16BITS *in =(ARTYP_16BITS
*)inputBuffer;</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>volatile ARTYP_16BITS *out=(ARTYP_16BITS
*)outputBuffer;</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>volatile ARTYP_16BITS *out2;<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>short<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>*in_left =
in_buffer_calc;<span style="">&nbsp;&nbsp; </span>//for stereo encoding</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>short<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>*out_left = out_buffer_calc;
//for stereo encoding</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>short<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>*out2_buffer_calc;
</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">&nbsp;</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>if (SPEEX_DISABLED == g_iSpeexEnabled)
//Activated by a pushbutton</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>{ </span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>memcpy((void *)out, (void *)in, </span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span>SPEEX_FRAME_SIZE*NUM_CHANNELS*sizeof(ARTYP_16BITS));<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>}</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>else //Speex is enabled so do a lot more work</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>{</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">#ifndef
ACTIVATE_STEREO<span style="">&nbsp;&nbsp; </span></span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>// Demux the stereo<span style="">&nbsp; </span>stream <span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>for(i = 0; i &lt; SPEEX_FRAME_SIZE; i++) </span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>{</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>*in_left++ = *in++; // channel 1</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>in++; // channel 2<span style="">&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>}<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>in_left = in_buffer_calc;</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>speex_bits_reset(&amp;g_Bits);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>// Encode the frame</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>speex_encode_int(g_pvEnc, (spx_int16_t
*)in_left, &amp;g_Bits);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>nbBits = speex_bits_write(&amp;g_Bits,
cbits, 200);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>speex_bits_rewind(&amp;g_Bits);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>SpeexEchoState *st=
speex_echo_state_init(SPEEX_FRAME_SIZE,filter_length);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>speex_echo_cancel(st,(spx_int16_t
*)in_left,(spx_int16_t *)out_left,(spx_int16_t *)out2,NULL);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>speex_echo_state_destroy(st);<span style="">&nbsp;&nbsp;&nbsp; </span></span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span></span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>// Decode the frame</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>speex_decode_int(g_pvDec, &amp;g_Bits,
(spx_int16_t *)out_left);<span style="">&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;</span></span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">#ifdef
ALWAYS_PASS_THROUGH</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>memcpy(out_buffer_calc, in_buffer_calc, </span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp;
</span>SPEEX_FRAME_SIZE*sizeof(SND_FIXED_16_TYPE));</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">#endif
//ALWAYS_PASS_THROUGH</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>// Mux the Speex output onto the stereo
audio stream</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>for(i = 0; i &lt; SPEEX_FRAME_SIZE; i++) </span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>{</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>*out++ = *out_left; // channel 1</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>*out++ = *out_left++; // channel 2<span style="">&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>}</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">#else
//ACTIVATE_STEREO</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>speex_bits_reset(&amp;g_Bits);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">&nbsp;</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>// Encode the frame</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>speex_encode_stereo_int((spx_int16_t *)in,
SPEEX_FRAME_SIZE, &amp;g_Bits);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>speex_encode_int(g_pvEnc, (spx_int16_t
*)in, &amp;g_Bits);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>g_nBits = speex_bits_write(&amp;g_Bits,
g_cBits, 200);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>speex_bits_rewind(&amp;g_Bits);<span style="">&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>// Decode the frame</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>speex_decode_int(g_pvDec, &amp;g_Bits,
(spx_int16_t *)out);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>speex_decode_stereo_int((spx_int16_t *)out,
SPEEX_FRAME_SIZE, &amp;g_StereoState);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">#ifdef
ALWAYS_PASS_THROUGH</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp;&nbsp;&nbsp; </span>memcpy(out, in,
SPEEX_FRAME_SIZE*NUM_CHANNELS*sizeof(SND_FIXED_16_TYPE));</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">#endif
//ALWAYS_PASS_THROUGH</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">#endif
//ACTIVATE_STEREO</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">}</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB">&nbsp;</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>if (1 == ezIsButtonPushed(BUTTON_QUIT)) {
g_EOS = 1; } //Quit Btn pressed</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>CYCLES_STOP(g_CycleStats);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>ezTurnOffLED(LED_CALLBACK);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span>//speex_echo_state_destroy(st);</span></p>

<p class="MsoNormal"><span style="" lang="EN-GB"><span style="">&nbsp; </span></span>return 0;</p>

<p class="MsoNormal">}</p><br><p class="MsoNormal"><br></p><p class="MsoNormal">thanks<br><br></p><p class="MsoNormal">Damien Guiserix<br></p>