[Speex-dev] Decoding producing garbled sound
Vinod Vijayan
vinod at speechdesk.com
Tue Jan 11 04:37:45 PST 2005
Hi,
I am back. Thanks everybody for their suggestions.
Finally I could get something out of the decoder that
makes sense. But the problem is it is highly noisy and the
voice is not very clear. Normally without using the codec I
get good audible sound through the Microphone.
I'm using Speex version 1.1.6. I've also used 1.0.4 beforehand
and experienced the same problem with it.
1. I record my audio at mono 8000Hz, 16bits per sample.
2. I encode frame-sized (320 bytes) fragments.
char *encode(char *buffer, int &encodeSize)
{
char *encodedBuffer = new char[160];
short speexShort;
float *speexFloat = new float[160];
// Convert the audio to a short then to a float buffer
for (int i = 0; i < 160; i++)
{
memcpy(&speexShort, &buffer[i*2], sizeof(short));
speexFloat[i] = speexShort;
}
// Encode the sound data using the float buffer
speex_bits_init(&mBits);
speex_bits_reset(&mBits);
speex_encode(mEncode, speexFloat, &mBits);
encodeSize = speex_bits_write(&mBits, encodedBuffer, 160);
delete[] speexFloat;
speexFloat = 0;
// Return the encoded buffer
return encodedBuffer;
}
3.I immediately decode the encoded buffer. Encoded size is always 38 bytes
for this sample set and expected decoded size is 320 bytes
char *CRecNplayDlg::decode(char *buffer, int encodeSize)
{
char *decodedBuffer = new char[320];
void *mDecode = speex_decoder_init(&speex_nb_mode);
short speexShort;
float *speexFloat = new float[160];
// Decode the sound data into a float buffer
speex_bits_init(&dBits);
speex_bits_reset(&dBits);
speex_bits_read_from(&dBits, buffer, encodeSize);
speex_decode(mDecode, &dBits, speexFloat);
// Convert from float to short to char
for (int i = 0, j=0; i < 160; i++, j++)
{
speexShort = speexFloat[i];
memcpy(&decodedBuffer[j*2], &speexShort, sizeof(short));
}
delete[] speexFloat;
// Return the buffer
return decodedBuffer;
}
I have tried every way possible but it isn't helping so I had no option
but to post my problem. I tried debugging the speexenc and speexdec
projects but it was of no help. Now what happens is this :-
Encoding side
char[320] -> float[160] >>encoding>> char[38]
Decoding side
char[38] >>decoding>> float[160] -> char[320]
If the above looks fine then where am i going wrong. Plz can anybody
who faced the same problem as mine help. Thanks.
More information about the Speex-dev
mailing list