<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> </DIV>
<DIV>
<DIV>hi all,</DIV>
<DIV>I'm developing an app 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> </DIV>
<DIV>BOOL EncodeSpeex(CVoiceMsg *pMsg)<BR>{<BR> SpeexBits bits;<BR> <BR> void* enc_state;</DIV>
<DIV> </DIV>
<DIV> // Initialize.<BR> speex_bits_init(&bits);<BR> enc_state = speex_encoder_init(&speex_nb_mode);<BR> <BR> int frame_size = 0;<BR> // get frame size.<BR> speex_encoder_ctl(enc_state,SPEEX_GET_FRAME_SIZE,&frame_size);</DIV>
<DIV> </DIV>
<DIV> int nbBytes = 0;<BR> <BR> //unsigned char *input_frame,*encodedstr;<BR> unsigned char *encodedstr;<BR> float* input_frame;//approx of frame size</DIV>
<DIV> </DIV>
<DIV> input_frame = new float[frame_size];<BR> encodedstr = new unsigned char[MAX_FRAME_BYTES];<BR> <BR> ZeroMemory(input_frame,frame_size);<BR> ZeroMemory(encodedstr,MAX_FRAME_BYTES);<BR> <BR> int pos = 0;<BR> unsigned char*result;<BR> result = new unsigned char[pMsg->m_nBufferSize];<BR> ZeroMemory(result,pMsg->m_nBufferSize);<BR> <BR> int encoded_bytes =0;<BR> <BR> int complexity=4;<BR> int bitrate =3;<BR> speex_encoder_ctl(enc_state, SPEEX_SET_COMPLEXITY, &complexity);<BR> //speex_encoder_ctl(enc_state, SPEEX_SET_SAMPLING_RATE, &rate);</DIV>
<DIV> </DIV>
<DIV> speex_encoder_ctl(enc_state, SPEEX_SET_BITRATE, &bitrate);<BR> int tmp=1;<BR>// speex_encoder_ctl(enc_state, SPEEX_SET_VAD, &tmp);<BR> <BR> while(pos<pMsg->m_nBufferSize && encoded_bytes<pMsg->m_nBufferSize)<BR> {<BR> if((pMsg->m_nBufferSize-pos)>frame_size)<BR> {<BR> CopyMemory(input_frame,pMsg->m_pBuffer+pos,frame_size);<BR> pos += frame_size;<BR> }<BR> else<BR> {<BR> CopyMemory(input_frame,pMsg->m_pBuffer+pos,pMsg->m_nBufferSize-pos);<BR> pos+=(pMsg->m_nBufferSize-pos);<BR> }<BR> <BR> //encode input frame<BR> speex_bits_reset(&bits);<BR> <BR> speex_encode(enc_state,input_frame,&bits);<BR> nbBytes = speex_bits_write(&bits,(char*)encodedstr,MAX_FRAME_BYTES);<BR> <BR> unsigned char lenbytes[1];<BR> lenbytes[0]=nbBytes;</DIV>
<DIV> </DIV>
<DIV> CopyMemory(result+encoded_bytes ,lenbytes,1);<BR> encoded_bytes++;<BR> CopyMemory(result+encoded_bytes ,encodedstr,nbBytes);<BR> <BR> encoded_bytes+= nbBytes;<BR> <BR> }<BR> <BR> // save again to message buffer<BR> if(pMsg->m_pBuffer != NULL)<BR> {<BR> delete pMsg->m_pBuffer;<BR> pMsg->m_pBuffer = NULL;<BR> }</DIV>
<DIV> </DIV>
<DIV> pMsg->m_pBuffer = new UCHAR[encoded_bytes];<BR> CopyMemory(pMsg->m_pBuffer,result,encoded_bytes);<BR> <BR> pMsg->m_nBufferSize = encoded_bytes;<BR> <BR> // destroy and free resources...<BR> speex_bits_destroy(&bits);<BR> speex_encoder_destroy(enc_state);<BR> <BR> delete[] result;<BR> delete[] input_frame ;<BR> delete[] encodedstr;<BR> <BR> result = NULL;<BR> input_frame = NULL;<BR> encodedstr = NULL;</DIV>
<DIV> </DIV>
<DIV> return TRUE;<BR>} </DIV>
<DIV> </DIV>
<DIV>where pMsg->m_pBuffer is an UCHAR buffer containing recorded speech. and at the end of encode it contains the encoded bytes.</DIV>
<DIV> </DIV>
<DIV>BOOL DecodeSpeex(CVoiceMsg *pMsg)<BR>{<BR> SpeexBits bits;<BR> <BR> void* dec_state;</DIV>
<DIV> </DIV>
<DIV> // Initialize.<BR> speex_bits_init(&bits);<BR> dec_state = speex_decoder_init(&speex_nb_mode);<BR> <BR> int frame_size = 0;<BR> // get frame size.<BR> speex_decoder_ctl(dec_state,SPEEX_GET_FRAME_SIZE,&frame_size);</DIV>
<DIV> </DIV>
<DIV> int nbBytes = 0;<BR> <BR> unsigned char *input_frame;<BR> short *output_frame;</DIV>
<DIV> </DIV>
<DIV> input_frame = new unsigned char[frame_size];<BR> <BR> int enh = 1;<BR> speex_decoder_ctl(dec_state,SPEEX_SET_ENH,&enh);</DIV>
<DIV> </DIV>
<DIV> unsigned char*result;<BR> int scale=25;</DIV>
<DIV> </DIV>
<DIV> int size= max(pMsg->m_nBufferSize*scale,frame_size*scale*(pMsg->m_nBufferSize/frame_size)) + frame_size*scale;<BR> result = new unsigned char[size];<BR> ZeroMemory(result,size);</DIV>
<DIV> </DIV>
<DIV> output_frame = new short[frame_size];<BR> ZeroMemory(output_frame,frame_size);<BR> <BR> float* out_float;<BR> out_float = new float[frame_size];<BR> ZeroMemory(out_float,frame_size);<BR> <BR> int encoded_bytes =0;<BR> int pos=0;<BR> <BR> while(pos<pMsg->m_nBufferSize && encoded_bytes<size)<BR> {<BR> nbBytes = pMsg->m_pBuffer[pos];<BR> if(nbBytes>frame_size)<BR> nbBytes = frame_size;</DIV>
<DIV> </DIV>
<DIV> if((pMsg->m_nBufferSize-pos)<nbBytes)<BR> nbBytes = pMsg->m_nBufferSize-pos;<BR> <BR> pos++;// skip lenght byte.</DIV>
<DIV> </DIV>
<DIV> CopyMemory(input_frame,pMsg->m_pBuffer+pos,nbBytes);<BR> <BR> //encode input frame.<BR> speex_bits_read_from(&bits,(char*)input_frame,nbBytes);<BR> speex_decode(dec_state,&bits,out_float);<BR> //speex_decode_int(dec_state,&bits,output_frame);<BR> //output_frame =(short*) out_float;<BR> for(int i=0;i<frame_size;i++)<BR> output_frame[i] = out_float[i];<BR> pos += nbBytes;<BR> CopyMemory(result+encoded_bytes,output_frame,frame_size);<BR> encoded_bytes+= frame_size;</DIV>
<DIV> </DIV>
<DIV> }<BR> <BR> speex_bits_destroy(&bits);<BR> speex_decoder_destroy(dec_state);</DIV>
<DIV> </DIV>
<DIV> // save again to message buffer<BR> if(pMsg->m_pBuffer != NULL)<BR> {<BR> delete pMsg->m_pBuffer;<BR> pMsg->m_pBuffer = NULL;<BR> }</DIV>
<DIV> </DIV>
<DIV> <BR> pMsg->m_pBuffer = new UCHAR[encoded_bytes];<BR> CopyMemory(pMsg->m_pBuffer,result,encoded_bytes);<BR> <BR> pMsg->m_nBufferSize = encoded_bytes;<BR> pMsg->m_nSampleSize = pMsg->m_nBufferSize / 2;//wfx2.nBlockAlign;</DIV>
<DIV> </DIV>
<DIV> delete[] result;<BR> delete[] output_frame ;<BR> delete[] input_frame;</DIV>
<DIV> </DIV>
<DIV> result = NULL;<BR> input_frame = NULL;<BR> output_frame = NULL;</DIV>
<DIV> </DIV>
<DIV> return TRUE;</DIV>
<DIV>}</DIV></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><IMG id=INCREDI_SIGIMG src="cid:4E4E6A70-0D9A-4008-9B69-0FF0C1288C76"></DIV>
<DIV> </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> <B>FREE Emoticons for your email! </FONT><FONT face="Arial, Helvetica, sans-serif" size=2><U>Click Here!</U></B> </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>