Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
I am building a simple program as proof of concept and I want to add background music to it. What is the best way to have a music being played in the background without much compromise in performance? What frameworks will I use? Will I need to write that code to the application's delegate?

Does background music use many system resources from the iPhone OS?

Note that I want the background music to be looped!

Any recommendations are well appreciated.
 

orchiss

macrumors newbie
Mar 19, 2009
3
0
Check out the crash landing app - SoundEngine.cpp and .h

There's no example of the background music, so here's a bit to get you started:

Code:
NSBundle*	 bundle = [NSBundle mainBundle];
  SoundEngine_Initialize(44100);
  SoundEngine_SetListenerPosition(0.0, 0.0, 1.0);
  SoundEngine_LoadBackgroundMusicTrack([[bundle  pathForResource:@"your_file_name" ofType:@"caf"] UTF8String],NO,YES);
  SoundEngine_StartBackgroundMusic();

Keep in mind the format for this seems to be really picky. I'm using a .caf file. Make sure your encodings are in little endian order too.
For converting wav to caf:
afconvert -f caff -d LEI16@44100 -c 1 in.wav out.caf

Hope that gives you a starting point.

-M
 

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
Check out the crash landing app - SoundEngine.cpp and .h

There's no example of the background music, so here's a bit to get you started:

Code:
NSBundle*	 bundle = [NSBundle mainBundle];
  SoundEngine_Initialize(44100);
  SoundEngine_SetListenerPosition(0.0, 0.0, 1.0);
  SoundEngine_LoadBackgroundMusicTrack([[bundle  pathForResource:@"your_file_name" ofType:@"caf"] UTF8String],NO,YES);
  SoundEngine_StartBackgroundMusic();

Keep in mind the format for this seems to be really picky. I'm using a .caf file. Make sure your encodings are in little endian order too.
For converting wav to caf:
afconvert -f caff -d LEI16@44100 -c 1 in.wav out.caf

Hope that gives you a starting point.

-M

Thanks a lot for your answer! Yes, the iPhone is really picky about resources. It uses caf for sound and pvrtc for images. I wish I knew why, though!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.