pub struct AudioBusGraph { /* private fields */ }
Expand description
Audio bus graph is a complex audio data processing entity; it allows you to route samples from audio sources through a chain of audio buses or directly to an audio playback device. To get a better understanding of how the audio graph works take a look the data flow diagram below:
┌────────────┐ ┌────────────┐
│ │ │ │
│ Source1 ├────────────┐ ┌──────────┤ Source2 │
│ │ │ │ │ │
└────────────┘ │ │ └────────────┘
▼ ▼
┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐
│ │ │ │ │ │ │ │
│ Source3 ├─────►│ Bus1 │ │ BusN │◄───┤ Source4 │
│ │ ├────────────┤ ├────────────┤ │ │
└────────────┘ │ │ │ │ └────────────┘
│ Effect1 │ │ ┌───────────┐ │ Effect1 │ │
│ │ │ │ │ │ │ │
│ Effect2 │ │ │ SourceN │ │ Effect2 │ │
│ │ │ │ │ │ │ │
│ EffectN ▼ │ └─────┬─────┘ │ EffectN ▼ │
│ │ │ │ │
└─────┬──────┘ │ └─────┬──────┘
│ │ │
│ ▼ │
│ ┌────────────┐ │
│ │ │ │
└─────────►│ Primary │◄──────┘
├────────────┤
│ │
│ Effect1 │ │
│ │ │
│ Effect2 │ │
│ │ │
│ EffectN ▼ │
│ │
└─────┬──────┘
│
│
▼
┌───────────────────────────┐
│ │
│ Output Device │
│ │
└───────────────────────────┘
Each audio bus is backed with data (samples) by a set of sound sources (Source1
, Source2
, ..) of
current audio context. This data is then passed through a set of effects, which could include various
filters (lowpass, highpass, bandpass, shelf filters, etc.) and complex effects such as reverberation.
By default, each audio bus graph has a single audio bus called Primary. It is mandatory to at least one audio bus. Primary bus is responsible for outputting the data to an audio playback device.
§Sound source binding
Each sound source binds to an audio bus using its name; this is so called implicit binding. While it may look weird, it is actually very useful. Explicit binding requires you to know the exact handle of an audio bus to which a sound is “attached”. This makes it less convenient to re-route data from one bus to another. Implicit binding is as much more effective: all you need to do is to set a new name of a bus to which output the samples from a sound source and the engine will do the rest for you. A simple example of a such binding is something like this:
let context = SoundContext::new();
let mut state = context.state();
let sfx_bus = AudioBus::new("SFX".to_string());
let bus_graph = state.bus_graph_mut();
let primary_bus = bus_graph.primary_bus_handle();
bus_graph.add_bus(sfx_bus, primary_bus);
// Create a source and implicitly bind to the SFX audio bus. By default each source
// is bound to the primary audio bus.
state.add_source(SoundSourceBuilder::new().with_bus("SFX").build().unwrap());
If you delete an audio bus to which a bunch of sound sources is bound, then they will simply stop playing.
Implementations§
Source§impl AudioBusGraph
impl AudioBusGraph
Source§impl AudioBusGraph
impl AudioBusGraph
Sourcepub const PRIMARY_BUS: &'static str = "Primary"
pub const PRIMARY_BUS: &'static str = "Primary"
The name of the audio bus that output samples directly to an audio playback device.
Sourcepub fn new() -> AudioBusGraph
pub fn new() -> AudioBusGraph
Creates a new audio bus graph. Sound context already has an audio graph instance, so calling this method is needed only for very specific cases (mostly tests).
Sourcepub fn add_bus(
&mut self,
bus: AudioBus,
parent: Handle<AudioBus>,
) -> Handle<AudioBus>
pub fn add_bus( &mut self, bus: AudioBus, parent: Handle<AudioBus>, ) -> Handle<AudioBus>
Adds a new audio bus to the graph and attaches it to the given parent. parent
handle must be
valid, otherwise the method will panic. In most cases you can use primary bus as a parent.
§Examples
use fyrox_sound::bus::{AudioBus, AudioBusGraph};
// By default it has one primary audio bus.
let mut graph = AudioBusGraph::new();
// Add another bus to the graph and attach it to the primary bus.
let primary_bus_handle = graph.primary_bus_handle();
graph.add_bus(AudioBus::new("SFX".to_owned()), primary_bus_handle);
Sourcepub fn link_buses(&mut self, child: Handle<AudioBus>, parent: Handle<AudioBus>)
pub fn link_buses(&mut self, child: Handle<AudioBus>, parent: Handle<AudioBus>)
Attaches the child
audio bus to the parent
audio bus. Important: this method does not
checks for any loops, adding any loops to the graph will cause infinite loop in the mixer thread.
Sourcepub fn remove_bus(&mut self, handle: Handle<AudioBus>) -> AudioBus
pub fn remove_bus(&mut self, handle: Handle<AudioBus>) -> AudioBus
Removes an audio bus at the given handle.
Sourcepub fn primary_bus_handle(&self) -> Handle<AudioBus>
pub fn primary_bus_handle(&self) -> Handle<AudioBus>
Returns a handle of the primary audio bus. Primary bus outputs its samples directly to an audio playback device.
Sourcepub fn primary_bus_ref(&self) -> &AudioBus
pub fn primary_bus_ref(&self) -> &AudioBus
Returns a reference to the primary audio bus.
Sourcepub fn primary_bus_mut(&mut self) -> &mut AudioBus
pub fn primary_bus_mut(&mut self) -> &mut AudioBus
Returns a reference to the primary audio bus.
Sourcepub fn try_get_bus_ref(&self, handle: Handle<AudioBus>) -> Option<&AudioBus>
pub fn try_get_bus_ref(&self, handle: Handle<AudioBus>) -> Option<&AudioBus>
Tries to borrow an audio bus by its handle.
Sourcepub fn try_get_bus_mut(
&mut self,
handle: Handle<AudioBus>,
) -> Option<&mut AudioBus>
pub fn try_get_bus_mut( &mut self, handle: Handle<AudioBus>, ) -> Option<&mut AudioBus>
Tries to borrow an audio bus by its handle.
Sourcepub fn try_take_reserve_bus(
&mut self,
handle: Handle<AudioBus>,
) -> Option<(Ticket<AudioBus>, AudioBus)>
pub fn try_take_reserve_bus( &mut self, handle: Handle<AudioBus>, ) -> Option<(Ticket<AudioBus>, AudioBus)>
Tries to move out an audio bus with a promise that it will be returned back. See Pool::try_take_reserve
method
docs for more info.
Sourcepub fn put_bus_back(
&mut self,
ticket: Ticket<AudioBus>,
bus: AudioBus,
) -> Handle<AudioBus>
pub fn put_bus_back( &mut self, ticket: Ticket<AudioBus>, bus: AudioBus, ) -> Handle<AudioBus>
Puts the audio bus back to graph on its previous place by the given ticket. See Pool::put_back
method docs
for more info.
Sourcepub fn forget_bus_ticket(&mut self, ticket: Ticket<AudioBus>)
pub fn forget_bus_ticket(&mut self, ticket: Ticket<AudioBus>)
Forget an audio bus ticket making the respective handle free again. See Pool::forget_ticket
method docs for
more info.
Sourcepub fn buses_iter(&self) -> impl Iterator<Item = &AudioBus>
pub fn buses_iter(&self) -> impl Iterator<Item = &AudioBus>
Returns an iterator over each audio bus in the graph.
Sourcepub fn buses_iter_mut(&mut self) -> impl Iterator<Item = &mut AudioBus>
pub fn buses_iter_mut(&mut self) -> impl Iterator<Item = &mut AudioBus>
Returns an iterator over each audio bus in the graph.
Trait Implementations§
Source§impl Clone for AudioBusGraph
impl Clone for AudioBusGraph
Source§fn clone(&self) -> AudioBusGraph
fn clone(&self) -> AudioBusGraph
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for AudioBusGraph
impl Debug for AudioBusGraph
Source§impl Default for AudioBusGraph
impl Default for AudioBusGraph
Source§fn default() -> AudioBusGraph
fn default() -> AudioBusGraph
Source§impl Reflect for AudioBusGraph
impl Reflect for AudioBusGraph
fn source_path() -> &'static str
fn type_name(&self) -> &'static str
fn doc(&self) -> &'static str
Source§fn assembly_name(&self) -> &'static str
fn assembly_name(&self) -> &'static str
#[derive(Reflect)]
) to ensure that this method will return correct assembly
name. In other words - there’s no guarantee, that any implementation other than proc-macro
will return a correct name of the assembly. Alternatively, you can use env!("CARGO_PKG_NAME")
as an implementation.Source§fn type_assembly_name() -> &'static str
fn type_assembly_name() -> &'static str
#[derive(Reflect)]
) to ensure that this method will return correct assembly
name. In other words - there’s no guarantee, that any implementation other than proc-macro
will return a correct name of the assembly. Alternatively, you can use env!("CARGO_PKG_NAME")
as an implementation.fn fields_info(&self, func: &mut dyn FnMut(&[FieldInfo<'_, '_>]))
fn into_any(self: Box<AudioBusGraph>) -> Box<dyn Any>
fn set( &mut self, value: Box<dyn Reflect>, ) -> Result<Box<dyn Reflect>, Box<dyn Reflect>>
fn as_any(&self, func: &mut dyn FnMut(&(dyn Any + 'static)))
fn as_any_mut(&mut self, func: &mut dyn FnMut(&mut (dyn Any + 'static)))
fn as_reflect(&self, func: &mut dyn FnMut(&(dyn Reflect + 'static)))
fn as_reflect_mut(&mut self, func: &mut dyn FnMut(&mut (dyn Reflect + 'static)))
fn fields(&self, func: &mut dyn FnMut(&[&(dyn Reflect + 'static)]))
fn fields_mut( &mut self, func: &mut dyn FnMut(&mut [&mut (dyn Reflect + 'static)]), )
fn field( &self, name: &str, func: &mut dyn FnMut(Option<&(dyn Reflect + 'static)>), )
fn field_mut( &mut self, name: &str, func: &mut dyn FnMut(Option<&mut (dyn Reflect + 'static)>), )
Source§fn set_field(
&mut self,
field: &str,
value: Box<dyn Reflect>,
func: &mut dyn FnMut(Result<Box<dyn Reflect>, Box<dyn Reflect>>),
)
fn set_field( &mut self, field: &str, value: Box<dyn Reflect>, func: &mut dyn FnMut(Result<Box<dyn Reflect>, Box<dyn Reflect>>), )
#[reflect(setter = ..)]
or falls back to
Reflect::field_mut
fn as_array(&self, func: &mut dyn FnMut(Option<&(dyn ReflectArray + 'static)>))
fn as_array_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectArray + 'static)>), )
fn as_list(&self, func: &mut dyn FnMut(Option<&(dyn ReflectList + 'static)>))
fn as_list_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectList + 'static)>), )
fn as_inheritable_variable( &self, func: &mut dyn FnMut(Option<&(dyn ReflectInheritableVariable + 'static)>), )
fn as_inheritable_variable_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectInheritableVariable + 'static)>), )
fn as_hash_map( &self, func: &mut dyn FnMut(Option<&(dyn ReflectHashMap + 'static)>), )
fn as_hash_map_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectHashMap + 'static)>), )
Auto Trait Implementations§
impl Freeze for AudioBusGraph
impl !RefUnwindSafe for AudioBusGraph
impl Send for AudioBusGraph
impl Sync for AudioBusGraph
impl Unpin for AudioBusGraph
impl UnwindSafe for AudioBusGraph
Blanket Implementations§
Source§impl<T> AsyncTaskResult for T
impl<T> AsyncTaskResult for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Any
. Could be used to downcast a trait object
to a particular type.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Any
. Could be used to downcast a trait object
to a particular type.fn into_any(self: Box<T>) -> Box<dyn Any>
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.Source§impl<T> ReflectBase for Twhere
T: Reflect,
impl<T> ReflectBase for Twhere
T: Reflect,
fn as_any_raw(&self) -> &(dyn Any + 'static)
fn as_any_raw_mut(&mut self) -> &mut (dyn Any + 'static)
Source§impl<T> ResolvePath for Twhere
T: Reflect,
impl<T> ResolvePath for Twhere
T: Reflect,
fn resolve_path<'p>( &self, path: &'p str, func: &mut dyn FnMut(Result<&(dyn Reflect + 'static), ReflectPathError<'p>>), )
fn resolve_path_mut<'p>( &mut self, path: &'p str, func: &mut dyn FnMut(Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>), )
fn get_resolve_path<'p, T>(
&self,
path: &'p str,
func: &mut dyn FnMut(Result<&T, ReflectPathError<'p>>),
)where
T: Reflect,
fn get_resolve_path_mut<'p, T>(
&mut self,
path: &'p str,
func: &mut dyn FnMut(Result<&mut T, ReflectPathError<'p>>),
)where
T: Reflect,
Source§impl<T> ScriptMessagePayload for T
impl<T> ScriptMessagePayload for T
Source§fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_ref(&self) -> &(dyn Any + 'static)
self
as &dyn Any
Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
self
as &dyn Any
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.