Search code examples
audiokit

Save / Analyze output after applying a filter


I'm trying to analyze the amplitude data of an audio file, but I can't seem to find a way to get this data after applying a filter. Is it possible to get the floatChannelData or write the output to a new file for analysis?

    player = AKPlayer(audioFile: file)
    player.buffering = .always
    player.preroll()
    let filter = AKBandPassButterworthFilter(player, centerFrequency: 1000, bandwidth: 100)
    AudioKit.output = filter

    do {
        try AudioKit.start()
    } catch {
        print("Failed to start AudioKit")
        return nil
    }

    // This is the peak as though no filter was applied
    print(player.buffer?.peak())

Solution

  • Yes, you can choose to render the output to file. You can also tap the filter node to get its data for use in plots, or to save the contents to a buffer and save the data external to AudioKit's rendering.