RE: Native Device Formats
RE: Native Device Formats
- Subject: RE: Native Device Formats
- From: "Richard Furse" <email@hidden>
- Date: Sun, 8 Jun 2008 16:15:38 +0100
What a marvellous old can of worms... :-)
Quite a lot of systems handle the float<->int mapping this way. It provides
a nice simple mapping between the integer form and the mantissa of the
float. The fact that +1 clips is a horror, but it's the only one - and IMHO
probably better than some of the things that start happening when the other
mapping is used:
The main problems have to do with zeros and mixing different bit depths. For
instance, if we map an 8bit range [-128,127] to [-1.0,1.0] linearly, i.e. by
f(x)=(x+128)/255*2-1, then we immediately find ourselves mapping 8bit 0 to
float 0.003922. Which means you can mix two "silent" signals together in
float space and, depending on how the gain varies, end up with a decidedly
non-silent signal.
The other problem is that this type of mapping changes with bit depth. If we
map a 16bit range from [-32768,32767] to [-1.0,1.0], we would use
g(x)=(x+32768)/65535*2-1, which isn't the same as the function f(x) above.
Assuming we're reading a 16bit file, processing using floats and then
writing out in 8bits, we end up with a mapping that is NOT the same as the
(correct!) approach of just dropping the 8 least significant bits in integer
space. The exact manifestation of the problem here depends on rounding
conventions in the 8bit conversion, but basically we're stuffed.
Horrible - better to put up with the occasional clipping!
Best wishes,
--Richard
PS the remaining scheme is of course to only use the [-32767,+32767] and
[-127,+127] ranges and ban -32768 and -128 etc. Let's just not go there ;-)
> -----Original Message-----
> From:
> coreaudio-api-bounces+rf015d9821=email@hidden.
com [mailto:coreaudio-api-bounces+rf015d9821>
=email@hidden] On Behalf Of Mikael Hakman
> Sent: 08 June 2008 16:22
> To: Jeff Moore; CoreAudio API
> Subject: Re: Native Device Formats
>
> Many thanks Jeff!
>
> AudioConverter tells me that in order to get the lowest 24-bit value
> (0x800000) I have to use -1.0 Float32 value (0xbf800000). In
> order to get highest 24-bit value (0x7fffff) I have to use
> 0.99999988 Float32 value (0x3f7ffffe). This means that FS
> amplitude when using Float32 is 0.99999944 (0x3f7fffff), not 1.0.
>
> This may have some significance when e.g. generating FS
> precision test signals as in:
>
> s = 0.99999944 * (sin (2 * PI * f * t) + 1.0) - 1.0
>
> Omitting the scaling as in:
>
> s = sin (2 * PI * f * t)
>
> would result in a slight clipping on the positive side.
>
> Could you please give some explanation why we are using this
> mapping as compared to (more intuitive) mapping of [-1.0,
> 1.0] to [0x800000, 0x7fffff] which would allow using sin()
> function results directly as input to CoreAudio?
>
> Regards/Mikael
>
> On Friday, June 06, 2008 8:27 PM, Jeff Moore wrote:
>
>
> >A 32 bit floating point number can losslessly encode a 24
> bit integer
> >sample. That's why we use it. So, as long as you are doing the
> >conversion from 24 bit int to 32 bit float properly, it will
> come out
> >of the 24 bit hardware properly.
> >
> > The easiest way to do the conversion correctly is to use an
> > AudioConverter or an AudioConverter-derived API like AUHAL or
> > ExtendedAudioFile.
> >
> > On Jun 6, 2008, at 5:41 AM, Mikael Hakman wrote:
> >
> >> Then the following question arises:
> >>
> >> Starting with 24-bits signed integer values, how do I
> output them to
> >> a digital audio interface, so that the values appearing on the
> >> digital wire (S/PDIF) are exactly the same as those I have
> in my application?
> >> Consider a simple setup consisting of connecting MBP built-in
> >> digital output to its digital input. My application needs
> to output
> >> 24-bits signed integer values in such a way that the very same
> >> values are obtained on digital input. How do I do this?
> >>
> >> On Thursday, June 05, 2008 8:16 PM, Jeff Moore wrote:
> >>
> >>
> >>> ... But there is also conversion going on because we feed the
> >>> driver floating point samples which then have to be
> converted to
> >>> the appropriate integer format.
> >
> >
> >
> > --
> >
> > Jeff Moore
> > Core Audio
> > Apple
> >
> >
> > _______________________________________________
> > Do not post admin requests to the list. They will be ignored.
> > Coreaudio-api mailing list (email@hidden)
> > Help/Unsubscribe/Update your Subscription:
> >
> > t
> >
> > This email sent to email@hidden
> >
> > __________ NOD32 3165 (20080606) Information __________
> >
> > Detta meddelande är genomsökt av NOD32 Antivirus.
> > http://www.nod32.com
> >
> >
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Coreaudio-api mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
email@hidden
>
> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden