Osc
struct Phasor¶
Phasor Oscillator.
An oscillator that generates a ramp waveform from 0.0 to 1.0. The phasor is the root of all oscillators in MMMAudio.
The Phasor can act as a simple phasor with the .next() function.
However, it can also be an impulse with next_impulse() and a boolean impulse with next_bool().
Traits: AnyType, Copyable, Movable, Representable, UnknownDestructibility
Phasor Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of channels. |
| os_index | Int |
0 |
Oversampling index (0 = no oversampling, 1 = 2x, up to 4 = 16x). Phasor does not downsample its output, so oversampling is only useful when used as part of other oversampled oscillators. |
Phasor Functions¶
struct Phasor . fn init¶
Args: world: Pointer to the MMMWorld instance.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | — |
fn init Returns
: Self
Static Method
This is a static method.
struct Phasor . fn next¶
Creates the next sample of the phasor output based on the inputs.
fn next Signature
next(mut self: Phasor[num_chans, os_index], freq: SIMD[DType.float64, num_chans] = 100, phase_offset: SIMD[DType.float64, num_chans] = 0, trig: SIMD[DType.bool, num_chans] = SIMD[DType.bool, num_chans](True)) -> SIMD[DType.float64, num_chans]
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD |
100 |
Frequency of the phasor in Hz. |
| phase_offset | SIMD |
0 |
Offsets the phase of the oscillator. |
| trig | SIMD |
SIMD[DType.bool, num_chans](True) |
Trigger signal to reset the phase when switching from False to True. |
fn next Returns
: SIMD
The next sample of the phasor output.
struct Phasor . fn next_bool¶
Increments the phasor and returns a boolean impulse when the phase wraps around from 1.0 to 0.0.
fn next_bool Signature
next_bool(mut self, freq: SIMD[DType.float64, num_chans] = 100, phase_offset: SIMD[DType.float64, num_chans] = 0, trig: SIMD[DType.bool, num_chans] = SIMD[DType.bool, num_chans](True)) -> SIMD[DType.bool, num_chans]
fn next_bool Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD |
100 |
Frequency of the phasor in Hz (default is 100.0). |
| phase_offset | SIMD |
0 |
Offsets the phase of the oscillator (default is 0.0). |
| trig | SIMD |
SIMD[DType.bool, num_chans](True) |
Trigger signal to reset the phase when switching from False to True (default is all True, which resets the phasor on the first sample). |
fn next_bool Returns
: SIMD
A boolean SIMD indicating True when the impulse occurs.
struct Phasor . fn next_impulse¶
Generates an impulse waveform where the output is 1.0 for one sample when the phase wraps around from 1.0 to 0.0, and 0.0 otherwise.
fn next_impulse Signature
next_impulse(mut self, freq: SIMD[DType.float64, num_chans] = 100, phase_offset: SIMD[DType.float64, num_chans] = 0, trig: SIMD[DType.bool, num_chans] = SIMD[DType.bool, num_chans](True)) -> SIMD[DType.float64, num_chans]
fn next_impulse Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD |
100 |
Frequency of the phasor in Hz (default is 100.0). |
| phase_offset | SIMD |
0 |
Offsets the phase of the oscillator (default is 0.0). |
| trig | SIMD |
SIMD[DType.bool, num_chans](True) |
Trigger signal to reset the phase when switching from False to True (default is all True, which resets the phasor on the first sample). |
fn next_impulse Returns
: SIMD
The next impulse sample as a Float64. 1.0 when the impulse occurs, 0.0 otherwise.
struct Impulse¶
Impulse Oscillator.
An oscillator that outputs a 1.0 or True for one sample when the phase wraps around from 1.0 to 0.0.
Impulse is essentially a wrapper around the Phasor oscillator that provides impulse-specific methods.
Traits: AnyType, Copyable, Movable, UnknownDestructibility
Impulse Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of channels (default is 1). |
| os_index | Int |
0 |
Oversampling index (0 = no oversampling, 1 = 2x, etc.; default is 0). |
Impulse Functions¶
struct Impulse . fn init¶
Args: world: Pointer to the MMMWorld instance.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | — |
fn init Returns
: Self
Static Method
This is a static method.
struct Impulse . fn next_bool¶
Increments the phasor and returns a boolean impulse when the phase wraps around from 1.0 to 0.0.
fn next_bool Signature
next_bool(mut self, freq: SIMD[DType.float64, num_chans] = 100, phase_offset: SIMD[DType.float64, num_chans] = 0, trig: SIMD[DType.bool, num_chans] = SIMD[DType.bool, num_chans](True)) -> SIMD[DType.bool, num_chans]
fn next_bool Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD |
100 |
Frequency of the phasor in Hz (default is 100.0). |
| phase_offset | SIMD |
0 |
Offsets the phase of the oscillator (default is 0.0). |
| trig | SIMD |
SIMD[DType.bool, num_chans](True) |
Trigger signal to reset the phase when switching from False to True (default is all True, which resets the phasor on the first sample). |
fn next_bool Returns
: SIMD
A boolean SIMD indicating True when the impulse occurs.
struct Impulse . fn next¶
Generates an impulse waveform where the output is 1.0 for one sample when the phase wraps around from 1.0 to 0.0, and 0.0 otherwise.
fn next Signature
next(mut self, freq: SIMD[DType.float64, num_chans] = 100, phase_offset: SIMD[DType.float64, num_chans] = 0, trig: SIMD[DType.bool, num_chans] = SIMD[DType.bool, num_chans](True)) -> SIMD[DType.float64, num_chans]
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD |
100 |
Frequency of the phasor in Hz (default is 100.0). |
| phase_offset | SIMD |
0 |
Offsets the phase of the oscillator (default is 0.0). |
| trig | SIMD |
SIMD[DType.bool, num_chans](True) |
Trigger signal to reset the phase when switching from False to True (default is all True, which resets the phasor on the first sample). |
fn next Returns
: SIMD
The next impulse sample as a Float64. 1.0 when the impulse occurs, 0.0 otherwise.
struct Osc¶
Wavetable Oscillator Core.
A wavetable oscillator capable of all standard waveforms and also able to load custom wavetables. Capable of linear, cubic, quadratic, lagrange, or sinc interpolation. Also capable of Oversampling.
- Pure tones can be generated without oversampling or sinc interpolation.
- When doing extreme modulation, best practice is to use sinc interpolation and an oversampling index of 1 (2x).
- Try all the combinations of interpolation and oversampling to find the best tradeoff between quality and CPU usage for your application.
Traits: AnyType, Copyable, Movable, Representable, UnknownDestructibility
Osc Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of channels (default is 1). |
| interp | Int |
1 |
Interpolation method. See Interp struct for options (default is Interp.linear). |
| os_index | Int |
0 |
Oversampling index (0 = no oversampling, 1 = 2x, 2 = 4x, etc.; default is 0). |
Osc Functions¶
struct Osc . fn init¶
Args: world: Pointer to the MMMWorld instance.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | — |
fn init Returns
: Self
Static Method
This is a static method.
struct Osc . fn next¶
Generate the next oscillator sample on a single waveform type. All inputs are SIMD types except trig, which is a scalar. This means that an oscillator can have num_chans different instances, each with its own frequency, phase offset, and waveform type, but they will all share the same trigger signal.
fn next Signature
next(mut self: Osc[num_chans, interp, os_index], freq: SIMD[DType.float64, num_chans] = 100, phase_offset: SIMD[DType.float64, num_chans] = 0, trig: Bool = False, osc_type: SIMD[DType.int64, num_chans] = 0) -> SIMD[DType.float64, num_chans]
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD |
100 |
Frequency of the oscillator in Hz. |
| phase_offset | SIMD |
0 |
Offsets the phase of the oscillator (default is 0.0). |
| trig | Bool |
False |
Trigger signal to reset the phase when switching from False to True (default is 0.0). |
| osc_type | SIMD |
0 |
Type of waveform. See the OscType struct for options (default is OscType.sine). Best if provided as OscType.sine, OscType.triangle, etc. |
fn next Returns
: SIMD
The next sample of the oscillator output.
struct Osc . fn next_vwt¶
Variable Wavetable Oscillator using built-in waveforms. Generates the next oscillator sample on a variable waveform where the output is interpolated between different waveform types. All inputs are SIMD types except trig and osc_types, which are scalar. This means that an oscillator can have num_chans different instances, each with its own frequency, phase offset, and waveform type, but they will all share the same trigger signal and the same list of waveform types to interpolate between.
fn next_vwt Signature
next_vwt(mut self, freq: SIMD[DType.float64, num_chans] = 100, phase_offset: SIMD[DType.float64, num_chans] = 0, trig: Bool = False, osc_types: List[Int64] = List[Int64](SIMD[DType.int64, 1](0), SIMD[DType.int64, 1](4), SIMD[DType.int64, 1](5), SIMD[DType.int64, 1](6), Tuple[]()), osc_frac: SIMD[DType.float64, num_chans] = 0) -> SIMD[DType.float64, num_chans]
fn next_vwt Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD |
100 |
Frequency of the oscillator in Hz. |
| phase_offset | SIMD |
0 |
Offsets the phase of the oscillator (default is 0.0). |
| trig | Bool |
False |
Trigger signal to reset the phase when switching from False to True (default is 0.0). |
| osc_types | List |
List[Int64](SIMD[DType.int64, 1](0), SIMD[DType.int64, 1](4), SIMD[DType.int64, 1](5), SIMD[DType.int64, 1](6), Tuple[]()) |
List of waveform types (OscType) to interpolate between (default is [OscType.sine,OscType.bandlimited_triangle,OscType.bandlimited_saw,OscType.bandlimited_square]. |
| osc_frac | SIMD |
0 |
Fractional index for wavetable interpolation. Values are between 0.0 and 1.0. 0.0 corresponds to the first waveform in the osc_types list, 1.0 corresponds to the last waveform in the osc_types list, and values in between interpolate linearly between all waveforms in the list. |
fn next_vwt Returns
: SIMD
The next sample of the oscillator output.
struct Osc . fn next_vwt¶
Variable Wavetable Oscillator that interpolates over a loaded Buffer. Generates the next oscillator sample on a variable waveform where the output is interpolated between different different channels of a provided Buffer.
fn next_vwt Signature
next_vwt(mut self: Osc[num_chans, interp, os_index], ref buffer: Buffer, freq: SIMD[DType.float64, num_chans] = 100, phase_offset: SIMD[DType.float64, num_chans] = 0, trig: Bool = False, osc_frac: SIMD[DType.float64, num_chans] = 0) -> SIMD[DType.float64, num_chans]
fn next_vwt Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| buffer | Buffer |
— | Reference to a Buffer containing the waveforms to interpolate between. |
| freq | SIMD |
100 |
Frequency of the oscillator in Hz. |
| phase_offset | SIMD |
0 |
Offsets the phase of the oscillator (default is 0.0). |
| trig | Bool |
False |
Trigger signal to reset the phase when switching from False to True (default is 0.0). All waveforms will reset together. |
| osc_frac | SIMD |
0 |
Fractional index for wavetable interpolation. Values are between 0.0 and 1.0. 0.0 corresponds to the first channel in the input buffer, 1.0 corresponds to the last channel in the input buffer, and values in between interpolate linearly between all channels in the buffer. |
fn next_vwt Returns
: SIMD
struct SinOsc¶
A sine wave oscillator.
This is a convenience struct as internally it uses Osc and indicates osc_type = OscType.sine.
Args: world: Pointer to the MMMWorld instance.
Traits: AnyType, Copyable, Movable, Representable, UnknownDestructibility
SinOsc Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of channels (default is 1). |
| os_index | Int |
0 |
Oversampling index (0 = no oversampling, 1 = 2x, etc.; default is 0). |
SinOsc Functions¶
struct SinOsc . fn init¶
Args: world: Pointer to the MMMWorld instance.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | — |
fn init Returns
: Self
Static Method
This is a static method.
struct SinOsc . fn next¶
fn next Signature
next(mut self: SinOsc[num_chans, os_index], freq: SIMD[DType.float64, num_chans] = 100, phase_offset: SIMD[DType.float64, num_chans] = 0, trig: Bool = False, interp: Int64 = 0) -> SIMD[DType.float64, num_chans]
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD |
100 |
— |
| phase_offset | SIMD |
0 |
— |
| trig | Bool |
False |
— |
| interp | Int64 |
0 |
— |
fn next Returns
: SIMD
struct LFSaw¶
A low-frequency sawtooth oscillator.
This oscillator generates a non-bandlimited sawtooth waveform. It is useful for modulation, but should be avoided for audio-rate synthesis due to aliasing.
Outputs values between 0.0 and 1.0.
Traits: AnyType, Copyable, Movable, Representable, UnknownDestructibility
LFSaw Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of channels (default is 1). |
LFSaw Functions¶
struct LFSaw . fn init¶
Args: world: Pointer to the MMMWorld instance.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | — |
fn init Returns
: Self
Static Method
This is a static method.
struct LFSaw . fn next¶
Generate the next sawtooth wave sample.
fn next Signature
next(mut self: LFSaw[num_chans], freq: SIMD[DType.float64, num_chans] = 100, phase_offset: SIMD[DType.float64, num_chans] = 0, trig: Bool = False) -> SIMD[DType.float64, num_chans]
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD |
100 |
Frequency of the sawtooth wave in Hz. |
| phase_offset | SIMD |
0 |
Offsets the phase of the oscillator (default is 0.0). |
| trig | Bool |
False |
Trigger signal to reset the phase when switching from False to True (default is 0.0). |
fn next Returns
: SIMD
struct LFSquare¶
A low-frequency square wave oscillator.
Creates a non-band-limited square wave. Outputs values of -1.0 or 1.0. Useful for modulation, but should be avoided for audio-rate synthesis due to aliasing.
Traits: AnyType, Copyable, Movable, Representable, UnknownDestructibility
LFSquare Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of channels (default is 1). |
LFSquare Functions¶
struct LFSquare . fn init¶
Args: world: Pointer to the MMMWorld instance.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | — |
fn init Returns
: Self
Static Method
This is a static method.
struct LFSquare . fn next¶
Generate the next square wave sample.
fn next Signature
next(mut self: LFSquare[num_chans], freq: SIMD[DType.float64, num_chans] = 100, phase_offset: SIMD[DType.float64, num_chans] = 0, trig: Bool = False) -> SIMD[DType.float64, num_chans]
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD |
100 |
Frequency of the square wave in Hz. |
| phase_offset | SIMD |
0 |
Offsets the phase of the oscillator (default is 0.0). |
| trig | Bool |
False |
Trigger signal to reset the phase when switching from False to True (default is 0.0). |
fn next Returns
: SIMD
struct LFTri¶
A low-frequency triangle wave oscillator.
This oscillator generates a triangle wave at audio rate. It is useful for modulation, but should be avoided for audio-rate synthesis due to aliasing.
Traits: AnyType, Copyable, Movable, Representable, UnknownDestructibility
LFTri Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of channels (default is 1). |
LFTri Functions¶
struct LFTri . fn init¶
Args: world: Pointer to the MMMWorld instance.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | — |
fn init Returns
: Self
Static Method
This is a static method.
struct LFTri . fn next¶
Generate the next triangle wave sample.
fn next Signature
next(mut self: LFTri[num_chans], freq: SIMD[DType.float64, num_chans] = 100, phase_offset: SIMD[DType.float64, num_chans] = 0, trig: Bool = False) -> SIMD[DType.float64, num_chans]
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD |
100 |
Frequency of the triangle wave in Hz. |
| phase_offset | SIMD |
0 |
Offsets the phase of the oscillator. |
| trig | Bool |
False |
Trigger signal to reset the phase when switching from False to True. |
fn next Returns
: SIMD
struct Dust¶
A dust noise oscillator that generates random impulses at random intervals.
Dust has a Phasor as its core, and the frequency of the Phasor is randomly changed each time an impulse is generated. This allows the Dust to be used in multiple ways. It can be used as a simple random impulse generator, or the user can use the get_phase() method to get the current phase of the internal Phasor and use that phase to drive other oscillators or processes. The user can also set the phase of the internal Phasor using the set_phase() method, allowing for more complex interactions.
Traits: AnyType, Copyable, Movable, Representable, UnknownDestructibility
Dust Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of channels. |
Dust Functions¶
struct Dust . fn init¶
Args: world: Pointer to the MMMWorld instance.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | — |
fn init Returns
: Self
Static Method
This is a static method.
struct Dust . fn next¶
Generate the next dust noise sample.
fn next Signature
next(mut self: Dust[num_chans], low: SIMD[DType.float64, num_chans] = 100, high: SIMD[DType.float64, num_chans] = 2000, trig: SIMD[DType.bool, num_chans] = SIMD[DType.bool, num_chans](False)) -> SIMD[DType.float64, num_chans]
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| low | SIMD |
100 |
Lower bound for the random frequency range. |
| high | SIMD |
2000 |
Upper bound for the random frequency range. |
| trig | SIMD |
SIMD[DType.bool, num_chans](False) |
Trigger signal to reset the phase when switching from False to True. |
fn next Returns
: SIMD
The next dust noise sample as a Float64. Will be 1.0 when an impulse occurs, 0.0 otherwise.
struct Dust . fn next_bool¶
Generate the next dust noise sample as a boolean impulse.
fn next_bool Signature
next_bool(mut self: Dust[num_chans], low: SIMD[DType.float64, num_chans] = 100, high: SIMD[DType.float64, num_chans] = 2000, trig: SIMD[DType.bool, num_chans] = SIMD[DType.bool, num_chans](False)) -> SIMD[DType.bool, num_chans]
fn next_bool Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| low | SIMD |
100 |
Lower bound for the random frequency range. |
| high | SIMD |
2000 |
Upper bound for the random frequency range. |
| trig | SIMD |
SIMD[DType.bool, num_chans](False) |
Trigger signal to reset the phase when switching from False to True. |
fn next_bool Returns
: SIMD
The next dust noise sample as a boolean SIMD. Will be True when an impulse occurs, False otherwise.
struct Dust . fn get_phase¶
fn get_phase Signature
fn get_phase Returns
: SIMD
struct Dust . fn set_phase¶
fn set_phase Signature
fn set_phase Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| phase | SIMD |
— | — |
struct LFNoise¶
Low-frequency interpolating noise generator.
With stepped (none), linear, or cubic interpolation.
Traits: AnyType, Copyable, Movable, Representable, UnknownDestructibility
LFNoise Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of channels. |
| interp | Int |
3 |
Interpolation method. Options are Interp.none (stepped), Interp.linear, Interp.cubic. |
LFNoise Functions¶
struct LFNoise . fn init¶
Args: world: Pointer to the MMMWorld instance.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | — |
fn init Returns
: Self
Static Method
This is a static method.
struct LFNoise . fn next¶
Generate the next low-frequency noise sample.
fn next Signature
next(mut self: LFNoise[num_chans, interp], freq: SIMD[DType.float64, num_chans] = 100) -> SIMD[DType.float64, num_chans]
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD |
100 |
Frequency of the noise in Hz. |
fn next Returns
: SIMD
The next sample as a Float64.
struct Sweep¶
A phase accumulator.
Phase accumulator that sweeps from 0 up to inf at a given frequency, resetting on trigger.
Traits: AnyType, Copyable, Movable, Representable, UnknownDestructibility
Sweep Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of channels. |
Sweep Functions¶
struct Sweep . fn init¶
Args: world: Pointer to the MMMWorld instance.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | — |
fn init Returns
: Self
Static Method
This is a static method.
struct Sweep . fn next¶
Generate the next sweep sample.
fn next Signature
next(mut self, freq: SIMD[DType.float64, num_chans] = 100, trig: SIMD[DType.bool, num_chans] = False) -> SIMD[DType.float64, num_chans]
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| freq | SIMD |
100 |
Frequency of the sweep in Hz. |
| trig | SIMD |
False |
Trigger signal to reset the phase when switching from False to True (default is all False). |
fn next Returns
: SIMD
The next sample as a Float64.
Documentation generated with mojo doc from Mojo version 0.25.6.1