From 0437f88601ebca10930e3d050c58872abfa3c951 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Mon, 20 May 2019 12:25:44 -0600 Subject: [PATCH] Prevent audio crashes by blocking jack by default Former-commit-id: 61243a38667f64d1c8f106b1191ae876fc652c63 --- voxygen/src/audio/mod.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index e04154adfe..48820619b0 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -5,6 +5,7 @@ use std::{ collections::HashMap, fs::File, io::BufReader, + iter::{Filter, Iterator}, path::PathBuf, sync::mpsc::{channel, Receiver, Sender, TryRecvError}, thread, @@ -21,7 +22,7 @@ pub struct AudioFrontend { impl AudioFrontend { pub fn new() -> Self { - let mut device = rodio::default_output_device().unwrap(); + let mut device = AudioFrontend::get_devices_raw()[0].clone(); let mut sink = rodio::SpatialSink::new(&device, [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [-1.0, 0.0, 0.0]); @@ -37,17 +38,10 @@ impl AudioFrontend { let bufreader = assets::load_from_path(path).unwrap(); let src = Decoder::new(bufreader).unwrap(); - let mut sink = rodio::SpatialSink::new( - &self.device, - [0.0, 0.0, 0.0], - [1.0, 0.0, 0.0], - [-1.0, 0.0, 0.0], - ); - - sink.append(src); - - // self.streams.insert(path.to_string(), sink); - self.stream = sink; + // TODO: stop previous audio from playing. Sink has this ability, but + // SpatialSink does not for some reason. This means that we will + // probably want to use sinks for music, and SpatialSink for sfx. + self.stream.append(src); } pub fn maintain(&mut self) { @@ -72,6 +66,13 @@ impl AudioFrontend { self.stream.set_volume(volume.min(1.0).max(0.0)) } + /// Internal method for working with rodio. Filters out the jack audio server. + fn get_devices_raw() -> Vec { + rodio::output_devices() + .filter(|x| !x.name().contains("jack")) + .collect() + } + /// Returns a vec of the audio devices available. /// Does not return rodio Device struct in case our audio backend changes. // TODO: Decide if this should be an associated function