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, Movable, Representable, UnknownDestructibility
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 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 = 1, bWrap: Bool = False](mut self, buf: Buffer, rate: Float64 = 1, loop: Bool = True, trig: Bool = True, start_frame: Int64 = 0, var num_frames: Int64 = -1, start_chan: Int64 = 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 |
1 |
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 | Int64 |
0 |
The start frame for playback (default: 0) upon receiving a trigger. |
| num_frames | Int64 |
-1 |
The end frame for playback (default: -1 means to the end of the buf). |
| start_chan | Int64 |
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 Grain¶
A single grain for granular synthesis.
Used as part of the TGrains struct for triggered granular synthesis.
Traits: AnyType, Copyable, Movable, Representable, UnknownDestructibility
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 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: Buffer, rate: Float64 = 1, loop: Bool = False, trig: Bool = False, start_frame: Int64 = 0, duration: Float64 = 0, start_chan: Int = 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 | Buffer |
— | 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). |
| trig | Bool |
False |
Trigger signal (>0 to start a new grain). |
| start_frame | Int64 |
0 |
Starting frame position in the buffer. |
| duration | Float64 |
0 |
Duration of the grain in seconds. |
| start_chan | Int |
0 |
Starting 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 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 = 1, bWrap: Bool = False](mut self, mut buffer: Buffer, rate: Float64 = 1, loop: Bool = False, trig: Bool = False, start_frame: Int64 = 0, duration: Float64 = 0, start_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 |
1 |
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 | Buffer |
— | 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). |
| trig | Bool |
False |
Trigger signal (>0 to start a new grain). |
| start_frame | Int64 |
0 |
Starting frame position in the buffer. |
| duration | Float64 |
0 |
Duration of the grain in seconds. |
| start_chan | Int |
0 |
Starting channel in the buffer to read from. |
| 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.
fn next Signature
next[num_playback_chans: Int = 1, win_type: Int = 1, bWrap: Bool = False](mut self, mut buffer: Buffer, rate: Float64 = 1, loop: Bool = False, trig: Bool = False, start_frame: Int64 = 0, duration: Float64 = 0, start_chan: Int = 0, pan: Float64 = 0, gain: Float64 = 1) -> SIMD[DType.float64, num_playback_chans]
fn next Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_playback_chans | Int |
1 |
Number of output channels to read from the buffer and also the size of the output SIMD vector. |
| win_type | Int |
1 |
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 | Buffer |
— | 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). |
| trig | Bool |
False |
Trigger signal (>0 to start a new grain). |
| start_frame | Int64 |
0 |
Starting frame position in the buffer. |
| duration | Float64 |
0 |
Duration of the grain in seconds. |
| start_chan | Int |
0 |
Starting 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 grain. |
fn next Returns
: SIMD
struct TGrains¶
Triggered granular synthesis. Each trigger starts a new grain.
Traits: AnyType, Copyable, Movable, Representable, UnknownDestructibility
TGrains Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| max_grains | Int |
5 |
Maximum number of overlapping grains. |
TGrains Functions¶
struct TGrains . 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 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 = 1, bWrap: Bool = False](mut self, mut buffer: Buffer, rate: Float64 = 1, trig: Bool = False, start_frame: Int64 = 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 |
1 |
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 | Buffer |
— | — |
| rate | Float64 |
1 |
— |
| trig | Bool |
False |
— |
| start_frame | Int64 |
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 = 1, bWrap: Bool = False](mut self, mut buffer: Buffer, rate: Float64 = 1, trig: Bool = False, start_frame: Int64 = 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 |
1 |
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 | Buffer |
— | 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 | Int64 |
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, Movable, UnknownDestructibility
PitchShift Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_chans | Int |
1 |
Number of input/output channels. |
| overlaps | Int |
4 |
Number of overlapping grains (default is 4). |
| win_type | Int |
1 |
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. buf_dur: duration of the internal buffer in seconds.
fn init Signature
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | — |
| buf_dur | Float64 |
1 |
— |
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, pitch_ratio: Float64 = 1, pitch_dispersion: Float64 = 0, time_dispersion: 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. |
| 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. |
| gain | Float64 |
1 |
Amplitude scaling factor for the output. |
fn next Returns
: SIMD
Documentation generated with mojo doc from Mojo version 0.25.6.1