Skip to content
Structs

struct Buffer

Buffer for holding data (often audio data).

There are two ways to initialize a Buffer (see the two __init__ methods below):

  1. By providing a list of lists of Float64 samples, where each inner list represents a channel. You can also specify the sample rate of the buffer.

  2. As an "empty" buffer (filled with zeros) by specifying the number of channels and the number of samples per channel.

Traits: AnyType, Buffable, Copyable, Movable, UnknownDestructibility


Buffer Functions

struct Buffer . fn init

Initialize a Buffer of data with channels.

fn init Signature

__init__(out self, lists: List[List[Float64]] = List[List[Float64]](), buf_sample_rate: Float64 = 48000)

fn init Arguments

Name Type Default Description
lists List List[List[Float64]]() List of channels, each channel is a List of Float64 samples.
buf_sample_rate Float64 48000 Sample rate of the buffer (default is 48000.0).

fn init Returns : Self

Static Method

This is a static method.

struct Buffer . fn init

Initialize a Buffer filled with zeros.

fn init Signature

__init__(out self, num_chans: Int64 = 2, samples: Int64 = 48000, buf_sample_rate: Float64 = 48000)

fn init Arguments

Name Type Default Description
num_chans Int64 2 Number of channels (default is 2 for stereo).
samples Int64 48000 Number of samples per channel (default is 48000 for 1 second at 48kHz).
buf_sample_rate Float64 48000 Sample rate of the buffer (default is 48000.0).

fn init Returns : Self

Static Method

This is a static method.

struct Buffer . fn init

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

fn init Signature

__init__(out self, filename: String, chans_per_channel: Int64 = 1)

fn init Arguments

Name Type Default Description
filename String Path to the WAV file to load.
chans_per_channel Int64 1

fn init Returns : Self

Static Method

This is a static method.

struct Buffer . fn get_num_frames

fn get_num_frames Signature

get_num_frames(self) -> Float64

fn get_num_frames Returns : Float64

struct Buffer . fn get_item

fn get_item Signature

get_item(self, chan_index: Int64, frame_index: Int64) -> Float64

fn get_item Arguments

Name Type Default Description
chan_index Int64
frame_index Int64

fn get_item Returns : Float64

struct Buffer . fn quadratic_interp_loc

Perform quadratic interpolation between three samples in the buffer.

fn quadratic_interp_loc Signature

quadratic_interp_loc(self, idx: Int64, idx1: Int64, idx2: Int64, frac: Float64, chan: Int64) -> Float64

fn quadratic_interp_loc Arguments

Name Type Default Description
idx Int64
idx1 Int64
idx2 Int64
frac Float64
chan Int64

fn quadratic_interp_loc Returns : Float64

struct Buffer . fn linear_interp_loc

Perform linear interpolation between two samples in the buffer.

fn linear_interp_loc Signature

linear_interp_loc(self, idx: Int64, idx1: Int64, frac: Float64, chan: Int64) -> Float64

fn linear_interp_loc Arguments

Name Type Default Description
idx Int64
idx1 Int64
frac Float64
chan Int64

fn linear_interp_loc Returns : Float64

struct Buffer . fn read_phase_none

read one sample with no interpolation.

fn read_phase_none Signature

read_phase_none(self, phase: Float64, chan: Int64) -> Float64

fn read_phase_none Arguments

Name Type Default Description
phase Float64
chan Int64

fn read_phase_none Returns : Float64

struct Buffer . fn read_sinc

fn read_sinc Signature

read_sinc(self, phase: Float64, last_phase: Float64, channel: Int64) -> Float64

fn read_sinc Arguments

Name Type Default Description
phase Float64
last_phase Float64
channel Int64

fn read_sinc Returns : Float64

struct Buffer . fn read_index

fn read_index Signature

read_index[N: Int = 1, interp: Int64 = 0](self, start_chan: Int64, f_idx: Float64) -> SIMD[DType.float64, N]

fn read_index Parameters

Name Type Description
N Int
interp Int64

fn read_index Arguments

Name Type Default Description
start_chan Int64
f_idx Float64

fn read_index Returns : SIMD

struct Buffer . fn read_phase

A read operation on the buffer that reads a multichannel buffer and returns a SIMD vector of size N. It will start reading from the channel specified by start_chan and read N channels from there.

fn read_phase Signature

read_phase[N: Int = 1, interp: Int64 = 0](self, start_chan: Int64, phase: Float64) -> SIMD[DType.float64, N]

fn read_phase Parameters

Name Type Description
N Int The number of channels to read (default is 1). The SIMD vector returned will have this size as well.
interp Int64

fn read_phase Arguments

Name Type Default Description
start_chan Int64 The starting channel index to read from (0-based).
phase Float64 The phase position to read from, where 0.0 is the start of the buffer and 1.0 is the end.

fn read_phase Returns : SIMD

struct Buffer . fn write

Write a SIMD vector of values to the buffer at a specific index and channel. None fn write Signature

write[N: Int](mut self, value: SIMD[DType.float64, N], index: Int64, start_channel: Int64 = 0)

fn write Parameters

Name Type Description
N Int

fn write Arguments

Name Type Default Description
value SIMD The SIMD vector of values to write to the buffer.
index Int64 The index in the buffer to write to (0-based).
start_channel Int64 0 The starting channel index to write to (0-based).

struct Buffer . fn write_next_index

The Buffer struct keeps an internal index that tracks where the next write should occur. This method writes the given SIMD value to the buffer at the current index and then increments the index. If the index exceeds the number of frames, it wraps around to the beginning of the buffer. None. fn write_next_index Signature

