Skip to content

Buffer

Structs

struct SIMDBuffer

A multi-channel audio buffer for storing audio data.

Audio data is stored in the data variable as a List[MFloat[Self.num_chans]] where each MFloat[Self.num_chans] represents a single frame of audio data for all channels. For example, if num_chans is 2, each element of data would be an MFloat[2] where the first element is the sample value for the left channel and the second element is the sample value for the right channel.

Traits: AnyType, Copyable, ImplicitlyDeletable, Movable

SIMDBuffer Parameters

Name Type Default Description
num_chans Int 2

SIMDBuffer Functions

struct SIMDBuffer . fn init

Initialize a SIMDBuffer with the given audio data and sample rate.

fn init Signature

def __init__(out self, data: List[SIMD[DType.float64, num_chans]], sample_rate: Float64)

fn init Arguments

Name Type Default Description
data List[SIMD[DType.float64, num_chans]] A List of Lists of Float64 representing the audio data for each channel.
sample_rate Float64 The sample rate of the audio data.

fn init Returns : Self

Static Method

This is a static method.

struct SIMDBuffer . fn at_phase

Read a value from the SIMDBuffer at a given phase using sinc interpolation.

fn at_phase Signature

def at_phase[interp: Interp = Interp.none, bWrap: Bool = True, mask: Int = 0](self, world: UnsafePointer[MMMWorld, MutUntrackedOrigin], phase: Float64, prev_phase: Float64 = Float64("0")) -> SIMD[DType.float64, num_chans]

fn at_phase Parameters

Name Type Default Description
interp Interp Interp.none Interpolation method to use (from Interp enum).
bWrap Bool True Whether to wrap indices that go out of bounds.
mask Int 0 Bitmask for wrapping indices (if applicable). If 0, standard modulo wrapping is used. If non-zero, bitwise AND wrapping is used (only valid for power-of-two lengths).

fn at_phase Arguments

Name Type Default Description
world UnsafePointer[MMMWorld, MutUntrackedOrigin] Pointer to the MMMWorld instance.
phase Float64 The phase to read at, where 0.0 is the beginning of the buffer and 1.0 is the end of the buffer.
prev_phase Float64 Float64("0") The previous phase (used for calculating the sinc interpolation).

fn at_phase Returns : SIMD[DType.float64, num_chans] The interpolated sample value at the given phase.

struct SIMDBuffer . fn zeros

Initialize a SIMDBuffer with zeros.

fn zeros Signature

def zeros(num_frames: Int, sample_rate: Float64 = 48000) -> Self

fn zeros Arguments

Name Type Default Description
num_frames Int Number of frames in the buffer.
sample_rate Float64 48000 Sample rate of the buffer.

fn zeros Returns : Self A SIMDBuffer initialized with zero-valued samples.

Static Method

This is a static method.

struct SIMDBuffer . fn zero

Utility function to set all samples in the buffer to zero.

fn zero Signature

def zero(mut self)

struct SIMDBuffer . fn load

Initialize a SIMDBuffer by loading data from a WAV file using SciPy and NumPy.

fn load Signature

def load(file_name: String, num_wavetables: Int = 1, verbose: Bool = False) -> Self

fn load Arguments

Name Type Default Description
file_name String Path to the WAV file to load.
num_wavetables Int 1 Number of wavetables per channel. This is only used if the sound file being loaded contains multiple wavetables concatenated in a single channel.
verbose Bool False Whether to print verbose output.

fn load Returns : Self A SIMDBuffer containing the loaded audio data.

Static Method

This is a static method.

struct SIMDBuffer . fn write_to_file

Write the SIMDBuffer to a WAV file.

fn write_to_file Signature

def write_to_file(self, file_name: String, num_samps: Int = -1, verbose: Bool = False)

fn write_to_file Arguments

Name Type Default Description
file_name String Path to the WAV file to write to.
num_samps Int -1 Number of samples to write.
verbose Bool False Whether to print confirmation of written file.

struct SIMDBuffer . fn write_circular_buf_to_file

Write the SIMDBuffer to a WAV file in a circular manner, starting from the current write head position.

fn write_circular_buf_to_file Signature

def write_circular_buf_to_file(mut self, write_head: Int, file_name: String, num_samps: Int = -1, rotate_back: Bool = False, verbose: Bool = False)

fn write_circular_buf_to_file Arguments

