Hey all, looking for some advice on using the experimental sound-engine in cocos2d-iphone v0.8. What I have done is to create a class called audioManager and house it in the appDelegate so that it is available to the whole application pretty easily. I don't instantiate the class until the splash page has started so it should atleast have a loading message to the user.
My problem is that the application takes about 10 seconds to start on the device (debugging and normal usage) and I'm only using the trance-loop.ogg they provide with the sample. This seems really slow and I'm looking for any advice on how I can improve this or if I should change over to the AVFramework or OpenAL.
Heres the code:
AppDel.h
#import <UIKit/UIKit.h>
#import "audioManager.h"
@interface HaloJumpAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
audioManager *sndManager;
}
@property (nonatomic, retain) audioManager *sndManager;
-(void)setAudioManager:(audioManager *)object;
@end
AppDel.m
#import "HaloJumpAppDelegate.h"
#import "cocos2d.h"
#import "SplashScene.h"
#import "Scene.h"
@implementation HaloJumpAppDelegate
@synthesize sndManager;
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window setUserInteractionEnabled:YES];
[window setMultipleTouchEnabled:YES];
// set up Director, probably something like this:
[[Director sharedDirector] attachInWindow:window];
[window makeKeyAndVisible];
// make a scene, probably something like this:
SplashScene *scene = [SplashScene node];
[[Director sharedDirector] runWithScene:scene];
}
// store the passed audioManager for use through app
-(void)setAudioManager:(audioManager *)object
{
sndManager = object;
}
// get outta here
- (void)dealloc
{
[window release];
[super dealloc];
}
@end
audioManager.h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "PASoundMgr.h"
@interface audioManager : NSObject {
BOOL playAudio;
// sound list
PASoundSource *mainMenuBackTrack;
}
@property (retain, nonatomic) PASoundSource *mainMenuBackTrack;
@property BOOL playAudio;
-(void)playMenuBackTrack;
-(void)setAudioEnabled:(BOOL)value;
@end
audioManager.m
#import "audioManager.h"
#import "PASoundSource.h"
@implementation audioManager
@synthesize playAudio, mainMenuBackTrack;
-(id)init {
self = [super init];
if (self != nil) {
// ok lets initialise the sound manager
[PASoundMgr sharedSoundManager];
// add the background track
mainMenuBackTrack = [[PASoundMgr sharedSoundManager] addSound:@"tranceloop" withExtension:@"ogg" position:CGPointZero looped:YES];
}
// return instance
return self;
}
// this option sets the audio mode to Enabled (1)
-(void)setAudioEnabled:(BOOL)value
{
NSLog(@"audio toggled to :%d", value);
playAudio = value;
}
// plays the main menu background track once
-(void)playMenuBackTrack {
[mainMenuBackTrack setGain:0.8f];
[mainMenuBackTrack playAtListenerPosition];
}
@end
splash.m
#import "SplashScene.h"
#import "AudioChoiceScene.h"
#import "cocos2d.h"
#import "audioManager.h"
#import "HaloJumpAppDelegate.h"
// the main splash scene
@implementation SplashScene
-(id)init
{
// instantiate this class
self = [super init];
if (self != nil)
{
// add the main splash graphic
Sprite *bg = [Sprite spriteWithFile:@"splash.png"];
[bg setPosition:ccp(160, 240)];
[self addChild:bg z:0];
[self addChild:[SplashLayer node] z:1];
// set the timer for the splash countdown
[self schedule: @selector(tick:) interval:6.0];
[self setupAudio];
}
return self;
}
-(void)setupAudio
{
// instantiate the audio Manager in the appDel
audioManager *audMan = [[audioManager alloc] init];
HaloJumpAppDelegate *appDelegate = (HaloJumpAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setSndManager:audMan];
[audMan release];
//[appDelegate release];
}
// The tick method is a countdown that wait for the audioManager to preload it's content
-(void) tick: (ccTime) dt
{
// instantiate the AudioChoiceScene and set the audioManager
AudioChoiceScene *acs = [AudioChoiceScene node];
// transition
[[Director sharedDirector] replaceScene:[FadeTransition transitionWithDuration:2.2f scene:acs]];
}
@end
// Layer empty at the moment
@implementation SplashLayer
-(id) init
{
self = [super init];
if(self != nil)
{
}
return self;
}
@end
Any help/sugestions appreciated! anton