Skip to content

Pan

Structs

struct VBAP2D

An implementation of VBAP (Vector Base Amplitude Panning). Pans a mono sample to a 2D array of N speakers of arbitrary positions in radians that are equidistant from the listener. For more on VBAP see the paper written by Ville Pulkki: https://www.audiolabs-erlangen.de/media/pages/resources/aps-w23/papers/935eb793db-1663358804/sap_Pulkki1997.pdf .

Traits: AnyType, Copyable, Deinitable, Movable


VBAP2D Functions

struct VBAP2D . fn init

Initializes an instance of VBAP2D.

fn init Signature

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

fn init Arguments

Name Type Default Description
speaker_positions List[Float64] A List of azimuth values in radians. The order of speakers given corresponds to the output channels ie. The speaker defined as the first element of the list will output on channel 0.

fn init Returns : Self

Static Method

This is a static method.

struct VBAP2D . fn calc_speaker_unit_vectors

Used internally to calculate the unit vectors of each speaker from a given azimuth.

fn calc_speaker_unit_vectors Signature

def calc_speaker_unit_vectors(mut self) -> List[SIMD[DType.float64, SIMDLength(2)]]

fn calc_speaker_unit_vectors Returns : List[SIMD[DType.float64, SIMDLength(2)]] A list of unit vectors.

struct VBAP2D . fn calc_inverse_base

Used internally to calculate the inverse bases of speaker matrices.

fn calc_inverse_base Signature

def calc_inverse_base(mut self) -> List[Array[SIMD[DType.float64, SIMDLength(2)], Int(2)]]

fn calc_inverse_base Returns : List[Array[SIMD[DType.float64, SIMDLength(2)], Int(2)]] A list of inverse base matrices.

struct VBAP2D . fn index_of

Finds the index of the first appearance of an element in a list.

fn index_of Signature

def index_of(mut self, list: List[Float64], element: Float64) -> Int

fn index_of Arguments

Name Type Default Description
list List[Float64] The list to search through.
element Float64 The element to search for.

fn index_of Returns : Int The index of the element.

struct VBAP2D . fn calc_speaker_pairs

Used internally by VBAP2D to determine speaker pairs.

fn calc_speaker_pairs Signature

def calc_speaker_pairs(mut self) -> List[List[Int]]

fn calc_speaker_pairs Returns : List[List[Int]] A list of speaker pairs.

struct VBAP2D . fn calc_gain_factors

Internal method used for calculating gain factors of speaker pairs.

fn calc_gain_factors Signature

def calc_gain_factors(mut self, source_vec: SIMD[DType.float64, SIMDLength(2)], mut active_pair: List[Int], mut active_gains: SIMD[DType.float64, SIMDLength(2)], source_az: Float64)

fn calc_gain_factors Arguments

Name Type Default Description
source_vec SIMD[DType.float64, SIMDLength(2)] The unit vector of the source.
active_pair List[Int] The current active speaker pair.
active_gains SIMD[DType.float64, SIMDLength(2)] The current active gains.
source_az Float64 The azimuth position of the source.

struct VBAP2D . fn next

Pans a mono sample based on a target azimuth.

fn next Signature

def next[simd_out_size: Int](mut self, sample: Float64, az: Float64) -> SIMD[DType.float64, simd_out_size]

fn next Parameters

Name Type Default Description
simd_out_size Int Number of channels of the SIMD output vector. Must be a power of two that is at least as large as num_speakers.

fn next Arguments

Name Type Default Description
sample Float64 A mono sample to pan.
az Float64 The azimuth in radians.

fn next Returns : SIMD[DType.float64, simd_out_size] MFloat[simd_out_size]: The panned output sample for each speaker.

Functions

(Functions that are not associated with a Struct)

fn pan2

Simple constant power panning function.

Signature

def pan2(sample: Float64, pan: Float64) -> SIMD[DType.float64, SIMDLength(2)]

Arguments

Name Type Default Description
sample Float64 Float64 - Mono input sample.
pan Float64 Float64 - Pan value from -1.0 (left) to 1.0 (right).

Returns

Type: SIMD[DType.float64, SIMDLength(2)] Stereo output as MFloat[2].

fn pan_stereo

Simple constant power panning function for stereo samples.

Signature

def pan_stereo(samples: SIMD[DType.float64, SIMDLength(2)], pan: Float64) -> SIMD[DType.float64, SIMDLength(2)]

Arguments

