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

Jonas Tärnström njt at
Sat Sep 16 11:52:40 PDT 2006

What kind of crazy old Win32 API is that?
I’ve used DirectSound and WinMM and never needed to do something like
what you are doing.
AFAIK, all existing Win32 APIs for capturing sound returns buffers of
16-bit PCM data, assuming PCM was specified as buffer format.

-----Ursprungligt meddelande-----
Från: speex-dev-bounces at [mailto:speex-dev-bounces at] För
Peter Gien
Skickat: den 16 september 2006 16:48
Till: speex-dev
Ämne: [Speex-dev] converting 16-bit samples in LPSTR to short

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;
     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 mailing list