Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add playback_rate to settings #22

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/sources/audio_file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ pub struct AudioFileSettings {
pub start_paused: bool,
/// Volume at which the audio will play at.
pub volume: f64,
/// The playback rate of the sound.
///
/// Changing the playback rate changes both the speed and the pitch of the
/// sound.
pub playback_rate: f64,
/// Panning (in 0..=1) for the sound, where 0 is hard left, and 1 is hard right.
pub panning: f64,
/// Optionally loop a region of the sound (given in seconds)
Expand All @@ -123,6 +128,7 @@ impl Default for AudioFileSettings {
Self {
start_paused: false,
volume: 1.0,
playback_rate: 1.0,
panning: 0.5,
loop_region: None,
play_region: Region::from(..),
Expand Down
3 changes: 3 additions & 0 deletions src/sources/audio_file/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ impl AudioSource for AudioFile {
let settings = (*kira_settings)
.output_destination(output_destination)
.volume(asset_settings.volume)
.playback_rate(asset_settings.playback_rate)
.panning(asset_settings.panning)
.loop_region(asset_settings.loop_region)
.reverse(asset_settings.reverse)
.start_position(asset_settings.play_region.start);

let static_data = StaticSoundData::from_cursor(Cursor::new(data.clone()))
.map_err(|err| {
PlaySoundError::IntoSoundError(AudioFileError::FromFileError(err))
Expand All @@ -81,6 +83,7 @@ impl AudioSource for AudioFile {
let settings = (*kira_settings)
.output_destination(output_destination)
.volume(asset_settings.volume)
.playback_rate(asset_settings.playback_rate)
.panning(asset_settings.panning)
.loop_region(asset_settings.loop_region);
let streaming_sound_data = StreamingSoundData::from_file(path)
Expand Down
Loading