Struct awedio::sounds::MemorySound
source · pub struct MemorySound { /* private fields */ }
Expand description
A Sound that stores all samples on the heap.
The heap samples can be shared between multiple MemorySounds that can be played simultaneously. Optionally the sound can repeat forever.
Implementations§
source§impl MemorySound
impl MemorySound
sourcepub fn from_sound(orig: impl Sound) -> Result<Self, Error>
pub fn from_sound(orig: impl Sound) -> Result<Self, Error>
Create a MemorySound be consuming another Sound and storing the samples
until it returns Finished
or Paused
.
If an Error is encountered it is returned and any already obtained samples are lost.
It is not currently supported for the the originating sample to change its metadata (i.e. channel count or sample rate). If it does an IoError of ErrorKind::Other with a UnsupportedMetadataChangeError is returned.
sourcepub fn from_samples(
samples: Arc<Vec<i16>>,
channel_count: u16,
sample_rate: u32
) -> MemorySound
pub fn from_samples( samples: Arc<Vec<i16>>, channel_count: u16, sample_rate: u32 ) -> MemorySound
Create memory sound from the raw data of samples.
Samples should be in the same order as they will be returned from the next_samples function (e.g. interleaved by channel).
sourcepub fn set_looping(&mut self, should_loop: bool)
pub fn set_looping(&mut self, should_loop: bool)
Instead of finishing after playing all samples, start back at the beginning and continue forever.
Trait Implementations§
source§impl Clone for MemorySound
impl Clone for MemorySound
source§fn clone(&self) -> MemorySound
fn clone(&self) -> MemorySound
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Sound for MemorySound
impl Sound for MemorySound
source§fn channel_count(&self) -> u16
fn channel_count(&self) -> u16
source§fn sample_rate(&self) -> u32
fn sample_rate(&self) -> u32
source§fn next_sample(&mut self) -> Result<NextSample, Error>
fn next_sample(&mut self) -> Result<NextSample, Error>
Sample
is returned then
the following NextSample::Sample
is for the first channel. If a Sound
has returned Paused
it is expected that the consumer will call
next_sample again in the future. If a Sound has returned Finished
it
is not expected for the consumer to call next_sample again but if called
Finished
will normally be returned again. After Finished has been
returned, channel_count() and sample_rate() may return different values
without MetadataChanged being returned. Read moresource§fn on_start_of_batch(&mut self)
fn on_start_of_batch(&mut self)
source§fn next_frame(&mut self) -> Result<Vec<i16>, Result<NextSample, Error>>
fn next_frame(&mut self) -> Result<Vec<i16>, Result<NextSample, Error>>
source§fn append_next_frame_to(
&mut self,
samples: &mut Vec<i16>
) -> Result<(), Result<NextSample, Error>>
fn append_next_frame_to( &mut self, samples: &mut Vec<i16> ) -> Result<(), Result<NextSample, Error>>
next_frame
but samples are appended into an existing Vec. Read moresource§fn into_memory_sound(self) -> Result<MemorySound, Error>where
Self: Sized,
fn into_memory_sound(self) -> Result<MemorySound, Error>where
Self: Sized,
source§fn loop_from_memory(self) -> Result<MemorySound, Error>where
Self: Sized,
fn loop_from_memory(self) -> Result<MemorySound, Error>where
Self: Sized,
source§fn controllable(self) -> (Controllable<Self>, Controller<Self>)where
Self: Sized,
fn controllable(self) -> (Controllable<Self>, Controller<Self>)where
Self: Sized,
Controller
. Read moresource§fn with_async_completion_notifier(
self
) -> (AsyncCompletionNotifier<Self>, Receiver<()>)where
Self: Sized,
fn with_async_completion_notifier(
self
) -> (AsyncCompletionNotifier<Self>, Receiver<()>)where
Self: Sized,
source§fn with_completion_notifier(self) -> (CompletionNotifier<Self>, Receiver<()>)where
Self: Sized,
fn with_completion_notifier(self) -> (CompletionNotifier<Self>, Receiver<()>)where
Self: Sized,
source§fn with_adjustable_volume(self) -> AdjustableVolume<Self>where
Self: Sized,
fn with_adjustable_volume(self) -> AdjustableVolume<Self>where
Self: Sized,
set_volume
.source§fn with_adjustable_volume_of(
self,
volume_adjustment: f32
) -> AdjustableVolume<Self>where
Self: Sized,
fn with_adjustable_volume_of(
self,
volume_adjustment: f32
) -> AdjustableVolume<Self>where
Self: Sized,
set_volume
and set
the initial volume adjustment.source§fn with_adjustable_speed(self) -> AdjustableSpeed<Self>where
Self: Sized,
fn with_adjustable_speed(self) -> AdjustableSpeed<Self>where
Self: Sized,
set_speed
. Read moresource§fn with_adjustable_speed_of(
self,
speed_adjustment: f32
) -> AdjustableSpeed<Self>where
Self: Sized,
fn with_adjustable_speed_of(
self,
speed_adjustment: f32
) -> AdjustableSpeed<Self>where
Self: Sized,
set_speed
and set
the initial speed adjustment. Read moresource§fn pausable(self) -> Pausable<Self>where
Self: Sized,
fn pausable(self) -> Pausable<Self>where
Self: Sized,
set_paused
. Starts unpaused.source§fn paused(self) -> Pausable<Self>where
Self: Sized,
fn paused(self) -> Pausable<Self>where
Self: Sized,
set_paused
. Starts paused.source§fn finish_after(self, duration: Duration) -> FinishAfter<Self>where
Self: Sized,
fn finish_after(self, duration: Duration) -> FinishAfter<Self>where
Self: Sized,
duration
of the sound, then finish even if samples
remain. Read more