[Speex-dev] speex multi frame

Vassili Gontcharov v.gontcharov at gmail.com
Wed Jun 9 21:46:28 PDT 2010


Hi Alls
Sorry for my newbe question
I want to decode a speex multi frame stream
I got 38 bytes packets and make 800 bytes buffer
this is my simple code

CSpeexCodec::CSpeexCodec(void)

{

  //
  speex_bits_init(&m_speexBitsOut);

  m_pSpeexEncStateOut = speex_encoder_init(&speex_nb_mode);



  int nEhc=1;

  int nSamplePerSec = SAMPLES_PER_SEC;

  static int nQuality = 8;

  speex_encoder_ctl(m_pSpeexEncStateOut, SPEEX_SET_SAMPLING_RATE, 
&nSamplePerSec);

  speex_encoder_ctl(m_pSpeexEncStateOut, SPEEX_SET_QUALITY, &nQuality);



  //speex_encoder_ctl(m_pSpeexEncStateOut, SPEEX_SET_VBR, &nEhc);

  //speex_encoder_ctl(m_pSpeexEncStateOut, SPEEX_SET_VAD, &nEhc);

  //speex_encoder_ctl(m_pSpeexEncStateOut, SPEEX_SET_DTX, &nEhc);



  speex_encoder_ctl(m_pSpeexEncStateOut, SPEEX_GET_FRAME_SIZE, 
&m_nEncodeFrameSize);



  //
  speex_bits_init(&m_speexBitsIn);

  m_pSpeexDecStateIn= speex_decoder_init(&speex_nb_mode); 

  speex_decoder_ctl(m_pSpeexDecStateIn, SPEEX_GET_FRAME_SIZE, 
&m_nDecodeFrameSize);



}

int  CSpeexCodec::Decode(const char* pcIndata, int nIndataSize, 
CShortCollection& dataOut)

{

  //

  speex_bits_read_from( &m_speexBitsIn, (char*)pcIndata, nIndataSize);

  static std::vector<float> floatDataOut;

  int nFrame = 0;

  size_t nbBytes = speex_bits_remaining(&m_speexBitsIn);

  while(nbBytes > 0 )

  {

      if( (nFrame+1) * m_nDecodeFrameSize > (int)floatDataOut.size( ) )

      {

          if( !floatDataOut.size( ) )

              floatDataOut.resize(m_nDecodeFrameSize );

          else
              floatDataOut.resize(floatDataOut.size( ) * 2 );

      }

      if ( speex_decode(m_pSpeexDecStateIn, &m_speexBitsIn, 
&floatDataOut[ nFrame++ * m_nDecodeFrameSize ] ) != 0 )

          break;

      nbBytes = speex_bits_remaining(&m_speexBitsIn);

  }

  // float -> short

  dataOut.resize( nFrame * m_nDecodeFrameSize );

  const float* pfSrc = &floatDataOut[0];

  short* phDst = &dataOut[0];

  size_t nOutSize = dataOut.size( );

  while(nOutSize-- ) { *phDst++ = (short)*pfSrc++; }



  return 0;



}

So speex_decode return -2 after 2-3 interation in my while loop
What is wrong ?
Thank for help




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20100610/4e09bf9e/attachment.htm 


More information about the Speex-dev mailing list