Name Type Default Description
samples SIMD[DType.float64, SIMDLength(2)] MFloat[2] - Stereo input sample.
pan Float64 Float64 - Pan value from -1.0 (left) to 1.0 (right).

Returns

Type: SIMD[DType.float64, SIMDLength(2)] Stereo output as MFloat[2].

fn splay

Splay multiple input channels into stereo output.

There are multiple versions of splay to handle different input types. It can take a List or Array of SIMD vectors, a VariadicList of SIMD, or a single 1 or many channel SIMD vector. In the case of a list of SIMD vectors, each channel within the vector is treated separately and panned individually.

Signature

def splay(*input: SIMD[DType.float64, N], *, world: Pointer[MMMWorld, MutUntrackedOrigin]) -> SIMD[DType.float64, SIMDLength(2)]

Arguments

Name Type Default Description
*input SIMD[DType.float64, N] VariadicList of input samples from multiple channels.
world Pointer[MMMWorld, MutUntrackedOrigin] Pointer to MMMWorld containing the pan_window. world is a keyword argument that needs to be explicitly assign (world=world) when calling splay().

Returns

Type: SIMD[DType.float64, SIMDLength(2)] Stereo output as MFloat[2].



fn splay

Splay multiple input channels into stereo output.

There are multiple versions of splay to handle different input types. It can take a List or Array of SIMD vectors, a VariadicList of SIMD, or a single 1 or many channel SIMD vector. In the case of a list of SIMD vectors, each channel within the vector is treated separately and panned individually.

Signature

def splay[num_simd: SIMDLength](input: Span[SIMD[DType.float64, num_simd]], world: Pointer[MMMWorld, MutUntrackedOrigin]) -> SIMD[DType.float64, SIMDLength(2)]

Parameters

Name Type Description
num_simd SIMDLength Number of channels in each SIMD input.

Arguments

Name Type Default Description
input Span[SIMD[DType.float64, num_simd]] VariadicList of input samples from multiple channels.
world Pointer[MMMWorld, MutUntrackedOrigin] Pointer to MMMWorld containing the pan_window.

Returns

Type: SIMD[DType.float64, SIMDLength(2)] Stereo output as MFloat[2].

fn splay

Splay multiple input channels into stereo output.

There are multiple versions of splay to handle different input types. It can take a List or Array of SIMD vectors, a VariadicList of SIMD, or a single 1 or many channel SIMD vector. In the case of a list of SIMD vectors, each channel within the vector is treated separately and panned individually.

Signature

def splay[num_input_channels: Int](input: SIMD[DType.float64, num_input_channels], world: Pointer[MMMWorld, MutUntrackedOrigin]) -> SIMD[DType.float64, SIMDLength(2)]

Parameters

Name Type Description
num_input_channels Int Number of input channels.

Arguments

Name Type Default Description
input SIMD[DType.float64, num_input_channels] VariadicList of input samples from multiple channels.
world Pointer[MMMWorld, MutUntrackedOrigin] Pointer to MMMWorld containing the pan_window.

Returns

Type: SIMD[DType.float64, SIMDLength(2)] Stereo output as MFloat[2].

fn make_mul_list

Signature

def make_mul_list[num_speakers: Int, simd_out_size: Int, pan_points: Int]() -> Array[SIMD[DType.float64, simd_out_size], pan_points]

Parameters

Name Type Description
num_speakers Int
simd_out_size Int
pan_points Int

Returns

Type: Array[SIMD[DType.float64, simd_out_size], pan_points]

fn splay_n

Splay multiple input channels into an arbitrary number of output channels.

Signature

def splay_n[simd_in_width: SIMDLength, num_speakers: Int, simd_out_size: SIMDLength, pan_points: Int](input: Span[SIMD[DType.float64, simd_in_width], address_space=input.address_space], world: Pointer[MMMWorld, MutUntrackedOrigin]) -> SIMD[DType.float64, simd_out_size]

Parameters

Name Type Description
simd_in_width SIMDLength Number of channels in each SIMD input.
num_speakers Int Number of output speakers. Must be less than or equal to simd_out_size.
simd_out_size SIMDLength Number of channels of the SIMD output vector. Must be a power of two that is at least as large as num_speakers.
pan_points Int Number of discrete pan points to calculate for the panning algorithm. More pan points will increase the resolution of the pan but also increase CPU usage. 100 is usually sufficient for smooth panning.

Arguments

