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, ImplicitlyDestructible, 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

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

fn init Arguments

Name Type Default Description
data List 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 zeros

Initialize a SIMDBuffer with zeros.

fn zeros Signature

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

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

zero(mut self)

struct SIMDBuffer . fn load

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

fn load Signature

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

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

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

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 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, ImplicitlyDestructible, Movable


Buffer Functions

struct Buffer . fn init

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

fn init Signature

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

fn init Arguments

Name Type Default Description
data List 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 zeros

Initialize a Buffer with zeros.

fn zeros Signature

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

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

zero(mut self)

struct Buffer . fn load

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

fn load Signature

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

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, ImplicitlyDestructible, Movable


SpanInterpolator Functions

struct SpanInterpolator . fn idx_in_range

fn idx_in_range Signature

idx_in_range[num_chans: Int = 1](data: Span[SIMD[DType.float64, num_chans], origin], 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
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

read[num_chans: Int = 1, interp: Int = Interp.none, bWrap: Bool = True, mask: Int = 0](world: UnsafePointer[MMMWorld, MutExternalOrigin], data: Span[SIMD[DType.float64, num_chans], origin], 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 Int 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 Pointer to the MMMWorld instance.
data Span 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

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

read_none[num_chans: Int = 1, bWrap: Bool = True, mask: Int = 0](data: Span[SIMD[DType.float64, num_chans], origin], 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 The Span[MFloat[num_chans]] to read from.
f_idx Float64 The floating-point index to read at.

fn read_none Returns : SIMD

Static Method

This is a static method.

struct SpanInterpolator . fn read_none

fn read_none Signature

read_none[num_chans: Int = 1, bWrap: Bool = True, mask: Int = 0](data: Span[SIMD[DType.float64, num_chans], origin], 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
idx Int

fn read_none Returns : SIMD

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

read_linear[num_chans: Int = 1, bWrap: Bool = True, mask: Int = 0](data: Span[SIMD[DType.float64, num_chans], origin], 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 The Span[MFloat[num_chans]] to read from.
f_idx Float64 The floating-point index to read at.

fn read_linear Returns : SIMD

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

read_quad[num_chans: Int = 1, bWrap: Bool = True, mask: Int = 0](data: Span[SIMD[DType.float64, num_chans], origin], 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 The Span[MFloat[num_chans]] to read from.
f_idx Float64 The floating-point index to read at.

fn read_quad Returns : SIMD

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

read_cubic[num_chans: Int = 1, bWrap: Bool = True, mask: Int = 0](data: Span[SIMD[DType.float64, num_chans], origin], 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 The Span[MFloat[num_chans]] to read from.
f_idx Float64 The floating-point index to read at.

fn read_cubic Returns : SIMD

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

read_lagrange4[num_chans: Int = 1, bWrap: Bool = True, mask: Int = 0](data: Span[SIMD[DType.float64, num_chans], origin], 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 The Span[MFloat[num_chans]] to read from.
f_idx Float64 The floating-point index to read at.

fn read_lagrange4 Returns : SIMD

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

read_sinc[num_chans: Int = 1, bWrap: Bool = True, mask: Int = 0](world: UnsafePointer[MMMWorld, MutExternalOrigin], data: Span[SIMD[DType.float64, num_chans], origin], 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 Pointer to the MMMWorld instance.
data Span 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

Static Method

This is a static method.


Documentation generated with mojo doc from Mojo version 0.26.1.0