AVAudioPlayer making noise when playing multiple sounds at the same time

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-04-27T22:53:12Z Indexed on 2010/04/27 23:13 UTC
Read the original article Hit count: 477

Filed under:
|
|
|
|

I am having an issue where AVAudioPlayer is introducing noise into playback ONLY when I play multiple sound files at the same time. If I play them each individually, they all sound perfect. But, if I play sound clip B while sound clip A is still playing, the speakers start crackling like there is noise.

I have tried both m4a files AND caf files and both make the same noise, so it has to be something with how I am implementing this method or a quirk with AVAudioPlayer.

Any insights?

code I am using:

UITouch* touch = [[event allTouches] anyObject];    

NSString* filename = [soundArray objectAtIndex:[touch view].tag];
NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:@"m4a"];  

AVAudioPlayer * newAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];  
self.theAudio = newAudio; // automatically retain audio and dealloc old file if new m4a file is loaded

[newAudio release]; // release the audio safely

theAudio.delegate = self; 
[theAudio prepareToPlay];
[theAudio setNumberOfLoops:0];
[theAudio setVolume: volumeLevel];
[theAudio play];

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk