Popping noise with AEAudioFilePlayer
I'm probably doing something stupid, but I'm having a weird issue. I'm playing a sound when a button is tapped with the following code:
player = [AEAudioFilePlayer audioFilePlayerWithURL:file audioController:_audioController error:NULL];
player.removeUponFinish = YES;
player.completionBlock = ^{
player = nil;
};
player.volume = volume;
[_audioController addChannels:[NSArray arrayWithObject:player]];
When the button is tapped repeatedly (above code played), I'm hearing popping noises. I've narrowed it down to the removeUponFinish attribute. If I change this to NO, the popping noise goes away, but then my channels eventually get filled up and sounds stop playing.
Any ideas?
Thanks!
Comments
Hi @yosoycody,
By 'repeatedly', how fast are we talking? AEAudioFilePlayer isn't designed for multi-layered polyphony, and you'll start hearing audio stutters if you layer up too much or too fast.
For a polyphonic sample player, you'd need to create a new class that's designed for it. That's way beyond scope of this forum though, I'm afraid, as it's a bit of a job - someone else did indicate they were after this kind of functionality though, so maybe it'll happen one day.
Alternatively, take a look at kAudioUnitSubType_Sampler.
https://github.com/ElectricPeelSoftware/EPSSampler/blob/master/EPSSampler.m (note this doesn't use TAAE, but it is a reference for how to use the sampler unit)
Thanks for the response Michael. I'll take a look. FYI, I'm trying to replace OpenAL with TAAE so I can take advantage of Audiobus.
You're the second person who's making the attempt, so I'd be very interested to hear how you get on. Maybe it's time to start thinking more seriously about making a nice sampler class.
I can highly recommend both kAudioUnitSubType_Sampler and kAudioUnitSubType_AudioFilePlayer. The first is a polyphonic sample player that can also load SoundFont2 files, and responds to MIDI events. The latter plays scheduled regions of soundfiles, with optional looping, handling all necessary buffering and loading from disk to memory under the hood.
I use them both in AudioShare's soundfile/midifile player.
Nice! Cheers for the recommendation @j_liljedahl
Firstly, nicely done with Audiobus and now the Amazing Engine!
I was attempting to convert my drum app to use the Amazing Engine, but also experience popping and timing issues when using AudioFilePlayer, so back to the drawing board - is the sampler method correct for a drum app? What method of playing sound using AE would deliver the best timing?
I gave using AEAudioFileLoaderOperation a shot as well, but wasn't sure exactly how to use the AudioBuffer to achieve playback.
So, a few years later I am giving this another shot. Some other posts on this forum indicate:
AEBlockChannel
s (making-a-drum-pad-app-using-taaeSo, I am wondering @Michael if TAAE2 is any better suited for a drum kit/pad style app, or maybe I am better of with AudioKit?