swiftaudiokitspectrumamplitude

AudioKit v5 using multiple Taps


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
}

Solution

  • 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)
    ...