Name Type Default Description
write_head Int The current write head position in the buffer. This is the index of the most recently written sample.
file_name String Path to the WAV file to write to.
num_samps Int -1 Number of samples to write. If -1, the entire buffer will be written.
rotate_back Bool False Whether to rotate the buffer back to its original order after writing.
verbose Bool False Whether to print confirmation of written file.

struct SIMDBuffer . fn get_num_chans

Get the number of channels in the SIMDBuffer.

fn get_num_chans Signature

def get_num_chans(self) -> Int

fn get_num_chans Returns : Int The SIMD channel count of the buffer.

struct Buffer

A multi-channel audio buffer for storing audio data.

Audio data is stored in the data variable as a List[List[Float64]], where each inner List represents a channel of audio samples.

Traits: AnyType, Copyable, ImplicitlyDeletable, Movable


Buffer Functions

struct Buffer . fn init

Initialize a Buffer with the given audio data and sample rate.

fn init Signature

def __init__(out self, data: List[List[Float64]], sample_rate: Float64)

fn init Arguments

Name Type Default Description
data List[List[Float64]] A List of Lists of Float64 representing the audio data for each channel.
sample_rate Float64 The sample rate of the audio data.

fn init Returns : Self

Static Method

This is a static method.

struct Buffer . fn at_phase

Read a value from the Buffer at a given phase using interpolation.

fn at_phase Signature

def at_phase[interp: Interp = Interp.none, bWrap: Bool = True, mask: Int = 0](self, world: UnsafePointer[MMMWorld, MutUntrackedOrigin], chan: Int, phase: Float64, prev_phase: Float64 = Float64("0")) -> Float64

fn at_phase Parameters

Name Type Default Description
interp Interp Interp.none Interpolation method to use (from Interp enum).
bWrap Bool True Whether to wrap indices that go out of bounds.
mask Int 0 Bitmask for wrapping indices (if applicable). If 0, standard modulo wrapping is used. If non-zero, bitwise AND wrapping is used (only valid for power-of-two lengths).

fn at_phase Arguments

Name Type Default Description
world UnsafePointer[MMMWorld, MutUntrackedOrigin] Pointer to the MMMWorld instance.
chan Int The channel to read from.
phase Float64 The phase to read at, where 0.0 is the beginning of the buffer and 1.0 is the end of the buffer.
prev_phase Float64 Float64("0") The previous phase (used if calculating sinc interpolation).

fn at_phase Returns : Float64 The interpolated sample value at the given phase.

struct Buffer . fn zeros

Initialize a Buffer with zeros.

fn zeros Signature

def zeros(num_frames: Int, num_chans: Int = 1, sample_rate: Float64 = 48000) -> Self

fn zeros Arguments

Name Type Default Description
num_frames Int Number of frames in the buffer.
num_chans Int 1 Number of channels in the buffer.
sample_rate Float64 48000 Sample rate of the buffer.

fn zeros Returns : Self A Buffer initialized with zero-valued samples.

Static Method

This is a static method.

struct Buffer . fn zero

Utility function to set all samples in the buffer to zero.

fn zero Signature

def zero(mut self)

struct Buffer . fn load

Initialize a Buffer by loading data from a WAV file using SciPy and NumPy.

fn load Signature

def load(file_name: String, num_wavetables: Int = 1, verbose: Bool = False) -> Self

fn load Arguments

Name Type Default Description
file_name String Path to the WAV file to load.
num_wavetables Int 1 Number of wavetables per channel. This is only used if the sound file being loaded contains multiple wavetables concatenated in a single channel.
verbose Bool False Whether to print verbose output.

fn load Returns : Self A Buffer containing the loaded audio data.

Static Method

This is a static method.

struct SpanInterpolator

A collection of static methods for interpolating values from a List[Float64] or InlineArray[Float64].

SpanInterpolator supports various interpolation methods including

  • no interpolation (none)
  • linear interpolation
  • quadratic interpolation
  • cubic interpolation
  • lagrange interpolation (4th order)
  • sinc interpolation

The available interpolation methods are defined in the struct Interp.

Traits: AnyType, Copyable, ImplicitlyDeletable, Movable


SpanInterpolator Functions

struct SpanInterpolator . fn idx_in_range

fn idx_in_range Signature

def idx_in_range[num_chans: Int = 1](data: Span[SIMD[DType.float64, num_chans]], idx: Int) -> Bool

fn idx_in_range Parameters

Name Type Default Description
num_chans Int 1

fn idx_in_range Arguments

Name Type Default Description
data Span[SIMD[DType.float64, num_chans]]
idx Int

