[Speex-dev] converting 16-bit samples in LPSTR to short
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.
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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Speex-dev