FFT
struct RealFFT¶
Real-valued FFT implementation using Cooley-Tukey algorithm.
If you're looking to create an FFT-based FX, look to the FFTProcessable
trait used in conjunction with FFTProcess instead. This struct is a
lower-level implementation that provides
FFT and inverse FFT on fixed windows of real values. FFTProcessable structs will enable you to
send audio samples (such as in a custom struct's .next() fn) into and out of
an FFT, doing some manipulation of the magnitudes and phases in between. (FFTProcess
has this RealFFT struct inside of it.)
Traits: AnyType, Copyable, ImplicitlyDestructible, Movable
RealFFT Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of channels for SIMD processing. |
RealFFT Functions¶
struct RealFFT . fn init¶
Initialize the RealFFT struct.
All internal buffers and lookup tables are set up here based on the Parameters.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| window_size | Int |
— | — |
fn init Returns
: Self
Static Method
This is a static method.
struct RealFFT . fn fft¶
Compute the FFT of the input real-valued samples.
The resulting magnitudes and phases are stored in the internal mags and phases lists.
fn fft Signature
fn fft Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| input | List |
— | The input real-valued samples to transform. This can be a List of SIMD vectors for multi-channel processing or a List of Float64 for single-channel processing. |
struct RealFFT . fn fft¶
Compute the FFT of the input real-valued samples. The resulting magnitudes and phases are stored in the provided lists.
fn fft Signature
fft(mut self, input: List[SIMD[DType.float64, num_chans]], mut mags: List[SIMD[DType.float64, num_chans]], mut phases: List[SIMD[DType.float64, num_chans]])
fn fft Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| input | List |
— | The input real-valued samples to transform. This can be a List of SIMD vectors for multi-channel processing or a List of Float64 for single-channel processing. |
| mags | List |
— | A mutable list to store the magnitudes of the FFT result. |
| phases | List |
— | A mutable list to store the phases of the FFT result. |
struct RealFFT . fn ifft¶
Compute the inverse FFT using the internal magnitudes and phases. The output real-valued samples are written to the provided output list.
fn ifft Signature
fn ifft Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| output | List |
— | A mutable list to store the output real-valued samples. |
struct RealFFT . fn ifft¶
Compute the inverse FFT using the provided magnitudes and phases. The output real-valued samples are written to the provided output list.
fn ifft Signature
ifft(mut self, mags: List[SIMD[DType.float64, num_chans]], phases: List[SIMD[DType.float64, num_chans]], mut output: List[SIMD[DType.float64, num_chans]])
fn ifft Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List |
— | A list of magnitudes for the inverse FFT. |
| phases | List |
— | A list of phases for the inverse FFT. |
| output | List |
— | A mutable list to store the output real-valued samples. |
struct RealFFT . fn fft_frequencies¶
Compute the FFT bin center frequencies. This implementation is based on Librosa's eponymous function.
fn fft_frequencies Signature
fn fft_frequencies Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| sr | Float64 |
— | The sample rate of the audio signal. |
| n_fft | Int |
— | The size of the FFT. |
| min_bin | Int |
0 |
The minimum FFT bin index to include. |
| num_bins | Int |
-1 |
The number of FFT bins to include. Defaults to all bins from min_bin to n_fft//2. |
fn fft_frequencies Returns
: List
A List of Float64 representing the center frequencies of each FFT bin.
Static Method
This is a static method.
struct RealFFT . fn buf_analysis¶
Compute the Short-Time Fourier Transform (STFT) of a buffer.
fn buf_analysis Signature
buf_analysis[input_window_shape: Int = WindowType.hann](buf: Buffer, chan: Int, start_frame: Int, var num_frames: Int, window_size: Int, hop_size: Int) -> Tuple[List[List[Float64]], List[List[Float64]]]
fn buf_analysis Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| input_window_shape | Int |
WindowType.hann |
The type of window to apply to each frame before computing the FFT. |
fn buf_analysis Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| buf | Buffer |
— | The input audio buffer to analyze. |
| chan | Int |
— | The channel index to analyze from the buffer. |
| start_frame | Int |
— | The starting frame index in the buffer to begin analysis. |
| num_frames | Int |
— | The number of frames to analyze from the starting frame. |
| window_size | Int |
— | The size of the FFT window. |
| hop_size | Int |
— | The hop size between successive windows. |
fn buf_analysis Returns
: Tuple
A tuple containing two lists of lists of Float64 representing the magnitudes and phases of the STFT for each frame and frequency bin.
Static Method
This is a static method.
Documentation generated with mojo doc from Mojo version 0.26.1.0