Skip to content

Oversampling

Structs

struct Downsampler

A struct that collects times_oversampling samples and then downsamples them using a low-pass filter. Add a sample for each oversampling iteration with add_sample(), then get the downsampled output with get_sample(). VERY IMPORTANT, when initializing this struct, use the main world, not the oversampled subworld. The Downsampler exists outside of the oversampled subworld!

Traits: AnyType, Copyable, ImplicitlyDeletable, Movable, PolyReset

Downsampler Parameters

Name Type Default Description
num_chans Int 1 Number of channels for the downsampling buffer.
ov_samp TimesOversampling TimesOversampling.none A TimesOversampling struct to indicate times oversampling.

Downsampler Functions

struct Downsampler . fn init

Initialize the Downsampler struct.

fn init Signature

def __init__(out self, world: UnsafePointer[MMMWorld, MutUntrackedOrigin])

fn init Arguments

Name Type Default Description
world UnsafePointer[MMMWorld, MutUntrackedOrigin] Pointer to the MMMWorld instance. VERY IMPORTANT to use the main world, not the oversampled subworld, for this struct.

fn init Returns : Self

Static Method

This is a static method.

struct Downsampler . fn add_sample

Add a sample to the oversampling buffer.

fn add_sample Signature

def add_sample(mut self, sample: SIMD[DType.float64, num_chans])

fn add_sample Arguments

Name Type Default Description
sample SIMD[DType.float64, num_chans] The sample to add to the buffer.

struct Downsampler . fn get_sample

Get the next sample from a filled oversampling buffer.

fn get_sample Signature

def get_sample(mut self) -> SIMD[DType.float64, num_chans]

fn get_sample Returns : SIMD[DType.float64, num_chans] The downsampled output sample.

struct Downsampler . fn reset

Reset the internal state of the upsampler.

fn reset Signature

def reset(mut self)

struct Upsampler

A struct that upsamples the input signal by the specified factor using a low-pass filter.

Traits: AnyType, Copyable, ImplicitlyDeletable, Movable, PolyReset

Upsampler Parameters

Name Type Default Description
num_chans Int 1 Number of channels for the upsampler.
ov_samp TimesOversampling TimesOversampling.x2 A TimesOversampling struct to indicate times oversampling.

Upsampler Functions

struct Upsampler . fn init

Initialize the Upsampler.

fn init Signature

def __init__(out self, world: UnsafePointer[MMMWorld, MutUntrackedOrigin])

fn init Arguments

Name Type Default Description
world UnsafePointer[MMMWorld, MutUntrackedOrigin] Pointer to the MMMWorld instance.

fn init Returns : Self

Static Method

This is a static method.

struct Upsampler . fn next

Process one sample through the upsampler. Pass in the same sample times_oversampling times, once for each oversampling iteration. The algorithm will use the first sample given and fill the buffer with zeroes for the subsequent samples.

fn next Signature

def next(mut self, input: SIMD[DType.float64, num_chans], i: Int) -> SIMD[DType.float64, num_chans]

fn next Arguments

Name Type Default Description
input SIMD[DType.float64, num_chans] The input signal to process.
i Int The iterator for the oversampling loop. Should range from 0 to (times_oversampling - 1).

fn next Returns : SIMD[DType.float64, num_chans] The next sample of the upsampled output.

struct Upsampler . fn reset

Reset the internal state of the upsampler.

fn reset Signature

def reset(mut self)

struct OS_LPF

A simple 2nd-order low-pass filter for oversampling applications. Does not allow changing cutoff frequency on the fly to avoid that calculation each sample.

Traits: AnyType, Copyable, ImplicitlyDeletable, Movable

OS_LPF Parameters

Name Type Default Description
num_chans Int 1 Number of channels for the filter.

OS_LPF Functions

struct OS_LPF . fn init

Initialize the oversampling low-pass filter.

fn init Signature

def __init__(out self, sample_rate: Float64)

fn init Arguments

Name Type Default Description
sample_rate Float64 The sample rate in Hz.

fn init Returns : Self

Static Method

This is a static method.

struct OS_LPF . fn set_sample_rate

Set the sample rate for the filter.

fn set_sample_rate Signature

def set_sample_rate(mut self, sr: Float64)

fn set_sample_rate Arguments

Name Type Default Description
sr Float64 The sample rate in Hz.

struct OS_LPF . fn set_cutoff

Set the cutoff frequency for the low-pass filter.

fn set_cutoff Signature

def set_cutoff(mut self, fc: Float64)

fn set_cutoff Arguments

Name Type Default Description
fc Float64 The cutoff frequency in Hz.

struct OS_LPF . fn next

Process one sample through the 2nd-order low-pass filter.

fn next Signature

def next(mut self, x: SIMD[DType.float64, num_chans]) -> SIMD[DType.float64, num_chans]

fn next Arguments

Name Type Default Description
x SIMD[DType.float64, num_chans] The input signal to process.

fn next Returns : SIMD[DType.float64, num_chans] The filtered output sample.

struct OS_LPF . fn reset

Reset the internal state of the low-pass filter.

fn reset Signature

def reset(mut self)

struct OS_LPF4

A 4th-order low-pass filter for oversampling applications, implemented as two cascaded 2nd-order sections.

Traits: AnyType, Copyable, ImplicitlyDeletable, Movable

OS_LPF4 Parameters

Name Type Default Description
num_chans Int 1 Number of channels for the filter with fixed cutoff frequency.

OS_LPF4 Functions

struct OS_LPF4 . fn init

Initialize the 4th order oversampling low-pass filter.

fn init Signature

def __init__(out self, sample_rate: Float64)

fn init Arguments

Name Type Default Description
sample_rate Float64 The sample rate in Hz.

fn init Returns : Self

Static Method

This is a static method.

struct OS_LPF4 . fn set_sample_rate

fn set_sample_rate Signature

def set_sample_rate(mut self, sr: Float64)

fn set_sample_rate Arguments

Name Type Default Description
sr Float64

struct OS_LPF4 . fn set_cutoff

fn set_cutoff Signature

def set_cutoff(mut self, fc: Float64)

fn set_cutoff Arguments

Name Type Default Description
fc Float64

struct OS_LPF4 . fn next

Process one sample through the 4th-order low-pass filter with fixed cutoff frequency.

fn next Signature

def next(mut self, x: SIMD[DType.float64, num_chans]) -> SIMD[DType.float64, num_chans]

fn next Arguments

Name Type Default Description
x SIMD[DType.float64, num_chans] The input signal to process.

fn next Returns : SIMD[DType.float64, num_chans] The filtered output sample.

struct OS_LPF4 . fn reset

Reset the internal state of the 4th-order low-pass filter.

fn reset Signature

def reset(mut self)

Documentation generated with mojo doc from Mojo version 1.0.0b2