Struct crankstart::sound::sampleplayer::SamplePlayer
source · pub struct SamplePlayer { /* private fields */ }
Expand description
Note: Make sure you hold on to a SamplePlayer until the sample has played as much as you want, because dropping it will stop playback.
Implementations§
source§impl SamplePlayer
impl SamplePlayer
sourcepub fn set_sample(&mut self, audio_sample: &AudioSample) -> Result<()>
pub fn set_sample(&mut self, audio_sample: &AudioSample) -> Result<()>
Sets the sound effect to be played by this player.
sourcepub fn play(&self, repeat_count: c_int, playback_speed: f32) -> Result<()>
pub fn play(&self, repeat_count: c_int, playback_speed: f32) -> Result<()>
Play the sample ‘repeat_count’ times; if 0, play until stop
is called; if -1, play
forward, backward, forward, etc. (See set_play_range to change which part is looped.)
‘playback_speed’ is how fast the sample plays; 1.0 is normal speed, 0.5 is down an octave,
2.0 is up one, etc. A negative rate plays the sample in reverse.
sourcepub fn stop(&self) -> Result<()>
pub fn stop(&self) -> Result<()>
Can be used to stop a sample early, or stop one that’s repeating endlessly because ‘repeat’ was set to 0.
sourcepub fn set_paused(&self, paused: bool) -> Result<()>
pub fn set_paused(&self, paused: bool) -> Result<()>
Pause or resume playback.
sourcepub fn is_playing(&self) -> Result<bool>
pub fn is_playing(&self) -> Result<bool>
Returns whether the player is currently playing the sample.
sourcepub fn set_play_range(&self, start: c_int, end: c_int) -> Result<()>
pub fn set_play_range(&self, start: c_int, end: c_int) -> Result<()>
Sets the start and end position, in frames, when looping a sample with repeat_count -1.
sourcepub fn get_offset(&self) -> Result<f32>
pub fn get_offset(&self) -> Result<f32>
Returns the current offset into the sample, in seconds, increasing as it plays. This is not adjusted for rate.
sourcepub fn set_offset(&self, offset: f32) -> Result<()>
pub fn set_offset(&self, offset: f32) -> Result<()>
Set how far into the sample to start playing, in seconds. This is not adjusted for rate.
sourcepub fn get_volume(&self) -> Result<(f32, f32)>
pub fn get_volume(&self) -> Result<(f32, f32)>
Gets the current volume of the left and right audio channels, out of 1.
sourcepub fn set_volume(&self, left: f32, right: f32) -> Result<()>
pub fn set_volume(&self, left: f32, right: f32) -> Result<()>
Sets the volume of the left and right audio channels, out of 1.
sourcepub fn get_rate(&self) -> Result<f32>
pub fn get_rate(&self) -> Result<f32>
Gets the current playback speed. Returns 1 unless the value was changed by set_rate
- it
still returns 1 if the rate is changed with the argument to play
.
sourcepub fn set_rate(&self, playback_speed: f32) -> Result<()>
pub fn set_rate(&self, playback_speed: f32) -> Result<()>
Sets the playback speed of the player after a sample has started playing. 1.0 is normal, 0.5 is down an octave, 2.0 is up one, etc. A negative rate plays the sample in reverse.
sourcepub fn get_length(&self) -> Result<f32>
pub fn get_length(&self) -> Result<f32>
Returns the length of the assigned sample, in seconds.