Skip to content

Commit

Permalink
fix garbled audio after parameter tweens finish
Browse files Browse the repository at this point in the history
  • Loading branch information
tesselode committed Dec 31, 2024
1 parent 2b76de2 commit 2aaedf7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/kira/src/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ impl<T: Tweenable> Parameter<T> {
///
/// Returns `true` if a transition just finished after this update.
pub fn update(&mut self, dt: f64, info: &Info) -> JustFinishedTween {
self.previous_raw_value = self.raw_value;
if self.stagnant {
return false;
}
let just_finished_tween = self.update_tween(dt, info);
if let Some(raw_value) = self.calculate_new_raw_value(info) {
self.previous_raw_value = self.raw_value;
self.raw_value = raw_value;
}
just_finished_tween
Expand Down
4 changes: 1 addition & 3 deletions crates/kira/src/playback_state_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ impl PlaybackStateManager {
}

pub fn update(&mut self, dt: f64, info: &Info) -> ChangedPlaybackState {
let finished = self.volume_fade.update(dt, info);
match &mut self.state {
State::Playing => {}
State::Pausing => {
let finished = self.volume_fade.update(dt, info);
if finished {
self.state = State::Paused;
return true;
Expand All @@ -109,14 +109,12 @@ impl PlaybackStateManager {
}
}
State::Resuming => {
let finished = self.volume_fade.update(dt, info);
if finished {
self.state = State::Playing;
return true;
}
}
State::Stopping => {
let finished = self.volume_fade.update(dt, info);
if finished {
self.state = State::Stopped;
return true;
Expand Down
10 changes: 8 additions & 2 deletions crates/kira/src/sound/static_sound/sound/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use crate::{
PlaybackState, Sound,
},
test_helpers::expect_frame_soon,
Tween,
Decibels, Panning, StartTime,
Decibels, Panning, StartTime, Tween,
};

/// Tests that a `StaticSound` will play all of its samples before finishing.
Expand Down Expand Up @@ -201,6 +200,13 @@ fn pauses_and_resumes_with_fades() {
PlaybackState::Playing
);
}

let mut frames = vec![Frame::ZERO; 3];
sound.process(&mut frames, 1.0, &MockInfoBuilder::new().build());
assert_eq!(
frames,
vec![Frame::from_mono(1.0).panned(Panning::CENTER); 3]
);
}

/// Tests that a `StaticSound` stops and finishes after a fade-out.
Expand Down
10 changes: 8 additions & 2 deletions crates/kira/src/sound/streaming/sound/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use crate::{
PlaybackState, Sound,
},
test_helpers::expect_frame_soon,
Tween,
Decibels, Panning, StartTime,
Decibels, Panning, StartTime, Tween,
};

use super::decode_scheduler::NextStep;
Expand Down Expand Up @@ -247,6 +246,13 @@ fn pauses_and_resumes_with_fades() {
PlaybackState::Playing
);
}

let mut frames = vec![Frame::ZERO; 3];
sound.process(&mut frames, 1.0, &MockInfoBuilder::new().build());
assert_eq!(
frames,
vec![Frame::from_mono(1.0).panned(Panning::CENTER); 3]
);
}

/// Tests that a `StreamingSound` stops and finishes after a fade-out.
Expand Down

0 comments on commit 2aaedf7

Please sign in to comment.