write_next_index[N: Int](mut self, value: SIMD[DType.float64, N], start_channel: Int64 = 0)

fn write_next_index Parameters

Name Type Description
N Int

fn write_next_index Arguments

Name Type Default Description
value SIMD The SIMD vector of values to write to the buffer.
start_channel Int64 0 The starting channel index to write to (0-based).

struct Sinc_Interpolator

Traits: AnyType, Copyable, Movable, UnknownDestructibility

Sinc_Interpolator Parameters

Name Type Description
ripples Int64
power Int64

Sinc_Interpolator Functions

struct Sinc_Interpolator . fn init

fn init Signature

__init__(out self, num_frames: Int64)

fn init Arguments

Name Type Default Description
num_frames Int64

fn init Returns : Self

Static Method

This is a static method.

struct Sinc_Interpolator . fn interp_points

fn interp_points Signature

interp_points(self: Sinc_Interpolator[ripples, power], sp: Int64, sinc_offset: Int64, sinc_mult: Int64, frac: Float64) -> Float64

fn interp_points Arguments

Name Type Default Description
sp Int64
sinc_offset Int64
sinc_mult Int64
frac Float64

fn interp_points Returns : Float64

struct Sinc_Interpolator . fn spaced_sinc

fn spaced_sinc Signature

spaced_sinc[T: Buffable](self, ref buffer: T, channel: Int64, index: Int64, frac: Float64, spacing: Int64) -> Float64

fn spaced_sinc Parameters

Name Type Description
T Buffable

fn spaced_sinc Arguments

Name Type Default Description
buffer T
channel Int64
index Int64
frac Float64
spacing Int64

fn spaced_sinc Returns : Float64

struct Sinc_Interpolator . fn read_sinc

fn read_sinc Signature

read_sinc[T: Buffable](self, ref buffer: T, phase: Float64, last_phase: Float64, channel: Int64) -> Float64

fn read_sinc Parameters

Name Type Description
T Buffable

fn read_sinc Arguments

Name Type Default Description
buffer T
phase Float64
last_phase Float64
channel Int64

fn read_sinc Returns : Float64

struct OscBuffers

Traits: AnyType, Buffable, Copyable, Movable, UnknownDestructibility


OscBuffers Functions

struct OscBuffers . fn init

fn init Signature

__init__(out self)

fn init Returns : Self

Static Method

This is a static method.

struct OscBuffers . fn get_num_frames

fn get_num_frames Signature

get_num_frames(self) -> Float64

fn get_num_frames Returns : Float64

struct OscBuffers . fn get_item

fn get_item Signature

get_item(self, chan_index: Int64, frame_index: Int64) -> Float64

fn get_item Arguments

Name Type Default Description
chan_index Int64
frame_index Int64

fn get_item Returns : Float64

struct OscBuffers . fn init_sine

fn init_sine Signature

init_sine(mut self)

struct OscBuffers . fn init_triangle

fn init_triangle Signature

init_triangle(mut self)

struct OscBuffers . fn init_sawtooth

fn init_sawtooth Signature

init_sawtooth(mut self)

struct OscBuffers . fn init_square

fn init_square Signature

init_square(mut self)

struct OscBuffers . fn init_triangle2

fn init_triangle2 Signature

init_triangle2(mut self)

struct OscBuffers . fn init_sawtooth2

fn init_sawtooth2 Signature

init_sawtooth2(mut self)

struct OscBuffers . fn init_square2

fn init_square2 Signature

init_square2(mut self)

struct OscBuffers . fn quadratic_interp_loc

fn quadratic_interp_loc Signature

quadratic_interp_loc(self, x: Float64, buf_num: Int64) -> Float64

fn quadratic_interp_loc Arguments

Name Type Default Description
x Float64
buf_num Int64

fn quadratic_interp_loc Returns : Float64

struct OscBuffers . fn lerp

fn lerp Signature

lerp(self, x: Float64, buf_num: Int64) -> Float64

fn lerp Arguments

Name Type Default Description
x Float64
buf_num Int64

fn lerp Returns : Float64

struct OscBuffers . fn read_none

fn read_none Signature

read_none(self, phase: Float64, buf_num: Int64) -> Float64

fn read_none Arguments

Name Type Default Description
phase Float64
buf_num Int64

fn read_none Returns : Float64

struct OscBuffers . fn read_lin

fn read_lin Signature

read_lin(self, phase: Float64, buf_num: Int64) -> Float64

fn read_lin Arguments

Name Type Default Description
phase Float64
buf_num Int64

fn read_lin Returns : Float64

struct OscBuffers . fn read_quadratic

fn read_quadratic Signature

read_quadratic(self, phase: Float64, buf_num: Int64) -> Float64

fn read_quadratic Arguments

Name Type Default Description
phase Float64
buf_num Int64

fn read_quadratic Returns : Float64

struct OscBuffers . fn read

fn read Signature

read[interp: Int = 0](self, phase: Float64, osc_type: Int64 = 0) -> Float64

fn read Parameters

Name Type Description
interp Int

fn read Arguments

Name Type Default Description
phase Float64
osc_type Int64 0

fn read Returns : Float64

struct OscBuffers . fn read_sinc

fn read_sinc Signature

read_sinc(self, phase: Float64, last_phase: Float64, channel: Int64) -> Float64

fn read_sinc Arguments

Name Type Default Description
phase Float64
last_phase Float64
channel Int64

fn read_sinc Returns : Float64


Documentation generated with mojo doc from Mojo version 0.25.6.1