Hi,<br><br>I am facing a problem with my Voice Communication application. I am using the Speex API, and have based my application on the given example files sampleenc.c and sampledec.c. I'm using the OpenAL SDK for voice capture. I have provided below the two main functions within which the problem exists. &quot;Compress()&quot; and &quot;Decompress()&quot;. Below the code for these functions, I have written the while loop in 
main.cpp. When I comment out the calls to Compress and Decompress, I am able to instantly hear the playback of my own recorded voice. However, when I uncomment the calls, I am unable to hear my voice, and instead I get some other garbage noise.
<br><br>The basic dynamics of the program are slightly different from normal such applications, in that instead of reading a file at once, I am attempting to read a frame, and compress, then uncompress, and then playback that frame before I move on to the next frame. 
<br><br>While initializing the device for reading the sound information, I give it the following parameters:<br><br>22050 (which is the frequency with which to take sound samples)<br>AL_FORMAT_MONO16 (which is the OpenAL format in use)
<br>BUFFERSIZE (which is 1024, the size of the frames which I read)<br><br>As for the arguments for &quot;Compress()&quot;, pData is the ALchar pointer which contains the data. iFrameSize is the integer which will store the number of bytes actually written to the compressed frame. cComeFrame is the character array which eventually stores the compressed voice data.
<br><p class="MsoNormal">As for the arguments for &quot;Decompress()&quot;,
pDecomData is the ALchar pointer
which will store the decompressed voice data. iFrameSize is the integer which provides the actual number of bytes written to the compressed frame. cComeFrame is the
character array which provides the compressed voice data as input for
this function.</p><p class="MsoNormal"><br></p>


<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">void</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> OALCapture::Compress(ALchar* pData, 
<span style="color: blue;">int</span> *iFrameSize, <span style="color: blue;">char</span>*
cComFrame)</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">{</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>speex_bits_init(&amp;m_oBits);</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">int</span> i;</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">/*Flush all the
bits in the struct so we can encode a new frame*/</span></span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>speex_bits_reset(&amp;m_oBits);</span></p><p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">
<span style=""></span><span style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Copy the data from ALchar array to a float array */</span></span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">for</span>(i =
0; i &lt; BUFFERSIZE; ++i)</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>input[i] = pData[i];</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: green;">&nbsp;</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">/*Encode the
frame*/</span></span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>speex_encode(m_poSpeexCompressState,
input, &amp;m_oBits);</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">/*Copy the bits
to an array of char that can be written*/</span></span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>nbBytes = speex_bits_write(&amp;m_oBits,
cbits, BUFFERSIZE);</span></p><p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>strcpy(cComFrame, cbits);</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;  </span></span></p>

<p class="MsoNormal"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">}</span></p><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">void</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">
 OALCapture::Decompress(ALchar* pDecomData, <span style="color: blue;">int</span> iFrameSize, <span style="color: blue;">char</span>*
cComFrame)</span>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">{</span></p><p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>speex_bits_init(&amp;m_oDecompressBits);</span></p><p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">int
</span> i;</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">///*Copy the
data into the bit-stream struct*/</span></span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>speex_bits_read_from(&amp;m_oDecompressBits,
cComFrame, iFrameSize);</span></p>



<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">/*Decode the
data*/</span></span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>speex_decode(m_poSpeexDecompressState,
&amp;m_oDecompressBits, output);</span></p>



<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">/*Copy from
float to short (16 bits) for output*/</span></span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">for</span> (i =
0; i &lt; BUFFERSIZE; i++)</span></p>



<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>out[i] = output[i];</span><br><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: green;">
&nbsp;</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>strcpy(pDecomData, out);</span></p><p class="MsoNormal"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">
}</span></p>



<p class="MsoNormal"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;</span><br><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; font-weight: bold; text-decoration: underline;">main.cpp
</span><span style="font-size: 11pt;"></span></p>

<p class="MsoNormal"><span style="font-size: 11pt;">&nbsp;</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">while</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> (!_kbhit() )</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">{</span></p><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">
 (
g_oCapture.CaptureSamples(g_ArrBuffer, (BUFFERSIZE / <span style="">&nbsp;</span><span style=""></span>g_sWaveHeader.wfex.nBlockAlign)
) )</span>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">int</span>
iFrameSize = 0;</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">char</span>
cComFrame[200];</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ALchar ArrTemp[BUFFERSIZE];</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>g_oCapture.Compress(g_ArrBuffer,
&amp;iFrameSize, cComFrame );<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>g_oCapture.Decompress(ArrTemp,
iFrameSize, cComFrame);</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&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; </span></span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>g_oCapture.ProcessBuffers(g_uiSourceID);</span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>g_oCapture.QueueBuffer(g_uiSourceID,
ArrTemp, BUFFERSIZE );</span></p>





<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>g_oCapture.PlayStream(g_uiSourceID);<br><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">
</span></span></p>

<p class="MsoNormal" style=""><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>

<p class="MsoNormal"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">}</span><span style="font-size: 10pt;"></span></p>

<br>