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 /mumd/src | |
| parent | 1014f6c85b3d77009d8ee34f9517c73fc32f5379 (diff) | |
| parent | 5b2716505d0cfcb71cb7799714970be2255e618f (diff) | |
| download | mum-1db4ab3868df2e1cdeffa80b74ddf92ddf341848.tar.gz | |
Merge branch 'dasp' into 'main'
samplerate -> DASP
See merge request gustav/mum!38
Diffstat (limited to 'mumd/src')
| -rw-r--r-- | mumd/src/audio.rs | 31 |
1 files changed, 9 insertions, 22 deletions
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) {} } |
