0

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 ?

Guru
  • 21,652
  • 10
  • 63
  • 102
user1280535
  • 347
  • 3
  • 13
  • 1
    Are you sure that new record is also called `temp0.caf`? When you want to play a file, you run all this code? I didn't have experience with this Engine, but maybe you should unloadEffect before preloading it again? – DanSkeel May 20 '12 at 11:24
  • I don't really understand what you are trying to ask, you say: "even that I have already recorded some other file" Well can we please see that code... – MCKapur May 20 '12 at 11:27
  • i am recording a file using simple avaudioRecorder, there is nothing special to see in there. and yes, its recorded to same file path. if i play it with CDSoundEngine it does change the recoding . – user1280535 May 20 '12 at 11:29

2 Answers2

1

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

MCKapur
  • 9,127
  • 9
  • 58
  • 101
  • have tried that thanks. thats doesnt work . even without the preload its not. still play same audio over and over. if i play the audio with , CDSoundEngine its working great . – user1280535 May 20 '12 at 12:01
  • got it: [[SimpleAudioEngine sharedEngine] unloadEffect:soundFilePath]; – user1280535 May 20 '12 at 12:56
0

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;
akuritsu
  • 440
  • 1
  • 4
  • 18