EZAudioFFT

@interface EZAudioFFT : NSObject

The EZAudioFFT provides a base class to quickly calculate the FFT of incoming audio data using the Accelerate framework. In addition, the EZAudioFFT contains an EZAudioFFTDelegate to receive an event anytime an FFT is computed.

  • Initializes an EZAudioFFT (or subclass) instance with a maximum buffer size and sample rate. The sample rate is used specifically to calculate the maxFrequency property. If you don’t care about the maxFrequency property then you can set the sample rate to 0. - parameter: maximumBufferSize A vDSP_Length (unsigned long) representing the maximum length of the incoming audio data. - parameter: sampleRate A float representing the sample rate of the incoming audio data.

    Declaration

    Objective-C

    - (instancetype)initWithMaximumBufferSize:(vDSP_Length)maximumBufferSize
                                   sampleRate:(float)sampleRate;

    Swift

    init!(maximumBufferSize: vDSP_Length, sampleRate: Float)

    Parameters

    maximumBufferSize

    A vDSP_Length (unsigned long) representing the maximum length of the incoming audio data.

    sampleRate

    A float representing the sample rate of the incoming audio data.

    Return Value

    A newly created EZAudioFFT (or subclass) instance.

  • Initializes an EZAudioFFT (or subclass) instance with a maximum buffer size, sample rate, and EZAudioFFTDelegate. The sample rate is used specifically to calculate the maxFrequency property. If you don’t care about the maxFrequency property then you can set the sample rate to 0. The EZAudioFFTDelegate will act as a receive to get an event whenever the FFT is calculated. - parameter: maximumBufferSize A vDSP_Length (unsigned long) representing the maximum length of the incoming audio data. - parameter: sampleRate A float representing the sample rate of the incoming audio data. - parameter: delegate An EZAudioFFTDelegate to receive an event whenever the FFT is calculated. - returns: A newly created EZAudioFFT (or subclass) instance.

    Declaration

    Objective-C

    - (instancetype)initWithMaximumBufferSize:(vDSP_Length)maximumBufferSize
                                   sampleRate:(float)sampleRate
                                     delegate:(id<EZAudioFFTDelegate>)delegate;

    Swift

    init!(maximumBufferSize: vDSP_Length, sampleRate: Float, delegate: EZAudioFFTDelegate!)

    Parameters

    maximumBufferSize

    A vDSP_Length (unsigned long) representing the maximum length of the incoming audio data.

    sampleRate

    A float representing the sample rate of the incoming audio data.

    delegate

    An EZAudioFFTDelegate to receive an event whenever the FFT is calculated.

    Return Value

    A newly created EZAudioFFT (or subclass) instance.

  • Class method to initialize an EZAudioFFT (or subclass) instance with a maximum buffer size and sample rate. The sample rate is used specifically to calculate the maxFrequency property. If you don’t care about the maxFrequency property then you can set the sample rate to 0. - parameter: maximumBufferSize A vDSP_Length (unsigned long) representing the maximum length of the incoming audio data. - parameter: sampleRate A float representing the sample rate of the incoming audio data. - returns: A newly created EZAudioFFT (or subclass) instance.

    Declaration

    Objective-C

    + (instancetype)fftWithMaximumBufferSize:(vDSP_Length)maximumBufferSize
                                  sampleRate:(float)sampleRate;

    Parameters

    maximumBufferSize

    A vDSP_Length (unsigned long) representing the maximum length of the incoming audio data.

    sampleRate

    A float representing the sample rate of the incoming audio data.

    Return Value

    A newly created EZAudioFFT (or subclass) instance.

  • Class method to initialize an EZAudioFFT (or subclass) instance with a maximum buffer size, sample rate, and EZAudioFFTDelegate. The sample rate is used specifically to calculate the maxFrequency property. If you don’t care about the maxFrequency property then you can set the sample rate to 0. The EZAudioFFTDelegate will act as a receive to get an event whenever the FFT is calculated. - parameter: maximumBufferSize A vDSP_Length (unsigned long) representing the maximum length of the incoming audio data. - parameter: sampleRate A float representing the sample rate of the incoming audio data. - parameter: delegate An EZAudioFFTDelegate to receive an event whenever the FFT is calculated. - returns: A newly created EZAudioFFT (or subclass) instance.

    Declaration

    Objective-C

    + (instancetype)fftWithMaximumBufferSize:(vDSP_Length)maximumBufferSize
                                  sampleRate:(float)sampleRate
                                    delegate:(id<EZAudioFFTDelegate>)delegate;

    Parameters

    maximumBufferSize

    A vDSP_Length (unsigned long) representing the maximum length of the incoming audio data.

    sampleRate

    A float representing the sample rate of the incoming audio data.

    delegate

    An EZAudioFFTDelegate to receive an event whenever the FFT is calculated.

    Return Value

    A newly created EZAudioFFT (or subclass) instance.

  • An EZAudioFFTDelegate to receive an event whenever the FFT is calculated.

    Declaration

    Objective-C

    @property (readwrite, nonatomic) id<EZAudioFFTDelegate> delegate;

    Swift

    weak var delegate: EZAudioFFTDelegate! { get set }
  • A COMPLEX_SPLIT data structure used to hold the FFT’s imaginary and real components.

    Declaration

    Objective-C

    @property (readonly, nonatomic) COMPLEX_SPLIT complexSplit;

    Swift

    var complexSplit: COMPLEX_SPLIT { get }
  • A float array containing the last calculated FFT data.

    Declaration

    Objective-C

    @property (readonly, nonatomic) float *fftData;

    Swift

    var fftData: UnsafeMutablePointer
  • An FFTSetup data structure used to internally calculate the FFT using Accelerate.

    Declaration

    Objective-C

    @property (readonly, nonatomic) FFTSetup fftSetup;

    Swift

    var fftSetup: FFTSetup! { get }
  • A float array containing the last calculated inverse FFT data (the time domain signal).

    Declaration

    Objective-C

    @property (readonly, nonatomic) float *inversedFFTData;

    Swift

    var inversedFFTData: UnsafeMutablePointer
  • A float representing the frequency with the highest energy is the last FFT calculation.

    Declaration

    Objective-C

    @property (readonly, nonatomic) float maxFrequency;

    Swift

    var maxFrequency: Float { get }
  • A vDSP_Length (unsigned long) representing the index of the frequency with the highest energy is the last FFT calculation.

    Declaration

    Objective-C

    @property (readonly, nonatomic) vDSP_Length maxFrequencyIndex;

    Swift

    var maxFrequencyIndex: vDSP_Length { get }
  • A float representing the magnitude of the frequency with the highest energy is the last FFT calculation.

    Declaration

    Objective-C

    @property (readonly, nonatomic) float maxFrequencyMagnitude;

    Swift

    var maxFrequencyMagnitude: Float { get }
  • A vDSP_Length (unsigned long) representing the maximum buffer size. This is the maximum length the incoming audio data in the computeFFTWithBuffer:withBufferSize method can be.

    Declaration

    Objective-C

    @property (readonly, nonatomic) vDSP_Length maximumBufferSize;

    Swift

    var maximumBufferSize: vDSP_Length { get }
  • A float representing the sample rate of the incoming audio data.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) float sampleRate;

    Swift

    var sampleRate: Float { get set }
  • Computes the FFT for a float array representing an incoming audio signal. This will trigger the EZAudioFFTDelegate method fft:updatedWithFFTData:bufferSize:. - parameter: buffer A float array representing the audio data. - parameter: bufferSize The length of the float array of audio data. - returns: A float array containing the computed FFT data. The length of the output will be half the incoming buffer (half the bufferSize argument).

    Declaration

    Objective-C

    - (float *)computeFFTWithBuffer:(float *)buffer
                     withBufferSize:(UInt32)bufferSize;

    Swift

    func computeFFT(withBuffer buffer: UnsafeMutablePointer

    Parameters

    buffer

    A float array representing the audio data.

    bufferSize

    The length of the float array of audio data.

    Return Value

    A float array containing the computed FFT data. The length of the output will be half the incoming buffer (half the bufferSize argument).

  • Provides the frequency corresponding to an index in the last computed FFT data. - parameter: index A vDSP_Length (unsigned integer) representing the index of the frequency bin value you’d like to get - returns: A float representing the frequency value at that index.

    Declaration

    Objective-C

    - (float)frequencyAtIndex:(vDSP_Length)index;

    Swift

    func frequency(at index: vDSP_Length) -> Float

    Parameters

    index

    A vDSP_Length (unsigned integer) representing the index of the frequency bin value you’d like to get

    Return Value

    A float representing the frequency value at that index.

  • Provides the magnitude of the frequenecy corresponding to an index in the last computed FFT data. - parameter: index A vDSP_Length (unsigned integer) representing the index of the frequency bin value you’d like to get - returns: A float representing the frequency magnitude value at that index.

    Declaration

    Objective-C

    - (float)frequencyMagnitudeAtIndex:(vDSP_Length)index;

    Swift

    func frequencyMagnitude(at index: vDSP_Length) -> Float

    Parameters

    index

    A vDSP_Length (unsigned integer) representing the index of the frequency bin value you’d like to get

    Return Value

    A float representing the frequency magnitude value at that index.