tags:

views:

2324

answers:

4

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.

+3  A: 

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
hhafez
I'm less interested in the different formats that the iphone is able to play, more what the base format of the output is. That way I can match my output type, and it will require less cycles for the iPhone to convert.
Oliver Hume
I would have assumed that by using a hardware codec you would use fewer cpu cycles... I might be wrong, try out and tell us how it goes
hhafez
+1  A: 

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.

John Fricker
A: 

How are you using Shark with the iPhone?
Are you sure you're not profiling the simulator?

RF

Rhythmic Fistman
No, I'm profiling the device.Here is a page that tells you how to setup shark to profile iPhones : https://developer.apple.com/iphone/library/documentation/DeveloperTools/Conceptual/SharkUserGuide/SelectingExecutiontoSampleorTrace/chapter_6_section_9.html
Oliver Hume
+3  A: 

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;
dendryte