• 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: 8.24-bit Fixed point Math
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 8.24-bit Fixed point Math


  • Subject: Re: 8.24-bit Fixed point Math
  • From: Mark's Studio <email@hidden>
  • Date: Sat, 8 Nov 2008 20:22:03 +0100

Thanks that make sense,
but what about negative float numbers ?


SInt32 x = (SInt32)((Float32)(1<<24)*0.123f)

16777216 * 0.123 = 2063597,568 cast to SInt32, so x = 2063597


1.0 / (Float32)((Float32)(1<<24) / (Float32) 2063597) and if i convert it back i get 0,122999958813193


On 08/11/2008, at 17.34, David Duncan wrote:

On Nov 8, 2008, at 2:28 AM, Mark's Studio wrote:

I am porting an AU to the iPhone,
and since the canonical format is 8.24 on the device,
i thought it might be better to do the processing in that format.


I presume you mean as a part of your application...

Fixed point math is reasonably simple, you just have to know a few details to get it right.

Addition and subtraction are the same as always (8.24 + 8.24 => 8.24). The only thing you have to worry about is standard integer overflow.

Multiplication is a little complicated however, as you get a double precision result (8.24 * 8.24 => 16.48). Thus you need to worry about both clipping and you have to shift back by the number of fractional bits (i.e. right shift by 24 after the multiplication.

Division is the opposite problem, as you divide away all the fractional bits, so you need to shift back again. Division tends to be rare in performance code anyway, but a left shift by 24 after a division gets you more or less what you need.

For most other operations you can just treat it like the underlying operation. Conversion from Int to Fixed (and back) are just bit shifts, and conversion to/from Float is multiplication/division by the shift value (1<<24 in this case).
--
Reality is what, when you stop believing in it, doesn't go away.
Failure is not an option. It is a privilege reserved for those who try.


David Duncan


Peter Mark

Mark's Recording Studio A/S
Lundeskovsvej 3
2900 Hellerup
Denmark
Tel: +45 35366078
Fax: +45 35366038
Mobile: +45 20416018
www.marks-studio.dk
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


  • Follow-Ups:
    • Re: 8.24-bit Fixed point Math
      • From: David Duncan <email@hidden>
References: 
 >8.24-bit Fixed point Math (From: Mark's Studio <email@hidden>)
 >Re: 8.24-bit Fixed point Math (From: philippe wicker <email@hidden>)
 >Re: 8.24-bit Fixed point Math (From: Mark's Studio <email@hidden>)
 >Re: 8.24-bit Fixed point Math (From: David Duncan <email@hidden>)

  • Prev by Date: IPhone: Recorded audio echoes through receiver during play and record audio session
  • Next by Date: Re: 8.24-bit Fixed point Math
  • Previous by thread: Re: 8.24-bit Fixed point Math
  • Next by thread: Re: 8.24-bit Fixed point Math
  • Index(es):
    • Date
    • Thread