fn idx_in_range Returns : Bool

Static Method

This is a static method.

struct SpanInterpolator . fn read

Read a value from a Span[MFloat[num_chans], ...] using provided index and interpolation method, which is determined at compile time.

fn read Signature

def read[num_chans: Int = 1, interp: Interp = Interp.none, bWrap: Bool = True, mask: Int = 0](world: UnsafePointer[MMMWorld, MutUntrackedOrigin], data: Span[SIMD[DType.float64, num_chans]], f_idx: Float64, prev_f_idx: Float64 = 0) -> SIMD[DType.float64, num_chans]

fn read Parameters

Name Type Default Description
num_chans Int 1 Number of channels in the data.
interp Interp Interp.none Interpolation method to use (from Interp enum).
bWrap Bool True Whether to wrap indices that go out of bounds.
mask Int 0 Bitmask for wrapping indices (if applicable). If 0, standard modulo wrapping is used. If non-zero, bitwise AND wrapping is used (only valid for power-of-two lengths).

fn read Arguments

Name Type Default Description
world UnsafePointer[MMMWorld, MutUntrackedOrigin] Pointer to the MMMWorld instance.
data Span[SIMD[DType.float64, num_chans]] The Span[MFloat[num_chans], ...] to read from.
f_idx Float64 The floating-point index to read at.
prev_f_idx Float64 0 The previous floating-point index (used for SincInterpolation).

fn read Returns : SIMD[DType.float64, num_chans] The interpolated sample value.

Static Method

This is a static method.

struct SpanInterpolator . fn read_none

Read a value from a Span[MFloat[num_chans], ...] using provided index with no interpolation.

fn read_none Signature

def read_none[num_chans: Int = 1, bWrap: Bool = True, mask: Int = 0](data: Span[SIMD[DType.float64, num_chans]], f_idx: Float64) -> SIMD[DType.float64, num_chans]

fn read_none Parameters

Name Type Default Description
num_chans Int 1 Number of channels in the data.
bWrap Bool True Whether to wrap indices that go out of bounds.
mask Int 0 Bitmask for wrapping indices (if applicable). If 0, standard modulo wrapping is used. If non-zero, bitwise AND wrapping is used (only valid for power-of-two lengths).

fn read_none Arguments

Name Type Default Description
data Span[SIMD[DType.float64, num_chans]] The Span[MFloat[num_chans], ...] to read from.
f_idx Float64 The floating-point index to read at. It will be truncated to an integer for indexing.

fn read_none Returns : SIMD[DType.float64, num_chans] The sample value at the requested index.

Static Method

This is a static method.

struct SpanInterpolator . fn read_none

fn read_none Signature

def read_none[num_chans: Int = 1, bWrap: Bool = True, mask: Int = 0](data: Span[SIMD[DType.float64, num_chans]], idx: Int) -> SIMD[DType.float64, num_chans]

fn read_none Parameters

Name Type Default Description
num_chans Int 1
bWrap Bool True
mask Int 0

fn read_none Arguments

Name Type Default Description
data Span[SIMD[DType.float64, num_chans]]
idx Int

fn read_none Returns : SIMD[DType.float64, num_chans]

Static Method

This is a static method.

struct SpanInterpolator . fn read_linear

Read a value from a Span[MFloat[num_chans], ...] using provided index with linear interpolation.

fn read_linear Signature

def read_linear[num_chans: Int = 1, bWrap: Bool = True, mask: Int = 0](data: Span[SIMD[DType.float64, num_chans]], f_idx: Float64) -> SIMD[DType.float64, num_chans]

fn read_linear Parameters

Name Type Default Description
num_chans Int 1 Number of channels in the data.
bWrap Bool True Whether to wrap indices that go out of bounds.
mask Int 0 Bitmask for wrapping indices (if applicable). If 0, standard modulo wrapping is used. If non-zero, bitwise AND wrapping is used (only valid for power-of-two lengths).

fn read_linear Arguments

Name Type Default Description
data Span[SIMD[DType.float64, num_chans]] The Span[MFloat[num_chans], ...] to read from.
f_idx Float64 The floating-point index to read at.

fn read_linear Returns : SIMD[DType.float64, num_chans] The linearly interpolated sample value.

Static Method

This is a static method.

struct SpanInterpolator . fn read_quad

Read a value from a Span[MFloat[num_chans], ...] using provided index with quadratic interpolation.

fn read_quad Signature

