1

I have an application which has two kinds of sounds: 1. Background sounds, looping forever till next view. 2. Sounds clips that could be played separately or all in one go.

Previously i tried using AVAudioPlayer but there was always a very little silence interval between two clips (to which i didn't find any solution, if you have one, please post in reply), so shifted to Finch e.g. http://github.com/zoul/Finch/tree/master

Now here is the deal: I am using AVAudioPlayer to play looping forever sounds while Finch to play those back-to-back clips. I am doing this:

- (void)viewDidLoad {
    [super viewDidLoad];

    soundEngine = [[Finch alloc] init];
/***
CLIPPED
***/
}
-(void) playclip:(id) sender {
    NSString *fullPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"sitar.wav"];
    NSLog(@"Song is %@", fullPath);
    clip = [[Sound alloc] initWithFile:fullPath];
    NSLog(@"Clip Length: %@", clip.length);
    NSLog(@"Clip Playing ? : %d", clip.playing);
    [clip play];
    NSLog(@"Played Clip");
}

This is almost same code as the demo project provided as in the git repository. But for some reason i get this on console:

Song is /Users/shoaibi/Library/Application Support/iPhone Simulator/User/Applications/17FBA26F-6047-4D56-9E45-ADAFE07B7234/Test.app/sitar.wav
Failed to create OpenAL source, error code a004.
Clip Length: (null)
Clip Playing ? : 0
Played Clip

An ls on the directory printed on console reveals that there is sitar.wav there with the correct permissions. What could be the issue? may be the background sound AVAudioPlayer which i stop using:

- (void)viewWillAppear:(BOOL)animated {

    //Stop the background music before my ears bleed :P
    d = [[UIApplication sharedApplication] delegate];
    if (d.bg.playing)
    {
        [d.bg stop];
        NSLog(@"Background music stoped");
    }

}

is not freeing up sound resource?

Shoaibi
  • 859
  • 2
  • 11
  • 23
  • The AVAudioPlayer should not be an issue, Finch should go along AVAudioPlayer just fine. Are you running the code in Simulator? (The file paths would suggest so.) There are problems with OpenAL on the Simulator, you have to try on the device. – zoul Jul 15 '09 at 04:25
  • The same code fails on device, its just that while writing this post i happen to use simulator. Plus the demo app works in simulator without any issues. – Shoaibi Jul 15 '09 at 04:48

2 Answers2

3

Latest Finch now checks whether OpenAL is initialized when you initialize a new Sound. If current OpenAL context is not set because you forgot or failed to initialize Finch, you get a better error message. Give it a try, it might be the case that your initialization code is buggy.

zoul
  • 102,279
  • 44
  • 260
  • 354
0

I got the same error when I called the sound clip allocs in my viewWillAppear - seems it was called before the awakeFromNib finished doing its stuff. Anyway, shifting the allocs so they happened later fixed it.

SomaMan
  • 4,127
  • 1
  • 34
  • 45