Utilities
struct Changed¶
Detect changes in a Bool value.
Traits: AnyType, Copyable, Movable, Representable, UnknownDestructibility
Changed Functions¶
struct Changed . fn init¶
Initialize the Changed struct.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| initial | Bool |
False |
The initial value to compare against. |
fn init Returns
: Self
Static Method
This is a static method.
struct Changed . fn next¶
Check if the value has changed.
fn next Signature
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| val | Bool |
— | The current value to check. |
fn next Returns
: Bool
True if the value has changed since the last check, False otherwise.
(Functions that are not associated with a Struct)
fn dbamp¶
Converts decibel values to amplitude.
amplitude = 10^(dB/20).
Signature
Parameters
| Name | Type | Description |
|---|---|---|
| width | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| db | SIMD |
— | The decibel values to convert. |
Returns
Type: SIMD
The corresponding amplitude values.
fn ampdb¶
Converts amplitude values to decibels.
dB = 20 * log10(amplitude).
Signature
Parameters
| Name | Type | Description |
|---|---|---|
| width | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| amp | SIMD |
— | The amplitude values to convert. |
Returns
Type: SIMD
The corresponding decibel values.
fn select¶
Selects a value from a SIMD vector based on a floating-point index and using linear interpolation.
Signature
Parameters
| Name | Type | Description |
|---|---|---|
| num_chans | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| index | Float64 |
— | The floating-point index to select. |
| vals | SIMD |
— | The SIMD vector containing the values. |
Returns
Type: Float64
The selected value.
fn select¶
Selects a SIMD vector from a List of SIMD vectors based on a floating-point index using linear interpolation.
Signature
select[num_chans: Int](index: Float64, vals: List[SIMD[DType.float64, num_chans]]) -> SIMD[DType.float64, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| num_chans | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| index | Float64 |
— | The floating-point index to select. |
| vals | List |
— | The List of SIMD vectors containing the values. |
Returns
Type: SIMD
The selected value.
fn linlin¶
Maps samples from one range to another range linearly.
Samples outside the input range are clamped to the corresponding output boundaries.
Signature
linlin[dtype: DType, num_chans: Int, //](input: SIMD[dtype, num_chans], in_min: SIMD[dtype, num_chans] = 0, in_max: SIMD[dtype, num_chans] = 1, out_min: SIMD[dtype, num_chans] = 0, out_max: SIMD[dtype, num_chans] = 1) -> SIMD[dtype, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| dtype | DType |
The data type of the SIMD vector. This parameter is inferred by the values passed to the function. |
| num_chans | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| input | SIMD |
— | The samples to map. |
| in_min | SIMD |
0 |
The minimum of the input range. |
| in_max | SIMD |
1 |
The maximum of the input range. |
| out_min | SIMD |
0 |
The minimum of the output range. |
| out_max | SIMD |
1 |
The maximum of the output range. |
Returns
Type: SIMD
fn linexp¶
Maps samples from one linear range to another exponential range.
Signature
linexp[num_chans: Int, //](input: SIMD[DType.float64, num_chans], in_min: SIMD[DType.float64, num_chans], in_max: SIMD[DType.float64, num_chans], out_min: SIMD[DType.float64, num_chans], out_max: SIMD[DType.float64, num_chans]) -> SIMD[DType.float64, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| num_chans | Int |
Size of the SIMD vector - defaults to 1. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| input | SIMD |
— | The samples to map. |
| in_min | SIMD |
— | The minimum of the input range. |
| in_max | SIMD |
— | The maximum of the input range. |
| out_min | SIMD |
— | The minimum of the output range (must be > 0). |
| out_max | SIMD |
— | The maximum of the output range (must be > 0). |
Returns
Type: SIMD
The exponentially mapped samples in the output range.
fn lincurve¶
Maps samples from one linear range to another curved range.
Signature
lincurve[num_chans: Int, //](input: SIMD[DType.float64, num_chans], in_min: SIMD[DType.float64, num_chans], in_max: SIMD[DType.float64, num_chans], out_min: SIMD[DType.float64, num_chans], out_max: SIMD[DType.float64, num_chans], curve: SIMD[DType.float64, num_chans]) -> SIMD[DType.float64, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| num_chans | Int |
Size of the SIMD vector - defaults to 1. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| input | SIMD |
— | The samples to map. |
| in_min | SIMD |
— | The minimum of the input range. |
| in_max | SIMD |
— | The maximum of the input range. |
| out_min | SIMD |
— | The minimum of the output range (must be > 0). |
| out_max | SIMD |
— | The maximum of the output range (must be > 0). |
| curve | SIMD |
— | The curve factor. Positive values create an exponential-like curve, negative values create a logarithmic-like curve, and zero results in a linear mapping. |
Returns
Type: SIMD
The curved mapped samples in the output range.
fn clip¶
Clips each element in the SIMD vector to the specified range.
Signature
clip[dtype: DType, num_chans: Int, //](x: SIMD[dtype, num_chans], lo: SIMD[dtype, num_chans], hi: SIMD[dtype, num_chans]) -> SIMD[dtype, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| dtype | DType |
The data type of the SIMD vector. This parameter is inferred by the values passed to the function. |
| num_chans | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| x | SIMD |
— | The SIMD vector to clip. Each element will be clipped individually. |
| lo | SIMD |
— | The minimum possible value. |
| hi | SIMD |
— | The maximum possible value. |
Returns
Type: SIMD
The clipped SIMD vector.
fn wrap¶
Wraps a sample around a specified range.
The wrapped sample within the range [min_val, max_val). This function uses modulus arithmetic so the output can never equal max_val. Returns the sample if min_val >= max_val.
Signature
wrap[dtype: DType, num_chans: Int, //](input: SIMD[dtype, num_chans], min_val: SIMD[dtype, num_chans], max_val: SIMD[dtype, num_chans]) -> SIMD[dtype, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| dtype | DType |
The data type of the SIMD vector. This parameter is inferred by the values passed to the function. |
| num_chans | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| input | SIMD |
— | The sample to wrap. |
| min_val | SIMD |
— | The minimum of the range. |
| max_val | SIMD |
— | The maximum of the range. |
Returns
Type: SIMD
The wrapped value.
fn quadratic_interp¶
Performs quadratic interpolation between three points.
Signature
quadratic_interp[dtype: DType, num_chans: Int, //](y0: SIMD[dtype, num_chans], y1: SIMD[dtype, num_chans], y2: SIMD[dtype, num_chans], x: SIMD[dtype, num_chans]) -> SIMD[dtype, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| dtype | DType |
The data type of the SIMD vector. This parameter is inferred by the values passed to the function. |
| num_chans | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| y0 | SIMD |
— | The sample at position 0. |
| y1 | SIMD |
— | The sample at position 1. |
| y2 | SIMD |
— | The sample at position 2. |
| x | SIMD |
— | The interpolation position (fractional part between 0 and 1). |
Returns
Type: SIMD
The interpolated sample at position x.
fn cubic_interp¶
Performs cubic interpolation.
Cubic Intepolation equation from The Audio Programming Book by Richard Boulanger and Victor Lazzarini. pg. 400
Signature
cubic_interp[dtype: DType, num_chans: Int, //](p0: SIMD[dtype, num_chans], p1: SIMD[dtype, num_chans], p2: SIMD[dtype, num_chans], p3: SIMD[dtype, num_chans], t: SIMD[dtype, num_chans]) -> SIMD[dtype, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| dtype | DType |
The data type of the SIMD vector. This parameter is inferred by the values passed to the function. |
| num_chans | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| p0 | SIMD |
— | Point to the left of p1. |
| p1 | SIMD |
— | Point to the left of the float t. |
| p2 | SIMD |
— | Point to the right of the float t. |
| p3 | SIMD |
— | Point to the right of p2. |
| t | SIMD |
— | Interpolation parameter (fractional part between p1 and p2). |
Returns
Type: SIMD
Interpolated sample.
fn lagrange4¶
Perform Lagrange interpolation for 4th order case (from JOS Faust Model). This is extrapolated from the JOS Faust filter model.
Signature
lagrange4[dtype: DType, num_chans: Int, //](sample0: SIMD[dtype, num_chans], sample1: SIMD[dtype, num_chans], sample2: SIMD[dtype, num_chans], sample3: SIMD[dtype, num_chans], sample4: SIMD[dtype, num_chans], frac: SIMD[dtype, num_chans]) -> SIMD[dtype, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| dtype | DType |
The data type of the SIMD vector. This parameter is inferred by the values passed to the function. |
| num_chans | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| sample0 | SIMD |
— | The first sample. |
| sample1 | SIMD |
— | The second sample. |
| sample2 | SIMD |
— | The third sample. |
| sample3 | SIMD |
— | The fourth sample. |
| sample4 | SIMD |
— | The fifth sample. |
| frac | SIMD |
— | The fractional part between sample0 and sample1. |
Returns
Type: SIMD
The interpolated sample.
fn linear_interp¶
Performs linear interpolation between two points.
Signature
linear_interp[dtype: DType, num_chans: Int, //](p0: SIMD[dtype, num_chans], p1: SIMD[dtype, num_chans], t: SIMD[dtype, num_chans]) -> SIMD[dtype, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| dtype | DType |
The data type of the SIMD vector. This parameter is inferred by the values passed to the function. |
| num_chans | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| p0 | SIMD |
— | The starting point. |
| p1 | SIMD |
— | The ending point. |
| t | SIMD |
— | The interpolation parameter (fractional part between p0 and p1). |
Returns
Type: SIMD
The interpolated sample.
fn midicps¶
Convert MIDI note numbers to frequencies in Hz.
(cps = "cycles per second")
Conversion happens based on equating the reference_midi_note to the reference_frequency.
For standard tuning, leave the defaults of MIDI note 69 (A4) and 440.0 Hz.
Signature
midicps[num_chans: Int, //](midi_note_number: SIMD[DType.float64, num_chans], reference_midi_note: Float64 = 69, reference_frequency: Float64 = 440) -> SIMD[DType.float64, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| num_chans | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| midi_note_number | SIMD |
— | The MIDI note number(s) to convert. |
| reference_midi_note | Float64 |
69 |
The reference MIDI note number. |
| reference_frequency | Float64 |
440 |
The frequency of the reference MIDI note. |
Returns
Type: SIMD
Frequency in Hz.
fn cpsmidi¶
Convert frequencies in Hz to MIDI note numbers.
(cps = "cycles per second")
Conversion happens based on equating the reference_midi_note to the reference_frequency.
For standard tuning, leave the defaults of MIDI note 69 (A4) and 440.0 Hz.
Signature
cpsmidi[num_chans: Int, //](freq: SIMD[DType.float64, num_chans], reference_midi_note: Float64 = 69, reference_frequency: Float64 = 440) -> SIMD[DType.float64, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| num_chans | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD |
— | The frequency in Hz to convert. |
| reference_midi_note | Float64 |
69 |
The reference MIDI note number. |
| reference_frequency | Float64 |
440 |
The frequency of the reference MIDI note. |
Returns
Type: SIMD
The corresponding MIDI note number.
fn sanitize¶
Sanitizes a SIMD float64 vector by zeroing out elements that are too large, too small, or NaN.
Signature
sanitize[num_chans: Int, //](mut x: SIMD[DType.float64, num_chans]) -> SIMD[DType.float64, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| num_chans | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| x | SIMD |
— | The SIMD float64 vector to sanitize. |
Returns
Type: SIMD
The sanitized SIMD float64 vector.
fn random_uni_float64¶
Generates a random float64 sample from a uniform distribution.
Signature
random_uni_float64[num_chans: Int = 1](min: SIMD[DType.float64, num_chans], max: SIMD[DType.float64, num_chans]) -> SIMD[DType.float64, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| num_chans | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| min | SIMD |
— | The minimum sample (inclusive). |
| max | SIMD |
— | The maximum sample (inclusive). |
Returns
Type: SIMD
fn random_exp_float64¶
Generates a random float64 sample from an exponential distribution.
Signature
random_exp_float64[num_chans: Int, //](min: SIMD[DType.float64, num_chans], max: SIMD[DType.float64, num_chans]) -> SIMD[DType.float64, num_chans]
Parameters
| Name | Type | Description |
|---|---|---|
| num_chans | Int |
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| min | SIMD |
— | The minimum sample (inclusive). |
| max | SIMD |
— | The maximum sample (inclusive). |
Returns
Type: SIMD
fn sign¶
Returns the sign of x: -1 if negative, 1 if positive, and 0 if zero.
Signature
Parameters
| Name | Type | Description |
|---|---|---|
| num_chans | Int |
Number of channels in the SIMD vector. This parameter is inferred by the values passed to the function. |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| x | SIMD |
— | The input SIMD vector. |
Returns
Type: SIMD
A SIMD vector containing the sign of each element in x.
Documentation generated with mojo doc from Mojo version 0.25.6.1