I'm using speex to encode some audio data and send it over UDP, and decode it on the other side. I ran a few tests with speex, and noticed that if I decode a packet straight after I encoded it, the decoded data is in no way close to the original data. Most of the bytes at the start of the buffer are 0. So when I decode the audio sent over UDP, all I get is noise. This is how I am encoding the audio:
bool AudioEncoder::encode( float *raw, char *encoded_bits )
{
for ( size_t i = 0; i < 256; i++ )
this->_rfdata[i] = raw[i];
speex_bits_reset(&this->_bits);
speex_encode(this->_state, this->_rfdata, &this->_bits);
int bytesWritten = speex_bits_write(&this->_bits, encoded_bits, 512);
if (bytesWritten)
return true;
return false;
}
this is how I am decoding the audio:
float *f = new float[256];
// recvbuf is the buffer I pass to my recv function on the socket
speex_bits_read_from(&this->_bits, recvbuf, 512);
speex_decode(this->state, &this->_bits, f);
I've check out the docs, and most of my code comes from the example encoding/decoding sample from the speex website. I'm not sure what I'm missing here.