SimpleAudioEngine always play the same effect?

303 views Asked by At

i record some file then play it with :

NSArray *dirPaths;
    NSString *docsDir;
    dirPaths = NSSearchPathForDirectoriesInDomains(
                                                   NSDocumentDirectory, NSUserDomainMask, YES);
    docsDir = [dirPaths objectAtIndex:0];
    NSString *soundFilePath = [docsDir
                               stringByAppendingPathComponent:@"temp0.caf"];

 //play
[[SimpleAudioEngine sharedEngine] preloadEffect:soundFilePath];
    [[SimpleAudioEngine sharedEngine] playEffect:soundFilePath  pitch:1.5f pan:0.0f gain:0.3f];

it works at the first time, but second time it plays the same file again even that i have already recorded some other file .

any help ?

2

There are 2 answers

0
akuritsu On

What I think is happening is your audio file is refusing to be overwritten by the new one. Maybe you should try to change the name of the file every time that the user records one. So that when he records, you save the file as a string, with the format:

[NSMutableString stringWithFormat:@"temp%d.caf",number];

Then whenever the user wants to record, you increase 'number' by one.

number = number +1;
2
MCKapur On

Maybe your audio engine is preloading that effect and keeping that preload, try:

[[SimpleAudioEngine sharedEngine] preloadEffect:nil];
[[SimpleAudioEngine sharedEngine] preloadEffect:soundFilePath];

    [[SimpleAudioEngine sharedEngine] playEffect:soundFilePath  pitch:1.5f pan:0.0f gain:0.3f];

Also, when and where is that code called. Its called after your record right? Maybe try:

NSArray *dirPaths = nil;
    NSString *docsDir = nil;

At the top. Try this, if it doesn't work I need to see your recording code