Oliver Hume
Oliver Hume

Reputation: 479

Native iPhone audio format

I've currently got my output audio on the iPhone setup as this :

AudioStreamBasicDescription audioFormat;

audioFormat.mSampleRate = 48000;

audioFormat.mFormatID   = kAudioFormatLinearPCM;

audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;

audioFormat.mFramesPerPacket = 1;

audioFormat.mChannelsPerFrame = 2;

audioFormat.mBitsPerChannel = 16;

audioFormat.mBytesPerPacket = 4;

audioFormat.mBytesPerFrame = 4;

However, when I examine my performance figures through shark I am seeing functions such as : SRC_Convert_table_i32_scalar_stereo

take a fair chunk of time.

This made me think - what is the ideal and suggested output format for the iPhone? The one that requires as little work for the device to play.

Upvotes: 7

Views: 8221

Answers (3)

dendryte
dendryte

Reputation: 221

Shark does work with the iPhone. You can enable iPhone profiling by selecting "Sampling > Network/iPhone Profiling..." in the menu.

Definitely try using a 44100 Hz sampling rate. With 48000 I see the same function that you posted appearing in the callstacks -- no such function shows up when using 44100. The canonical audio format for Audio Units on the iPhone is non-interleaved 8.24 linear PCM:

streamFormat.mFormatID         = kAudioFormatLinearPCM;
streamFormat.mFormatFlags      = 
                  kAudioFormatFlagIsSignedInteger
                | kAudioFormatFlagsNativeEndian
                | kLinearPCMFormatFlagIsNonInterleaved
                | (24 << kLinearPCMFormatFlagsSampleFractionShift);
streamFormat.mSampleRate       = mixing_rate;
streamFormat.mBitsPerChannel   = 32;
streamFormat.mChannelsPerFrame = 2;
streamFormat.mFramesPerPacket  = 1;
streamFormat.mBytesPerFrame    = ( streamFormat.mBitsPerChannel / 8 );
streamFormat.mBytesPerPacket   = streamFormat.mBytesPerFrame *
                                 streamFormat.mFramesPerPacket;

Upvotes: 11

John Fricker
John Fricker

Reputation: 3334

48000 is a weird format for audio in general. While it's marginally (and imperceptibly) better than CD standard 44.1Khz it's not worth the size.

Is there any compelling reason in your app to use high quality stereo sound? In other words is the app likely to be played on speakers or good headphones?

LinearPCM format is hardware native so it should be optimal. (No decompression to fiddle with.) So that call may be a downsample to 44.1Khz.

Upvotes: 1

hhafez
hhafez

Reputation: 39750

From iphone dev centre (requires login) the hardware suppoorted codecs are

iPhone Audio Hardware Codecs

iPhone OS applications can use a wide range of audio data formats, as described in the next section. Some of these formats use software-based encoding and decoding. You can simultaneously play multiple sounds in these formats. Moreover, your application and a background application (notably, the iPod application) can simultaneously play sounds in these formats.

Other iPhone OS audio formats employ a hardware codec for playback. These formats are:

  • AAC
  • ALAC (Apple Lossless)
  • MP3

Upvotes: 3

Related Questions