<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
<div class="moz-text-flowed"
style="font-family: -moz-fixed; font-size: 12px;" lang="x-western">Hi
Alls
<br>
Sorry for my newbe question
<br>
I want to decode a speex multi frame stream
<br>
I got 38 bytes packets and make 800 bytes buffer
<br>
this is my simple code
<br>
<br>
CSpeexCodec::CSpeexCodec(void)
<br>
<br>
{
<br>
<br>
//
<br>
speex_bits_init(&m_speexBitsOut);
<br>
<br>
m_pSpeexEncStateOut = speex_encoder_init(&speex_nb_mode);
<br>
<br>
<br>
<br>
int nEhc=1;
<br>
<br>
int nSamplePerSec = SAMPLES_PER_SEC;
<br>
<br>
static int nQuality = 8;
<br>
<br>
speex_encoder_ctl(m_pSpeexEncStateOut, SPEEX_SET_SAMPLING_RATE,
&nSamplePerSec);
<br>
<br>
speex_encoder_ctl(m_pSpeexEncStateOut, SPEEX_SET_QUALITY,
&nQuality);
<br>
<br>
<br>
<br>
//speex_encoder_ctl(m_pSpeexEncStateOut, SPEEX_SET_VBR, &nEhc);
<br>
<br>
//speex_encoder_ctl(m_pSpeexEncStateOut, SPEEX_SET_VAD, &nEhc);
<br>
<br>
//speex_encoder_ctl(m_pSpeexEncStateOut, SPEEX_SET_DTX, &nEhc);
<br>
<br>
<br>
<br>
speex_encoder_ctl(m_pSpeexEncStateOut, SPEEX_GET_FRAME_SIZE,
&m_nEncodeFrameSize);
<br>
<br>
<br>
<br>
//
<br>
speex_bits_init(&m_speexBitsIn);
<br>
<br>
m_pSpeexDecStateIn= speex_decoder_init(&speex_nb_mode); <br>
<br>
speex_decoder_ctl(m_pSpeexDecStateIn, SPEEX_GET_FRAME_SIZE,
&m_nDecodeFrameSize);
<br>
<br>
<br>
<br>
}
<br>
<br>
int CSpeexCodec::Decode(const char* pcIndata, int nIndataSize,
CShortCollection& dataOut)
<br>
<br>
{
<br>
<br>
//
<br>
<br>
speex_bits_read_from( &m_speexBitsIn, (char*)pcIndata,
nIndataSize);
<br>
<br>
static std::vector<float> floatDataOut;
<br>
<br>
int nFrame = 0;
<br>
<br>
size_t nbBytes = speex_bits_remaining(&m_speexBitsIn);
<br>
<br>
while(nbBytes > 0 )
<br>
<br>
{
<br>
<br>
if( (nFrame+1) * m_nDecodeFrameSize > (int)floatDataOut.size(
) )
<br>
<br>
{
<br>
<br>
if( !floatDataOut.size( ) )
<br>
<br>
floatDataOut.resize(m_nDecodeFrameSize );
<br>
<br>
else
<br>
floatDataOut.resize(floatDataOut.size( ) * 2 );
<br>
<br>
}
<br>
<br>
if ( speex_decode(m_pSpeexDecStateIn, &m_speexBitsIn,
&floatDataOut[ nFrame++ * m_nDecodeFrameSize ] ) != 0 )
<br>
<br>
break;
<br>
<br>
nbBytes = speex_bits_remaining(&m_speexBitsIn);
<br>
<br>
}
<br>
<br>
// float -> short
<br>
<br>
dataOut.resize( nFrame * m_nDecodeFrameSize );
<br>
<br>
const float* pfSrc = &floatDataOut[0];
<br>
<br>
short* phDst = &dataOut[0];
<br>
<br>
size_t nOutSize = dataOut.size( );
<br>
<br>
while(nOutSize-- ) { *phDst++ = (short)*pfSrc++; }
<br>
<br>
<br>
<br>
return 0;
<br>
<br>
<br>
<br>
}
<br>
<br>
So speex_decode return -2 after 2-3 interation in my while loop
<br>
What is wrong ?
<br>
Thank for help
<br>
<br>
<br>
<br>
<br>
</div>
</body>
</html>