[Speex-dev] How to convert from Microsft PCM 16bit to float
illiminable
ogg at illiminable.com
Tue Dec 28 02:06:08 PST 2004
Here's the gist of it... plucked from one of my directshow filters.
This assumes it's being passed an array of unsigned char (which are really
16-bit PCM)
It basically amounts to...
FOR EACH 16-bit short sample in ShortBuffer DO
floatBuffer[uptoSample] = ((float)(ShortBuffer[uptosample]) / 32767.0)
NEXT uptoSample
HRESULT SpeexEncodeInputPin::TransformData(unsigned char* inBuf, long
inNumBytes) {
//Note the 2 is because a float is twice the width of a short.
float* locFloatBuf = new float[inNumBytes/2];
short locTempShort = 0;
float locTempFloat = 0;
for (int i = 0; i < inNumBytes; i += 2) {
locTempShort = *((short*)(inBuf + i));
locTempFloat = (float)locTempShort;
locTempFloat /= 32767.0;
locFloatBuf[i/2] = locTempFloat;;
}
//ETC ETC ETC
}
----- Original Message -----
From: "Tay YueWeng" <yueweng at yahoo.com>
To: <speex-dev at xiph.org>
Sent: Tuesday, December 28, 2004 5:50 PM
Subject: [Speex-dev] How to convert from Microsft PCM 16bit to float
> Dear all,
>
> I have one simple question. I understand that
> speex_encode and speex_decode takes float * as an
> arguement to encode and decode the sound. However,
> when I get the PCM data from the sound card under
> win32, it is a just 16 bit array. May I know how do I
> convert this 16 bit value to speex float format and to
> convert back? Is there got any routine to do this?
>
> YueWeng
>
>
>
> __________________________________
> Do you Yahoo!?
> Read only the mail you want - Yahoo! Mail SpamGuard.
> http://promotions.yahoo.com/new_mail
> _______________________________________________
> Speex-dev mailing list
> Speex-dev at xiph.org
> http://lists.xiph.org/mailman/listinfo/speex-dev
>
>
>
More information about the Speex-dev
mailing list