[Speex-dev] decoded sample is completely differen from original one
Andre Kirchner
supercroc1974 at yahoo.com
Thu Nov 13 15:09:22 PST 2008
Hi all,
I have just started playing with speex, and come up with the following code, which just encode a frame of 160 shorts, and the decode it.
For some reason the decoded sample is completely different than the original one. is my code wrong? If so what? Or is it a reasonable which depends of values that weren't correctly set?
Thanks,
Andre
#include <stdio.h>
#include <tchar.h>
#include <speex/speex.h>
#define FRAME_SIZE 160
#define QUALITY 8
#define ENHANCEMENT 1
int encode(int * nbBytes, char * encSamples)
{
void * state;
SpeexBits bits;
int quality = QUALITY;
spx_int16_t input[] = {0x703B, 0x7361, 0x7567, 0x3969, 0x6874, 0x3B76, 0x3020, 0x3534,
0x3871, 0x7967, 0x3B75, 0x6C6F, 0x7261, 0x7965, 0x2038, 0x3B67,
0x7639, 0x3238, 0x3634, 0x6879, 0x3B20, 0x6F74, 0x6C69, 0x7276,
0x7771, 0x6564, 0x6E76, 0x6B2C, 0x206A, 0x6168, 0x6662, 0x763B,
0x6F2E, 0x7569, 0x7720, 0x7134, 0x2736, 0x3079, 0x3239, 0x5D75,
0x6D20, 0x5B79, 0x7530, 0x3160, 0x7120, 0x2765, 0x3974, 0x7570,
0x6867, 0x5B62, 0x3032, 0x3834, 0x7579, 0x5B67, 0x6F27, 0x7169,
0x6733, 0x6879, 0x633B, 0x696F, 0x7175, 0x6576, 0x2772, 0x3039,
0x6A62, 0x3471, 0x5D74, 0x2D67, 0x7539, 0x7168, 0x656D, 0x3527,
0x6967, 0x3930, 0x6A68, 0x626D, 0x7227, 0x6577, 0x7030, 0x6879,
0x276D, 0x725B, 0x3577, 0x2069, 0x2762, 0x696F, 0x7765, 0x7468,
0x766A, 0x3067, 0x3927, 0x3477, 0x7579, 0x7027, 0x7769, 0x6562,
0x276A, 0x6C67, 0x766B, 0x6E63, 0x716A, 0x6576, 0x3B6C, 0x6F69,
0x6772, 0x3B68, 0x5B77, 0x3470, 0x6733, 0x6A68, 0x7170, 0x6F6B,
0x6A67, 0x6E66, 0x3B63, 0x276D, 0x6F20, 0x716C, 0x6869, 0x3874,
0x3979, 0x7220, 0x7663, 0x6874, 0x716A, 0x6570, 0x7775, 0x6A72,
0x7666, 0x3063, 0x7139, 0x772D, 0x7533, 0x7974, 0x696F, 0x2770,
0x6372, 0x6B67, 0x6577, 0x2762, 0x6F34, 0x6220, 0x345D, 0x7730,
0x3638, 0x7935, 0x7475, 0x5B63, 0x306E, 0x3371, 0x7738, 0x7432,
0x5B79, 0x676E, 0x665D, 0x6376, 0x696F, 0x6830, 0x6577, 0x6D74};
state = speex_encoder_init(speex_lib_get_mode(SPEEX_MODEID_NB));
speex_encoder_ctl(state, SPEEX_SET_QUALITY, &quality);
speex_bits_init(&bits);
speex_bits_reset(&bits);
speex_encode_int(state, &input[0], &bits);
speex_bits_insert_terminator(&bits);
* nbBytes = speex_bits_write(&bits, encSamples, FRAME_SIZE);
speex_encoder_destroy(state);
speex_bits_destroy(&bits);
return 0;
}
int decode(int nbBytes, char * encSamples)
{
spx_int16_t output[FRAME_SIZE];
void * state;
SpeexBits bits;
int enhancement = ENHANCEMENT;
state = speex_decoder_init(speex_lib_get_mode(SPEEX_MODEID_NB));
speex_decoder_ctl(state, SPEEX_SET_ENH, &enhancement);
speex_bits_init(&bits);
speex_bits_read_from(&bits, encSamples, nbBytes);
speex_decode_int(state, &bits, output);
for(int i = 0; i < FRAME_SIZE; i++)
{
printf(" %04X", (short)output[i] & 0xFFFF);
if((i + 1) % 8 == 0)
{
printf("\n");
}
}
speex_decoder_destroy(state);
speex_bits_destroy(&bits);
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
int nbBytes;
char encSamples[FRAME_SIZE];
encode(&nbBytes, encSamples);
decode(nbBytes, encSamples);
return 0;
}
More information about the Speex-dev
mailing list