diff options
Diffstat (limited to 'mumd')
| -rw-r--r-- | mumd/Cargo.toml | 10 | ||||
| -rw-r--r-- | mumd/src/audio.rs | 31 |
2 files changed, 13 insertions, 28 deletions
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) {} } |
