• 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: Jeff Moore <email@hidden>
  • Date: Fri, 22 Jun 2001 14:08:09 -0700

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


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

  • Prev by Date: Converting from INT to Float samples
  • Next by Date: Attaching audio driver to another driver.
  • Previous by thread: Converting from INT to Float samples
  • Next by thread: Re: Converting from INT to Float samples
  • Index(es):
    • Date
    • Thread