Skip to content

Commit 866b24f

Browse files
committed
fix(playback): output sample count of resampler may vary
1 parent d05e374 commit 866b24f

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

anni-playback/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repository.workspace = true
88
license = "LGPL-3.0"
99

1010
[dependencies]
11-
cpal = "0.15.2"
11+
cpal = "0.15.3"
1212
reqwest = { workspace = true, features = [
1313
"blocking",
1414
"rustls-tls",
@@ -22,7 +22,7 @@ symphonia = { version = "0.5.4", default-features = false, features = [
2222
] }
2323
symphonia-core = "0.5.4"
2424
crossbeam = { version = "0.8.2", features = ["crossbeam-channel"] }
25-
rubato = "0.14.1"
25+
rubato = "0.14.0"
2626
rangemap = "1.3.0"
2727
arrayvec = "0.7.2"
2828
ebur128 = "0.1.7"

anni-playback/src/cpal_output.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl CpalOutput {
248248
sample_buffer,
249249
resampler,
250250
normalizer: Normalizer::new(spec.channels.count(), sample_rate),
251-
controls: controls,
251+
controls,
252252
}
253253
}
254254

@@ -266,7 +266,7 @@ impl CpalOutput {
266266
resampler.resample(decoded).unwrap_or(&[])
267267
}
268268
_ => {
269-
// no resampler, or the target sampe rate is the same as the input
269+
// no resampler, or the target sample rate is the same as the input
270270
self.sample_buffer.copy_interleaved_ref(decoded);
271271
self.sample_buffer.samples()
272272
}

anni-playback/src/dsp/resampler.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,24 @@ where
2222
T: Sample + FromSample<f32> + IntoSample<f32>,
2323
{
2424
fn resample_inner(&mut self) -> &[T] {
25-
{
25+
let output_size = {
2626
let mut input: arrayvec::ArrayVec<&[f32], 32> = Default::default();
2727

2828
for channel in self.input.iter() {
2929
input.push(&channel[..self.duration]);
3030
}
3131

3232
// Resample.
33-
rubato::Resampler::process_into_buffer(
33+
let (_, output_size) = rubato::Resampler::process_into_buffer(
3434
&mut self.resampler,
3535
&input,
3636
&mut self.output,
3737
None,
3838
)
3939
.unwrap();
40-
}
40+
41+
output_size
42+
};
4143

4244
// Remove consumed samples from the input buffer.
4345
for channel in self.input.iter_mut() {
@@ -47,8 +49,7 @@ where
4749
// Interleave the planar samples from Rubato.
4850
let num_channels = self.output.len();
4951

50-
self.interleaved
51-
.resize(num_channels * self.output[0].len(), T::MID);
52+
self.interleaved.resize(num_channels * output_size, T::MID);
5253

5354
for (i, frame) in self.interleaved.chunks_exact_mut(num_channels).enumerate() {
5455
for (ch, s) in frame.iter_mut().enumerate() {

0 commit comments

Comments
 (0)