From 3b0d0f7aee5b6d8dc4ab59c1c16315c2c80347b3 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 16 Nov 2020 02:23:28 +0100 Subject: cargo fmt --- mumd/src/audio.rs | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'mumd/src/audio.rs') diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs index 7f6dd51..a51c2f2 100644 --- a/mumd/src/audio.rs +++ b/mumd/src/audio.rs @@ -1,26 +1,41 @@ pub mod input; pub mod output; +use crate::audio::output::SaturatingAdd; use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use cpal::{SampleFormat, SampleRate, Stream, StreamConfig}; use log::*; use mumble_protocol::voice::VoicePacketPayload; use opus::Channels; +use samplerate::ConverterType; use std::collections::hash_map::Entry; use std::collections::{HashMap, VecDeque}; use std::sync::{Arc, Mutex}; use tokio::sync::{mpsc, watch}; -use samplerate::ConverterType; -use crate::audio::output::SaturatingAdd; //TODO? move to mumlib pub const EVENT_SOUNDS: &[(&str, NotificationEvents)] = &[ ("resources/connect.wav", NotificationEvents::ServerConnect), - ("resources/disconnect.wav", NotificationEvents::ServerDisconnect), - ("resources/channel_join.wav", NotificationEvents::UserConnected), - ("resources/channel_leave.wav", NotificationEvents::UserDisconnected), - ("resources/channel_join.wav", NotificationEvents::UserJoinedChannel), - ("resources/channel_leave.wav", NotificationEvents::UserLeftChannel), + ( + "resources/disconnect.wav", + NotificationEvents::ServerDisconnect, + ), + ( + "resources/channel_join.wav", + NotificationEvents::UserConnected, + ), + ( + "resources/channel_leave.wav", + NotificationEvents::UserDisconnected, + ), + ( + "resources/channel_join.wav", + NotificationEvents::UserJoinedChannel, + ), + ( + "resources/channel_leave.wav", + NotificationEvents::UserLeftChannel, + ), ("resources/mute.wav", NotificationEvents::Mute), ("resources/unmute.wav", NotificationEvents::Unmute), ("resources/deafen.wav", NotificationEvents::Deafen), @@ -200,21 +215,29 @@ impl Audio { output_stream.play().unwrap(); - let sounds = EVENT_SOUNDS.iter() + let sounds = EVENT_SOUNDS + .iter() .map(|(path, event)| { - let reader = hound::WavReader::open(path).unwrap(); + let reader = hound::WavReader::open(path).unwrap(); let spec = reader.spec(); let samples = match spec.sample_format { - hound::SampleFormat::Float => reader.into_samples::().map(|e| e.unwrap()).collect::>(), - hound::SampleFormat::Int => reader.into_samples::().map(|e| cpal::Sample::to_f32(&e.unwrap())).collect::>(), + hound::SampleFormat::Float => reader + .into_samples::() + .map(|e| e.unwrap()) + .collect::>(), + hound::SampleFormat::Int => reader + .into_samples::() + .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(); + &samples, + ) + .unwrap(); (*event, samples) }) .collect(); -- cgit v1.2.1