It's lossy encoding.<br><br><div class="gmail_quote">On Mon, Mar 12, 2012 at 1:17 AM, Mashal al-shboul <span dir="ltr"><<a href="mailto:shboul8989@yahoo.com">shboul8989@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><div><div style="font-size:14pt;font-family:times new roman,new york,times,serif">
<div style="font-family:times new roman,new york,times,serif;font-size:14pt"><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div><div><div style="font-size:14pt;font-family:times new roman,new york,times,serif">
<div>Hi All,</div><div>i need your help in determining the problem in the following sample code (taken from speex manual) for fixed point encoding.</div><div>i tested encoding a 160 sample frame and then decoding it back But The problem is that the decoded frame is totally different from the original frame(see output below).What is the possible reason for this?.thanks for any help<br>
</div><div><br></div><div>#include<stdio.h><br>#include"intel16.h"<br>#include <speex/speex.h></div><div><br>#define FRAME_SIZE 160<br>#define MAX_NB_BYTES 25<br>SpeexBits bits;<br>void *enc_state;<br>
int quality=4; <br>int
nbBytes;<br>int byte_ptr;<br>int frame_size;<br>short frame[FRAME_SIZE]; <br>char outBuffer[20];<br><br>SpeexBits decBits;<br>void *dec_state;<br>short
decFrame[FRAME_SIZE];<br>/*===========END ===============================*/<br><br><br>int z=0;<br>int frame_size;<br><br><br>int main (int argc,char **argv)<br>{<br>for( z=0;z<160;z++)<br> {<br> frame[z]=intel_theme[z]; //array of short from "intel16" header file<br>
}<br> printf("\n =================================== \n");<br><br> for( z=0;z<160;z++)<br> {<br> printf("%i",frame[z]);<br> printf (" ");<br> }<br><br>/*===============================ENCODING==============================================*/<br>
<br> speex_bits_init(&bits);<br> enc_state = speex_encoder_init(&speex_nb_mode);<br>
speex_encoder_ctl(enc_state,SPEEX_GET_FRAME_SIZE,&frame_size);<br> speex_encoder_ctl(enc_state,SPEEX_SET_QUALITY,&quality);<br> speex_bits_reset(&bits);<br> <br>//-----------TWO CALLS FOR ENCODING-------------------<br>
speex_encode_int(enc_state, frame, &bits); // encoding from frame to &bits<br> nbBytes = speex_bits_write(&bits, outBuffer, MAX_NB_BYTES); //writing from &bits to outBuffer<br>//----------------------------------------------------<br>
<br> speex_bits_destroy(&bits);<br> speex_encoder_destroy(enc_state); <br><br>printf("\n outBuffer: ");<br>for(z=0;z<20;z++)<br>{<br>printf("%c",outBuffer[z]);<br>}<br>printf("\n
\n");<br>/*===============================END OF ENCODING=========================================*/<br><br><br>/*===============================DECODING==============================================*/<br><br>speex_bits_init(&decBits);<br>
dec_state=speex_decoder_init(&speex_nb_mode);<br>speex_decoder_ctl(dec_state, SPEEX_GET_FRAME_SIZE, &frame_size);<br><br>//-----------TWO CALLS FOR DECODING-------------------<br>speex_bits_read_from(&decBits,outBuffer,nbBytes);<br>
speex_decode_int(dec_state,&decBits,decFrame);<br>//----------------------------------------------------<br>printf("\n BUFFER DECODED BACK \n");<br><span style="font-weight:bold"></span></div><div><span style="font-weight:bold"><br>
</span></div><div><span style="font-weight:bold">for(z=0;z<160;z++)</span><br style="font-weight:bold"><span style="font-weight:bold">{</span><br style="font-weight:bold"><span style="font-weight:bold">printf("%i",decFrame[z]);</span><br style="font-weight:bold">
<span style="font-weight:bold">printf (" ");</span><br style="font-weight:bold"><span style="font-weight:bold">}</span><br style="font-weight:bold"><br>speex_bits_destroy(&decBits);<br>speex_decoder_destroy(dec_state);<br>
/*===============================END OF DECODING==============================================*/<br>printf("\n nbBytes: ");<br>printf("%i",nbBytes);<br>printf("\n frame_size= ");<br>printf("%i",frame_size);<br>
printf ("\n");<br>//-----------------<br>printf("end of run!");<br><br>return 0;<br>}</div><div><br></div><div><span style="font-weight:bold">OUTPUT:</span></div><div>//the original frame<br><span style="font-weight:bold"></span></div>
<div>1 -512 16384 512 -768 -2048 -1280 256 -1024 12288 0 8192 253 256 -768 12288 0 -16 -768
-512 -1 0 -512 -768 -1536 -512 -512 -768 16384 0 8192 -512 16384 512 -768 -2048 -1280 256 -1024 12288 0 8192 253 256 -768 12288 0 -16 -768 -512 -1 0 -512 -768 -1536 -512 -512 -768 16384 0 8192 -512 16384 512 -768 -2048 -1280 256 -1024 12288 0 8192 253 256 -768 12288 0 -16 -768 -512 -1 0 -512 -768 -1536 -512 -512 -768 16384 0 8192 -512 16384 512 -768 -2048 -1280 256 -1024 12288 0 8192 253 256 -768 12288 0 -16 -768 -512
-1 0 -512 -768 -1536 -512 -512 -768 16384 0 8192 -512 16384 512 -768 -2048 -1280 256 -1024 12288 0 8192 253 256 -768 12288 0 -16 -768 -512 -1 0 -512 -768 -1536 -512 -512 -768 16384 0 -1 0 -512 -768 -1536 -512 -512 -768 16384 -1 <br>
=================================== <br><br> outBuffer: �9�p�C��m�Cx6��<br> <br>//the decoded frame .totally different<br> BUFFER DECODED BACK <br>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2838 -3982 4801 -4136 432 -1945 610 1035 -1090 2752 -558 1431 -2320 -1016 789 5084 -2395 -2916 -225 -311 -703 586 1110 -557 -1152 1096 229 425 5825 -933 3922 -6289 7423 -6636 -793 -2123 -354 991 -1947 3958 -1070 1380 -2120 -2777 -679 9010 -2451 -4210 -1845 229 -1687
317 1443 -1355 -2818 214 721 -313 9997 -60 3489 -5953 9277 -6990 -2716 -1642 -792 477 -2417 5801 -1200 1055 -1744 -2927 -2053 10273 -1913 -4342 -2718 427 <br> nbBytes: 20<br> frame_size= 160<br>
<br><span style="font-weight:bold"></span></div><div><br><span style="font-weight:bold"></span></div><div><br><span style="font-weight:bold"></span></div><div><br><span style="font-weight:bold"></span></div><div><br><span style="font-weight:bold"></span></div>
<div><span style="font-weight:bold"></span></div></div></div></div><br><br> </div> </div> </div></div></div></div><br>_______________________________________________<br>
Speex-dev mailing list<br>
<a href="mailto:Speex-dev@xiph.org">Speex-dev@xiph.org</a><br>
<a href="http://lists.xiph.org/mailman/listinfo/speex-dev" target="_blank">http://lists.xiph.org/mailman/listinfo/speex-dev</a><br>
<br></blockquote></div><br>