Name Type Default Description
input Span[SIMD[DType.float64, simd_in_width], address_space=input.address_space] Span of input samples from multiple channels, where each channel is a SIMD vector.
world Pointer[MMMWorld, MutUntrackedOrigin] Pointer to MMMWorld containing the pan_window.

Returns

Type: SIMD[DType.float64, simd_out_size] MFloat[simd_out_size]: The panned output with one speaker per channel. Extra SIMD channels will be filled with zeros.

fn pan_az

Pan a mono sample to N speakers arranged in a circle around the listener using azimuth panning.

Signature

def pan_az[simd_out_size: Int = Int(2)](sample: Float64, pan: Float64, num_speakers: Int, width: Float64 = 2, orientation: Float64 = 0.5) -> SIMD[DType.float64, simd_out_size]

Parameters

Name Type Description
simd_out_size Int Number of output channels (speakers). Must be a power of two that is at least as large as num_speakers.

Arguments

Name Type Default Description
sample Float64 Mono input sample.
pan Float64 Pan position from 0.0 to 1.0.
num_speakers Int Number of speakers to pan to.
width Float64 2 Width of the speaker array (default is 2.0).
orientation Float64 0.5 Orientation offset of the speaker array (default is 0.5).

Returns

Type: SIMD[DType.float64, simd_out_size] MFloat[simd_out_size]: The panned output sample for each speaker.




fn pan_az

Pan a mono sample to N speakers arranged in a circle around the listener using azimuth panning. This version fixes the number of speakers, width, and orientation at compile time for better performance.

Signature

def pan_az[num_speakers: Int = Int(2), simd_out_size: Int = Int(2), width: Float64 = 2, orientation: Float64 = 0.5](sample: Float64, pan: Float64) -> SIMD[DType.float64, simd_out_size]

Parameters

Name Type Description
num_speakers Int Number of output speakers. Can be any integer, but must be less than or equal to simd_out_size.
simd_out_size Int Number of channels of the SIMD output vector. Must be a power of two that is at least as large as num_speakers.
width Float64 Width of the speaker array (default is 2.0).
orientation Float64 Orientation offset of the speaker array (default is 0.5).

Arguments

Name Type Default Description
sample Float64 Mono input sample.
pan Float64 Pan position from 0.0 to 1.0.

Returns

Type: SIMD[DType.float64, simd_out_size] MFloat[simd_out_size]: The panned output sample for each speaker.

fn dbap2D

Implements DBAP (Distance Based Amplitude Panning). Pans a mono sample to N speakers of arbitrary positions in meters. For more on DBAP see the paper written by Trond Lossius, Pascal Baltazar, and Theo de la Hague. https://jamoma.org/publications/attachments/icmc2009-dbap-rev1.pdf .

Signature

def dbap2D[num_speakers: Int, simd_out_size: Int, speaker_positions: Array[SIMD[DType.float64, SIMDLength(2)], num_speakers], weights: Array[Float64, num_speakers]](sample: Float64, pos: SIMD[DType.float64, SIMDLength(2)], blur: Float64 = 0.10000000000000001, rolloff: Float64 = Float64("6")) -> SIMD[DType.float64, simd_out_size]

Parameters

Name Type Description
num_speakers Int The number of speakers as an integer.
simd_out_size Int Must be a power of 2 and greater than num_speakers.
speaker_positions Array[SIMD[DType.float64, SIMDLength(2)], num_speakers] The speaker positions as an Array of MFloat[2] x/y pairs in meters from a center position.
weights Array[Float64, num_speakers] An Array of Float64s (between 0.0 and 1.0) defining speaker weights for DBAP. Speaker weights allow for a source to be restricted to a subset of speakers. Speaker weights of 0.0 will disallow a source from playing through that speaker.

Arguments

Name Type Default Description
sample Float64 Mono input sample.
pos SIMD[DType.float64, SIMDLength(2)] X/Y position of the source from center in meters as an MFloat[2].
blur Float64 0.10000000000000001 Blurs the source, causing it to spread to more speakers. Values must be greater than or equal to 0, with 0 being the most localizable and values > 0 becoming less and less localizable. There is no limit to the amount of blur but values over 5 have diminishing returns.
rolloff Float64 Float64("6") The amplitude rolloff in dB, this must be > 0.0. 6.0 equals the inverse distance law for sound in an open field. Lower values will decrease the attenuation of the signal over distance, while larger values will increase this attenuation.

Returns

Type: SIMD[DType.float64, simd_out_size] MFloat[simd_out_size]: The panned output sample for each speaker.


Documentation generated with mojo doc from Mojo version 1.0.0