views:

302

answers:

2

I am creating an application,in my app i am changing images for countdown.I want to play a Tick sound when one second completes(i mean when image changes).I have a 25 second long sound with repeated tick sound and within time interval of 1 second. sometimes it works fine but sometimes it's not.Now how do i sync audio with my timer.any help appreciated thanks.

A: 

record with 25 ticks?) why don't you use record with one tick? if the loudness is not your aim, you can play it using AudioServicesCreateSystemSoundID then call AudioServicesPlaySystemSound every second.

Morion
can you give me a one second long sound.but in my iphone iphone 3gs i'm unable to hear system sound.I've already tried the system sound.
Rahul Vyas
hmm.. you can cut part of your audio file with, for example, Audion. It's free and easy to use. what about systemsound... you can use OpenAL. Maybe it's not very friendly, but works correctly. and it uses low-level API so I prefer to use it with animation. here's an article which can help you to create some simple cover to play sounds using openAL http://benbritten.com/2008/11/06/openal-sound-on-the-iphone/comment-page-1/#comment-292
Morion
i think using openAL becomes very complex,i wold prefer to use avaudioplayer(i'm currently using avaudioplayer).cut a part of sound is also needs to be precised.Isn't there any tick sound available for free to use
Rahul Vyas
this is your choice. but be careful. one simple example. two files played simultaneously using avaudioplayer will cause lags with animation on 3G. I avoided it only by using openAL.
Morion
can you post a simple code for playing sound using openAL with one second long sound file please
Rahul Vyas
look through the article at link below. there you will find how to load sound to openAL, play it, stop it, and unload. you can create some simple cover class to use it in the whole app.
Morion
A: 

I suggest using AudioServicesCreateSystemSoundID with a sound file that is just one tick, which is about 1/16 of a second long or less, and using this in your init:

clickSound = [[self createSoundWithName:@"click"] intValue];

Here is the code to set up the sound:

- (NSNumber*) createSoundWithName: (NSString*) name {
SystemSoundID soundID = -1;

NSString *path =[[NSBundle mainBundle] pathForResource:name ofType:@"caf"];
if (path != nil) {
    NSURL *url = [NSURL fileURLWithPath:path];
    if (url != nil) {
        OSStatus err = AudioServicesCreateSystemSoundID ((CFURLRef) url, &soundID);
        if (err) NSLog (@"AudioServicesCreateSystemSoundID error %d", err);
    }
}
return [NSNumber numberWithInt:soundID];
}

And here is where you play the click:

- (void) playClick  {
AudioServicesPlaySystemSound (clickSound);
}
lucius