Skip to main content

MathAudioSource

Struct MathAudioSource 

Source
pub struct MathAudioSource {
Show 14 fields pub function: MathFunction, pub frequency_range: (f32, f32), pub amplitude: f32, pub waveform: Waveform, pub filter: Option<AudioFilter>, pub position: Vec3, pub filter2: Option<AudioFilter>, pub tag: Option<String>, pub lifetime: f32, pub detune_cents: f32, pub spatial: bool, pub max_distance: f32, pub fade_in: f32, pub fade_out: f32,
}
Expand description

A mathematical audio source — oscillator driven by a MathFunction.

Fields§

§function: MathFunction

The function driving this source’s frequency/amplitude modulation.

§frequency_range: (f32, f32)

Maps function output [-1, 1] to Hz: (freq_at_neg1, freq_at_pos1).

§amplitude: f32

Base amplitude [0, 1].

§waveform: Waveform

Waveform shape.

§filter: Option<AudioFilter>

Optional filter chain.

§position: Vec3

3D world position for stereo panning and distance attenuation.

§filter2: Option<AudioFilter>

Optional second filter (two-pole filtering).

§tag: Option<String>

Tag for grouping related sources (e.g. “chaos_rift”, “music”, “sfx”).

§lifetime: f32

Lifetime in seconds. -1.0 = infinite.

§detune_cents: f32

Frequency detune in cents (+100 = 1 semitone up).

§spatial: bool

Whether this source should spatialize (attenuate with distance from listener).

§max_distance: f32

Maximum distance for spatialization (beyond this = silent).

§fade_in: f32

Fade-in duration in seconds (0.0 = instant).

§fade_out: f32

Fade-out duration in seconds before lifetime ends (0.0 = instant).

Implementations§

Source§

impl MathAudioSource

Source

pub fn ambient_tone(freq: f32, amplitude: f32, position: Vec3) -> Self

Sine tone driven by a breathing function (volume/pitch gently pulsates).

Source

pub fn chaos_tone(position: Vec3) -> Self

Lorenz-driven chaotic tone (for Chaos Rifts and high-entropy regions).

Source

pub fn sweep( freq_start: f32, freq_end: f32, period: f32, position: Vec3, ) -> Self

Sine sweep — frequency glides between two values over a period.

Source

pub fn boss_drone(position: Vec3) -> Self

Low-frequency drone (sub-bass rumble for boss encounters).

Source

pub fn death_knell(position: Vec3) -> Self

Death knell — descending pitch with exponential decay.

Source

pub fn electrical_crackle(position: Vec3, duration: f32) -> Self

Electrical crackle (noise burst for lightning effects).

Source

pub fn attractor_tone( attractor_scale: f32, root_hz: f32, position: Vec3, ) -> Self

Attractor-driven harmonic resonance (entropic, alien, chaotic but musical).

Source

pub fn wind(amplitude: f32) -> Self

Wind ambience (noise with slow modulation, for outdoor environments).

Source

pub fn combat_pulse(position: Vec3, frequency_hz: f32) -> Self

Combat pulse — rhythmic hit sound tied to gameplay events.

Source

pub fn victory(position: Vec3) -> Self

Victory fanfare tone — bright, rising, major third.

Source

pub fn heartbeat(bpm: f32, position: Vec3) -> Self

Heartbeat — pulsing low frequency with biological timing.

Source

pub fn portal_hum(position: Vec3, frequency_hz: f32) -> Self

Portal hum — steady resonant tone for dimensional gateways.

Source

pub fn with_tag(self, tag: impl Into<String>) -> Self

Source

pub fn with_lifetime(self, secs: f32) -> Self

Source

pub fn with_amplitude(self, amp: f32) -> Self

Source

pub fn with_position(self, pos: Vec3) -> Self

Source

pub fn with_detune(self, cents: f32) -> Self

Source

pub fn non_spatial(self) -> Self

Source

pub fn with_fade(self, fade_in: f32, fade_out: f32) -> Self

Source

pub fn is_one_shot(&self) -> bool

Whether this source is a one-shot (has a finite lifetime).

Source

pub fn is_expired(&self, age: f32) -> bool

Whether this source has expired.

Source

pub fn envelope(&self, age: f32) -> f32

Envelope factor accounting for fade-in and fade-out at a given age.

Source

pub fn map_to_frequency(&self, value: f32) -> f32

Map a function output value in [-1, 1] to a frequency in Hz.

Trait Implementations§

Source§

impl Clone for MathAudioSource

Source§

fn clone(&self) -> MathAudioSource

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MathAudioSource

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MathAudioSource

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,