AVAudioPlayer making noise when playing multiple sounds at the same time
- by Rob
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];