<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7226.0">
<TITLE>Speex Windows from 1.1.6 source</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT SIZE=2 FACE="Arial">Hi All,</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">I am using Speex for encoding/decoding the audio stream for</FONT>
<BR><FONT SIZE=2 FACE="Arial">my streaming application. I have used almost the same code</FONT>
<BR><FONT SIZE=2 FACE="Arial">In the sampleenc.c and sampledec.c, except that I have used</FONT>
<BR><FONT SIZE=2 FACE="Arial">The buffers from the mic as input for encoder and encoded audio</FONT>
<BR><FONT SIZE=2 FACE="Arial">As input for decoder, instead of files input.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">My Problem is the audio played on the receiving side after decoding</FONT>
<BR><FONT SIZE=2 FACE="Arial">Is only a "hush" or it is pure noise. </FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Below is my code, that I have used for encoding and decoding. </FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> /************** Encode ******************/</FONT>
<BR><FONT SIZE=2 FACE="Arial"> speex_bits_reset(&Encbits);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> psInput = (short *)InputBuf;</FONT>
<BR><FONT SIZE=2 FACE="Arial"> iIndex = 80;</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> memset(OutputBuf,0,(200 * sizeof(float)));</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> /*Copy the 16 bits values to float so Speex can work on them*/</FONT>
<BR><FONT SIZE=2 FACE="Arial"> for (i=0;i<iIndex;i++){</FONT>
<BR><FONT SIZE=2 FACE="Arial"> /* float */pfEncBuf[i]=/* short */psInput[i]; </FONT>
<BR><FONT SIZE=2 FACE="Arial"> }</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> /*Encode the frame*/</FONT>
<BR><FONT SIZE=2 FACE="Arial"> speex_encode(encState,pfEncBuf, &Encbits);</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> memset(OutputBuf,0,outputSize);</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> /*Copy the bits to an array of char that can be written*/</FONT>
<BR><FONT SIZE=2 FACE="Arial"> iEncBytes = speex_bits_write(&Encbits, OutputBuf, outputSize);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> return iEncBytes;</FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial">/**************** Decode ******************/</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> /* Flush all the bits in the struct so we can code a new frame */</FONT>
<BR><FONT SIZE=2 FACE="Arial"> speex_bits_reset(&Decbits);</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> /* Copy the data into the bit-stream struct */</FONT>
<BR><FONT SIZE=2 FACE="Arial"> speex_bits_read_from(&Decbits, InputBuf, InputSize);</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> /* Get the Size of the Decoded Frame */</FONT>
<BR><FONT SIZE=2 FACE="Arial"> speex_decoder_ctl(decState, SPEEX_GET_FRAME_SIZE, &iDecBytes);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> if(iIndex > outputSize)</FONT>
<BR> <FONT SIZE=2 FACE="Arial">return -1;</FONT>
<BR><FONT SIZE=2 FACE="Arial"> iIndex = iDecBytes/sizeof(short);</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> /* Allocate the Decode Frame */</FONT>
<BR><FONT SIZE=2 FACE="Arial"> memset(pfDecBuf,0,sizeof(200 * sizeof(float)));</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> /* Decode the data */</FONT>
<BR><FONT SIZE=2 FACE="Arial"> speex_decode(decState, &Decbits, pfDecBuf);</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> memset(OutputBuf,0,outputSize);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> psOutput = (short *)OutputBuf;</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> /* Copy from float to short (16 bits) for output */</FONT>
<BR><FONT SIZE=2 FACE="Arial"> for (i=0;i<iIndex;i++)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> psOutput[i]=(short) pfDecBuf[i];</FONT>
<BR><FONT SIZE=2 FACE="Arial"> return iDecBytes;</FONT>
</P>
<BR>
<P><FONT SIZE=2 FACE="Arial">I tried encoding, decoding and playing on the</FONT>
<BR><FONT SIZE=2 FACE="Arial">Same , the results are the same. I am not sure</FONT>
<BR><FONT SIZE=2 FACE="Arial">If I am missing something here.Any Light on this is </FONT>
<BR><FONT SIZE=2 FACE="Arial">much appreciated.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Thanx,</FONT>
<BR><FONT SIZE=2 FACE="Arial">Palani.<I></I></FONT><I></I><I></I>
</P>
</BODY>
</HTML>