<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1256">
<META content="IncrediMail 1.0" name=GENERATOR>
<!--IncrdiXMLRemarkStart>
<IncrdiX-Info>
<X-FID>B2BD7C40-142F-43ED-B255-55F935D5A432</X-FID>
<X-FVER>4.0</X-FVER>
<X-FIT>Letter</X-FIT>
<X-FILE>Letter\floral_azure.imf</X-FILE>
<X-FCOL>Elegant Paper</X-FCOL>
<X-FCAT>Stationary</X-FCAT>
<X-FDIS>Floral Azure</X-FDIS>
<X-Extensions>SU1CTDEsNDYsgUmBSTCRMCidNImBTYWJkThNiZUsKE0wkY2NTY2NOMWVjSiNJImVkUmBSYFJgSxJTUJMMiwwLCxJTUJMMywwLCw=</X-Extensions>
<X-BG>CD5E6622-F810-46A1-A653-C233398DEB13</X-BG>
<X-BGT>repeat</X-BGT>
<X-BGC>#fafefd</X-BGC>
<X-BGPX>left</X-BGPX>
<X-BGPY>0px</X-BGPY>
<X-ASN>2D6C0820-4542-11D4-BA40-0050DAC68030</X-ASN>
<X-ASNF>0</X-ASNF>
<X-ASH>2D6C0820-4542-11D4-BA40-0050DAC68030</X-ASH>
<X-ASHF>1</X-ASHF>
<X-AN>6486DDE0-3EFD-11D4-BA3D-0050DAC68030</X-AN>
<X-ANF>0</X-ANF>
<X-AP>6486DDE0-3EFD-11D4-BA3D-0050DAC68030</X-AP>
<X-APF>1</X-APF>
<X-AD>C3C52140-4147-11D4-BA3D-0050DAC68030</X-AD>
<X-ADF>0</X-ADF>
<X-AUTO>X-ASN,X-ASH,X-AN,X-AP,X-AD</X-AUTO>
<X-CNT>;</X-CNT>
</IncrdiX-Info>
<IncrdiXMLRemarkEnd-->
</HEAD>
<BODY style="BACKGROUND-POSITION: left 0px; SCROLLBAR-FACE-COLOR: #c6d7ff; FONT-SIZE: 12pt; MARGIN: 0px 10px 10px 25px; SCROLLBAR-HIGHLIGHT-COLOR: #ffffff; SCROLLBAR-SHADOW-COLOR: #ffffff; COLOR: #3a3570; SCROLLBAR-3DLIGHT-COLOR: #7b9ed6; SCROLLBAR-ARROW-COLOR: #4a6184; BACKGROUND-REPEAT: repeat; FONT-FAMILY: Times New Roman; SCROLLBAR-DARKSHADOW-COLOR: #bebebe" text=#3a3570 bgColor=#fafefd background=cid:CD5E6622-F810-46A1-A653-C233398DEB13 scroll=yes SIGCOLOR="30975" ORGYPOS="0">
<TABLE id=INCREDIMAINTABLE cellSpacing=0 cellPadding=2 width="100%" border=0>
<TBODY>
<TR>
<TD id=INCREDITEXTREGION style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 12pt; PADDING-BOTTOM: 0px; CURSOR: auto; PADDING-TOP: 0px" vAlign=top width="100%">
<DIV>&nbsp;</DIV>
<DIV>&nbsp;
<DIV>hi all,</DIV>
<DIV>I'm developing an app&nbsp;to broadcast voice over web. i tried to use speex and download ver 1.04 documentation and use it to develop encoding and decoding but after decoding voice is damaged i attach my encode/decode function. </DIV>
<DIV>&nbsp;</DIV>
<DIV>BOOL EncodeSpeex(CVoiceMsg *pMsg)<BR>{<BR>&nbsp;SpeexBits bits;<BR>&nbsp;<BR>&nbsp;void* enc_state;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;// Initialize.<BR>&nbsp;speex_bits_init(&amp;bits);<BR>&nbsp;enc_state = speex_encoder_init(&amp;speex_nb_mode);<BR>&nbsp;<BR>&nbsp;int frame_size = 0;<BR>&nbsp;// get frame size.<BR>&nbsp;speex_encoder_ctl(enc_state,SPEEX_GET_FRAME_SIZE,&amp;frame_size);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;int nbBytes = 0;<BR>&nbsp;<BR>&nbsp;//unsigned char *input_frame,*encodedstr;<BR>&nbsp;unsigned char *encodedstr;<BR>&nbsp;float* input_frame;//approx of frame size</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;input_frame = new float[frame_size];<BR>&nbsp;encodedstr = new unsigned char[MAX_FRAME_BYTES];<BR>&nbsp;<BR>&nbsp;ZeroMemory(input_frame,frame_size);<BR>&nbsp;ZeroMemory(encodedstr,MAX_FRAME_BYTES);<BR>&nbsp;<BR>&nbsp;int pos = 0;<BR>&nbsp;unsigned char*result;<BR>&nbsp;result = new unsigned char[pMsg-&gt;m_nBufferSize];<BR>&nbsp;ZeroMemory(result,pMsg-&gt;m_nBufferSize);<BR>&nbsp;<BR>&nbsp;int encoded_bytes =0;<BR>&nbsp;<BR>&nbsp;int complexity=4;<BR>&nbsp;int bitrate =3;<BR>&nbsp;speex_encoder_ctl(enc_state, SPEEX_SET_COMPLEXITY, &amp;complexity);<BR>&nbsp;&nbsp;&nbsp; //speex_encoder_ctl(enc_state, SPEEX_SET_SAMPLING_RATE, &amp;rate);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;speex_encoder_ctl(enc_state, SPEEX_SET_BITRATE, &amp;bitrate);<BR>&nbsp;&nbsp;&nbsp; int tmp=1;<BR>//&nbsp;speex_encoder_ctl(enc_state, SPEEX_SET_VAD, &amp;tmp);<BR>&nbsp;&nbsp; <BR>&nbsp;while(pos&lt;pMsg-&gt;m_nBufferSize &amp;&amp; encoded_bytes&lt;pMsg-&gt;m_nBufferSize)<BR>&nbsp;{<BR>&nbsp;&nbsp;if((pMsg-&gt;m_nBufferSize-pos)&gt;frame_size)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;CopyMemory(input_frame,pMsg-&gt;m_pBuffer+pos,frame_size);<BR>&nbsp;&nbsp;&nbsp;pos += frame_size;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;else<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;CopyMemory(input_frame,pMsg-&gt;m_pBuffer+pos,pMsg-&gt;m_nBufferSize-pos);<BR>&nbsp;&nbsp;&nbsp;pos+=(pMsg-&gt;m_nBufferSize-pos);<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;//encode input frame<BR>&nbsp;&nbsp;speex_bits_reset(&amp;bits);<BR>&nbsp;<BR>&nbsp;&nbsp;speex_encode(enc_state,input_frame,&amp;bits);<BR>&nbsp;&nbsp;nbBytes = speex_bits_write(&amp;bits,(char*)encodedstr,MAX_FRAME_BYTES);<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;unsigned char lenbytes[1];<BR>&nbsp;&nbsp;lenbytes[0]=nbBytes;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;CopyMemory(result+encoded_bytes ,lenbytes,1);<BR>&nbsp;&nbsp;encoded_bytes++;<BR>&nbsp;&nbsp;CopyMemory(result+encoded_bytes ,encodedstr,nbBytes);<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;encoded_bytes+= nbBytes;<BR>&nbsp;&nbsp;<BR>&nbsp;}<BR>&nbsp;<BR>&nbsp;// save again to message buffer<BR>&nbsp;if(pMsg-&gt;m_pBuffer != NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;delete pMsg-&gt;m_pBuffer;<BR>&nbsp;&nbsp;pMsg-&gt;m_pBuffer = NULL;<BR>&nbsp;}</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;pMsg-&gt;m_pBuffer = new UCHAR[encoded_bytes];<BR>&nbsp;CopyMemory(pMsg-&gt;m_pBuffer,result,encoded_bytes);<BR>&nbsp;<BR>&nbsp;pMsg-&gt;m_nBufferSize = encoded_bytes;<BR>&nbsp;<BR>&nbsp;// destroy and free resources...<BR>&nbsp;speex_bits_destroy(&amp;bits);<BR>&nbsp;speex_encoder_destroy(enc_state);<BR>&nbsp;<BR>&nbsp;delete[] result;<BR>&nbsp;delete[] input_frame ;<BR>&nbsp;delete[] encodedstr;<BR>&nbsp;<BR>&nbsp;result&nbsp;&nbsp;= NULL;<BR>&nbsp;input_frame = NULL;<BR>&nbsp;encodedstr&nbsp; = NULL;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;return TRUE;<BR>}&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>where pMsg-&gt;m_pBuffer is an UCHAR buffer containing recorded speech. and at the end of encode it contains the encoded bytes.</DIV>
<DIV>&nbsp;</DIV>
<DIV>BOOL DecodeSpeex(CVoiceMsg *pMsg)<BR>{<BR>&nbsp;SpeexBits bits;<BR>&nbsp;<BR>&nbsp;void* dec_state;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;// Initialize.<BR>&nbsp;speex_bits_init(&amp;bits);<BR>&nbsp;dec_state = speex_decoder_init(&amp;speex_nb_mode);<BR>&nbsp;<BR>&nbsp;int frame_size = 0;<BR>&nbsp;// get frame size.<BR>&nbsp;speex_decoder_ctl(dec_state,SPEEX_GET_FRAME_SIZE,&amp;frame_size);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;int nbBytes = 0;<BR>&nbsp;<BR>&nbsp;unsigned char *input_frame;<BR>&nbsp;short *output_frame;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;input_frame = new unsigned char[frame_size];<BR>&nbsp;<BR>&nbsp;int enh = 1;<BR>&nbsp;speex_decoder_ctl(dec_state,SPEEX_SET_ENH,&amp;enh);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;unsigned char*result;<BR>&nbsp;int scale=25;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;int size= max(pMsg-&gt;m_nBufferSize*scale,frame_size*scale*(pMsg-&gt;m_nBufferSize/frame_size)) + frame_size*scale;<BR>&nbsp;result = new unsigned char[size];<BR>&nbsp;ZeroMemory(result,size);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;output_frame = new short[frame_size];<BR>&nbsp;ZeroMemory(output_frame,frame_size);<BR>&nbsp;<BR>&nbsp;float* out_float;<BR>&nbsp;out_float = new float[frame_size];<BR>&nbsp;ZeroMemory(out_float,frame_size);<BR>&nbsp;<BR>&nbsp;int encoded_bytes =0;<BR>&nbsp;int pos=0;<BR>&nbsp;<BR>&nbsp;while(pos&lt;pMsg-&gt;m_nBufferSize &amp;&amp; encoded_bytes&lt;size)<BR>&nbsp;{<BR>&nbsp;&nbsp;nbBytes = pMsg-&gt;m_pBuffer[pos];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(nbBytes&gt;frame_size)<BR>&nbsp;&nbsp;&nbsp;nbBytes = frame_size;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;if((pMsg-&gt;m_nBufferSize-pos)&lt;nbBytes)<BR>&nbsp;&nbsp;&nbsp;nbBytes = pMsg-&gt;m_nBufferSize-pos;<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;pos++;// skip lenght byte.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;CopyMemory(input_frame,pMsg-&gt;m_pBuffer+pos,nbBytes);<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;//encode input frame.<BR>&nbsp;&nbsp;speex_bits_read_from(&amp;bits,(char*)input_frame,nbBytes);<BR>&nbsp;&nbsp;speex_decode(dec_state,&amp;bits,out_float);<BR>&nbsp;&nbsp;//speex_decode_int(dec_state,&amp;bits,output_frame);<BR>&nbsp;&nbsp;//output_frame =(short*) out_float;<BR>&nbsp;&nbsp;for(int i=0;i&lt;frame_size;i++)<BR>&nbsp;&nbsp;&nbsp;output_frame[i] = out_float[i];<BR>&nbsp;&nbsp;pos += nbBytes;<BR>&nbsp;&nbsp;CopyMemory(result+encoded_bytes,output_frame,frame_size);<BR>&nbsp;&nbsp;encoded_bytes+= frame_size;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;}<BR>&nbsp;<BR>&nbsp;speex_bits_destroy(&amp;bits);<BR>&nbsp;speex_decoder_destroy(dec_state);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;// save again to message buffer<BR>&nbsp;if(pMsg-&gt;m_pBuffer != NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;delete pMsg-&gt;m_pBuffer;<BR>&nbsp;&nbsp;pMsg-&gt;m_pBuffer = NULL;<BR>&nbsp;}</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;<BR>&nbsp;pMsg-&gt;m_pBuffer = new UCHAR[encoded_bytes];<BR>&nbsp;CopyMemory(pMsg-&gt;m_pBuffer,result,encoded_bytes);<BR>&nbsp;<BR>&nbsp;pMsg-&gt;m_nBufferSize = encoded_bytes;<BR>&nbsp;pMsg-&gt;m_nSampleSize = pMsg-&gt;m_nBufferSize / 2;//wfx2.nBlockAlign;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;delete[] result;<BR>&nbsp;delete[] output_frame ;<BR>&nbsp;delete[] input_frame;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;result&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = NULL;<BR>&nbsp;input_frame&nbsp;&nbsp; = NULL;<BR>&nbsp;output_frame&nbsp; = NULL;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;return TRUE;</DIV>
<DIV>}</DIV></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><IMG id=INCREDI_SIGIMG src="cid:4E4E6A70-0D9A-4008-9B69-0FF0C1288C76"></DIV>
<DIV>&nbsp;</DIV></TD></TR>
<TR>
<TD id=INCREDIFOOTER width="100%">
<TABLE cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD width="100%"></TD>
<TD id=INCREDISOUND vAlign=bottom align=middle></TD>
<TD id=INCREDIANIM vAlign=bottom align=middle></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></BOD Body: Font: html MS Sans Serif <><SPAN id=IncrediStamp><SPAN dir=ltr><A title="Add FUN to your email - CLICK HERE!" style="TEXT-DECORATION: none" href="http://www.incredimail.com/index.asp?id=96316"><FONT style="COLOR: black" face="Arial, Helvetica, sans-serif" size=2>_____________________________________________________________________<BR>&nbsp;<B>FREE Emoticons for your email! </FONT><FONT face="Arial, Helvetica, sans-serif" size=2><U>Click Here!</U></B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT><BR><IMG hspace=0 src="http://www2.incredimail.com/contents/stamps/imstp_7_05_4.gif" align=baseline border=0></A></SPAN></SPAN></BODY></HTML>