[Speex-dev] converting 16-bit samples in LPSTR to short
John Miles
jmiles at pop.net
Sat Sep 16 09:35:53 PDT 2006
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.
Also, if this is a little-endian (Windows on x86?) machine, you're
reassembling the word backwards.
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.
-- john
for(j=0;j<nBytes;++J)
{
BYTE a = lpSaveBuffer[2*j]; // left byte
BYTE b = lpSaveBuffer[2*j + 1]; // right byte
short sample = (a << 8) | (b & 0xff);
}
I'm getting garbage as a result of this conversion. Any help would be
appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20060916/62c5e7a8/attachment.html
More information about the Speex-dev
mailing list