[Speex-dev] converting 16-bit samples in LPSTR to short

Peter Gien peterg at podglo.com
Sat Sep 16 07:48:19 PDT 2006


Hi,

I am capturing 16 bit mono sound samples using some Win32 API function
calls. These function calls return the sound samples in an array of
characters. My assumption is that this array of characters represents pairs
of bytes that make up a short integer.

I'm using the following code to convert the samples:

LPTSTR *lpSaveBuffer;
......
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.

Thanks,
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20060916/1ce9e9cd/attachment.htm


More information about the Speex-dev mailing list