Re: Converting from INT to Float samples
Re: Converting from INT to Float samples
- Subject: Re: Converting from INT to Float samples
- From: email@hidden
- Date: Fri, 22 Jun 2001 15:57:23 -0700
Hi Jeff,
I just get junk when I play it back. I'm not entirely sure i understand
why. If I use "AudioDevice" to record/playback the sound there is no
problem at all -- I hear what I record..
(In this case I have 2 IOAudioProc. IOAudioProcIn, IOAudioProcOut.) I
just take the input of one proc, and drop it into the output of the other
Proc AS-IS. Everything sounds great.
Now eventually I want to get an SRC in there, so I convert the playback
IOAudioProc to use an "AudioUnit" instead.
Now, I open the output device a little differently, and have an
audiorenderer, "MyAudioRenderer", that fills in the data to the AudioUnit.
When I do this, and try to playback the sound, the recorded sound is no
longer recognizable. It's just a bunch of static (??). I figured it was
because the AudioUnit required float data, since the sample code I had was
generating a SIN table with float data. But, when I convert my Sint16
data with the algorithm found below, all I get is bursts of White noise...
Any ideas,
Thanks
Jeff Moore
<email@hidden> To: CoreAudio API <email@hidden>
Sent by: cc:
coreaudio-api-admin@lists Subject: Re: Converting from INT to Float samples
.apple.com
06/22/01 02:08 PM
on 6/22/01 1:36 PM, email@hidden
<email@hidden> wrote:
>
Ok, so now I have my AudioUnit playing properly. However, I'm having
>
trouble with the conversion of Sint to float.
>
>
I am trying to "Record" some data from an AudioDevice -- Which ends up in
>
an SINT16 formatted array. If I play back this array using AudioDevice
>
everything sounds OK.
>
>
BUT, if I try to feed this out to the AudioUnit, it sounds quite bad. I
>
assume this is because AudioUnit requires float samples over Sint. I'm
not
>
exactly sure how to do this. I tried to copy an Int-to-float routine
from
>
a sample driver:
>
>
if (integer >=0 {
>
floatSample = integer / 32767.0;
>
} else {
>
floatSample = integer / 32768.0;
>
}
>
That algorithm is needlessly slow. The algorithm is more or less like the
one you are using except it doesn't use an division.
Here's a routine to do it in C++:
inline Float32 SInt16ToFloat32(Sint16 inValue)
{
static const Float32 kSInt16ToFloatScalar = 1.0 / 32768.0;
return static_cast<Float32>(inValue) * kSInt16ToFloatScalar;
}
Here's a C macro (be careful about expressions with it!):
#define kSInt16ToFloatScalar (1.0 / 32768.0)
#define SInt16ToFloat32(v) (((Float32)(v)) * kSInt16ToFloatScalar)
>
However, this sounds bad too. Any ideas?
What do yo mean by "sounds bad"? That algorithm should result in reasonable
sounding float samples.
--
Jeff Moore
Core Audio
Apple
_______________________________________________
coreaudio-api mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/coreaudio-api