Env
Envelope generator module.
This module provides an envelope generator class that can create complex envelopes with multiple segments, curves, and looping capabilities.
struct EnvParams¶
Parameters for the Env class.
This struct holds the parameters for the envelope generator. It
is not required to use the Env struct, but it might be convenient.
Elements:
values: List of envelope values at each breakpoint.
times: List of durations (in seconds) for each segment between adjacent breakpoints. This List should be one element shorter than the values List.
curves: List of curve shapes for each segment. Positive values for convex "exponential" curves, negative for concave "logarithmic" curves. (if the output of the envelope is negative, the curve will be inverted).
loop: Bool to indicate if the envelope should loop.
time_warp: Time warp factor to speed up or slow down the envelope. Default is 1.0 meaning no warp. A value of 2.0 will make the envelop take twice as long to complete. A value of 0.5 will make the envelope take half as long to complete.
Traits: AnyType, Copyable, ImplicitlyDestructible, Movable, Representable
EnvParams Functions¶
struct EnvParams . fn init¶
Initialize EnvParams.
For information on the arguments, see the documentation of the Env::next() method that takes each parameter individually.
fn init Signature
__init__(out self, values: List[Float64] = List[Float64](0, 1, 0, Tuple[]()), times: List[Float64] = List[Float64](1, 1, Tuple[]()), curves: List[Float64] = List[Float64](1, Tuple[]()), loop: Bool = False, time_warp: Float64 = 1)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| values | List |
List[Float64](0, 1, 0, Tuple[]()) |
— |
| times | List |
List[Float64](1, 1, Tuple[]()) |
— |
| curves | List |
List[Float64](1, Tuple[]()) |
— |
| loop | Bool |
False |
— |
| time_warp | Float64 |
1 |
— |
fn init Returns
: Self
Static Method
This is a static method.
struct Env¶
Envelope generator with an arbitrary number of segments.
Traits: AnyType, Copyable, ImplicitlyDestructible, Movable, Representable
Env Functions¶
struct Env . fn init¶
Initialize the Env2 struct - with internal params.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | Pointer to the MMMWorld. |
fn init Returns
: Self
Static Method
This is a static method.
struct Env . fn next¶
Generate the next envelope value. Uses the internal params struct for envelope parameters. See EnvParams for more details on the parameters. Args: trig: Trigger to start the envelope. Returns: The next envelope value.
fn next Signature
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| trig | Bool |
True |
— |
fn next Returns
: Float64
struct Env . fn next¶
Generate the next envelope value with a provided phase rather than using the internal phasor. Uses the internal params struct for envelope parameters. See EnvParams for more details on the parameters. Args: trig: Trigger to start the envelope. phase: The current phase of the envelope, between 0 and 1. This allows the user to control the progression of the envelope externally rather than using the internal phasor. Returns: The envelope value at the specified phase.
fn next Signature
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| trig | Bool |
— | — |
| phase | Float64 |
— | — |
fn next Returns
: Float64
struct Env . fn get_phase¶
Get the current phase of the envelope (between 0 and 1).
fn get_phase Signature
fn get_phase Returns
: Float64
struct ASREnv¶
Simple ASR envelope generator.
Traits: AnyType, Copyable, ImplicitlyDestructible, Movable
ASREnv Functions¶
struct ASREnv . fn init¶
Initialize the ASREnv struct.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | Pointer to the MMMWorld. |
fn init Returns
: Self
Static Method
This is a static method.
struct ASREnv . fn next¶
Simple ASR envelope generator.
fn next Signature
next(mut self, attack: Float64, sustain: Float64, release: Float64, gate: Bool, curve: SIMD[DType.float64, 2] = 1) -> Float64
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| attack | Float64 |
— | (Float64): Attack time in seconds. |
| sustain | Float64 |
— | (Float64): Sustain level (0 to 1). |
| release | Float64 |
— | (Float64): Release time in seconds. |
| gate | Bool |
— | (Bool): Gate signal (True or False). |
| curve | SIMD |
1 |
(MFloat[2]): Can pass a Float64 for equivalent curve on rise and fall or MFloat[2] for different rise and fall curve. Positive values for convex "exponential" curves, negative for concave "logarithmic" curves. |
fn next Returns
: Float64
struct Compressor¶
Compressor from Nathan Ho's Negative Compression web post.
Params: num_chans: Number of channels of input/output.
Traits: AnyType, Copyable, ImplicitlyDestructible, Movable
Compressor Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
— | — |
Compressor Functions¶
struct Compressor . fn init¶
Initialize the Compressor struct.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | Pointer to the MMMWorld. |
fn init Returns
: Self
Static Method
This is a static method.
struct Compressor . fn next¶
Returns the compressed signal, which is the original signal multiplied by the negative compression gain.
fn next Signature
next(mut self, input: SIMD[DType.float64, num_chans], threshold: Float64 = -20, ratio: Float64 = 4, attack: Float64 = 0.01, release: Float64 = 0.10000000000000001, knee_width: Float64 = 0) -> SIMD[DType.float64, num_chans]
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| input | SIMD |
— | MFloat[Self.num_chans] audio signal to be compressed. |
| threshold | Float64 |
-20 |
MFloat[1] threshold in dBFS above which compression occurs. |
| ratio | Float64 |
4 |
MFloat[1] compression ratio. For example, a ratio of 4.0 means that for every 4 dB the input signal exceeds the threshold, the output will only exceed the threshold by 1 dB. |
| attack | Float64 |
0.01 |
MFloat[1] attack time in seconds for the compressor's envelope follower. |
| release | Float64 |
0.10000000000000001 |
MFloat[1] release time in seconds for the compressor's envelope follower. |
| knee_width | Float64 |
0 |
MFloat[1] width of the knee in dB. A value of 0 means a hard knee, while higher values create a softer knee N/2 decibels around the threshold. |
fn next Returns
: SIMD
MFloat[Self.num_chans] compressed audio signal, which is the original signal multiplied by the negative compression gain.
struct Compressor . fn next_neg_comp¶
Returns the negative compression gain (in amplitude units, not dB) for the input signal, which can be multiplied with the original signal or used as a sidechain.
fn next_neg_comp Signature
next_neg_comp(mut self, input: SIMD[DType.float64, num_chans], threshold: Float64 = -20, ratio: Float64 = 4, attack: Float64 = 0.01, release: Float64 = 0.10000000000000001, knee_width: Float64 = 0) -> Float64
fn next_neg_comp Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| input | SIMD |
— | MFloat[Self.num_chans] audio signal to be compressed. |
| threshold | Float64 |
-20 |
MFloat[1] threshold in dBFS above which compression occurs. |
| ratio | Float64 |
4 |
MFloat[1] compression ratio. For example, a ratio of 4.0 means that for every 4 dB the input signal exceeds the threshold, the output will only exceed the threshold by 1 dB. |
| attack | Float64 |
0.01 |
MFloat[1] attack time in seconds for the compressor's envelope follower. |
| release | Float64 |
0.10000000000000001 |
MFloat[1] release time in seconds for the compressor's envelope follower. |
| knee_width | Float64 |
0 |
MFloat[1] width of the knee in dB. A value of 0 means a hard knee, while higher values create a softer knee N/2 decibels around the threshold. |
fn next_neg_comp Returns
: Float64
MFloat[1] negative compression gain in amplitude units, which can be multiplied with the original signal or used as a sidechain.
(Functions that are not associated with a Struct)
fn win_env¶
Signature
win_env[window_type: Int, interp: Int = Interp.none](world: UnsafePointer[MMMWorld, MutExternalOrigin], win_phase: Float64) -> Float64
Parameters
| Name | Type | Description |
|---|---|---|
| window_type | Int |
— |
| interp | Int |
— |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | — |
| win_phase | Float64 |
— | — |
Returns
Type: Float64
fn min_env¶
Simple envelope.
Envelope that rises linearly from 0 to 1 over rampdur seconds, stays at 1 until totaldur - rampdur,
then falls linearly back to 0 over the final rampdur seconds. This envelope isn't "triggered," instead
the user provides the current phase between 0 (beginning) and 1 (end) of the envelope.
Signature
min_env[N: Int = 1](phase: SIMD[DType.float64, N] = 0.01, totaldur: SIMD[DType.float64, N] = 0.10000000000000001, rampdur: SIMD[DType.float64, N] = 0.001) -> SIMD[DType.float64, N]
Parameters
| Name | Type | Description |
|---|---|---|
| N | Int |
— |
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| phase | SIMD |
0.01 |
Current env position between 0 (beginning) and 1 (end). |
| totaldur | SIMD |
0.10000000000000001 |
Total duration of the envelope. |
| rampdur | SIMD |
0.001 |
Duration of the rise and fall segments that occur at the beginning and end of the envelope. |
Returns
Type: SIMD
Envelope value at the current ramp position.
Documentation generated with mojo doc from Mojo version 0.26.1.0