[Speex-dev] converting 16-bit samples in LPSTR to short
Peter Gien
peterg at podglo.com
Sat Sep 23 10:53:27 PDT 2006
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.
On 9/16/06, John Miles <jmiles at pop.net> wrote:
>
> 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/20060923/2159dd39/attachment.htm
More information about the Speex-dev
mailing list