Struct comfy::StaticSoundSettings
pub struct StaticSoundSettings {
pub start_time: StartTime,
pub playback_region: Region,
pub loop_region: Option<Region>,
pub reverse: bool,
pub volume: Value<Volume>,
pub playback_rate: Value<PlaybackRate>,
pub panning: Value<f64>,
pub output_destination: OutputDestination,
pub fade_in_tween: Option<Tween>,
}Expand description
Settings for a static sound.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.start_time: StartTimeWhen the sound should start playing.
playback_region: RegionThe portion of the sound that should be played.
loop_region: Option<Region>The portion of the sound that should be looped.
reverse: boolWhether the sound should be played in reverse.
volume: Value<Volume>The volume of the sound.
playback_rate: Value<PlaybackRate>The playback rate of the sound.
Changing the playback rate will change both the speed and the pitch of the sound.
panning: Value<f64>The panning of the sound, where 0 is hard left and 1 is hard right.
output_destination: OutputDestinationThe destination that this sound should be routed to.
fade_in_tween: Option<Tween>An optional fade-in from silence.
Implementations§
§impl StaticSoundSettings
impl StaticSoundSettings
pub fn new() -> StaticSoundSettings
pub fn new() -> StaticSoundSettings
Creates a new StaticSoundSettings with the default settings.
pub fn start_time(self, start_time: impl Into<StartTime>) -> StaticSoundSettings
pub fn start_time(self, start_time: impl Into<StartTime>) -> StaticSoundSettings
Sets when the sound should start playing.
Examples
Configuring a sound to start 4 ticks after a clock’s current time:
use kira::{
manager::{AudioManager, AudioManagerSettings, backend::DefaultBackend},
sound::static_sound::{StaticSoundData, StaticSoundSettings},
clock::ClockSpeed,
};
let mut manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())?;
let clock_handle = manager.add_clock(ClockSpeed::TicksPerMinute(120.0))?;
let settings = StaticSoundSettings::new().start_time(clock_handle.time() + 4);
let sound = StaticSoundData::from_file("sound.ogg", settings);pub fn playback_region(
self,
playback_region: impl Into<Region>
) -> StaticSoundSettings
pub fn playback_region( self, playback_region: impl Into<Region> ) -> StaticSoundSettings
Sets the portion of the sound that should be played.
Examples
Configure a sound to play from 3 seconds in to the end:
let settings = StaticSoundSettings::new().playback_region(3.0..);Configure a sound to play from 2 to 4 seconds:
let settings = StaticSoundSettings::new().playback_region(2.0..4.0);pub fn reverse(self, reverse: bool) -> StaticSoundSettings
pub fn reverse(self, reverse: bool) -> StaticSoundSettings
Sets whether the sound should be played in reverse.
pub fn loop_region(
self,
loop_region: impl IntoOptionalRegion
) -> StaticSoundSettings
pub fn loop_region( self, loop_region: impl IntoOptionalRegion ) -> StaticSoundSettings
Sets the portion of the sound that should be looped.
Examples
Configure a sound to loop the portion from 3 seconds in to the end:
let settings = StaticSoundSettings::new().loop_region(3.0..);Configure a sound to loop the portion from 2 to 4 seconds:
let settings = StaticSoundSettings::new().loop_region(2.0..4.0);pub fn volume(self, volume: impl Into<Value<Volume>>) -> StaticSoundSettings
pub fn volume(self, volume: impl Into<Value<Volume>>) -> StaticSoundSettings
Sets the volume of the sound.
Examples
Set the volume as a factor:
let settings = StaticSoundSettings::new().volume(0.5);Set the volume as a gain in decibels:
let settings = StaticSoundSettings::new().volume(kira::Volume::Decibels(-6.0));Link the volume to a modulator:
use kira::{
manager::{AudioManager, AudioManagerSettings, backend::DefaultBackend},
modulator::tweener::TweenerBuilder,
sound::static_sound::{StaticSoundSettings},
};
let mut manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())?;
let tweener = manager.add_modulator(TweenerBuilder {
initial_value: 0.5,
})?;
let settings = StaticSoundSettings::new().volume(&tweener);pub fn playback_rate(
self,
playback_rate: impl Into<Value<PlaybackRate>>
) -> StaticSoundSettings
pub fn playback_rate( self, playback_rate: impl Into<Value<PlaybackRate>> ) -> StaticSoundSettings
Sets the playback rate of the sound.
Changing the playback rate will change both the speed and the pitch of the sound.
Examples
Set the playback rate as a factor:
let settings = StaticSoundSettings::new().playback_rate(0.5);Set the playback rate as a change in semitones:
use kira::sound::PlaybackRate;
let settings = StaticSoundSettings::new().playback_rate(PlaybackRate::Semitones(-2.0));Link the playback rate to a modulator:
use kira::{
manager::{AudioManager, AudioManagerSettings, backend::DefaultBackend},
modulator::tweener::TweenerBuilder,
sound::static_sound::{StaticSoundSettings},
};
let mut manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())?;
let tweener = manager.add_modulator(TweenerBuilder {
initial_value: 0.5,
})?;
let settings = StaticSoundSettings::new().playback_rate(&tweener);pub fn panning(self, panning: impl Into<Value<f64>>) -> StaticSoundSettings
pub fn panning(self, panning: impl Into<Value<f64>>) -> StaticSoundSettings
Sets the panning of the sound, where 0 is hard left and 1 is hard right.
Examples
Set the panning to a static value:
let settings = StaticSoundSettings::new().panning(0.25);Link the panning to a modulator:
use kira::{
manager::{AudioManager, AudioManagerSettings, backend::DefaultBackend},
modulator::tweener::TweenerBuilder,
sound::static_sound::{StaticSoundSettings},
};
let mut manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())?;
let tweener = manager.add_modulator(TweenerBuilder {
initial_value: 0.25,
})?;
let settings = StaticSoundSettings::new().panning(&tweener);pub fn output_destination(
self,
output_destination: impl Into<OutputDestination>
) -> StaticSoundSettings
pub fn output_destination( self, output_destination: impl Into<OutputDestination> ) -> StaticSoundSettings
Sets the destination that this sound should be routed to.
Examples
Set the output destination of a sound to a mixer track:
use kira::{
manager::{AudioManager, AudioManagerSettings, backend::DefaultBackend},
track::TrackBuilder,
sound::static_sound::{StaticSoundSettings},
};
let mut manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())?;
let sub_track = manager.add_sub_track(TrackBuilder::new())?;
let settings = StaticSoundSettings::new().output_destination(&sub_track);Set the output destination of a sound to an emitter in a spatial scene:
use kira::{
manager::{AudioManager, AudioManagerSettings, backend::DefaultBackend},
spatial::{scene::SpatialSceneSettings, emitter::EmitterSettings},
sound::static_sound::{StaticSoundSettings},
};
let mut manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())?;
let mut scene = manager.add_spatial_scene(SpatialSceneSettings::default())?;
let emitter = scene.add_emitter(mint::Vector3 {
x: 0.0,
y: 0.0,
z: 0.0,
}, EmitterSettings::default())?;
let settings = StaticSoundSettings::new().output_destination(&emitter);pub fn fade_in_tween(
self,
fade_in_tween: impl Into<Option<Tween>>
) -> StaticSoundSettings
pub fn fade_in_tween( self, fade_in_tween: impl Into<Option<Tween>> ) -> StaticSoundSettings
Sets the tween used to fade in the sound from silence.
Trait Implementations§
§impl Clone for StaticSoundSettings
impl Clone for StaticSoundSettings
§fn clone(&self) -> StaticSoundSettings
fn clone(&self) -> StaticSoundSettings
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for StaticSoundSettings
impl Debug for StaticSoundSettings
§impl Default for StaticSoundSettings
impl Default for StaticSoundSettings
§fn default() -> StaticSoundSettings
fn default() -> StaticSoundSettings
§impl PartialEq<StaticSoundSettings> for StaticSoundSettings
impl PartialEq<StaticSoundSettings> for StaticSoundSettings
§fn eq(&self, other: &StaticSoundSettings) -> bool
fn eq(&self, other: &StaticSoundSettings) -> bool
self and other values to be equal, and is used
by ==.