Hackily upgraded rodio and cpal to 0.13

This commit is contained in:
jiminycrick 2020-11-04 23:48:06 -08:00
parent ca7399b547
commit a02a5d63c3
9 changed files with 387 additions and 133 deletions

300
Cargo.lock generated
View File

@ -56,10 +56,22 @@ dependencies = [
]
[[package]]
name = "alsa-sys"
version = "0.1.2"
name = "alsa"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0edcbbf9ef68f15ae1b620f722180b82a98b6f0628d30baa6b8d2a5abc87d58"
checksum = "44581add1add74ade32aca327b550342359ec00191672c23c1caa3d492b85930"
dependencies = [
"alsa-sys",
"bitflags",
"libc",
"nix 0.15.0",
]
[[package]]
name = "alsa-sys"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5a0559bcd3f7a482690d98be41c08a43e92f669b179433e95ddf5e8b8fd36a3"
dependencies = [
"libc",
"pkg-config",
@ -196,6 +208,12 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
[[package]]
name = "ascii"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e"
[[package]]
name = "ascii"
version = "1.0.0"
@ -275,7 +293,7 @@ dependencies = [
"hex",
"rust-argon2",
"serde_json",
"ureq",
"ureq 1.4.1",
"uuid",
]
@ -311,6 +329,21 @@ version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b20b618342cf9891c292c4f5ac2cde7287cc5c87e87e9c769d617793607dec1"
[[package]]
name = "base64"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e"
dependencies = [
"byteorder",
]
[[package]]
name = "base64"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
[[package]]
name = "base64"
version = "0.12.3"
@ -435,6 +468,12 @@ dependencies = [
"iovec",
]
[[package]]
name = "bytes"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
[[package]]
name = "calloop"
version = "0.6.4"
@ -469,6 +508,12 @@ dependencies = [
"jobserver",
]
[[package]]
name = "cesu8"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
[[package]]
name = "cexpr"
version = "0.4.0"
@ -643,6 +688,30 @@ dependencies = [
"objc",
]
[[package]]
name = "combine"
version = "3.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680"
dependencies = [
"ascii 0.9.3",
"byteorder",
"either",
"memchr",
"unreachable",
]
[[package]]
name = "combine"
version = "4.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2809f67365382d65fd2b6d9c22577231b954ed27400efeafbe687bda75abcc0b"
dependencies = [
"bytes 0.5.6",
"memchr",
"pin-project-lite",
]
[[package]]
name = "conrod_core"
version = "0.63.0"
@ -885,18 +954,26 @@ dependencies = [
[[package]]
name = "cpal"
version = "0.11.0"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b55d55d69f403f62a95bd3c04b431e0aedf5120c70f15d07a8edd234443dd59"
checksum = "4919d30839e3924b45b84319997a554db1a56918bc5b2a08a6c29886e65e2dca"
dependencies = [
"alsa-sys",
"alsa",
"core-foundation-sys 0.6.2",
"coreaudio-rs",
"jni 0.17.0",
"js-sys",
"lazy_static",
"libc",
"num-traits 0.2.12",
"mach 0.3.2",
"ndk",
"ndk-glue",
"nix 0.15.0",
"oboe",
"parking_lot 0.9.0",
"stdweb 0.1.3",
"thiserror",
"web-sys",
"winapi 0.3.9",
]
@ -1490,6 +1567,17 @@ dependencies = [
"syn 1.0.42",
]
[[package]]
name = "fetch_unroll"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5c55005e95bbe15f5f72a73b6597d0dc82ddc97ffe2ca097a99dcd591fefbca"
dependencies = [
"libflate",
"tar",
"ureq 0.11.4",
]
[[package]]
name = "filetime"
version = "0.2.12"
@ -1980,7 +2068,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462"
dependencies = [
"byteorder",
"bytes",
"bytes 0.4.12",
"fnv",
"futures 0.1.29",
"http",
@ -2067,7 +2155,7 @@ version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6ccf5ede3a895d8856620237b2f02972c1bbc78d2965ad7fe8838d4a0ed41f0"
dependencies = [
"bytes",
"bytes 0.4.12",
"fnv",
"itoa",
]
@ -2078,7 +2166,7 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d"
dependencies = [
"bytes",
"bytes 0.4.12",
"futures 0.1.29",
"http",
"tokio-buf",
@ -2091,7 +2179,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9625f605ddfaf894bf78a544a7b8e31f562dc843654723a49892d9c7e75ac708"
dependencies = [
"async-std",
"bytes",
"bytes 0.4.12",
"futures 0.3.5",
"http",
"pin-project-lite",
@ -2121,7 +2209,7 @@ version = "0.12.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dbe6ed1438e1f8ad955a4701e9a944938e9519f6888d12d8558b645e247d5f6"
dependencies = [
"bytes",
"bytes 0.4.12",
"futures 0.1.29",
"futures-cpupool",
"h2",
@ -2305,7 +2393,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f21dcc74995dd4cd090b147e79789f8d65959cbfb5f0b118002db869ea3bd0a0"
dependencies = [
"core-foundation-sys 0.6.2",
"mach",
"mach 0.2.3",
]
[[package]]
@ -2332,6 +2420,34 @@ version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
[[package]]
name = "jni"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1981310da491a4f0f815238097d0d43d8072732b5ae5f8bd0d8eadf5bf245402"
dependencies = [
"cesu8",
"combine 3.8.1",
"error-chain",
"jni-sys",
"log",
"walkdir 2.3.1",
]
[[package]]
name = "jni"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36bcc950632e48b86da402c5c077590583da5ac0d480103611d5374e7c967a3c"
dependencies = [
"cesu8",
"combine 4.3.2",
"error-chain",
"jni-sys",
"log",
"walkdir 2.3.1",
]
[[package]]
name = "jni-sys"
version = "0.3.0"
@ -2416,6 +2532,18 @@ version = "0.2.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235"
[[package]]
name = "libflate"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9135df43b1f5d0e333385cb6e7897ecd1a43d7d11b91ac003f4d2c2d2401fdd"
dependencies = [
"adler32",
"crc32fast",
"rle-decode-fast",
"take_mut",
]
[[package]]
name = "libgit2-sys"
version = "0.12.13+1.0.1"
@ -2567,6 +2695,15 @@ dependencies = [
"libc",
]
[[package]]
name = "mach"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa"
dependencies = [
"libc",
]
[[package]]
name = "malloc_buf"
version = "0.0.6"
@ -3125,6 +3262,29 @@ version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5"
[[package]]
name = "oboe"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6a13c9fe73346ff3cee5530b8dd9da1ce3e13cb663be210af3938a2a1dd3eab"
dependencies = [
"jni 0.14.0",
"ndk",
"ndk-glue",
"num-derive",
"num-traits 0.2.12",
"oboe-sys",
]
[[package]]
name = "oboe-sys"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68ff7a51600eabe34e189eec5c995a62f151d8d97e5fbca39e87ca738bb99b82"
dependencies = [
"fetch_unroll",
]
[[package]]
name = "ogg"
version = "0.7.0"
@ -3842,14 +4002,19 @@ dependencies = [
]
[[package]]
name = "rodio"
version = "0.11.0"
name = "rle-decode-fast"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73bbf260262fd5501b7a17d6827e0d25c1127e921eb177150a060faf6e217a70"
checksum = "cabe4fa914dec5870285fa7f71f602645da47c486e68486d2b4ceb4a343e90ac"
[[package]]
name = "rodio"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9683532495146e98878d4948fa1a1953f584cd923f2a5f5c26b7a8701b56943"
dependencies = [
"cpal",
"hound",
"lazy_static",
"lewton",
]
@ -3859,7 +4024,7 @@ version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8a58080b7bb83b2ea28c3b7a9a994fd5e310330b7c8ca5258d99b98128ecfe4"
dependencies = [
"base64",
"base64 0.12.3",
"bitflags",
"serde",
]
@ -3882,7 +4047,7 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dab61250775933275e84053ac235621dfb739556d5c54a2f2e9313b7cf43a19"
dependencies = [
"base64",
"base64 0.12.3",
"blake2b_simd",
"constant_time_eq",
"crossbeam-utils 0.7.2",
@ -3909,13 +4074,26 @@ dependencies = [
"semver",
]
[[package]]
name = "rustls"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b25a18b1bf7387f0145e7f8324e700805aade3842dd3db2e74e4cdeb4677c09e"
dependencies = [
"base64 0.10.1",
"log",
"ring",
"sct",
"webpki",
]
[[package]]
name = "rustls"
version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d1126dcf58e93cee7d098dbda643b5f92ed724f1f6a63007c1116eed6700c81"
dependencies = [
"base64",
"base64 0.12.3",
"log",
"ring",
"sct",
@ -4424,7 +4602,7 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d"
dependencies = [
"bytes",
"bytes 0.4.12",
]
[[package]]
@ -4509,6 +4687,24 @@ dependencies = [
"unicode-xid 0.2.1",
]
[[package]]
name = "take_mut"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60"
[[package]]
name = "tar"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "489997b7557e9a43e192c527face4feacc78bfbe6eed67fd55c4c9e381cba290"
dependencies = [
"filetime",
"libc",
"redox_syscall",
"xattr",
]
[[package]]
name = "textwrap"
version = "0.11.0"
@ -4585,7 +4781,7 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15ce4fc3c4cdea1a4399bb1819a539195fb69db4bbe0bde5b7c7f18fed412e02"
dependencies = [
"ascii",
"ascii 1.0.0",
"chrono",
"chunked_transfer",
"log",
@ -4614,7 +4810,7 @@ version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6"
dependencies = [
"bytes",
"bytes 0.4.12",
"futures 0.1.29",
"mio 0.6.22",
"num_cpus",
@ -4632,7 +4828,7 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fb220f46c53859a4b7ec083e41dec9778ff0b1851c0942b211edb89e0ccdc46"
dependencies = [
"bytes",
"bytes 0.4.12",
"either",
"futures 0.1.29",
]
@ -4663,7 +4859,7 @@ version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674"
dependencies = [
"bytes",
"bytes 0.4.12",
"futures 0.1.29",
"log",
]
@ -4703,7 +4899,7 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98df18ed66e3b72e742f185882a9e201892407957e45fbff8da17ae7a7c51f72"
dependencies = [
"bytes",
"bytes 0.4.12",
"futures 0.1.29",
"iovec",
"mio 0.6.22",
@ -4975,26 +5171,52 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "unreachable"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
dependencies = [
"void",
]
[[package]]
name = "untrusted"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
[[package]]
name = "ureq"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "801125e6d1ba6864cf3a5a92cfb2f0b0a3ee73e40602a0cd206ad2f3c040aa96"
dependencies = [
"base64 0.11.0",
"chunked_transfer",
"cookie",
"lazy_static",
"qstring",
"rustls 0.16.0",
"url 2.1.1",
"webpki",
"webpki-roots 0.18.0",
]
[[package]]
name = "ureq"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7fb6c9aba13a511bcbb7770864c0e9b8392acda0454a71104498a2bb112d701"
dependencies = [
"base64",
"base64 0.12.3",
"chunked_transfer",
"lazy_static",
"qstring",
"rustls",
"rustls 0.18.1",
"url 2.1.1",
"webpki",
"webpki-roots",
"webpki-roots 0.20.0",
]
[[package]]
@ -5648,6 +5870,15 @@ dependencies = [
"untrusted",
]
[[package]]
name = "webpki-roots"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91cd5736df7f12a964a5067a12c62fa38e1bd8080aff1f80bc29be7c80d19ab4"
dependencies = [
"webpki",
]
[[package]]
name = "webpki-roots"
version = "0.20.0"
@ -5804,6 +6035,15 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "xattr"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c"
dependencies = [
"libc",
]
[[package]]
name = "xcb"
version = "0.9.0"

View File

@ -58,7 +58,7 @@ server = {package = "veloren-server", path = "../server", optional = true}
backtrace = "0.3.40"
bincode = "1.2"
chrono = "0.4.9"
cpal = "0.11"
cpal = "0.13"
copy_dir = "0.1.2"
crossbeam = "=0.7.2"
deunicode = "1.0"
@ -75,7 +75,7 @@ native-dialog = { version = "0.4.2", default-features = false, optional = true }
num = "0.2"
ordered-float = { version = "2.0.0", default-features = false }
rand = "0.7"
rodio = {version = "0.11", default-features = false, features = ["wav", "vorbis"]}
rodio = {version = "0.13", default-features = false, features = ["wav", "vorbis"]}
ron = {version = "0.6", default-features = false}
serde = {version = "1.0", features = [ "rc", "derive" ]}
treeculler = "0.1.0"

View File

@ -20,7 +20,7 @@ use crate::audio::{
fader::{FadeDirection, Fader},
Listener,
};
use rodio::{Device, Sample, Sink, Source, SpatialSink};
use rodio::{Device, OutputStream, OutputStreamHandle, Sample, Sink, Source, SpatialSink};
use vek::*;
#[derive(PartialEq, Clone, Copy)]
@ -53,9 +53,9 @@ pub struct MusicChannel {
}
impl MusicChannel {
pub fn new(device: &Device) -> Self {
pub fn new(stream: &OutputStreamHandle) -> Self {
Self {
sink: Sink::new(device),
sink: Sink::try_new(stream).unwrap(),
tag: MusicChannelTag::TitleMusic,
state: ChannelState::Stopped,
fader: Fader::default(),
@ -151,9 +151,10 @@ pub struct SfxChannel {
}
impl SfxChannel {
pub fn new(device: &Device) -> Self {
pub fn new(stream: &OutputStreamHandle) -> Self {
Self {
sink: SpatialSink::new(device, [0.0; 3], [1.0, 0.0, 0.0], [-1.0, 0.0, 0.0]),
sink: SpatialSink::try_new(stream, [0.0; 3], [1.0, 0.0, 0.0], [-1.0, 0.0, 0.0])
.unwrap(),
pos: Vec3::zero(),
}
}

View File

@ -14,7 +14,7 @@ use tracing::warn;
use common::assets;
use cpal::traits::DeviceTrait;
use rodio::{source::Source, Decoder, Device};
use rodio::{source::Source, Decoder, Device, OutputStream, OutputStreamHandle, StreamError};
use vek::*;
#[derive(Default, Clone)]
@ -31,9 +31,10 @@ pub struct Listener {
/// Voxygen's [`GlobalState`](../struct.GlobalState.html#structfield.audio) to
/// provide access to devices and playback control in-game
pub struct AudioFrontend {
pub device: String,
pub device_list: Vec<String>,
audio_device: Option<Device>,
//pub device: String,
pub stream: Option<rodio::OutputStream>,
//pub device_list: Vec<String>,
audio_stream: Option<rodio::OutputStreamHandle>,
sound_cache: SoundCache,
music_channels: Vec<MusicChannel>,
@ -45,18 +46,23 @@ pub struct AudioFrontend {
impl AudioFrontend {
/// Construct with given device
pub fn new(device: String, max_sfx_channels: usize) -> Self {
let audio_device = get_device_raw(&device);
pub fn new(max_sfx_channels: usize) -> Self {
//let audio_device = get_device_raw(&device);
let (stream, audio_stream) = match get_default_stream() {
Ok(s) => (Some(s.0), Some(s.1)),
Err(_) => (None, None),
};
let mut sfx_channels = Vec::with_capacity(max_sfx_channels);
if let Some(audio_device) = &audio_device {
sfx_channels.resize_with(max_sfx_channels, || SfxChannel::new(&audio_device));
}
if let Some(audio_stream) = &audio_stream {
sfx_channels.resize_with(max_sfx_channels, || SfxChannel::new(audio_stream));
};
Self {
device,
device_list: list_devices(),
audio_device,
//device,
//device_list: list_devices(),
stream,
audio_stream,
sound_cache: SoundCache::default(),
music_channels: Vec::new(),
sfx_channels,
@ -69,9 +75,11 @@ impl AudioFrontend {
/// Construct in `no-audio` mode for debugging
pub fn no_audio() -> Self {
Self {
device: "none".to_string(),
device_list: Vec::new(),
audio_device: None,
//device: "none".to_string(),
//device_list: Vec::new(),
//audio_device: None,
stream: None,
audio_stream: None,
sound_cache: SoundCache::default(),
music_channels: Vec::new(),
sfx_channels: Vec::new(),
@ -91,7 +99,7 @@ impl AudioFrontend {
}
fn get_sfx_channel(&mut self) -> Option<&mut SfxChannel> {
if self.audio_device.is_some() {
if self.audio_stream.is_some() {
if let Some(channel) = self.sfx_channels.iter_mut().find(|c| c.is_done()) {
channel.set_volume(self.sfx_volume);
@ -111,9 +119,9 @@ impl AudioFrontend {
&mut self,
next_channel_tag: MusicChannelTag,
) -> Option<&mut MusicChannel> {
if let Some(audio_device) = &self.audio_device {
if let Some(audio_stream) = &self.audio_stream {
if self.music_channels.is_empty() {
let mut next_music_channel = MusicChannel::new(&audio_device);
let mut next_music_channel = MusicChannel::new(audio_stream);
next_music_channel.set_volume(self.music_volume);
self.music_channels.push(next_music_channel);
@ -125,7 +133,7 @@ impl AudioFrontend {
existing_channel
.set_fader(Fader::fade_out(Duration::from_secs(2), self.music_volume));
let mut next_music_channel = MusicChannel::new(&audio_device);
let mut next_music_channel = MusicChannel::new(&audio_stream);
next_music_channel
.set_fader(Fader::fade_in(Duration::from_secs(12), self.music_volume));
@ -140,7 +148,7 @@ impl AudioFrontend {
/// Play (once) an sfx file by file path at the give position and volume
pub fn play_sfx(&mut self, sound: &str, pos: Vec3<f32>, vol: Option<f32>) {
if self.audio_device.is_some() {
if self.audio_stream.is_some() {
let sound = self
.sound_cache
.load_sound(sound)
@ -258,47 +266,52 @@ impl AudioFrontend {
}
}
// TODO: figure out how badly this will break things when it is called
pub fn set_device(&mut self, name: String) {
self.device = name.clone();
self.audio_device = get_device_raw(&name);
}
//// TODO: figure out how badly this will break things when it is called
//pub fn set_device(&mut self, name: String) {
// self.device = name.clone();
// self.audio_device = get_device_raw(&name);
//}
}
/// Returns the default audio device.
/// Does not return rodio Device struct in case our audio backend changes.
pub fn get_default_device() -> Option<String> {
match rodio::default_output_device() {
Some(x) => Some(x.name().ok()?),
None => None,
}
///// Returns the default audio device.
///// Does not return rodio Device struct in case our audio backend changes.
//pub fn get_default_device() -> Option<String> {
// match rodio::default_output_device() {
// Some(x) => Some(x.name().ok()?),
// None => None,
// }
//}
/// Returns the default stream
pub fn get_default_stream() -> Result<(OutputStream, OutputStreamHandle), StreamError> {
rodio::OutputStream::try_default()
}
/// Returns a vec of the audio devices available.
/// Does not return rodio Device struct in case our audio backend changes.
pub fn list_devices() -> Vec<String> {
list_devices_raw()
.iter()
.map(|x| x.name().unwrap())
.collect()
}
///// Returns a vec of the audio devices available.
///// Does not return rodio Device struct in case our audio backend changes.
//pub fn list_devices() -> Vec<String> {
// list_devices_raw()
// .iter()
// .map(|x| x.name().unwrap())
// .collect()
//}
/// Returns vec of devices
fn list_devices_raw() -> Vec<Device> {
match rodio::output_devices() {
Ok(devices) => {
// Filter out any devices that the name isn't available for
devices.filter(|d| d.name().is_ok()).collect()
},
Err(_) => {
warn!("Failed to enumerate audio output devices, audio will not be available");
Vec::new()
},
}
}
fn get_device_raw(device: &str) -> Option<Device> {
list_devices_raw()
.into_iter()
.find(|d| d.name().unwrap() == device)
}
///// Returns vec of devices
//fn list_devices_raw() -> Vec<Device> {
// match rodio::output_devices() {
// Ok(devices) => {
// // Filter out any devices that the name isn't available for
// devices.filter(|d| d.name().is_ok()).collect()
// },
// Err(_) => {
// warn!("Failed to enumerate audio output devices, audio will not be
// available"); Vec::new()
// },
// }
//}
//
//fn get_device_raw(device: &str) -> Option<Device> {
// list_devices_raw()
// .into_iter()
// .find(|d| d.name().unwrap() == device)
//}

View File

@ -319,7 +319,7 @@ pub enum Event {
AdjustFigureLoDRenderDistance(u32),
AdjustMusicVolume(f32),
AdjustSfxVolume(f32),
ChangeAudioDevice(String),
//ChangeAudioDevice(String),
ChangeMaxFPS(u32),
ChangeFOV(u16),
ChangeGamma(f32),
@ -2131,9 +2131,9 @@ impl Hud {
settings_window::Event::MaximumFPS(max_fps) => {
events.push(Event::ChangeMaxFPS(max_fps));
},
settings_window::Event::ChangeAudioDevice(name) => {
events.push(Event::ChangeAudioDevice(name));
},
//settings_window::Event::ChangeAudioDevice(name) => {
// events.push(Event::ChangeAudioDevice(name));
//},
settings_window::Event::CrosshairType(crosshair_type) => {
events.push(Event::CrosshairType(crosshair_type));
},

View File

@ -291,7 +291,7 @@ pub enum Event {
ChangeRenderMode(Box<RenderMode>),
AdjustMusicVolume(f32),
AdjustSfxVolume(f32),
ChangeAudioDevice(String),
//ChangeAudioDevice(String),
MaximumFPS(u32),
CrosshairTransp(f32),
CrosshairType(CrosshairType),
@ -2693,30 +2693,32 @@ impl<'a> Widget for SettingsWindow<'a> {
events.push(Event::AdjustSfxVolume(new_val));
}
// Audio Device Selector --------------------------------------------
let device = &self.global_state.audio.device;
let device_list = &self.global_state.audio.device_list;
Text::new(&self.localized_strings.get("hud.settings.audio_device"))
.down_from(state.ids.sfx_volume_slider, 10.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR)
.set(state.ids.audio_device_text, ui);
// Audio Device Selector
// --------------------------------------------
// let device = &self.global_state.audio.device;
//let device_list = &self.global_state.audio.device_list;
//Text::new(&self.localized_strings.get("hud.settings.audio_device"
// )) .down_from(state.ids.sfx_volume_slider, 10.0)
// .font_size(self.fonts.cyri.scale(14))
// .font_id(self.fonts.cyri.conrod_id)
// .color(TEXT_COLOR)
// .set(state.ids.audio_device_text, ui);
// Get which device is currently selected
let selected = device_list.iter().position(|x| x.contains(device));
//// Get which device is currently selected
//let selected = device_list.iter().position(|x|
// x.contains(device));
if let Some(clicked) = DropDownList::new(&device_list, selected)
.w_h(400.0, 22.0)
.color(MENU_BG)
.label_color(TEXT_COLOR)
.label_font_id(self.fonts.opensans.conrod_id)
.down_from(state.ids.audio_device_text, 10.0)
.set(state.ids.audio_device_list, ui)
{
let new_val = device_list[clicked].clone();
events.push(Event::ChangeAudioDevice(new_val));
}
//if let Some(clicked) = DropDownList::new(&device_list, selected)
// .w_h(400.0, 22.0)
// .color(MENU_BG)
// .label_color(TEXT_COLOR)
// .label_font_id(self.fonts.opensans.conrod_id)
// .down_from(state.ids.audio_device_text, 10.0)
// .set(state.ids.audio_device_list, ui)
//{
// let new_val = device_list[clicked].clone();
// events.push(Event::ChangeAudioDevice(new_val));
//}
}
// 5) Languages Tab -----------------------------------

View File

@ -144,10 +144,10 @@ fn main() {
// Setup audio
let mut audio = match settings.audio.output {
AudioOutput::Off => None,
AudioOutput::Automatic => audio::get_default_device(),
AudioOutput::Device(ref dev) => Some(dev.clone()),
AudioOutput::Automatic => audio::get_default_stream().ok(),
//AudioOutput::Device(ref dev) => Some(dev.clone()),
}
.map(|dev| AudioFrontend::new(dev, settings.audio.max_sfx_channels))
.map(|dev| AudioFrontend::new(/* dev, */ settings.audio.max_sfx_channels))
.unwrap_or_else(AudioFrontend::no_audio);
audio.set_music_volume(settings.audio.music_volume);

View File

@ -901,12 +901,12 @@ impl PlayState for SessionState {
global_state.settings.audio.sfx_volume = sfx_volume;
global_state.settings.save_to_file_warn();
},
HudEvent::ChangeAudioDevice(name) => {
global_state.audio.set_device(name.clone());
//HudEvent::ChangeAudioDevice(name) => {
// global_state.audio.set_device(name.clone());
global_state.settings.audio.output = AudioOutput::Device(name);
global_state.settings.save_to_file_warn();
},
// global_state.settings.audio.output = AudioOutput::Device(name);
// global_state.settings.save_to_file_warn();
//},
HudEvent::ChangeMaxFPS(fps) => {
global_state.settings.graphics.max_fps = fps;
global_state.settings.save_to_file_warn();

View File

@ -654,8 +654,6 @@ pub enum AudioOutput {
// If this option is disabled, functions in the rodio
// library MUST NOT be called.
Off,
Device(String),
#[serde(other)]
Automatic,
}