Play
struct Play¶
The principle buffer playback object for MMMAudio.
Plays back audio from a Buffer with variable rate, interpolation, looping, and triggering capabilities.
Traits: AnyType, Copyable, ImplicitlyDestructible, Movable, Representable
Play Functions¶
struct Play . 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 Play . fn next¶
Get the next sample from a SIMD audio buf (SIMDBuffer). The internal phasor is advanced according to the specified rate. If a trigger is received, playback starts at the specified start_frame. If looping is enabled, playback will loop back to the start when reaching the end of the specified num_frames. A key difference between SIMDBuffer and Buffer is that calling next on a SIMDBuffer always returns the entire SIMD vector of samples for the current phase, whereas with Buffer, you can specify the number of channels to read.
fn next Signature
next[num_chans: Int = 1, interp: Int = Interp.linear, bWrap: Bool = False](mut self, buf: SIMDBuffer[num_chans], rate: Float64 = 1, loop: Bool = True, trig: Bool = True, start_frame: Int = 0, var num_frames: Int = -1) -> SIMD[DType.float64, num_chans]
fn next Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of output channels to read from the buffer and also the size of the output SIMD vector. |
| interp | Int |
Interp.linear |
Interpolation method to use when reading from the buffer (see the Interp struct for available options - default: Interp.linear). |
| bWrap | Bool |
False |
Whether to interpolate between the end and start of the buffer when reading (default: False). This is necessary when reading from a wavetable or other oscillating buffer, for instance, where the ending samples of the buffer connect seamlessly to the first. If this is false, reading beyond the end of the buffer will return 0. When True, the index into the buffer will wrap around to the beginning using a modulus. |
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| buf | SIMDBuffer |
— | The audio buf to read from (List[MFloat[num_chans]]). |
| rate | Float64 |
1 |
The playback rate. 1 is the normal speed of the buf. |
| loop | Bool |
True |
Whether to loop the buf (default: True). |
| trig | Bool |
True |
Trigger starts the synth at start_frame (default: 1.0). |
| start_frame | Int |
0 |
The start frame for playback (default: 0) upon receiving a trigger. |
| num_frames | Int |
-1 |
The end frame for playback (default: -1 means to the end of the buf). |
fn next Returns
: SIMD
The next sample(s) from the buf as a SIMD vector.
struct Play . fn next¶
Get the next sample from an audio buf (Buffer). The internal phasor is advanced according to the specified rate. If a trigger is received, playback starts at the specified start_frame. If looping is enabled, playback will loop back to the start when reaching the end of the specified num_frames.
fn next Signature
next[num_chans: Int = 1, interp: Int = Interp.linear, bWrap: Bool = False](mut self, buf: Buffer, rate: Float64 = 1, loop: Bool = True, trig: Bool = True, start_frame: Int = 0, var num_frames: Int = -1, start_chan: Int = 0) -> SIMD[DType.float64, num_chans]
fn next Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of output channels to read from the buffer and also the size of the output SIMD vector. |
| interp | Int |
Interp.linear |
Interpolation method to use when reading from the buffer (see the Interp struct for available options - default: Interp.linear). |
| bWrap | Bool |
False |
Whether to interpolate between the end and start of the buffer when reading (default: False). This is necessary when reading from a wavetable or other oscillating buffer, for instance, where the ending samples of the buffer connect seamlessly to the first. If this is false, reading beyond the end of the buffer will return 0. When True, the index into the buffer will wrap around to the beginning using a modulus. |
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| buf | Buffer |
— | The audio buf to read from (List[Float64]). |
| rate | Float64 |
1 |
The playback rate. 1 is the normal speed of the buf. |
| loop | Bool |
True |
Whether to loop the buf (default: True). |
| trig | Bool |
True |
Trigger starts the synth at start_frame (default: 1.0). |
| start_frame | Int |
0 |
The start frame for playback (default: 0) upon receiving a trigger. |
| num_frames | Int |
-1 |
The end frame for playback (default: -1 means to the end of the buf). |
| start_chan | Int |
0 |
The start channel for multi-channel bufs (default: 0). |
fn next Returns
: SIMD
The next sample(s) from the buf as a SIMD vector.
struct Play . fn get_relative_phase¶
fn get_relative_phase Signature
fn get_relative_phase Returns
: Float64
struct Play . fn reset_phase¶
struct Grain¶
A single grain for granular synthesis.
Used as part of the TGrains and the PitchShift structs for triggered granular synthesis.
Traits: AnyType, Copyable, ImplicitlyDestructible, Movable, PolyObject
Grain Functions¶
struct Grain . 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 Grain . fn check_active¶
struct Grain . fn set_trigger¶
fn set_trigger Signature
fn set_trigger Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| trigger | Bool |
— | — |
struct Grain . fn next_pan2¶
Generate the next grain and pan it to stereo using pan2. Depending on num_playback_chans, will either pan a mono signal out 2 channels using pan2 or a stereo signal out 2 channels using pan_stereo.
fn next_pan2 Signature
next_pan2[num_playback_chans: Int = 1, win_type: Int = 0, bWrap: Bool = False](mut self, mut buffer: SIMDBuffer[num_chans], rate: Float64 = 1, loop: Bool = False, start_frame: Int = 0, duration: Float64 = 0, pan: Float64 = 0, gain: Float64 = 1) -> SIMD[DType.float64, 2]
fn next_pan2 Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_playback_chans | Int |
1 |
Either 1 or 2, depending on whether you want to pan 1 channel of a buffer out 2 channels or 2 channels of the buffer with equal power panning. |
| win_type | Int |
0 |
Type of window to apply to the grain (default is Hann window (WinType.hann)). |
| bWrap | Bool |
False |
Whether to interpolate between the end and start of the buffer when reading (default: False). When False, reading beyond the end of the buffer will return 0. When True, the index into the buffer will wrap around to the beginning using a modulus. |
fn next_pan2 Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| buffer | SIMDBuffer |
— | Audio buffer containing the source sound. |
| rate | Float64 |
1 |
Playback rate of the grain (1.0 = normal speed). |
| loop | Bool |
False |
Whether to loop the grain (default: False). |
| start_frame | Int |
0 |
Starting frame position in the buffer. |
| duration | Float64 |
0 |
Duration of the grain in seconds. |
| pan | Float64 |
0 |
Panning position from -1.0 (left) to 1.0 (right). |
| gain | Float64 |
1 |
Amplitude scaling factor for the grain. |
fn next_pan2 Returns
: SIMD
struct Grain . fn next_pan_az¶
Generate the next grain and pan it to N speakers using azimuth panning.
fn next_pan_az Signature
next_pan_az[num_simd_chans: Int = 4, win_type: Int = WindowType.hann, bWrap: Bool = False](mut self, mut buffer: SIMDBuffer[num_chans], rate: Float64 = 1, loop: Bool = False, start_frame: Int = 0, duration: Float64 = 0, buffer_chan: Int = 0, pan: Float64 = 0, gain: Float64 = 1, num_speakers: Int = 4) -> SIMD[DType.float64, num_simd_chans]
fn next_pan_az Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_simd_chans | Int |
4 |
Number of output channels (speakers). Must be a power of two that is at least as large as num_speakers. |
| win_type | Int |
WindowType.hann |
Type of window to apply to the grain (default is Hann window (WindowType.hann) See WindowType for all options.). |
| bWrap | Bool |
False |
Whether to interpolate between the end and start of the buffer when reading (default: False). When False, reading beyond the end of the buffer will return 0. When True, the index into the buffer will wrap around to the beginning using a modulus. |
fn next_pan_az Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| buffer | SIMDBuffer |
— | Audio buffer containing the source sound. |
| rate | Float64 |
1 |
Playback rate of the grain (1.0 = normal speed). |
| loop | Bool |
False |
Whether to loop the grain (default: False). |
| start_frame | Int |
0 |
Starting frame position in the buffer. |
| duration | Float64 |
0 |
Duration of the grain in seconds. |
| buffer_chan | Int |
0 |
The buffer channel to read from for the grain (default: 0). |
| pan | Float64 |
0 |
Panning position from 0.0 to 1.0. |
| gain | Float64 |
1 |
Amplitude scaling factor for the grain. |
| num_speakers | Int |
4 |
Number of speakers to pan to. |
fn next_pan_az Returns
: SIMD
struct Grain . fn next¶
Generate the next unpanned grain. This is called internally by the panning functions, but can also be used directly if panning is not needed. The grain will always have the channel size of the SIMDBuffer.
fn next Signature
next[num_chans: Int = 1, win_type: Int = WindowType.hann, bWrap: Bool = False](mut self, mut buffer: SIMDBuffer[num_chans], rate: Float64 = 1, loop: Bool = False, start_frame: Int = 0, duration: Float64 = 0, pan: Float64 = 0, gain: Float64 = 1) -> SIMD[DType.float64, num_chans]
fn next Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of output channels to read from the buffer and also the size of the output SIMD vector. |
| win_type | Int |
WindowType.hann |
Type of window to apply to the grain (default is Hann window (WinType.hann)). |
| bWrap | Bool |
False |
Whether to interpolate between the end and start of the buffer when reading (default: False). When False, reading beyond the end of the buffer will return 0. When True, the index into the buffer will wrap around to the beginning using a modulus. |
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| buffer | SIMDBuffer |
— | Audio buffer containing the source sound. |
| rate | Float64 |
1 |
Playback rate of the grain (1.0 = normal speed). |
| loop | Bool |
False |
Whether to loop the grain (default: False). |
| start_frame | Int |
0 |
Starting frame position in the buffer. |
| duration | Float64 |
0 |
Duration of the grain in seconds. |
| pan | Float64 |
0 |
Panning position from -1.0 (left) to 1.0 (right). |
| gain | Float64 |
1 |
Amplitude scaling factor for the grain. |
fn next Returns
: SIMD
struct TGrains¶
Triggered granular synthesis. Each trigger starts a new grain.
Traits: AnyType, Copyable, ImplicitlyDestructible, Movable
TGrains Functions¶
struct TGrains . fn init¶
Args: num_grains: Number of grains to initialize. max_grains: Maximum number of grains that can be allocated. world: Pointer to the MMMWorld instance.
fn init Signature
__init__(out self, num_grains: Int, max_grains: Int, world: UnsafePointer[MMMWorld, MutExternalOrigin])
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| num_grains | Int |
— | — |
| max_grains | Int |
— | — |
| world | UnsafePointer |
— | — |
fn init Returns
: Self
Static Method
This is a static method.
struct TGrains . fn next¶
Generate the next set of grains. Uses pan2 to pan to 2 channels. Depending on num_playback_chans, will either pan a mono signal out 2 channels or a stereo signal out 2 channels. Args:. buffer: Audio buffer containing the source sound. rate: Playback rate of the grains (1.0 = normal speed). trig: Trigger signal (>0 to start a new grain). start_frame: Starting frame position in the buffer. duration: Duration of each grain in seconds. buf_chan: Channel in the buffer to read from. pan: Panning position from -1.0 (left) to 1.0 (right). gain: Amplitude scaling factor for the grains.
fn next Signature
next[num_playback_chans: Int = 1, win_type: Int = WindowType.hann, bWrap: Bool = False](mut self, mut buffer: SIMDBuffer[num_chans], rate: Float64 = 1, trig: Bool = False, start_frame: Int = 0, duration: Float64 = 0.10000000000000001, buf_chan: Int = 0, pan: Float64 = 0, gain: Float64 = 1) -> SIMD[DType.float64, 2]
fn next Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_playback_chans | Int |
1 |
Either 1 or 2, depending on whether you want to pan 1 channel of a buffer out 2 channels or 2 channels of the buffer with equal power panning. |
| win_type | Int |
WindowType.hann |
Type of window to apply to each grain (default is Hann window (WinType.hann)). |
| bWrap | Bool |
False |
Whether to interpolate between the end and start of the buffer when reading (default: False). When False, reading beyond the end of the buffer will return 0. When True, the index into the buffer will wrap around to the beginning using a modulus. |
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| buffer | SIMDBuffer |
— | — |
| rate | Float64 |
1 |
— |
| trig | Bool |
False |
— |
| start_frame | Int |
0 |
— |
| duration | Float64 |
0.10000000000000001 |
— |
| buf_chan | Int |
0 |
— |
| pan | Float64 |
0 |
— |
| gain | Float64 |
1 |
— |
fn next Returns
: SIMD
List of output samples for all channels.
struct TGrains . fn next_pan_az¶
Generate the next set of grains. Uses azimuth panning for N channel output.
fn next_pan_az Signature
next_pan_az[num_simd_chans: Int = 2, win_type: Int = WindowType.hann, bWrap: Bool = False](mut self, mut buffer: SIMDBuffer[num_chans], rate: Float64 = 1, trig: Bool = False, start_frame: Int = 0, duration: Float64 = 0.10000000000000001, buf_chan: Int = 0, pan: Float64 = 0, gain: Float64 = 1, num_speakers: Int = 2) -> SIMD[DType.float64, num_simd_chans]
fn next_pan_az Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_simd_chans | Int |
2 |
The size of the output SIMD vector. Must be a power of two that is at least as large as num_speakers. |
| win_type | Int |
WindowType.hann |
Type of window to apply to each grain (default is Hann window (WinType.hann)). |
| bWrap | Bool |
False |
Whether to interpolate between the end and start of the buffer when reading (default: False). When False, reading beyond the end of the buffer will return 0. When True, the index into the buffer will wrap around to the beginning using a modulus. |
fn next_pan_az Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| buffer | SIMDBuffer |
— | Audio buffer containing the source sound. |
| rate | Float64 |
1 |
Playback rate of the grains (1.0 = normal speed). |
| trig | Bool |
False |
Trigger signal (>0 to start a new grain). |
| start_frame | Int |
0 |
Starting frame position in the buffer. |
| duration | Float64 |
0.10000000000000001 |
Duration of each grain in seconds. |
| buf_chan | Int |
0 |
Channel in the buffer to read from. |
| pan | Float64 |
0 |
Panning position from -1.0 (left) to 1.0 (right). |
| gain | Float64 |
1 |
Amplitude scaling factor for the grains. |
| num_speakers | Int |
2 |
Number of speakers to pan to. Must be fewer than or equal to num_simd_chans. |
fn next_pan_az Returns
: SIMD
Output samples for all channels as a SIMD vector.
struct PitchShift¶
An N channel granular pitchshifter. Each channel is processed in parallel.
Args: world: Pointer to the MMMWorld instance. buf_dur: Duration of the internal buffer in seconds.
Traits: AnyType, Copyable, ImplicitlyDestructible, Movable
PitchShift Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of input/output channels. |
| win_type | Int |
WindowType.hann |
Type of window to apply to each grain (default is Hann window (WinType.hann)). |
PitchShift Functions¶
struct PitchShift . fn init¶
Args: world: pointer to the MMMWorld instance. overlaps: Number of overlapping grains (default is 4). buf_dur: duration of the internal buffer in seconds.
fn init Signature
__init__(out self, world: UnsafePointer[MMMWorld, MutExternalOrigin], buf_dur: Float64 = 2, num_grains: Int = 6, max_grains: Int = 12)
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | — |
| buf_dur | Float64 |
2 |
— |
| num_grains | Int |
6 |
— |
| max_grains | Int |
12 |
— |
fn init Returns
: Self
Static Method
This is a static method.
struct PitchShift . fn next¶
Generate the next set of grains for pitch shifting.
fn next Signature
next(mut self, in_sig: SIMD[DType.float64, num_chans], grain_dur: Float64 = 0.20000000000000001, overlaps: Int = 4, pitch_ratio: Float64 = 1, pitch_dispersion: Float64 = 0, time_dispersion: Float64 = 0, added_delay_low: Float64 = 0, added_delay_high: Float64 = 0, gain: Float64 = 1) -> SIMD[DType.float64, num_chans]
fn next Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| in_sig | SIMD |
— | Input signal to be pitch shifted. |
| grain_dur | Float64 |
0.20000000000000001 |
Duration of each grain in seconds. |
| overlaps | Int |
4 |
Number of overlapping grains (default is 4). |
| pitch_ratio | Float64 |
1 |
Pitch shift ratio (1.0 = no shift, 2.0 = one octave up, 0.5 = one octave down, etc). |
| pitch_dispersion | Float64 |
0 |
Amount of random variation in pitch ratio. |
| time_dispersion | Float64 |
0 |
Amount of random variation in grain triggering time. Value between 0.0 and 1.0, where 0.0 is no variation and 1.0 is maximum variation of up to the grain duration. |
| added_delay_low | Float64 |
0 |
Minimum amount of delay to add to the start of each grain in seconds. |
| added_delay_high | Float64 |
0 |
Maximum amount of delay to add to the start of each grain in seconds. (Maximum added delay should be set so that it does not exceed the internal buffer size when combined with the grain duration and time dispersion). |
| gain | Float64 |
1 |
Amplitude scaling factor for the output. |
fn next Returns
: SIMD
Documentation generated with mojo doc from Mojo version 0.26.1.0