Skip to content

Windows

Structs

struct Windows

Stores various window functions used in audio processing. This struct precomputes several common window types.

Traits: AnyType, Copyable, ImplicitlyDeletable, Movable


Windows Functions

struct Windows . fn init

fn init Signature

def __init__(out self)

fn init Returns : Self

Static Method

This is a static method.

struct Windows . fn at_pan

Get the left and right pan multipliers for a given pan value between 0.0 (left) and 1.0 (right). This uses a quarter cosine window for smooth panning.

fn at_pan Signature

def at_pan[interp: Interp = Interp.none](self, world: UnsafePointer[MMMWorld, MutUntrackedOrigin], pan: Float64) -> SIMD[DType.float64, 2]

fn at_pan Parameters

Name Type Default Description
interp Interp Interp.none Interpolation mode used when reading the window table.

fn at_pan Arguments

Name Type Default Description
world UnsafePointer[MMMWorld, MutUntrackedOrigin] The current audio world.
pan Float64 Pan position between 0.0 (left) and 1.0 (right).

fn at_pan Returns : SIMD[DType.float64, 2] MFloat[2] where the first element is the left channel multiplier and the second element is the right channel multiplier.

struct Windows . fn at_phase

Get a window value at the given normalized phase.

fn at_phase Signature

def at_phase[num_chans: Int, window_type: WindowType, interp: Interp = Interp.none](self, world: UnsafePointer[MMMWorld, MutUntrackedOrigin], phase: SIMD[DType.float64, num_chans], prev_phase: SIMD[DType.float64, num_chans] = 0) -> SIMD[DType.float64, num_chans]

fn at_phase Parameters

Name Type Default Description
num_chans Int Size of the SIMD vector.
window_type WindowType Window type to sample.
interp Interp Interp.none Interpolation mode used when reading the window table.

fn at_phase Arguments

Name Type Default Description
world UnsafePointer[MMMWorld, MutUntrackedOrigin] The current audio world.
phase SIMD[DType.float64, num_chans] Normalized phase values in the range 0.0 to 1.0.
prev_phase SIMD[DType.float64, num_chans] 0 Previous normalized phase values for interpolators that need them.

fn at_phase Returns : SIMD[DType.float64, num_chans] Window values sampled at the requested phases.

struct Windows . fn make_window

Generate a window of specified type and size.

fn make_window Signature

def make_window[window_type: WindowType](size: Int, beta: Float64 = 5) -> List[Float64]

fn make_window Parameters

Name Type Default Description
window_type WindowType Type of window to generate. Use comptime variables from WindowType struct (e.g. WindowType.hann).

fn make_window Arguments

Name Type Default Description
size Int Length of the window.
beta Float64 5 Shape parameter only used for Kaiser window. See kaiser_window() for details.

fn make_window Returns : List[Float64] List[Float64] of length size containing the window values.

Static Method

This is a static method.

Functions

(Functions that are not associated with a Struct)

fn rect_window

Generate a rectangular window of length size.

Signature

def rect_window(size: Int) -> List[Float64]

Arguments

Name Type Default Description
size Int Length of the window.

Returns

Type: List[Float64] List containing the rectangular window values (all ones).

fn tri_window

Generate a triangular window of length size.

Signature

def tri_window(size: Int) -> List[Float64]

Arguments

Name Type Default Description
size Int Length of the window.

Returns

Type: List[Float64] List containing the triangular window values.

fn bessel_i0

Calculate the modified Bessel function of the first kind, order 0 (I₀). Uses polynomial approximation for accurate results.

Signature

def bessel_i0(x: Float64) -> Float64

Arguments

Name Type Default Description
x Float64 Input value.

Returns

Type: Float64 I₀(x).

fn kaiser_window

Create a Kaiser window of length n with shape parameter beta.

  • beta = 0: rectangular window.
  • beta = 5: similar to Hamming window.
  • beta = 6: similar to Hanning window.
  • beta = 8.6: similar to Blackman window.

Signature

def kaiser_window(size: Int, beta: Float64) -> List[Float64]

Arguments

Name Type Default Description
size Int Length of the window.
beta Float64 Shape parameter that controls the trade-off between main lobe width and side lobe level. See description for details.

Returns

Type: List[Float64] List[Float64] containing the Kaiser window coefficients.

fn hann_window

Generate a Hann window of length size.

Signature

def hann_window(size: Int) -> List[Float64]

Arguments

Name Type Default Description
size Int Length of the window.

Returns

Type: List[Float64] List containing the Hann window values.

fn hamming_window

Generate a Hamming window of length size.

Signature

def hamming_window(size: Int) -> List[Float64]

Arguments

Name Type Default Description
size Int Length of the window.

Returns

Type: List[Float64] List containing the Hamming window values.

fn blackman_window

Generate a Blackman window of length size.

Signature

def blackman_window(size: Int) -> List[Float64]

Arguments

Name Type Default Description
size Int Length of the window.

Returns

Type: List[Float64] List containing the Blackman window values.

fn sine_window

Generate a Sine window of length size.

Signature

def sine_window(size: Int) -> List[Float64]

Arguments

Name Type Default Description
size Int Length of the window.

Returns

Type: List[Float64] List containing the Sine window values.

fn pan2_window

Generate a MFloat[2] quarter cosine window for panning. The first element of the SIMD vector is the multiplier for the left channel, and the second element is for the right channel. This allows any sample to be panned at one of size positions between left and right channels smoothly.

Signature

def pan2_window(size: Int) -> List[SIMD[DType.float64, 2]]

Arguments

Name Type Default Description
size Int Length of the window.

Returns

Type: List[SIMD[DType.float64, 2]] List containing the quarter cosine window values.

fn gaussian_window

Generate a Gaussian bell curve window of length size.

Signature

def gaussian_window(size: Int) -> List[Float64]

Arguments

Name Type Default Description
size Int Length of the window.

Returns

Type: List[Float64] List containing the gaussian window values.


Documentation generated with mojo doc from Mojo version 1.0.0b2