Skip to content

Commit 445f8b1

Browse files
committed
refactor: clean up Rodio fallback handling
1 parent 648c9e3 commit 445f8b1

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

playback/src/audio_backend/rodio.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,18 @@ fn create_sink(
193193
AudioFormat::S16 => cpal::SampleFormat::I16,
194194
};
195195

196-
let stream = rodio::OutputStreamBuilder::default()
197-
.with_device(cpal_device)
196+
let stream = match rodio::OutputStreamBuilder::default()
197+
.with_device(cpal_device.clone())
198198
.with_config(&config.config())
199199
.with_sample_format(sample_format)
200-
.open_stream_or_fallback()?;
200+
.open_stream()
201+
{
202+
Ok(exact_stream) => exact_stream,
203+
Err(e) => {
204+
warn!("unable to create Rodio output, falling back to default: {e}");
205+
rodio::OutputStreamBuilder::from_device(cpal_device)?.open_stream_or_fallback()?
206+
}
207+
};
201208

202209
let sink = rodio::Sink::connect_new(stream.mixer());
203210
Ok((sink, stream))
@@ -209,12 +216,6 @@ pub fn open(host: cpal::Host, device: Option<String>, format: AudioFormat) -> Ro
209216
host.id().name()
210217
);
211218

212-
let mut format = format;
213-
if format != AudioFormat::S16 && format != AudioFormat::F32 {
214-
error!("Rodio currently only supports F32 and S16 formats, falling back to S16");
215-
format = AudioFormat::S16;
216-
}
217-
218219
let (sink, stream) = create_sink(&host, device, format).unwrap();
219220

220221
debug!("Rodio sink was created");

0 commit comments

Comments
 (0)