Analysis
trait GetFloat64Featurable¶
GetFloat64Featurable Required Methods¶
trait GetFloat64Featurable . fn get_features¶
Signature
Returns
Type: List[Float64]
trait GetBoolFeaturable¶
GetBoolFeaturable Required Methods¶
trait GetBoolFeaturable . fn get_features¶
Signature
Returns
Type: List[Bool]
struct YIN¶
Monophonic Frequency ('F0') Detection using the YIN algorithm (FFT-based, O(N log N) version).
Traits: AnyType, BufferedProcessable, Copyable, GetFloat64Featurable, ImplicitlyDeletable, Movable
YIN Functions¶
struct YIN . fn init¶
Initialize the YIN pitch detector.
fn init Signature
def __init__(out self, sr: Float64, window_size: Int = 1024, min_freq: Float64 = 20, max_freq: Float64 = 2.0E+4)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| sr | Float64 |
— | The sample rate from the MMMWorld. |
| window_size | Int |
1024 |
The size of the analysis window in samples. |
| min_freq | Float64 |
20 |
The minimum frequency to consider for pitch detection. |
| max_freq | Float64 |
2.0E+4 |
The maximum frequency to consider for pitch detection. |
fn init Returns
: Self
An initialized YIN struct.
Static Method
This is a static method.
struct YIN . fn get_features¶
Get the pitch and confidence values.
fn get_features Signature
fn get_features Returns
: List[Float64]
The current pitch and confidence values as a List[Float64].
struct YIN . fn next_window¶
Compute the YIN pitch estimate for the given frame of audio samples.
Nothing is returned. The pitch and confidence are stored internally and can be accessed with .pitch and .confidence.
fn next_window Signature
fn next_window Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| frame | List[Float64] |
— | The input audio frame of size window_size. This List gets passed from BufferedProcess. |
struct SpectralCentroid¶
Spectral Centroid analysis.
Based on the Peeters (2003)
Traits: AnyType, Copyable, FFTProcessable, GetFloat64Featurable, ImplicitlyDeletable, Movable
SpectralCentroid Functions¶
struct SpectralCentroid . fn init¶
Initialize the Spectral Centroid analyzer.
fn init Signature
def __init__(out self, sr: Float64, min_freq: Float64 = Float64("20"), max_freq: Float64 = Float64("2.0E+4"), power_mag: Bool = False)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| sr | Float64 |
— | The sample rate from the MMMWorld. |
| min_freq | Float64 |
Float64("20") |
The minimum frequency to consider when computing the spectral centroid. |
| max_freq | Float64 |
Float64("2.0E+4") |
The maximum frequency to consider when computing the spectral centroid. |
| power_mag | Bool |
False |
Whether to use power magnitudes (mags^2) instead of linear magnitudes when computing the centroid. |
fn init Returns
: Self
An initialized SpectralCentroid struct.
Static Method
This is a static method.
struct SpectralCentroid . fn get_features¶
Get the spectral centroid value as a List of Float64.
fn get_features Signature
fn get_features Returns
: List[Float64]
The current spectral centroid feature value as a List[Float64] (with only the one element).
struct SpectralCentroid . fn next_frame¶
Compute the spectral centroid for a given FFT analysis. This function is to be used by FFTProcess if SpectralCentroid is passed as the "process".
fn next_frame Signature
fn next_frame Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The input magnitudes as a List of Float64. |
| phases | List[Float64] |
— | The input phases as a List of Float64. |
struct SpectralCentroid . fn from_mags¶
Compute the spectral centroid for the given magnitudes of an FFT frame. This static method is useful when there is an FFT already computed, perhaps as part of a custom struct that implements the FFTProcessable trait.
fn from_mags Signature
def from_mags(mags: List[Float64], sample_rate: Float64, min_freq: Float64 = Float64("20"), max_freq: Float64 = Float64("2.0E+4"), power_mag: Bool = False) -> Float64
fn from_mags Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The input magnitudes as a List of Float64. |
| sample_rate | Float64 |
— | The sample rate of the audio signal. |
| min_freq | Float64 |
Float64("20") |
The minimum frequency to consider when computing the spectral centroid. |
| max_freq | Float64 |
Float64("2.0E+4") |
The maximum frequency to consider when computing the spectral centroid. |
| power_mag | Bool |
False |
Whether to use power magnitudes (mags^2) instead of linear magnitudes when computing the centroid. |
fn from_mags Returns
: Float64
Float64. The spectral centroid value.
Static Method
This is a static method.
struct SpectralSpread¶
Spectral Spread analysis.
Traits: AnyType, Copyable, FFTProcessable, GetFloat64Featurable, ImplicitlyDeletable, Movable
SpectralSpread Functions¶
struct SpectralSpread . fn init¶
Initialize the Spectral Spread analyzer.
fn init Signature
def __init__(out self, sr: Float64, min_freq: Float64 = Float64("20"), max_freq: Float64 = Float64("2.0E+4"), log_freq: Bool = False, power_mag: Bool = False)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| sr | Float64 |
— | The sample rate from the MMMWorld. |
| min_freq | Float64 |
Float64("20") |
The minimum frequency to consider. |
| max_freq | Float64 |
Float64("2.0E+4") |
The maximum frequency to consider. |
| log_freq | Bool |
False |
Whether to use log-frequency (MIDI) bins. |
| power_mag | Bool |
False |
Whether to use power magnitudes (mags^2). |
fn init Returns
: Self
Static Method
This is a static method.
struct SpectralSpread . fn get_features¶
Get the current spectral spread value.
fn get_features Signature
fn get_features Returns
: List[Float64]
The current spectral spread feature value as a List[Float64] (with only the one element).
struct SpectralSpread . fn next_frame¶
Compute the spectral spread for a given FFT analysis. This function is to be used by FFTProcess if SpectralSpread is passed as the "process".
Nothing is returned. The spread is stored internally and can be accessed with .spread.
fn next_frame Signature
fn next_frame Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The input magnitudes as a List of Float64. |
| phases | List[Float64] |
— | The input phases as a List of Float64. |
struct SpectralSpread . fn from_mags¶
fn from_mags Signature
def from_mags(mags: List[Float64], sample_rate: Float64, min_freq: Float64 = Float64("20"), max_freq: Float64 = Float64("2.0E+4"), log_freq: Bool = False, power_mag: Bool = False) -> Float64
fn from_mags Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | — |
| sample_rate | Float64 |
— | — |
| min_freq | Float64 |
Float64("20") |
— |
| max_freq | Float64 |
Float64("2.0E+4") |
— |
| log_freq | Bool |
False |
— |
| power_mag | Bool |
False |
— |
fn from_mags Returns
: Float64
Static Method
This is a static method.
struct SpectralSkewness¶
Spectral Skewness analysis.
Traits: AnyType, Copyable, FFTProcessable, GetFloat64Featurable, ImplicitlyDeletable, Movable
SpectralSkewness Functions¶
struct SpectralSkewness . fn init¶
Initialize the Spectral Skewness analyzer.
fn init Signature
def __init__(out self, sr: Float64, min_freq: Float64 = Float64("20"), max_freq: Float64 = Float64("2.0E+4"), log_freq: Bool = False, power_mag: Bool = False)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| sr | Float64 |
— | The sample rate from the MMMWorld. |
| min_freq | Float64 |
Float64("20") |
The minimum frequency to consider. |
| max_freq | Float64 |
Float64("2.0E+4") |
The maximum frequency to consider. |
| log_freq | Bool |
False |
Whether to use log-frequency (MIDI) bins. |
| power_mag | Bool |
False |
Whether to use power magnitudes (mags^2). |
fn init Returns
: Self
Static Method
This is a static method.
struct SpectralSkewness . fn get_features¶
Return the current spectral skewness value as a List of Float64.
fn get_features Signature
fn get_features Returns
: List[Float64]
The current spectral skewness feature value as a List[Float64] (with only the one element).
struct SpectralSkewness . fn next_frame¶
Compute the spectral skewness for a given FFT analysis.
Nothing is returned. The skewness is stored internally and can be accessed with .skewness.
fn next_frame Signature
fn next_frame Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The input magnitudes as a List of Float64. |
| phases | List[Float64] |
— | The input phases as a List of Float64. |
struct SpectralSkewness . fn from_mags¶
fn from_mags Signature
def from_mags(mags: List[Float64], sample_rate: Float64, min_freq: Float64 = Float64("20"), max_freq: Float64 = Float64("2.0E+4"), log_freq: Bool = False, power_mag: Bool = False) -> Float64
fn from_mags Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | — |
| sample_rate | Float64 |
— | — |
| min_freq | Float64 |
Float64("20") |
— |
| max_freq | Float64 |
Float64("2.0E+4") |
— |
| log_freq | Bool |
False |
— |
| power_mag | Bool |
False |
— |
fn from_mags Returns
: Float64
Static Method
This is a static method.
struct SpectralKurtosis¶
Spectral Kurtosis analysis.
Traits: AnyType, Copyable, FFTProcessable, GetFloat64Featurable, ImplicitlyDeletable, Movable
SpectralKurtosis Functions¶
struct SpectralKurtosis . fn init¶
Initialize the Spectral Kurtosis analyzer.
fn init Signature
def __init__(out self, sr: Float64, min_freq: Float64 = Float64("20"), max_freq: Float64 = Float64("2.0E+4"), log_freq: Bool = False, power_mag: Bool = False)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| sr | Float64 |
— | The sample rate from the MMMWorld. |
| min_freq | Float64 |
Float64("20") |
The minimum frequency to consider. |
| max_freq | Float64 |
Float64("2.0E+4") |
The maximum frequency to consider. |
| log_freq | Bool |
False |
Whether to use log-frequency (MIDI) bins. |
| power_mag | Bool |
False |
Whether to use power magnitudes (mags^2). |
fn init Returns
: Self
Static Method
This is a static method.
struct SpectralKurtosis . fn get_features¶
Get the current spectral kurtosis value as a List of Float64.
fn get_features Signature
fn get_features Returns
: List[Float64]
The current spectral kurtosis feature value.
struct SpectralKurtosis . fn next_frame¶
Compute the spectral kurtosis for a given FFT analysis. This function is to be used by FFTProcess if SpectralKurtosis is passed as the "process".
Nothing is returned. The kurtosis is stored internally and can be accessed with .kurtosis.
fn next_frame Signature
fn next_frame Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The input magnitudes as a List of Float64. |
| phases | List[Float64] |
— | The input phases as a List of Float64. |
struct SpectralKurtosis . fn from_mags¶
fn from_mags Signature
def from_mags(mags: List[Float64], sample_rate: Float64, min_freq: Float64 = Float64("20"), max_freq: Float64 = Float64("2.0E+4"), log_freq: Bool = False, power_mag: Bool = False) -> Float64
fn from_mags Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | — |
| sample_rate | Float64 |
— | — |
| min_freq | Float64 |
Float64("20") |
— |
| max_freq | Float64 |
Float64("2.0E+4") |
— |
| log_freq | Bool |
False |
— |
| power_mag | Bool |
False |
— |
fn from_mags Returns
: Float64
Static Method
This is a static method.
struct SpectralRolloff¶
Spectral Rolloff analysis.
Traits: AnyType, Copyable, FFTProcessable, GetFloat64Featurable, ImplicitlyDeletable, Movable
SpectralRolloff Functions¶
struct SpectralRolloff . fn init¶
Initialize the Spectral Rolloff analyzer.
fn init Signature
def __init__(out self, sr: Float64, min_freq: Float64 = Float64("20"), max_freq: Float64 = Float64("2.0E+4"), rolloff_target: Float64 = 95, log_freq: Bool = False, power_mag: Bool = False)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| sr | Float64 |
— | The sample rate from the MMMWorld. |
| min_freq | Float64 |
Float64("20") |
The minimum frequency to consider. |
| max_freq | Float64 |
Float64("2.0E+4") |
The maximum frequency to consider. |
| rolloff_target | Float64 |
95 |
Percentage of spectral energy for rolloff. |
| log_freq | Bool |
False |
Whether to use log-frequency (MIDI) bins. |
| power_mag | Bool |
False |
Whether to use power magnitudes (mags^2). |
fn init Returns
: Self
Static Method
This is a static method.
struct SpectralRolloff . fn get_features¶
Get the current spectral rolloff value.
fn get_features Signature
fn get_features Returns
: List[Float64]
The current spectral rolloff feature value as a List[Float64] (with only the one element).
struct SpectralRolloff . fn next_frame¶
Compute the spectral rolloff for a given FFT analysis. This function is to be used by FFTProcess if SpectralRolloff is passed as the "process".
Nothing is returned. The rolloff is stored internally and can be accessed with .rolloff.
fn next_frame Signature
fn next_frame Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The input magnitudes as a List of Float64. |
| phases | List[Float64] |
— | The input phases as a List of Float64. |
struct SpectralRolloff . fn from_mags¶
fn from_mags Signature
def from_mags(mags: List[Float64], sample_rate: Float64, min_freq: Float64 = Float64("20"), max_freq: Float64 = Float64("2.0E+4"), rolloff_target: Float64 = 95, log_freq: Bool = False, power_mag: Bool = False) -> Float64
fn from_mags Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | — |
| sample_rate | Float64 |
— | — |
| min_freq | Float64 |
Float64("20") |
— |
| max_freq | Float64 |
Float64("2.0E+4") |
— |
| rolloff_target | Float64 |
95 |
— |
| log_freq | Bool |
False |
— |
| power_mag | Bool |
False |
— |
fn from_mags Returns
: Float64
Static Method
This is a static method.
struct SpectralFlatness¶
Spectral Flatness analysis.
Traits: AnyType, Copyable, FFTProcessable, GetFloat64Featurable, ImplicitlyDeletable, Movable
SpectralFlatness Functions¶
struct SpectralFlatness . fn init¶
Initialize the Spectral Flatness analyzer.
fn init Signature
def __init__(out self, sr: Float64, min_freq: Float64 = Float64("20"), max_freq: Float64 = Float64("2.0E+4"), log_freq: Bool = False, power_mag: Bool = False)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| sr | Float64 |
— | The sample rate from the MMMWorld. |
| min_freq | Float64 |
Float64("20") |
The minimum frequency to consider. |
| max_freq | Float64 |
Float64("2.0E+4") |
The maximum frequency to consider. |
| log_freq | Bool |
False |
Whether to use log-frequency (MIDI) bins. |
| power_mag | Bool |
False |
Whether to use power magnitudes (mags^2). |
fn init Returns
: Self
Static Method
This is a static method.
struct SpectralFlatness . fn get_features¶
Get the current spectral flatness value (dB).
fn get_features Signature
fn get_features Returns
: List[Float64]
The current spectral flatness feature value as a List[Float64] (with only the one element).
struct SpectralFlatness . fn next_frame¶
Compute the spectral flatness for a given FFT analysis. This function is to be used by FFTProcess if SpectralFlatness is passed as the "process".
Nothing is returned. The flatness is stored internally and can be accessed with .flatness.
fn next_frame Signature
fn next_frame Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The input magnitudes as a List of Float64. |
| phases | List[Float64] |
— | The input phases as a List of Float64. |
struct SpectralFlatness . fn from_mags¶
fn from_mags Signature
def from_mags(mags: List[Float64], sample_rate: Float64, min_freq: Float64 = Float64("20"), max_freq: Float64 = Float64("2.0E+4"), log_freq: Bool = False, power_mag: Bool = False) -> Float64
fn from_mags Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | — |
| sample_rate | Float64 |
— | — |
| min_freq | Float64 |
Float64("20") |
— |
| max_freq | Float64 |
Float64("2.0E+4") |
— |
| log_freq | Bool |
False |
— |
| power_mag | Bool |
False |
— |
fn from_mags Returns
: Float64
Static Method
This is a static method.
struct SpectralCrest¶
Spectral Crest analysis.
Traits: AnyType, Copyable, FFTProcessable, GetFloat64Featurable, ImplicitlyDeletable, Movable
SpectralCrest Functions¶
struct SpectralCrest . fn init¶
Initialize the Spectral Crest analyzer.
fn init Signature
def __init__(out self, sr: Float64, min_freq: Float64 = Float64("20"), max_freq: Float64 = Float64("2.0E+4"), log_freq: Bool = False, power_mag: Bool = False)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| sr | Float64 |
— | The sample rate from the MMMWorld. |
| min_freq | Float64 |
Float64("20") |
The minimum frequency to consider. |
| max_freq | Float64 |
Float64("2.0E+4") |
The maximum frequency to consider. |
| log_freq | Bool |
False |
Whether to use log-frequency (MIDI) bins. |
| power_mag | Bool |
False |
Whether to use power magnitudes (mags^2). |
fn init Returns
: Self
Static Method
This is a static method.
struct SpectralCrest . fn get_features¶
Get the current spectral crest value (dB).
fn get_features Signature
fn get_features Returns
: List[Float64]
The current spectral crest feature value as a List[Float64] (with only the one element).
struct SpectralCrest . fn next_frame¶
Compute the spectral crest for a given FFT analysis. This function is to be used by FFTProcess if SpectralCrest is passed as the "process".
Nothing is returned. The crest is stored internally and can be accessed with .crest.
fn next_frame Signature
fn next_frame Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The input magnitudes as a List of Float64. |
| phases | List[Float64] |
— | The input phases as a List of Float64. |
struct SpectralCrest . fn from_mags¶
fn from_mags Signature
def from_mags(mags: List[Float64], sample_rate: Float64, min_freq: Float64 = Float64("20"), max_freq: Float64 = Float64("2.0E+4"), log_freq: Bool = False, power_mag: Bool = False) -> Float64
fn from_mags Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | — |
| sample_rate | Float64 |
— | — |
| min_freq | Float64 |
Float64("20") |
— |
| max_freq | Float64 |
Float64("2.0E+4") |
— |
| log_freq | Bool |
False |
— |
| power_mag | Bool |
False |
— |
fn from_mags Returns
: Float64
Static Method
This is a static method.
struct RMS¶
Root Mean Square (RMS) amplitude analysis.
Traits: AnyType, BufferedProcessable, Copyable, GetFloat64Featurable, ImplicitlyDeletable, Movable
RMS Functions¶
struct RMS . fn init¶
Initialize the RMS analyzer.
fn init Signature
fn init Returns
: Self
Static Method
This is a static method.
struct RMS . fn get_features¶
Get the current RMS value.
fn get_features Signature
fn get_features Returns
: List[Float64]
The current RMS feature value as a List[Float64] (with only the one element).
struct RMS . fn next_window¶
Compute the RMS for the given window of audio samples. This function is to be used with a BufferedProcess.
The computed RMS value is stored in self.rms.
fn next_window Signature
fn next_window Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| input | List[Float64] |
— | The input audio frame of samples. This List gets passed from BufferedProcess. |
struct RMS . fn from_window¶
Compute the RMS for the given window of audio samples. This static method is useful when there is an audio frame already available, perhaps as part of a custom struct that implements the BufferedProcessable trait.
fn from_window Signature
fn from_window Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| frame | List[Float64] |
— | The input audio frame of samples. |
fn from_window Returns
: Float64
Float64. The computed RMS value.
Static Method
This is a static method.
struct MelBands¶
Mel Bands analysis.
This implementation follows the approach used in the Librosa library.
The Mel scale is a perceptual scale of pitches that approximates the human ear's response more closely than the linear frequency scale. Mel Bands analysis involves mapping the FFT frequency bins to the Mel scale and computing the energy in each Mel band. This way the "magnitudes" of each Mel band represent a, roughly, equal amount of perceptual frequency space (unlike the FFT).
Because the definition of the mel scale is conditioned by a finite number of subjective psychoacoustical experiments, several implementations coexist in the audio signal processing literature. MMMAudio replicates the default of Librosa, which replicates the behavior of the well-established MATLAB "Auditory Toolbox" of Slaney (citation below). According to this implementation, the conversion from Hertz to mel is linear below 1 kHz and logarithmic above 1 kHz. Additionally, the weights are normalized such that the area under each mel filter is equal. Slaney mel filter "triangles" all have equal area (visualization), which helps to ensure that the energy in each mel band is comparable.
Slaney, M. Auditory Toolbox: A MATLAB Toolbox for Auditory Modeling Work. Technical Report, version 2, Interval Research Corporation, 1998.
Traits: AnyType, Copyable, FFTProcessable, GetFloat64Featurable, ImplicitlyDeletable, Movable
MelBands Functions¶
struct MelBands . fn init¶
Initialize the Mel Bands analyzer.
fn init Signature
def __init__(out self, sr: Float64, num_bands: Int = 40, min_freq: Float64 = 20, max_freq: Float64 = 2.0E+4, fft_size: Int = 1024, power: Float64 = 2)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| sr | Float64 |
— | The sample rate from the MMMWorld. |
| num_bands | Int |
40 |
The number of mel bands to compute. |
| min_freq | Float64 |
20 |
The minimum frequency (in Hz) to consider when computing the mel bands. |
| max_freq | Float64 |
2.0E+4 |
The maximum frequency (in Hz) to consider when computing the mel bands. |
| fft_size | Int |
1024 |
The size of the FFT being used to compute the mel bands. |
| power | Float64 |
2 |
Exponent applied to magnitudes before mel filtering (librosa default is 2.0 for power). |
fn init Returns
: Self
An initialized MelBands struct.
Static Method
This is a static method.
struct MelBands . fn get_features¶
Get the current mel band values.
fn get_features Signature
fn get_features Returns
: List[Float64]
The current mel band feature vector.
struct MelBands . fn next_frame¶
Compute the mel bands for a given FFT analysis. This function is to be used by FFTProcess if MelBands is passed as the "process".
Nothing is returned from this function, but the computed mel band values are stored in self.bands.
fn next_frame Signature
fn next_frame Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The input magnitudes as a List of Float64. |
| phases | List[Float64] |
— | The input phases as a List of Float64. |
struct MelBands . fn from_mags¶
Compute the mel bands for a given list of magnitudes. This function is useful when there is an FFT already computed, perhaps as part of a custom struct that implements the FFTProcessable trait.
fn from_mags Signature
fn from_mags Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The input magnitudes as a List of Float64. |
struct MelBands . fn mel_frequencies¶
Compute an array of acoustic frequencies tuned to the mel scale. This implementation is based on Librosa's eponymous function. For more information on mel frequencies space see the MelBands documentation.
fn mel_frequencies Signature
fn mel_frequencies Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| n_mels | Int |
128 |
The number of mel bands to generate. |
| fmin | Float64 |
0 |
The lowest frequency (in Hz). |
| fmax | Float64 |
2.0E+4 |
The highest frequency (in Hz). |
fn mel_frequencies Returns
: List[Float64]
A List of Float64 representing the center frequencies of each mel band.
Static Method
This is a static method.
struct MelBands . fn hz_to_mel¶
Convert Hz to Mels. This implementation is based on Librosa's eponymous function. For more information on mel frequencies space see the MelBands documentation.
fn hz_to_mel Signature
def hz_to_mel[num_chans: Int = 1](freq: SIMD[DType.float64, num_chans]) -> SIMD[DType.float64, num_chans]
fn hz_to_mel Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
fn hz_to_mel Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD[DType.float64, num_chans] |
— | The frequencies in Hz to convert. |
fn hz_to_mel Returns
: SIMD[DType.float64, num_chans]
The corresponding mel frequencies.
Static Method
This is a static method.
struct MelBands . fn mel_to_hz¶
Convert mel bin numbers to frequencies. This implementation is based on Librosa's eponymous function. For more information on mel frequencies space see the MelBands documentation.
fn mel_to_hz Signature
def mel_to_hz[num_chans: Int = 1](mel: SIMD[DType.float64, num_chans]) -> SIMD[DType.float64, num_chans]
fn mel_to_hz Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of SIMD channels in the mel vector. |
fn mel_to_hz Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mel | SIMD[DType.float64, num_chans] |
— | Mel values to convert to Hertz. |
fn mel_to_hz Returns
: SIMD[DType.float64, num_chans]
Frequencies in Hertz for the input mel values.
Static Method
This is a static method.
struct MFCC¶
Mel-Frequency Cepstral Coefficients (MFCC) analysis.
This implementation follows the approach used in the Librosa library.
Learn more about MFCCs on the FluCoMa learn page and with this interactive demonstration.
Traits: AnyType, Copyable, FFTProcessable, GetFloat64Featurable, ImplicitlyDeletable, Movable
MFCC Functions¶
struct MFCC . fn init¶
Initialize the MFCC analyzer.
fn init Signature
def __init__(out self, sr: Float64, num_coeffs: Int = 13, num_bands: Int = 40, min_freq: Float64 = 20, max_freq: Float64 = 2.0E+4, fft_size: Int = 1024)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| sr | Float64 |
— | The sample rate for the mel band computation. |
| num_coeffs | Int |
13 |
The number of MFCC coefficients to compute (including the 0th coefficient). |
| num_bands | Int |
40 |
The number of mel bands to use when computing the MFCCs. |
| min_freq | Float64 |
20 |
The minimum frequency (in Hz) to consider when computing the mel bands for the MFCCs. |
| max_freq | Float64 |
2.0E+4 |
The maximum frequency (in Hz) to consider when computing the mel bands for the MFCCs. |
| fft_size | Int |
1024 |
The size of the FFT being used to compute the mel bands for the MFCCs. |
fn init Returns
: Self
An initialized MFCC struct.
Static Method
This is a static method.
struct MFCC . fn get_features¶
Get the current MFCC values.
fn get_features Signature
fn get_features Returns
: List[Float64]
The current MFCC feature vector as a List[Float64].
struct MFCC . fn next_frame¶
Compute the MFCCs for a given FFT analysis. This function is to be used by FFTProcess if MFCC is passed as the "process".
Nothing is returned from this function, but the computed MFCC values are stored in self.coeffs.
fn next_frame Signature
fn next_frame Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The input magnitudes as a List of Float64. |
| phases | List[Float64] |
— | The input phases as a List of Float64. |
struct MFCC . fn from_mags¶
Compute the MFCCs for a given list of magnitudes. This function is useful when there is an FFT already computed, perhaps as part of a custom struct that implements the FFTProcessable trait.
Nothing is returned from this function, but the computed MFCC values are stored in self.coeffs.
fn from_mags Signature
fn from_mags Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The input magnitudes as a List of Float64. |
struct MFCC . fn from_mel_bands¶
Compute the MFCCs for a given list of mel band energies. This function is useful when there is a mel band analysis already computed, perhaps as part of a custom struct that implements the FFTProcessable trait.
Nothing is returned from this function, but the computed MFCC values are stored in self.coeffs.
fn from_mel_bands Signature
fn from_mel_bands Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mbands | List[Float64] |
— | The input mel band energies as a List of Float64. |
struct MFCC . fn buf_analysis¶
fn buf_analysis Signature
def buf_analysis(buf: Buffer, chan: Int = 0, start_frame: Int = 0, var num_frames: Int = -1, num_coeffs: Int = 13, num_bands: Int = 40, min_freq: Float64 = 20, max_freq: Float64 = 2.0E+4, fft_size: Int = 1024, hop_size: Int = 512) -> List[List[Float64]]
fn buf_analysis Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| buf | Buffer |
— | — |
| chan | Int |
0 |
— |
| start_frame | Int |
0 |
— |
| num_frames | Int |
-1 |
— |
| num_coeffs | Int |
13 |
— |
| num_bands | Int |
40 |
— |
| min_freq | Float64 |
20 |
— |
| max_freq | Float64 |
2.0E+4 |
— |
| fft_size | Int |
1024 |
— |
| hop_size | Int |
512 |
— |
fn buf_analysis Returns
: List[List[Float64]]
Raises
Static Method
This is a static method.
struct DCT¶
Compute the Discrete Cosine Transform (DCT).
Traits: AnyType, Copyable, ImplicitlyDeletable, Movable
DCT Functions¶
struct DCT . fn init¶
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| input_size | Int |
— | — |
| output_size | Int |
— | — |
fn init Returns
: Self
Static Method
This is a static method.
struct DCT . fn process¶
Compute the first output_size DCT-II coefficients for input.
Nothing is returned from this function, but the computed DCT coefficients are stored in the output List passed as an argument.
fn process Signature
fn process Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| input | List[Float64] |
— | Input vector of length input_size. |
| output | List[Float64] |
— | Output vector of length output_size. |
struct SpectralFlux¶
Spectral Flux analysis.
This implementation computes the squared difference between the magnitudes of the current frame and the previous frame, summed across all frequency bins.
Args:
num_mags: The number of magnitude bins in the input to expect. This is typically the FFT size divided by 2, but could also be the number of mel bands or another spectral summary that produces a list of values.
positive_only: Whether to only consider positive differences (increases in energy) when computing the spectral flux. If `False`, spectral flux is the average of squared differences between the magnitudes. If `True`, spectral flux is the average of (non-squared to match FluCoMa) differences between the magnitudes, but negative differences are set to 0. Using `positive_only=True` is a common approach when using spectral flux for onset detection, as onsets are typically characterized by increases in energy.
Traits: AnyType, Copyable, FFTProcessable, GetFloat64Featurable, ImplicitlyDeletable, Movable
SpectralFlux Functions¶
struct SpectralFlux . fn init¶
Initialize the Spectral Flux analyzer.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| num_mags | Int |
— | The number of magnitude bins in the input to expect. This is typically the FFT size divided by 2, but could also be the number of mel bands or another spectral summary that produces a list of values. |
| positive_only | Bool |
False |
Whether to only consider positive differences (increases in energy) when computing the spectral flux. If False, spectral flux is the average of squared differences between the magnitudes. If True, spectral flux is the average of (non-squared to match FluCoMa) differences between the magnitudes, but negative differences are set to 0. Using positive_only=True is a common approach when using spectral flux for onset detection, as onsets are typically characterized by increases in energy. |
fn init Returns
: Self
Static Method
This is a static method.
struct SpectralFlux . fn next_frame¶
Compute the spectral flux onset value for a given FFT analysis. This function is to be used by FFTProcess if SpectralFluxOnsets is passed as the "process".
Nothing is returned from this function, but the computed spectral flux value is stored in self.flux.
fn next_frame Signature
fn next_frame Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The input magnitudes as a List of Float64. |
| phases | List[Float64] |
— | The input phases as a List of Float64. |
struct SpectralFlux . fn get_features¶
Get the current spectral flux value.
fn get_features Signature
fn get_features Returns
: List[Float64]
The current spectral flux feature value as a List[Float64] (with only the one element).
struct SpectralFlux . fn from_mags¶
Compute the spectral flux onset value for a given list of magnitudes. This function is useful when there is an FFT already computed, perhaps as part of a custom struct that implements the FFTProcessable trait.
Nothing is returned from this function, but the computed spectral flux value is stored in self.flux.
fn from_mags Signature
fn from_mags Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The input magnitudes as a List of Float64. |
fn from_mags Returns
: Float64
The computed spectral flux value.
struct SpectralFluxOnsets¶
Spectral Flux Onset analysis.
Traits: AnyType, Copyable, GetBoolFeaturable, ImplicitlyDeletable, Movable
SpectralFluxOnsets Functions¶
struct SpectralFluxOnsets . fn init¶
fn init Signature
def __init__(out self, world: UnsafePointer[MMMWorld, MutUntrackedOrigin], window_size: Int = 1024, hop_size: Int = 512, filter_size: Int = 5)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer[MMMWorld, MutUntrackedOrigin] |
— | — |
| window_size | Int |
1024 |
— |
| hop_size | Int |
512 |
— |
| filter_size | Int |
5 |
— |
fn init Returns
: Self
Static Method
This is a static method.
struct SpectralFluxOnsets . fn get_features¶
struct SpectralFluxOnsets . fn next¶
fn next Signature
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| input | Float64 |
— | — |
fn next Returns
: Bool
struct SpectralFluxOnsets . fn buf_analysis¶
fn buf_analysis Signature
def buf_analysis(world: UnsafePointer[MMMWorld, MutUntrackedOrigin], buf: Buffer, chan: Int = 0, start_frame: Int = 0, var num_frames: Int = -1, thresh: Float64 = 0.5, min_slice_len: Float64 = 1, window_size: Int = 1024, hop_size: Int = 512, filter_size: Int = 5) -> List[Int]
fn buf_analysis Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer[MMMWorld, MutUntrackedOrigin] |
— | — |
| buf | Buffer |
— | — |
| chan | Int |
0 |
— |
| start_frame | Int |
0 |
— |
| num_frames | Int |
-1 |
— |
| thresh | Float64 |
0.5 |
— |
| min_slice_len | Float64 |
1 |
— |
| window_size | Int |
1024 |
— |
| hop_size | Int |
512 |
— |
| filter_size | Int |
5 |
— |
fn buf_analysis Returns
: List[Int]
Raises
Static Method
This is a static method.
struct TopNFreqs¶
An FFTProcessable that identifies the top N frequency peaks in each FFT frame and provides their frequencies and amplitudes as output.
Args:
sample_rate: The sample rate of the audio signal.
window_size: The size of the FFT window. This determines the frequency resolution and the maximum number of frequency bins (window_size // 2 + 1).
num_peaks: The number of top peaks to identify in each FFT frame.
sort_by_freq: Whether to sort the output freq, amp pairs by frequency (True) or by amplitude (False).
thresh: The minimum amplitude threshold (in dB) for a peak to be considered. Peaks below this threshold will be ignored.
Traits: AnyType, Copyable, FFTProcessable, GetFloat64Featurable, ImplicitlyDeletable, Movable
TopNFreqs Functions¶
struct TopNFreqs . fn init¶
Initialize the TopNFreqs process.
fn init Signature
def __init__(out self, sample_rate: Float64, window_size: Int, num_peaks: Int = 5, sort_by_freq: Bool = True, thresh: Float64 = -30)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| sample_rate | Float64 |
— | The sample rate of the audio signal. |
| window_size | Int |
— | The size of the FFT window. This determines the frequency resolution and the maximum number of frequency bins (window_size // 2 + 1). |
| num_peaks | Int |
5 |
The number of top peaks to identify in each FFT frame. |
| sort_by_freq | Bool |
True |
Whether to sort the output freq, amp pairs by frequency (True) or by amplitude (False). |
| thresh | Float64 |
-30 |
The minimum amplitude threshold (in dB) for a peak to be considered. Peaks below this threshold will be ignored. |
fn init Returns
: Self
Static Method
This is a static method.
struct TopNFreqs . fn get_features¶
fn get_features Signature
fn get_features Returns
: List[Float64]
struct TopNFreqs . fn get_features_ptr¶
Get a pointer to the current List of freq, amp pairs.
fn get_features_ptr Signature
def get_features_ptr(self) -> Pointer[List[Tuple[Float64, Float64]], origin_of(self.freq_amp_pairs)]
fn get_features_ptr Returns
: Pointer[List[Tuple[Float64, Float64]], origin_of(self.freq_amp_pairs)]
A pointer to the current frequency and amplitude pairs.
struct TopNFreqs . fn get_messages¶
struct TopNFreqs . fn next_frame¶
fn next_frame Signature
fn next_frame Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | — |
| phases | List[Float64] |
— | — |
struct TopNFreqs . fn sort_pairs_by_freq¶
struct Chroma¶
A struct for computing chroma features.
Chroma features are a representation of the spectral content of an audio signal in terms of musical pitch classes. It can indicate how much of each pitch class is present in the audio signal.
This implementation imitates the Librosa library's chroma_stft.
Traits: AnyType, Copyable, FFTProcessable, GetFloat64Featurable, ImplicitlyDeletable, Movable
Chroma Functions¶
struct Chroma . fn init¶
Initialize the Chroma struct.
fn init Signature
def __init__(out self, sample_rate: Float64, window_size: Int, n_chroma: Int = 12, tuning: Float64 = 0, norm: Float64 = inf[DType.float64](), power: Float64 = 2, ctroct: Float64 = 5, octwidth: Float64 = 2, base_c: Bool = True)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| sample_rate | Float64 |
— | The sample rate of the audio signal. |
| window_size | Int |
— | The size of the FFT window. |
| n_chroma | Int |
12 |
The number of chroma bins (divisions per octave). |
| tuning | Float64 |
0 |
The tuning deviation of the reference pitch as a fraction of a division per octave (when n_chroma = 12, these are semitones). |
| norm | Float64 |
inf[DType.float64]() |
The normalization to apply to the chroma values. If inf the largest absolute chroma becomes 1 and everything is normalized to that. If 1, the sum of the chroma values is 1. If 0, no normalization is applied. |
| power | Float64 |
2 |
The power to which to raise the magnitude values before computing the chroma. |
| ctroct | Float64 |
5 |
Center of the octave weighting, measured in octaves above A0 = 27.5 Hz. FFT bins near this octave contribute most strongly to the chroma. For example, 4.0 centers the weighting near A4 (440 Hz) and 5.0 near A5 (880 Hz). Lower values emphasize lower-frequency octaves; higher values emphasize higher-frequency octaves. |
| octwidth | Float64 |
2 |
Width of the Gaussian octave weighting, in octaves. Smaller values give stronger octave focus; larger values approach flat weighting. 0 disables the octave weighting. |
| base_c | Bool |
True |
Whether to use C as the base pitch (True) or A as the base pitch (False). |
fn init Returns
: Self
Static Method
This is a static method.
struct Chroma . fn get_features¶
fn get_features Signature
fn get_features Returns
: List[Float64]
struct Chroma . fn from_mags¶
Compute the chroma features from the magnitude values.
Nothing is returned. The chroma values are updated internally and can be accessed via .chroma.
fn from_mags Signature
fn from_mags Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The magnitude values of the current FFT frame. |
struct Chroma . fn next_frame¶
Process the next FFT frame.
Nothing is returned. The chroma values are updated internally and can be accessed via .chroma.
fn next_frame Signature
fn next_frame Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| mags | List[Float64] |
— | The magnitude values of the current FFT frame. |
| phases | List[Float64] |
— | The phase values of the current FFT frame. |
Documentation generated with mojo doc from Mojo version 1.0.0b2