From 7715b8f72f54d922c9e57be4f231dc82518810b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 27 Nov 2020 11:29:47 +0100 Subject: samplerate -> dasp --- mumd/Cargo.toml | 7 ++++--- mumd/src/audio.rs | 22 ++++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) (limited to 'mumd') diff --git a/mumd/Cargo.toml b/mumd/Cargo.toml index f497524..936353a 100644 --- a/mumd/Cargo.toml +++ b/mumd/Cargo.toml @@ -13,7 +13,7 @@ default = ["notifications", "sound-effects"] notifications = ["libnotify"] -sound-effects = ["hound", "samplerate"] +sound-effects = ["hound", "dasp_signal", "dasp_interpolate"] [dependencies] mumlib = { path = "../mumlib" } @@ -36,8 +36,9 @@ 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 } +dasp_signal = { version = "0.11", optional = true } +dasp_interpolate = { version = "0.11", features = ["linear"], optional = true } +hound = { version = "3.4", optional = true } #compressor = "0.3" #daemonize = "0.4" diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs index d86cb84..2c7eead 100644 --- a/mumd/src/audio.rs +++ b/mumd/src/audio.rs @@ -5,11 +5,14 @@ pub mod output; use crate::audio::output::SaturatingAdd; use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use cpal::{SampleFormat, SampleRate, Stream, StreamConfig}; +#[cfg(feature = "sound-effects")] +use { + dasp_interpolate::linear::Linear, + dasp_signal::{self as signal, Signal, interpolate::Converter}, +}; 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}; @@ -236,14 +239,13 @@ impl Audio { .map(|e| cpal::Sample::to_f32(&e.unwrap())) .collect::>(), }; - 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 converter = Converter::from_hz_to_hz(signal, + interp, + spec.sample_rate.into(), + SAMPLE_RATE.into()); + let samples = converter.until_exhausted().collect::>(); (*event, samples) }) .collect(); -- cgit v1.2.1 From 9f02a43affa775cc45a0e3ba9147a2f4a882a6ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 27 Nov 2020 12:01:06 +0100 Subject: formatting --- mumd/src/audio.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'mumd') diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs index 2c7eead..9741a2e 100644 --- a/mumd/src/audio.rs +++ b/mumd/src/audio.rs @@ -5,11 +5,6 @@ pub mod output; use crate::audio::output::SaturatingAdd; use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use cpal::{SampleFormat, SampleRate, Stream, StreamConfig}; -#[cfg(feature = "sound-effects")] -use { - dasp_interpolate::linear::Linear, - dasp_signal::{self as signal, Signal, interpolate::Converter}, -}; use log::*; use mumble_protocol::voice::VoicePacketPayload; use opus::Channels; @@ -17,6 +12,11 @@ use std::collections::hash_map::Entry; use std::collections::{HashMap, VecDeque}; use std::sync::{Arc, Mutex}; use tokio::sync::{mpsc, watch}; +#[cfg(feature = "sound-effects")] +use { + dasp_interpolate::linear::Linear, + dasp_signal::{self as signal, Signal}, +}; //TODO? move to mumlib #[cfg(feature = "sound-effects")] @@ -241,11 +241,10 @@ impl Audio { }; let mut signal = signal::from_iter(samples.iter().cloned()); let interp = Linear::new(signal.next(), signal.next()); - let converter = Converter::from_hz_to_hz(signal, - interp, - spec.sample_rate.into(), - SAMPLE_RATE.into()); - let samples = converter.until_exhausted().collect::>(); + let samples = signal + .from_hz_to_hz(interp, spec.sample_rate.into(), SAMPLE_RATE.into()) + .until_exhausted() + .collect::>(); (*event, samples) }) .collect(); -- cgit v1.2.1 From 7314922fe32ab29757c61ed613b76fb0a0ad78b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 27 Nov 2020 21:04:51 +0100 Subject: remove sound-effects feature --- mumd/Cargo.toml | 11 ++++------- mumd/src/audio.rs | 20 +++----------------- 2 files changed, 7 insertions(+), 24 deletions(-) (limited to 'mumd') diff --git a/mumd/Cargo.toml b/mumd/Cargo.toml index 936353a..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", "dasp_signal", "dasp_interpolate"] - [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,9 +37,5 @@ tokio-util = { version = "0.3", features = ["codec", "udp"] } libnotify = { version = "1.0", optional = true } -dasp_signal = { version = "0.11", optional = true } -dasp_interpolate = { version = "0.11", features = ["linear"], optional = true } -hound = { version = "3.4", optional = true } - #compressor = "0.3" #daemonize = "0.4" diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs index 9741a2e..6d4d71a 100644 --- a/mumd/src/audio.rs +++ b/mumd/src/audio.rs @@ -1,10 +1,12 @@ 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; @@ -12,14 +14,8 @@ use std::collections::hash_map::Entry; use std::collections::{HashMap, VecDeque}; use std::sync::{Arc, Mutex}; use tokio::sync::{mpsc, watch}; -#[cfg(feature = "sound-effects")] -use { - dasp_interpolate::linear::Linear, - dasp_signal::{self as signal, Signal}, -}; //TODO? move to mumlib -#[cfg(feature = "sound-effects")] pub const EVENT_SOUNDS: &[(&'static [u8], NotificationEvents)] = &[ (include_bytes!("resources/connect.wav"), NotificationEvents::ServerConnect), ( @@ -78,10 +74,7 @@ pub struct Audio { client_streams: Arc>>, - #[cfg(feature = "sound-effects")] sounds: HashMap>, - - #[cfg(feature = "sound-effects")] play_sounds: Arc>>, } @@ -223,7 +216,6 @@ impl Audio { output_stream.play().unwrap(); - #[cfg(feature = "sound-effects")] let sounds = EVENT_SOUNDS .iter() .map(|(bytes, event)| { @@ -256,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, } } @@ -344,7 +334,6 @@ impl Audio { } } - #[cfg(feature = "sound-effects")] pub fn play_effect(&self, effect: NotificationEvents) { let samples = self.sounds.get(&effect).unwrap(); @@ -357,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) {} } -- cgit v1.2.1 From 5b2716505d0cfcb71cb7799714970be2255e618f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 27 Nov 2020 21:06:16 +0100 Subject: clearer casting --- mumd/src/audio.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mumd') diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs index 6d4d71a..812bb4c 100644 --- a/mumd/src/audio.rs +++ b/mumd/src/audio.rs @@ -234,7 +234,7 @@ impl Audio { 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.into(), SAMPLE_RATE.into()) + .from_hz_to_hz(interp, spec.sample_rate as f64, SAMPLE_RATE as f64) .until_exhausted() .collect::>(); (*event, samples) -- cgit v1.2.1