Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the canonical audio sample data type in iOS 5

In the iOS 5.0 documentation it is stated that the canonical audio data type is 16 bit signed int (link):

The canonical audio data sample type for input and output.

typedef SInt16 AudioSampleType;

Discussion

The canonical audio sample type for input and output in iPhone OS is linear PCM with 16-bit integer samples.

However if I right-click "jump to definition" on AudioSampleType I see the following definition, in CoreAudioTypes.h:

#if !CA_PREFER_FIXED_POINT
typedef Float32     AudioSampleType;
typedef Float32     AudioUnitSampleType;
#else
typedef SInt16      AudioSampleType;
typedef SInt32      AudioUnitSampleType;
#define kAudioUnitSampleFractionBits 24
#endif

and again when jump-to-def for CA_PREFER_FIXED_POINT I see:

#if !defined(CA_PREFER_FIXED_POINT)
    #if TARGET_OS_IPHONE
        #if (TARGET_CPU_X86 || TARGET_CPU_X86_64 || TARGET_CPU_PPC || TARGET_CPU_PPC64) && !TARGET_IPHONE_SIMULATOR
            #define CA_PREFER_FIXED_POINT 0
        #else
            #define CA_PREFER_FIXED_POINT 1
        #endif
    #else
        #define CA_PREFER_FIXED_POINT 0
    #endif
#endif

Checking in my code at run-time, I see that CA_PREFER_FIXED_POINT is defined to be 1, both on the simulator and on my iPod.

So, my questions:

  • What is the canonical type? Is it always SInt16 on the device?
  • Under what case does the 3rd line above evaluates to 'true'? I mean, which device runs iPhone OS and use one of listed CPU's?
  • Is there a use case where I should re-define CA_PREFER_FIXED_POINT to 0 (when programming for iPhone)?
like image 718
Itamar Katz Avatar asked Jan 31 '12 20:01

Itamar Katz


2 Answers

Read the contents of the link, and this line in your headers again:

#define kAudioUnitSampleFractionBits 24

The canonical type for audio input and output is equivalent to SInt16.

The canonical type for other audio processing, such as the new iOS 5 filter Audio Units, is 8.24 signed fixed-point.

If you do your own DSP code for near real-time iOS audio processing, benchmark it with the different types, as on some of the newest ARM cores, sequences of 32-bit floats are often faster than using either of the above canonical types, and coded in NEON asm code even faster.

like image 84
hotpaw2 Avatar answered Oct 23 '22 19:10

hotpaw2


In its Core Audio Essentials Apple clarifies about Canonical Audio Data Formats:

Canonical Audio Data Formats Depending on the platform, Core Audio has one or two “canonical” audio data formats in the sense that these formats may be:

  • Required as an intermediate format in conversions
  • The format for which a service in Core Audio is optimized
  • A default, or assumed, format, when you do not otherwise specify an ASBD

The canonical formats in Core Audio are as follows:

  • iOS input and output Linear PCM with 16-bit integer samples
  • iOS audio units and other audio processing Noninterleaved linear PCM with 8.24-bit fixed-point samples
  • Mac input and output Linear PCM with 32-bit floating point samples
  • Mac audio units and other audio processing Noninterleaved linear PCM with 32-bit floating point samples

But: If you have a look into the CoreAudioTypes.h in iOS 8 you will find a discussion on that:

The "canonical" flags are deprecated. CA_PREFER_FIXED_POINT is discouraged because floating-point performance on iOS is such that fixed point is no longer truly preferred. All Apple-supplied AudioUnits support floating point. Replacement should be done with careful consideration of the format being specified or expected, but often kAudioFormatFlagsCanonical can be replaced with kAudioFormatFlagsNativeFloatPacked, and kAudioFormatFlagsAudioUnitCanonical with kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved.

like image 33
Michael Dorner Avatar answered Oct 23 '22 19:10

Michael Dorner