New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FFT buffer size / scale #748
Comments
Okay it seems I've been able to reduce the number of node by manually cloning https://github.com/audiokit/AudioKit/blob/master/AudioKit/Common/Internals/AKSettings.swift#L18-L37 import Foundation
import AudioKit
class CustomTap: NSObject, EZAudioFFTDelegate {
internal let bufferSize: UInt32 = 32
internal var fft: EZAudioFFT?
/// Array of FFT data
open var fftData = [Double](zeros: 16)
/// Initialze the FFT calculation on a given node
///
/// - parameter input: Node on whose output the FFT will be computed
///
public init(_ input: AKNode) {
super.init()
fft = EZAudioFFT(maximumBufferSize: vDSP_Length(bufferSize), sampleRate: Float(AKSettings.sampleRate), delegate: self)
input.avAudioNode.installTap(onBus: 0, bufferSize: bufferSize, format: AudioKit.format) { [weak self] (buffer, time) -> Void in
guard let strongSelf = self else { return }
buffer.frameLength = strongSelf.bufferSize
let offset = Int(buffer.frameCapacity - buffer.frameLength)
let tail = buffer.floatChannelData?[0]
strongSelf.fft!.computeFFT(withBuffer: &tail![offset],
withBufferSize: strongSelf.bufferSize)
}
}
/// Callback function for FFT computation
@objc open func fft(_ fft: EZAudioFFT!, updatedWithFFTData fftData: UnsafeMutablePointer<Float>, bufferSize: vDSP_Length) {
DispatchQueue.main.async { () -> Void in
for i in 0..<16 {
self.fftData[i] = Double(fftData[i])
}
}
}
} |
It also looks like This line accesses |
Reducing the buffer size in |
Hi Steve, you're probably the person who will be delving into the internals of AudioKit the most. If you see something worth adding or fixing, please feel free. You've answered some of your own questions here so maybe you can re-ask what you most need to know. But here's a shot: Q1. The y-axis is relative magnitudes, you should be able to iterate through them to find the max. Thanks! |
Thanks @aure. Q1. Awesome, that might be tricky to do each time so I'll set a sensible default. |
I'm sure its possible, just not automatic/currently built. |
I'm going to close this for now, but if there's an actionable issue to sort out, just post some more information and reopen this issue. thanks. |
It might be worth looking into Constant Q Transform for this: Basically, you see so many "peaks" on the left because FFT output is logarithmic but you plot it on a linear axis (As far as I've understood so far - I'm a DSP newbie myself :D) What I want to build is a software version of this: I've started working on this a few days ago but tbh I'm a bit scared of the maths going on in there. However, as I said I've not been able to get this stuff running in a satisfying manner, yet. |
Greetings @ImJCabus, I'm very interested at a Constant Q Transform algorithm implemented at swift. Do tou think there's something there or just C/C++ codes? If you hear something please comment here. Reference for this conclusion: |
Hello! Apologies if this is the incorrect place and may belong more on StackOverflow.
We're working to build a spectrum analyser and are using
AKFFTTap
. It's working great and we're getting the expect 512 points in the data.This is my first time working with audio and I have a few questions:
AKNodeFFTPlot
the right of the graph never seems to be used. I'm assuming this is related to the 512 points returned fromAKFFTTap
containing mostly zero values. If this is the case is there a way they can be ignored and the X axis size reduced?Thanks again for an awesome framework and apologies if this is the wrong place 😄
The text was updated successfully, but these errors were encountered: