• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Converting from INT to Float samples
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting from INT to Float samples


  • Subject: Re: Converting from INT to Float samples
  • From: Bill Stewart <email@hidden>
  • Date: Sat, 23 Jun 2001 13:53:54 -0700

I think the confusion is about the format of the input device's samples.

They will also be Float32 - so when you pass them straight back to the
output device they sound fine. Correct?

This is the comment that bothers me:
>> 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.
To have these samples in an SINT16 array you'd have to have converted them
from the input format of floats (that the HAL publishes) to ints...

The DefaultOutputUnit just passes on the AudioBuffer from the HAL device to
your app. So if you took your input samples from the in device and give them
as is, to the buffer of the output unit, they should sound just fine.

Bill


on 22/6/01 3:57 PM, email@hidden wrote:
> 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
> _______________________________________________
> coreaudio-api mailing list
> email@hidden
> http://www.lists.apple.com/mailman/listinfo/coreaudio-api


mailto:email@hidden
tel: +1 408 974 4056
__________________________________________________________________________
Cat: "Leave me alone, I'm trying to nap... Ah, What's that clicking noise?"
__________________________________________________________________________


References: 
 >Re: Converting from INT to Float samples (From: email@hidden)

  • Prev by Date: Re: Using AudioUnit instead of AudioDevice
  • Next by Date: Audio capture using java JMF or CoreAudio or QuickTime on OS X
  • Previous by thread: Re: Converting from INT to Float samples
  • Next by thread: Re: Converting from INT to Float samples
  • Index(es):
    • Date
    • Thread