So I am building a small application that has a keyboard and a few other buttons that trigger audio samples.
For this application, there are several pre recorded audio tracks (drums, vocals, guitar) which can be muted/unmuted… I have that part working fine with AVAudioPlayer
But, as most of you know, AVAudioPlayer is a little slow and has some latency if its assigned to say triggering a small audio sample of a drum hit or a synth. So i implemented SystemSoundServices to play the short sound samples. It is working fine as far as the latency between hitting the button and the sound playing, but I have a slight problem. When the sample is say, hit twice repeatedly, you hear a small popping sound, which is expected because its cutting off the first sample from playing when the button is hit the second time.
I would like to solve this by basically detecting if a sample is playing, if it is, then set the volume to 0, stop playing, and then play the sample again. BUT systemsoundservices unfortunately doesnt have this functionality built in. AVAudioPlayer does but it is too slow. I know there is CoreAudio, AudioQueue, Open AL, but these all seem WAYYY to complex for what i need to be doing. I dont need to do audio processing of any kind.
Does anyone have any suggestions of an audio framework that doesnt require writing 100 lines of code just to play a short audio clip? EVerything seems to be pointing me to spend weeks learning CoreAudio/AudioQueue/OpenAL and that just seems like a waste of my time for what I am working on.
you can use an
AUSamplerfor the sampler. granted, it is more complex than SystemSounds. theAUSampleris a system-supplied AudioUnit. so you’ll have a little programmatic AU configuration to do, but the hard stuff is out of reach.you can use
AudioFileandExtAudioFilefor reading and creating audio files. in the case of the AUSampler, it knows how to load samples (in a subset of available formats), so you won’t even need to write the file i/o parts.for more complex audio, you will likely need to come to grips with working with audio streams yourself.