Thank you John. I simply reversed the order of the bytes and that cleared up everything. But now that you mention it, it does look like I'm overshooting by a factor of two. I should rather do a loop that has j incrementing like this j+=2 and make the j loop run from 0 to nBytes/2. Thanks for the advice.
<br><br>
<div><span class="gmail_quote">On 9/16/06, <b class="gmail_sendername">John Miles</b> <<a href="mailto:jmiles@pop.net">jmiles@pop.net</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>
<div><span><font face="Arial" color="#0000ff" size="2">Is "nBytes" what it says -- the number of bytes in the buffer? If so, you're overshooting the buffer by 2x by multiplying by 2 in your array access. You probably want a variable called "nSamples" that represents the number of 16-bit words.
</font></span></div>
<div><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div><span><font face="Arial" color="#0000ff" size="2">Also, if this is a little-endian (Windows on x86?) machine, you're reassembling the word backwards.</font></span></div>
<div><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div><span><font face="Arial" color="#0000ff" size="2">Not to mention, shifting a BYTE left by 8 inside those parentheses is probably turning it into 0. If you actually need to swap the bytes, try casting to a short before shifting.
</font></span></div><span class="sg">
<div><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div><span><font face="Arial" color="#0000ff" size="2">-- john</font></span></div></span><span class="q">
<div><font face="Arial" color="#0000ff" size="2"></font><br>for(j=0;j<nBytes;++J) <br>{<br> BYTE a = lpSaveBuffer[2*j]; // left byte<br> BYTE b = lpSaveBuffer[2*j + 1]; // right byte <br> short sample = (a << 8) | (b & 0xff);
<br>}<br><br>I'm getting garbage as a result of this conversion. Any help would be appreciated.</div>
<blockquote dir="ltr" style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px"> </blockquote></span></div></blockquote></div><br>