Skip to content

Commit 586dd35

Browse files
committed
remove reverse playback support for streaming sounds
There's some pretty serious issues with garbled audio when streaming mp3s and oggs backwards, and from the investigation I've done so far, I don't think they will be trivial to fix.
1 parent a4db8fb commit 586dd35

File tree

6 files changed

+11
-40
lines changed

6 files changed

+11
-40
lines changed

changelog.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# v0.8.3 - May 28, 2023
2+
3+
This release removes reverse playback support for streaming sounds. There's pretty
4+
serious issues with garbled audio when streaming an mp3 or ogg file backwards,
5+
and based the initial investigation, these issues won't be trivial to fix.
6+
This feature may return in the future, but for now, you should not rely on it.
7+
18
# v0.8.2 - May 27, 2023
29

310
- Fix errors when streaming some ogg files

crates/kira/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "kira"
3-
version = "0.8.2"
3+
version = "0.8.3"
44
authors = ["Andrew Minnich <aminnich3@gmail.com>"]
55
edition = "2018"
66
license = "MIT OR Apache-2.0"

crates/kira/src/sound/streaming/settings.rs

-8
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ pub struct StreamingSoundSettings {
1414
pub playback_region: Region,
1515
/// The portion of the sound that should be looped.
1616
pub loop_region: Option<Region>,
17-
/// Whether the sound should be played in reverse.
18-
pub reverse: bool,
1917
/// The volume of the sound.
2018
pub volume: Value<Volume>,
2119
/// The playback rate of the sound.
@@ -39,7 +37,6 @@ impl StreamingSoundSettings {
3937
start_time: StartTime::Immediate,
4038
playback_region: Region::default(),
4139
loop_region: None,
42-
reverse: false,
4340
volume: Value::Fixed(Volume::Amplitude(1.0)),
4441
playback_rate: Value::Fixed(PlaybackRate::Factor(1.0)),
4542
panning: Value::Fixed(0.5),
@@ -128,11 +125,6 @@ impl StreamingSoundSettings {
128125
}
129126
}
130127

131-
/// Sets whether the sound should be played in reverse.
132-
pub fn reverse(self, reverse: bool) -> Self {
133-
Self { reverse, ..self }
134-
}
135-
136128
/**
137129
Sets the volume of the sound.
138130

crates/kira/src/sound/streaming/sound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl Sound for StreamingSound {
250250
self.fractional_position as f32,
251251
);
252252
self.fractional_position +=
253-
self.sample_rate as f64 * self.playback_rate.value().as_factor() * dt;
253+
self.sample_rate as f64 * self.playback_rate.value().as_factor().max(0.0) * dt;
254254
while self.fractional_position >= 1.0 {
255255
self.fractional_position -= 1.0;
256256
self.frame_consumer.pop();

crates/kira/src/sound/streaming/sound/decode_scheduler.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<Error: Send + 'static> DecodeScheduler<Error> {
6464
transport: Transport::new(
6565
settings.playback_region,
6666
settings.loop_region,
67-
settings.reverse,
67+
false,
6868
sample_rate,
6969
num_frames,
7070
),
@@ -126,11 +126,7 @@ impl<Error: Send + 'static> DecodeScheduler<Error> {
126126
index: self.transport.position,
127127
})
128128
.expect("could not push frame to frame producer");
129-
if self.transport.reverse {
130-
self.transport.decrement_position()
131-
} else {
132-
self.transport.increment_position();
133-
}
129+
self.transport.increment_position();
134130
if !self.transport.playing {
135131
self.shared.reached_end.store(true, Ordering::SeqCst);
136132
return Ok(NextStep::End);

crates/kira/src/sound/streaming/sound/test.rs

-24
Original file line numberDiff line numberDiff line change
@@ -1097,30 +1097,6 @@ fn seek_by() {
10971097
expect_frame_soon(Frame::from_mono(20.0).panned(0.5), &mut sound);
10981098
}
10991099

1100-
/// Tests that a `StreamingSound` can play in reverse.
1101-
#[test]
1102-
fn reverse() {
1103-
let data = StreamingSoundData {
1104-
decoder: Box::new(MockDecoder::new(
1105-
(0..10).map(|i| Frame::from_mono(i as f32)).collect(),
1106-
)),
1107-
settings: StreamingSoundSettings::new().reverse(true),
1108-
};
1109-
let (mut sound, _, mut scheduler) = data.split().unwrap();
1110-
while matches!(scheduler.run().unwrap(), NextStep::Continue) {}
1111-
1112-
for i in (4..=9).rev() {
1113-
assert_eq!(
1114-
sound.process(
1115-
1.0,
1116-
&MockClockInfoProviderBuilder::new(0).build(),
1117-
&MockModulatorValueProviderBuilder::new(0).build()
1118-
),
1119-
Frame::from_mono(i as f32).panned(0.5)
1120-
);
1121-
}
1122-
}
1123-
11241100
fn expect_frame_soon(expected_frame: Frame, sound: &mut StreamingSound) {
11251101
const NUM_SAMPLES_TO_WAIT: usize = 10;
11261102
for _ in 0..NUM_SAMPLES_TO_WAIT {

0 commit comments

Comments
 (0)