[Speex-dev] Encode/Decode problem

James Stanton jstanton at clairvista.com
Fri Aug 12 08:05:14 PDT 2005


I'm trying to use the speex API, and I think I'm missing something.  I'm 
running on Mac OSX Tiger, and the attached microphone is a iSight.  If I 
call the "speex_encode_int" function, and then immediately call the 
"speex_decode_int" function, shouldn't I get back the same data?  i.e. 
in my example code, shouldn't the two arrays contain at least similar 
data?  The data I'm seeing is drastically different.  If so, is the 
encoding data sensitive?  If my data being fed in is wrong, will the 
encoding and decoding not work correctly?    Any help would be greatly 
appriciated.

Thanks!

Jamie Stanton
jstanton at clairvista.com

I've got the following code:

static void testAudio(UInt8 *data, long dataLength)
{
//data is a linear PCM stream from an attached microphone.  sample rate 
is 8000, 16 bits per sample
void *state;
void *state2;
SpeexBits bits;
short tempShort;
short tempPtr[160];
short tempPtrDecode[160];
state = speex_encoder_init(&speex_nb_mode);
state2 = speex_decoder_init(&speex_nb_mode);
speex_bits_init(&bits);
//code simplified to just read in the first frame
for (int i = 0; i < 320; i +=2)
{
    tempShort = *((short*)(data + i));
    tempPtr[i / 2] = tempShort;
}
speex_bits_reset(&bits);
speex_encode_int(state, tempPtr, &bits);
speex_bits_rewind(&bits);
speex_decode_int(state2, &bits, tempPtrDecode);
//tempPtr != tempPtrDecode, it's not even close.
}




More information about the Speex-dev mailing list