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'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> if(!m_Initialized) return false;<br><br> // Copy data into the local buffer<br> memcpy(m_pBuffer + m_BufferSize, inBuffer, inSize);<br> m_BufferSize += inSize;<br><br> // check if we have enougth data for the encoder,
<br> if(m_BufferSize < m_FrameSizeInBytes )<br> return false;<br><br> // start processing<br> short* input = (short*)m_pBuffer;<br> char* output = outBuffer;<br> *outSize = 0;<br> int tmpBufferSize = m_BufferSize;
<br><br> while(tmpBufferSize >= m_FrameSizeInBytes + m_SpeexLookAheadInBytes)<br> {<br> speex_bits_reset(&m_SpeexBits);<br> <br> if(m_Channels == 2)<br> speex_encode_stereo_int(input, m_FrameSizeInSamples, &m_SpeexBits);
<br><br> if (m_SpeexPreprocessState != NULL)<br> speex_preprocess(m_SpeexPreprocessState, input, NULL);<br><br> speex_encode_int(m_SpeexState, input, &m_SpeexBits);<br> int bytes = speex_bits_write(&m_SpeexBits, output, outMAXSize);
<br> <br> input += m_FrameSizeInBytes;<br> output += bytes;<br> *outSize += bytes;<br> <br> tmpBufferSize -= m_FrameSizeInBytes;<br> }<br> <br> // if we consumed data from the buffer, it needs to be rearanged in order to keep only
<br> ....<br><br> return true;<br>}<br><br><br>bool SpeexDecoder::DecodeData( char * inBuffer, int inSize, char ** outBuffer, int outMAXSize, int* outSize)<br>{<br> if(!m_Initialized) <br> return false;<br>
<br> int remains = inSize;<br> <br> char * input = inBuffer;<br> short * output = (short*) *outBuffer;<br> int size = 0;<br> <br> while(remains > 0)<br> {<br> speex_bits_read_from(&m_SpeexBits, input, remains);
<br><br> int locRet = speex_decode_int(m_SpeexState, &m_SpeexBits, output);<br> if (locRet == -1 || locRet == -2) <br> return false;<br><br> if ((remains = (speex_bits_remaining(&m_SpeexBits))/8) < 0)
<br> //Corrupted<br> return false;<br><br> if (m_Channels == 2)<br> speex_decode_stereo_int((short *)output, m_FrameSizeInSamples, &m_StereoState);<br><br> size += m_FrameSizeInBytes;
<br> output += m_FrameSizeInBytes;<br> input = inBuffer + inSize - remains;<br> } <br> <br> *outSize = size;<br> return true;<br>}<br><br>