AudioKit v5 using multiple Taps

450 Views Asked by At

I'd like to be able to get amplitude and spectrum data from my AudioPlayer, but since each Node can only have one tap, I'm unsure how to make this work in AudioKit 5

player = AudioPlayer(file: fileToPlay)!
fftTap = FFTTap(player, bufferSize: 4096, handler: { _ in })
ampTap = AmplitudeTap(player)
ampTap.analysisMode = .peak

do
{
    try engine.start()
    fftTap.start()     // installs this tap on the player bus
    ampTracker.start() // removes the fftTap and installs this one
 }
 catch
 {
    print("Could not start engine: %\(error)")
    return
}
1

There are 1 best solutions below

1
Aurelius Prochazka On BEST ANSWER

This is pretty simple actually, just make multiple nodes that just are copies of the data and tap them each. Something like this should do it:

player = AudioPlayer(file: fileToPlay)!
let playerCopy = Mixer(player)
fftTap = FFTTap(player, bufferSize: 4096, handler: { _ in })
ampTap = AmplitudeTap(playerCopy)
...