Skip to content

Commit 96059d9

Browse files
committed
core: Increase buffer size, try to open 44.1Khz stream
1 parent 3f95124 commit 96059d9

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

psst-core/src/audio/output.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl AudioOutput {
2727

2828
// Get the default device config, so we know what sample format and sample rate
2929
// the device supports.
30-
let supported = device.default_output_config()?;
30+
let supported = Self::preferred_output_config(&device)?;
3131

3232
let (callback_send, callback_recv) = bounded(16);
3333

@@ -48,6 +48,24 @@ impl AudioOutput {
4848
})
4949
}
5050

51+
fn preferred_output_config(
52+
device: &cpal::Device,
53+
) -> Result<cpal::SupportedStreamConfig, Error> {
54+
const PREFERRED_SAMPLE_RATE: cpal::SampleRate = cpal::SampleRate(44_100);
55+
56+
let mut configs: Vec<_> = device.supported_output_configs()?.collect();
57+
configs.sort_by(|a, b| a.cmp_default_heuristics(b));
58+
59+
for range in configs {
60+
let r = range.min_sample_rate()..=range.max_sample_rate();
61+
if r.contains(&PREFERRED_SAMPLE_RATE) {
62+
return Ok(range.with_sample_rate(PREFERRED_SAMPLE_RATE));
63+
}
64+
}
65+
66+
Ok(device.default_output_config()?)
67+
}
68+
5169
pub fn sink(&self) -> AudioSink {
5270
self.sink.clone()
5371
}
@@ -237,6 +255,12 @@ impl From<cpal::DefaultStreamConfigError> for Error {
237255
}
238256
}
239257

258+
impl From<cpal::SupportedStreamConfigsError> for Error {
259+
fn from(err: cpal::SupportedStreamConfigsError) -> Error {
260+
Error::AudioOutputError(Box::new(err))
261+
}
262+
}
263+
240264
impl From<cpal::BuildStreamError> for Error {
241265
fn from(err: cpal::BuildStreamError) -> Error {
242266
Error::AudioOutputError(Box::new(err))

psst-core/src/player/worker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl DecoderSource {
9595
norm_factor,
9696
} = loaded;
9797

98-
const REPORT_PRECISION: Duration = Duration::from_millis(1000);
98+
const REPORT_PRECISION: Duration = Duration::from_millis(900);
9999

100100
// Gather the source signal parameters and compute how often we should report
101101
// the play-head position.
@@ -258,7 +258,7 @@ struct Worker {
258258

259259
impl Worker {
260260
fn default_buffer() -> SpscRb<f32> {
261-
const DEFAULT_BUFFER_SIZE: usize = 64 * 1024;
261+
const DEFAULT_BUFFER_SIZE: usize = 128 * 1024;
262262

263263
SpscRb::new(DEFAULT_BUFFER_SIZE)
264264
}

0 commit comments

Comments
 (0)