diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-11-28 02:55:37 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-11-28 02:55:37 +0100 |
| commit | 1db4ab3868df2e1cdeffa80b74ddf92ddf341848 (patch) | |
| tree | f3ea383b49df4d2ace040dbad14c47700fba650a | |
| parent | 1014f6c85b3d77009d8ee34f9517c73fc32f5379 (diff) | |
| parent | 5b2716505d0cfcb71cb7799714970be2255e618f (diff) | |
| download | mum-1db4ab3868df2e1cdeffa80b74ddf92ddf341848.tar.gz | |
Merge branch 'dasp' into 'main'
samplerate -> DASP
See merge request gustav/mum!38
| -rw-r--r-- | Cargo.lock | 213 | ||||
| -rw-r--r-- | README.org | 2 | ||||
| -rw-r--r-- | mumd/Cargo.toml | 10 | ||||
| -rw-r--r-- | mumd/src/audio.rs | 31 |
4 files changed, 102 insertions, 154 deletions
@@ -1,15 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "aho-corasick" -version = "0.7.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" -dependencies = [ - "memchr", -] - -[[package]] name = "alsa" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -75,29 +66,6 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.51.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd71393f1ec0509b553aa012b9b58e81dadbdff7130bd3b8cba576e69b32f75" -dependencies = [ - "bitflags", - "cexpr", - "cfg-if", - "clang-sys", - "clap", - "env_logger", - "lazy_static", - "log", - "peeking_take_while", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "which", -] - -[[package]] -name = "bindgen" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99de13bb6361e01e493b3db7928085dcc474b7ba4f5481818e53a89d76b8393f" @@ -211,15 +179,6 @@ dependencies = [ ] [[package]] -name = "cmake" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e56268c17a6248366d66d4a47a3381369d068cce8409bb1716ed77ea32163bb" -dependencies = [ - "cc", -] - -[[package]] name = "colored" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -268,7 +227,7 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6570ee6e089131e928d5ec9236db9e818aa3cf850f48b0eec6ef700571271d4" dependencies = [ - "bindgen 0.53.1", + "bindgen", ] [[package]] @@ -313,16 +272,94 @@ dependencies = [ ] [[package]] -name = "env_logger" -version = "0.6.2" +name = "dasp_envelope" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3" +checksum = "8ec617ce7016f101a87fe85ed44180839744265fae73bb4aa43e7ece1b7668b6" dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", + "dasp_frame", + "dasp_peak", + "dasp_ring_buffer", + "dasp_rms", + "dasp_sample", +] + +[[package]] +name = "dasp_frame" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a3937f5fe2135702897535c8d4a5553f8b116f76c1529088797f2eee7c5cd6" +dependencies = [ + "dasp_sample", +] + +[[package]] +name = "dasp_interpolate" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc975a6563bb7ca7ec0a6c784ead49983a21c24835b0bc96eea11ee407c7486" +dependencies = [ + "dasp_frame", + "dasp_ring_buffer", + "dasp_sample", +] + +[[package]] +name = "dasp_peak" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cf88559d79c21f3d8523d91250c397f9a15b5fc72fbb3f87fdb0a37b79915bf" +dependencies = [ + "dasp_frame", + "dasp_sample", +] + +[[package]] +name = "dasp_ring_buffer" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07d79e19b89618a543c4adec9c5a347fe378a19041699b3278e616e387511ea1" + +[[package]] +name = "dasp_rms" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6c5dcb30b7e5014486e2822537ea2beae50b19722ffe2ed7549ab03774575aa" +dependencies = [ + "dasp_frame", + "dasp_ring_buffer", + "dasp_sample", +] + +[[package]] +name = "dasp_sample" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f" + +[[package]] +name = "dasp_signal" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa1ab7d01689c6ed4eae3d38fe1cea08cba761573fbd2d592528d55b421077e7" +dependencies = [ + "dasp_envelope", + "dasp_frame", + "dasp_interpolate", + "dasp_peak", + "dasp_ring_buffer", + "dasp_rms", + "dasp_sample", + "dasp_window", +] + +[[package]] +name = "dasp_window" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66bcb90ea007ba45fc48d426e28af3e8a653634f9a7174d768dcfe90fa6211f4" +dependencies = [ + "dasp_sample", ] [[package]] @@ -576,15 +613,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a164bb2ceaeff4f42542bdb847c41517c78a60f5649671b2a07312b6e117549" [[package]] -name = "humantime" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] - -[[package]] name = "iovec" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -687,16 +715,6 @@ dependencies = [ ] [[package]] -name = "libsamplerate-sys" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66575d1d489214f8767f90de2b1e115626d8277ca09d7c39549652a9602309eb" -dependencies = [ - "bindgen 0.51.1", - "cmake", -] - -[[package]] name = "lock_api" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -798,6 +816,8 @@ dependencies = [ "argparse", "bytes", "cpal", + "dasp_interpolate", + "dasp_signal", "futures", "futures-util", "hound", @@ -809,7 +829,6 @@ dependencies = [ "native-tls", "openssl", "opus", - "samplerate", "serde", "tokio", "tokio-tls", @@ -1081,12 +1100,6 @@ dependencies = [ ] [[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - -[[package]] name = "quote" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1148,10 +1161,7 @@ version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8963b85b8ce3074fecffde43b4b0dded83ce2f367dc8d363afc56679f3ee820b" dependencies = [ - "aho-corasick", - "memchr", "regex-syntax", - "thread_local", ] [[package]] @@ -1185,15 +1195,6 @@ dependencies = [ ] [[package]] -name = "samplerate" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6913e9f2ad7d0aa9528523f7e4385e160d690c66d43bb8bd7559f1be705aee8" -dependencies = [ - "libsamplerate-sys", -] - -[[package]] name = "schannel" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1326,15 +1327,6 @@ dependencies = [ ] [[package]] -name = "termcolor" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" -dependencies = [ - "winapi-util", -] - -[[package]] name = "textwrap" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1364,15 +1356,6 @@ dependencies = [ ] [[package]] -name = "thread_local" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" -dependencies = [ - "lazy_static", -] - -[[package]] name = "time" version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1566,15 +1549,6 @@ dependencies = [ ] [[package]] -name = "which" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" -dependencies = [ - "libc", -] - -[[package]] name = "winapi" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1603,15 +1577,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi 0.3.9", -] - -[[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -14,7 +14,6 @@ and operating systems, or they might be named something different. - `openssl` - `opus` - `libnotify` (optional) -- `libsamplerate` (optional) Windows is not currently supported but could be in the future. macOS should work. Other operating systems haven't been tested. The limiting factor on Windows @@ -41,7 +40,6 @@ The following features can be specified: | Name | Needed for | Additional crates | |--------------------+---------------+-------------------| | mumd/notifications | Notifications | 20 | -| mumd/sound-effects | Sound effects | 54 | Note that the "additional crates" isn't continually updated and might change. Features might also have overlapping dependencies. diff --git a/mumd/Cargo.toml b/mumd/Cargo.toml index f497524..ba0f5a0 100644 --- a/mumd/Cargo.toml +++ b/mumd/Cargo.toml @@ -9,20 +9,21 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = ["notifications", "sound-effects"] +default = ["notifications"] notifications = ["libnotify"] -sound-effects = ["hound", "samplerate"] - [dependencies] mumlib = { path = "../mumlib" } argparse = "0.2" bytes = "0.5" cpal = { git = "https://github.com/RustAudio/cpal" } +dasp_interpolate = { version = "0.11", features = ["linear"] } +dasp_signal = "0.11" futures = "0.3" futures-util = "0.3" +hound = "3.4" ipc-channel = "0.14" log = "0.4" mumble-protocol = "0.3" @@ -36,8 +37,5 @@ tokio-util = { version = "0.3", features = ["codec", "udp"] } libnotify = { version = "1.0", optional = true } -hound = { version = "3.4.0", optional = true } -samplerate = { version = "0.2.2", optional = true } - #compressor = "0.3" #daemonize = "0.4" diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs index d86cb84..812bb4c 100644 --- a/mumd/src/audio.rs +++ b/mumd/src/audio.rs @@ -1,22 +1,21 @@ pub mod input; pub mod output; -#[cfg(feature = "sound-effects")] use crate::audio::output::SaturatingAdd; + use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use cpal::{SampleFormat, SampleRate, Stream, StreamConfig}; +use dasp_interpolate::linear::Linear; +use dasp_signal::{self as signal, Signal}; use log::*; use mumble_protocol::voice::VoicePacketPayload; use opus::Channels; -#[cfg(feature = "sound-effects")] -use samplerate::ConverterType; use std::collections::hash_map::Entry; use std::collections::{HashMap, VecDeque}; use std::sync::{Arc, Mutex}; use tokio::sync::{mpsc, watch}; //TODO? move to mumlib -#[cfg(feature = "sound-effects")] pub const EVENT_SOUNDS: &[(&'static [u8], NotificationEvents)] = &[ (include_bytes!("resources/connect.wav"), NotificationEvents::ServerConnect), ( @@ -75,10 +74,7 @@ pub struct Audio { client_streams: Arc<Mutex<HashMap<u32, output::ClientStream>>>, - #[cfg(feature = "sound-effects")] sounds: HashMap<NotificationEvents, Vec<f32>>, - - #[cfg(feature = "sound-effects")] play_sounds: Arc<Mutex<VecDeque<f32>>>, } @@ -220,7 +216,6 @@ impl Audio { output_stream.play().unwrap(); - #[cfg(feature = "sound-effects")] let sounds = EVENT_SOUNDS .iter() .map(|(bytes, event)| { @@ -236,14 +231,12 @@ impl Audio { .map(|e| cpal::Sample::to_f32(&e.unwrap())) .collect::<Vec<_>>(), }; - let samples = samplerate::convert( - spec.sample_rate, - SAMPLE_RATE, - spec.channels as usize, - ConverterType::SincBestQuality, - &samples, - ) - .unwrap(); + let mut signal = signal::from_iter(samples.iter().cloned()); + let interp = Linear::new(signal.next(), signal.next()); + let samples = signal + .from_hz_to_hz(interp, spec.sample_rate as f64, SAMPLE_RATE as f64) + .until_exhausted() + .collect::<Vec<_>>(); (*event, samples) }) .collect(); @@ -255,11 +248,9 @@ impl Audio { input_volume_sender, input_channel_receiver: Some(input_receiver), client_streams, - #[cfg(feature = "sound-effects")] sounds, output_volume_sender, user_volumes, - #[cfg(feature = "sound-effects")] play_sounds, } } @@ -343,7 +334,6 @@ impl Audio { } } - #[cfg(feature = "sound-effects")] pub fn play_effect(&self, effect: NotificationEvents) { let samples = self.sounds.get(&effect).unwrap(); @@ -356,7 +346,4 @@ impl Audio { let l = play_sounds.len(); play_sounds.extend(samples.iter().skip(l)); } - - #[cfg(not(feature = "sound-effects"))] - pub fn play_effect(&self, _: NotificationEvents) {} } |