def read_quad[num_chans: Int = 1, bWrap: Bool = True, mask: Int = 0](data: Span[SIMD[DType.float64, num_chans]], f_idx: Float64) -> SIMD[DType.float64, num_chans]

fn read_quad Parameters

Name Type Default Description
num_chans Int 1 Number of channels in the data.
bWrap Bool True Whether to wrap indices that go out of bounds.
mask Int 0 Bitmask for wrapping indices (if applicable). If 0, standard modulo wrapping is used. If non-zero, bitwise AND wrapping is used (only valid for power-of-two lengths).

fn read_quad Arguments

Name Type Default Description
data Span[SIMD[DType.float64, num_chans]] The Span[MFloat[num_chans], ...] to read from.
f_idx Float64 The floating-point index to read at.

fn read_quad Returns : SIMD[DType.float64, num_chans] The quadratically interpolated sample value.

Static Method

This is a static method.

struct SpanInterpolator . fn read_cubic

Read a value from a Span[MFloat[num_chans], ...] using provided index with cubic interpolation.

fn read_cubic Signature

def read_cubic[num_chans: Int = 1, bWrap: Bool = True, mask: Int = 0](data: Span[SIMD[DType.float64, num_chans]], f_idx: Float64) -> SIMD[DType.float64, num_chans]

fn read_cubic Parameters

Name Type Default Description
num_chans Int 1 Number of channels in the data.
bWrap Bool True Whether to wrap indices that go out of bounds.
mask Int 0 Bitmask for wrapping indices (if applicable). If 0, standard modulo wrapping is used. If non-zero, bitwise AND wrapping is used. (only valid for power-of-two lengths).

fn read_cubic Arguments

Name Type Default Description
data Span[SIMD[DType.float64, num_chans]] The Span[MFloat[num_chans], ...] to read from.
f_idx Float64 The floating-point index to read at.

fn read_cubic Returns : SIMD[DType.float64, num_chans] The cubically interpolated sample value.

Static Method

This is a static method.

struct SpanInterpolator . fn read_lagrange4

Read a value from a Span[MFloat[num_chans], ...] using provided index with lagrange4 interpolation.

fn read_lagrange4 Signature

def read_lagrange4[num_chans: Int = 1, bWrap: Bool = True, mask: Int = 0](data: Span[SIMD[DType.float64, num_chans]], f_idx: Float64) -> SIMD[DType.float64, num_chans]

fn read_lagrange4 Parameters

Name Type Default Description
num_chans Int 1 Number of channels in the data.
bWrap Bool True Whether to wrap indices that go out of bounds.
mask Int 0 Bitmask for wrapping indices (if applicable). If 0, standard modulo wrapping is used. If non-zero, bitwise AND wrapping is used (only valid for power-of-two lengths).

fn read_lagrange4 Arguments

Name Type Default Description
data Span[SIMD[DType.float64, num_chans]] The Span[MFloat[num_chans], ...] to read from.
f_idx Float64 The floating-point index to read at.

fn read_lagrange4 Returns : SIMD[DType.float64, num_chans] The fourth-order Lagrange interpolated sample value.

Static Method

This is a static method.

struct SpanInterpolator . fn read_sinc

Read a value from a Span[MFloat[num_chans], ...] using provided index with SincInterpolation.

fn read_sinc Signature

def read_sinc[num_chans: Int = 1, bWrap: Bool = True, mask: Int = 0](world: UnsafePointer[MMMWorld, MutUntrackedOrigin], data: Span[SIMD[DType.float64, num_chans]], f_idx: Float64, prev_f_idx: Float64) -> SIMD[DType.float64, num_chans]

fn read_sinc Parameters

Name Type Default Description
num_chans Int 1 Number of channels in the data.
bWrap Bool True Whether to wrap indices that go out of bounds.
mask Int 0 Bitmask for wrapping indices (if applicable). If 0, standard modulo wrapping is used. If non-zero, bitwise AND wrapping is used (only valid for power-of-two lengths).

fn read_sinc Arguments

Name Type Default Description
world UnsafePointer[MMMWorld, MutUntrackedOrigin] Pointer to the MMMWorld instance.
data Span[SIMD[DType.float64, num_chans]] The Span[MFloat[num_chans], ...] to read from.
f_idx Float64 The floating-point index to read at.
prev_f_idx Float64 The previous floating-point index.

fn read_sinc Returns : SIMD[DType.float64, num_chans] The sinc-interpolated sample value.

Static Method

This is a static method.


Documentation generated with mojo doc from Mojo version 1.0.0b2