Hi all,<br><br>First of all, thanks to Speex developper for the all the job. <br><br>I am trying to implement my own Speex DirectShow fitlers for VoIP following the documentation and sample code&#39;s.<br>I am facing audio glitches when encoding - decoding PCM data. The encoder and decoder procedures are copied below. 
<br>What about the lookahead size ? how shouw we apply it in encoding stage ? <br><br>thanks in advance<br><br>bool SpeexEncoder::EncodeData(char * inBuffer, int inSize, char * outBuffer, int outMAXSize, int* outSize)<br>
{<br>&nbsp;&nbsp;&nbsp; if(!m_Initialized) return false;<br><br>&nbsp;&nbsp;&nbsp; // Copy data into the local buffer<br>&nbsp;&nbsp;&nbsp; memcpy(m_pBuffer + m_BufferSize, inBuffer, inSize);<br>&nbsp;&nbsp;&nbsp; m_BufferSize += inSize;<br><br>&nbsp;&nbsp;&nbsp; // check if we have enougth data for the encoder,&nbsp; 
<br>&nbsp;&nbsp;&nbsp; if(m_BufferSize &lt; m_FrameSizeInBytes )<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return false;<br><br>&nbsp;&nbsp;&nbsp; // start processing<br>&nbsp;&nbsp;&nbsp; short* input = (short*)m_pBuffer;<br>&nbsp;&nbsp;&nbsp; char*&nbsp; output = outBuffer;<br>&nbsp;&nbsp;&nbsp; *outSize = 0;<br>&nbsp;&nbsp;&nbsp; int tmpBufferSize = m_BufferSize;
<br><br>&nbsp;&nbsp;&nbsp; while(tmpBufferSize &gt;= m_FrameSizeInBytes + m_SpeexLookAheadInBytes)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; speex_bits_reset(&amp;m_SpeexBits);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(m_Channels == 2)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; speex_encode_stereo_int(input, m_FrameSizeInSamples, &amp;m_SpeexBits);
<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (m_SpeexPreprocessState != NULL)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; speex_preprocess(m_SpeexPreprocessState, input, NULL);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; speex_encode_int(m_SpeexState, input, &amp;m_SpeexBits);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int bytes = speex_bits_write(&amp;m_SpeexBits, output, outMAXSize);
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; input += m_FrameSizeInBytes;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output += bytes;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *outSize += bytes;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tmpBufferSize -= m_FrameSizeInBytes;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; // if we consumed data from the buffer, it needs to be rearanged in order to keep only 
<br>&nbsp;&nbsp;&nbsp; ....<br><br>&nbsp;&nbsp;&nbsp; return true;<br>}<br><br><br>bool SpeexDecoder::DecodeData( char * inBuffer, int inSize, char ** outBuffer, int outMAXSize, int* outSize)<br>{<br>&nbsp;&nbsp;&nbsp; if(!m_Initialized) <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return false;<br>
<br>&nbsp;&nbsp;&nbsp; int remains = inSize;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; char&nbsp; * input&nbsp; = inBuffer;<br>&nbsp;&nbsp;&nbsp; short * output = (short*) *outBuffer;<br>&nbsp;&nbsp;&nbsp; int size = 0;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; while(remains &gt; 0)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; speex_bits_read_from(&amp;m_SpeexBits, input, remains);
<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int locRet = speex_decode_int(m_SpeexState, &amp;m_SpeexBits, output);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (locRet == -1 || locRet == -2) <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ((remains = (speex_bits_remaining(&amp;m_SpeexBits))/8) &lt; 0) 
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //Corrupted<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return false;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (m_Channels == 2)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; speex_decode_stereo_int((short *)output, m_FrameSizeInSamples, &amp;m_StereoState);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size += m_FrameSizeInBytes;
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output += m_FrameSizeInBytes;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; input = inBuffer + inSize - remains;<br>&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; *outSize = size;<br>&nbsp;&nbsp;&nbsp; return true;<br>}<br><br>