pub struct AudioManager { /* private fields */ }Expand description
Resource that owns the audio output device and manages loaded sounds and active playback sinks (both global and 3D spatial).
Implementations§
Source§impl AudioManager
impl AudioManager
Sourcepub fn new() -> Result<AudioManager, AudioError>
pub fn new() -> Result<AudioManager, AudioError>
Creates a new audio manager bound to the default output device.
§Web (WASM) note
On wasm32 the backend is the browser’s AudioContext (via cpal’s
WebAudio backend). Browsers suspend an AudioContext created before a
user gesture (autoplay policy): construct the AudioManager from an
input handler (first click/keypress) rather than at startup, or the
sinks will play silently.
§Errors
Returns AudioError::Backend if no audio output device is available
or the default device cannot be opened.
Sourcepub fn load_sound(&mut self, name: &str, path: &str) -> Result<(), AudioError>
pub fn load_sound(&mut self, name: &str, path: &str) -> Result<(), AudioError>
Sesi diske gidip okuyarak byte array olarak RAM’e kaydeder
Sourcepub fn load_sound_bytes(&mut self, name: &str, bytes: impl Into<Arc<[u8]>>)
pub fn load_sound_bytes(&mut self, name: &str, bytes: impl Into<Arc<[u8]>>)
Registers an already-decoded-from-disk (or embedded / fetched) sound
buffer under name. The bytes must be a complete audio file in a
format rodio can decode (WAV/OGG/FLAC/MP3), exactly as
load_sound would have read from disk.
This is the loading path for targets without a filesystem (WASM, where
assets arrive via fetch/include_bytes!) and for games that embed
audio in the binary.
Sourcepub fn set_underwater(&mut self, on: bool)
pub fn set_underwater(&mut self, on: bool)
Su-altı “boğma” modunu aç/kapa. Aktifken tüm sesler kısılır + hafif düşük pitch’e iner
(rodio Sink canlı alçak-geçiren filtre desteklemediğinden gerçek low-pass yerine bu
dampening kullanılır — “muffled” hissi verir). İDEMPOTENT: yalnız durum DEĞİŞİNCE uygular,
bu yüzden her frame güvenle çağrılabilir. NOT: hacim çarpanla geri alındığından, su
altındayken oyun tarafı set_volume çağırırsa yüzeye çıkışta hafif sapma olabilir
(sürekli ambient sesler için sorun değil).
Sourcepub fn is_underwater(&self) -> bool
pub fn is_underwater(&self) -> bool
Su-altı boğma modu şu an aktif mi.
Sourcepub fn play(&mut self, name: &str) -> Result<u64, AudioError>
pub fn play(&mut self, name: &str) -> Result<u64, AudioError>
Normal (Global/Stereo) bir ses oynatır (tek seferlik)
§Errors
Returns AudioError::NotLoaded if name was never loaded,
AudioError::Decode if the bytes cannot be decoded, or
AudioError::Backend if a playback sink cannot be created.
Sourcepub fn play_looped(&mut self, name: &str) -> Result<u64, AudioError>
pub fn play_looped(&mut self, name: &str) -> Result<u64, AudioError>
Normal (Global/Stereo) bir sesi döngüsel oynatır
§Errors
Returns AudioError::NotLoaded if name was never loaded,
AudioError::Decode if the bytes cannot be decoded, or
AudioError::Backend if a playback sink cannot be created.
Sourcepub fn play_3d(
&mut self,
name: &str,
emitter_pos: [f32; 3],
left_ear: [f32; 3],
right_ear: [f32; 3],
) -> Result<u64, AudioError>
pub fn play_3d( &mut self, name: &str, emitter_pos: [f32; 3], left_ear: [f32; 3], right_ear: [f32; 3], ) -> Result<u64, AudioError>
3D Uzamsal (Spatial) bir ses oynatır (tek seferlik)
§Errors
Returns AudioError::NotLoaded if name was never loaded,
AudioError::Decode if the bytes cannot be decoded, or
AudioError::Backend if a spatial sink cannot be created.
Sourcepub fn play_3d_looped(
&mut self,
name: &str,
emitter_pos: [f32; 3],
left_ear: [f32; 3],
right_ear: [f32; 3],
) -> Result<u64, AudioError>
pub fn play_3d_looped( &mut self, name: &str, emitter_pos: [f32; 3], left_ear: [f32; 3], right_ear: [f32; 3], ) -> Result<u64, AudioError>
3D Uzamsal bir sesi döngüsel oynatır
§Errors
Returns AudioError::NotLoaded if name was never loaded,
AudioError::Decode if the bytes cannot be decoded, or
AudioError::Backend if a spatial sink cannot be created.
Sourcepub fn update_spatial_sink(
&mut self,
id: u64,
emitter_pos: [f32; 3],
left_ear: [f32; 3],
right_ear: [f32; 3],
max_distance: f32,
base_volume: f32,
)
pub fn update_spatial_sink( &mut self, id: u64, emitter_pos: [f32; 3], left_ear: [f32; 3], right_ear: [f32; 3], max_distance: f32, base_volume: f32, )
Updates an active spatial sink’s emitter/ear positions and recomputes
its volume based on distance attenuation and base_volume.
Sourcepub fn set_volume(&mut self, id: u64, volume: f32)
pub fn set_volume(&mut self, id: u64, volume: f32)
Sets the volume of the active sink with the given id.
Sourcepub fn set_pitch(&mut self, id: u64, pitch: f32)
pub fn set_pitch(&mut self, id: u64, pitch: f32)
Sets the pitch/playback speed of the active sink with the given id.
Sourcepub fn clean_dead_sinks(&mut self)
pub fn clean_dead_sinks(&mut self)
Çalan bitmiş sesleri (Sinks) Garbage Collector gibi temizler
Sourcepub fn is_playing(&self, id: u64) -> bool
pub fn is_playing(&self, id: u64) -> bool
Returns whether the sink with the given id is currently playing.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for AudioManager
impl !Send for AudioManager
impl !Sync for AudioManager
impl !UnwindSafe for AudioManager
impl Freeze for AudioManager
impl Unpin for AudioManager
impl UnsafeUnpin for AudioManager
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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.impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more