Andre Kirchner
2008-Nov-13 23:09 UTC
[Speex-dev] decoded sample is completely differen from original one
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; }
Jean-Marc Valin
2008-Nov-14 00:30 UTC
[Speex-dev] decoded sample is completely differen from original one
Hi, Please start with sampleenc.c/sampledec.c from the manual. Jean-Marc Andre Kirchner a ?crit :> 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; > } > > > > _______________________________________________ > Speex-dev mailing list > Speex-dev at xiph.org > http://lists.xiph.org/mailman/listinfo/speex-dev > >
Andre Kirchner
2008-Nov-14 19:16 UTC
[Speex-dev] decoded sample is completely differen from original one
Hi Jean_Marc, Thanks for the suggestion. But I still get the same results as before using sampleenc.c/sampledec.c. When sampleenc.c encodes the input frame bellow, it returns the encoded frame and nbBytes = 38. And sampledec.c returns the output frame when decoding it. Does it make any sense? If not, what should I look for in the Speex's documentation? Thanks, Andre Input frame: 3B6C 6169 6679 6776 3B62 6E63 356F 3879 766F 7938 7161 7275 396F 673B 7276 7920 3371 6F3B 7974 6238 7620 7131 6F33 793B 3B74 6663 716F 6832 7467 7168 3533 3B38 7438 3979 6862 7465 6F3B 6967 6875 6571 6F3B 7569 6772 7668 713B 6538 7469 3B79 6F62 7169 6532 6768 6E3B 696F 6875 3B65 6772 3B6C 6169 6679 6776 3B62 6E63 356F 3879 766F 7938 7161 7275 396F 673B 7276 7920 3371 6F3B 7974 6238 7620 7131 6F33 793B 3B74 6663 716F 6832 7467 7168 3533 3B38 7438 3979 6862 7465 6F3B 6967 6875 6571 6F3B 7569 6772 7668 713B 6538 7469 3B79 6F62 7169 6532 6768 6E3B 696F 6875 3B65 6772 3B6C 6169 6679 6776 3B62 6E63 356F 3879 766F 7938 7161 7275 396F 673B 7276 7920 3371 6F3B 7974 6238 7620 7131 6F33 793B 3B74 6663 716F 6832 7467 7168 3533 3B38 7438 3979 6862 7465 6F3B 6967 6875 6571 6F3B 7569 6772 7668 713B 6538 encoded frame: 2E 85 C2 38 FE 00 00 7F FF FF FF FF FF 8B A1 DC 91 B3 6C FF 3B 4E DD D8 71 F9 77 8D E6 2A 11 CD 7C C9 C5 26 B2 77 output frame: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 FFE6 FFF6 0012 0011 0002 FFE9 FFF2 000F 0011 0001 FFEC FFF8 000F 0013 0005 FFEE FFFB 0012 0013 0003 FFEB FFF8 0014 0012 0006 FFE4 FFEF 0014 0017 0000 FFE4 FFF4 000F 0013 0001 FFE3 FFF2 000D 000E 0002 1B13 254E 2014 1600 10A0 1055 072A FC5E 179D 14A6 10EA 158C CB4C FE28 05F7 076D C494 110F F5E1 E599 F5DA E9A7 E13D F641 B5D7 EA88 F81D F1D7 F8AC FC2D A54E E286 0532 F77A 18BB 196E FFAF 03FC F218 FC3D 0B0E 15A5 F37B FB91 0A43 FBC5 103C E0F0 FBC2 1B08 F652 FBA2 0A0C 0204 0084 E00C F4E9 EBC6 17A0 03C9 0974 E156 1ECB FA94 FF79 39FB 31D8 137D 1156 FAC8 193C 1E19 1BD2 E6A4 113A 24E8 06D7 1071 1144 F4C3 ----- Original Message ---- From: Jean-Marc Valin <jean-marc.valin at usherbrooke.ca> To: Andre Kirchner <supercroc1974 at yahoo.com> Cc: speex-dev at xiph.org Sent: Thursday, November 13, 2008 4:30:14 PM Subject: Re: [Speex-dev] decoded sample is completely differen from original one Hi, Please start with sampleenc.c/sampledec.c from the manual. Jean-Marc Andre Kirchner a ?crit :> 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; > } > > > > _______________________________________________ > Speex-dev mailing list > Speex-dev at xiph.org > http://lists.xiph.org/mailman/listinfo/speex-dev > >