From 64978fa17b6e0882d6bacb6e626b0bc9ead2c81d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Thu, 8 Apr 2021 14:42:18 +0200 Subject: document mumd::audio --- mumd/src/audio/output.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'mumd/src/audio/output.rs') diff --git a/mumd/src/audio/output.rs b/mumd/src/audio/output.rs index a2f6bcc..3d886d6 100644 --- a/mumd/src/audio/output.rs +++ b/mumd/src/audio/output.rs @@ -1,3 +1,4 @@ +//! Receives audio packets from the networking and plays them. use crate::audio::SAMPLE_RATE; use crate::error::{AudioError, AudioStream}; use crate::network::VoiceStreamType; @@ -13,6 +14,7 @@ use tokio::sync::watch; type ClientStreamKey = (VoiceStreamType, u32); +/// Collected state for client opus decoders and sound effects. pub struct ClientStream { buffer_clients: HashMap, opus::Decoder)>, //TODO ring buffer? buffer_effects: VecDeque, @@ -44,6 +46,7 @@ impl ClientStream { }) } + /// Decodes a voice packet. pub fn decode_packet(&mut self, client: ClientStreamKey, payload: VoicePacketPayload) { match payload { VoicePacketPayload::Opus(bytes, _eot) => { @@ -61,6 +64,7 @@ impl ClientStream { } } + /// Extends either a decoder queue or the buffer effect queue with some received values. pub fn extend(&mut self, client: Option, values: &[f32]) { let buffer = match client { Some(x) => &mut self.get_client(x).0, @@ -70,6 +74,12 @@ impl ClientStream { } } +/// Adds two values in some saturating way. +/// +/// Since we support [f32], [i16] and [u16] we need some way of adding two values +/// without peaking above/below the edge values. This trait ensures that we can +/// use all three primitive types as a generic parameter. + pub trait SaturatingAdd { fn saturating_add(self, rhs: Self) -> Self; } @@ -107,11 +117,16 @@ pub trait AudioOutputDevice { pub struct DefaultAudioOutputDevice { config: StreamConfig, stream: cpal::Stream, + /// The client stream per user ID. A separate stream is kept for UDP and TCP. + /// + /// Shared with [super::AudioOutput]. client_streams: Arc>, + /// Output volume configuration. volume_sender: watch::Sender, } impl DefaultAudioOutputDevice { + /// Initializes the default audio output. pub fn new( output_volume: f32, user_volumes: Arc>>, @@ -211,6 +226,7 @@ impl AudioOutputDevice for DefaultAudioOutputDevice { } } +/// Over-engineered way of handling multiple types of samples. pub fn curry_callback( user_bufs: Arc>, output_volume_receiver: watch::Receiver, -- cgit v1.2.1 From b97645143c70b8c69d659e46e5d0cfce97220b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 15 Jun 2021 13:25:16 +0200 Subject: saturating add method doc --- mumd/src/audio/output.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mumd/src/audio/output.rs') diff --git a/mumd/src/audio/output.rs b/mumd/src/audio/output.rs index 3d886d6..3c00116 100644 --- a/mumd/src/audio/output.rs +++ b/mumd/src/audio/output.rs @@ -1,4 +1,5 @@ //! Receives audio packets from the networking and plays them. + use crate::audio::SAMPLE_RATE; use crate::error::{AudioError, AudioStream}; use crate::network::VoiceStreamType; @@ -79,8 +80,8 @@ impl ClientStream { /// Since we support [f32], [i16] and [u16] we need some way of adding two values /// without peaking above/below the edge values. This trait ensures that we can /// use all three primitive types as a generic parameter. - pub trait SaturatingAdd { + /// Adds two values in some saturating way. See trait documentation. fn saturating_add(self, rhs: Self) -> Self; } -- cgit v1.2.1 From 17feef9da27aa7740c1b553a8ac331d10a1a391c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 15 Jun 2021 13:26:08 +0200 Subject: default audio ouput device --- mumd/src/audio/output.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'mumd/src/audio/output.rs') diff --git a/mumd/src/audio/output.rs b/mumd/src/audio/output.rs index 3c00116..597dcf0 100644 --- a/mumd/src/audio/output.rs +++ b/mumd/src/audio/output.rs @@ -115,6 +115,7 @@ pub trait AudioOutputDevice { fn client_streams(&self) -> Arc>; } +/// The default audio output device, as determined by [cpal]. pub struct DefaultAudioOutputDevice { config: StreamConfig, stream: cpal::Stream, -- cgit v1.2.1 From 1aec4a2385cc134ffd189e122f8b77c975e3dcb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 15 Jun 2021 13:29:58 +0200 Subject: better curry callback --- mumd/src/audio/output.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mumd/src/audio/output.rs') diff --git a/mumd/src/audio/output.rs b/mumd/src/audio/output.rs index 597dcf0..a3ce064 100644 --- a/mumd/src/audio/output.rs +++ b/mumd/src/audio/output.rs @@ -228,7 +228,8 @@ impl AudioOutputDevice for DefaultAudioOutputDevice { } } -/// Over-engineered way of handling multiple types of samples. +/// Returns a function that fills a buffer with audio from client streams +/// modified according to some audio configuration. pub fn curry_callback( user_bufs: Arc>, output_volume_receiver: watch::Receiver, -- cgit v1.2.1 From 37f1089cb5f2468c0659f7d83c7530b35eedeaec Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sat, 19 Jun 2021 17:48:21 +0200 Subject: fix compiler warning --- mumd/src/audio/output.rs | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'mumd/src/audio/output.rs') diff --git a/mumd/src/audio/output.rs b/mumd/src/audio/output.rs index 2015435..cdb7b8e 100644 --- a/mumd/src/audio/output.rs +++ b/mumd/src/audio/output.rs @@ -180,14 +180,6 @@ impl DefaultAudioOutputDevice { let err_fn = |err| error!("An error occurred on the output audio stream: {}", err); let (output_volume_sender, output_volume_receiver) = watch::channel::(output_volume); - let output_channels = match output_config.channels { - 1 => opus::Channels::Mono, - 2 => opus::Channels::Stereo, - _ => { - warn!("Trying to output to an unsupported number of channels ({}), defaulting to mono", output_config.channels); - opus::Channels::Mono - } - }; let output_stream = match output_supported_sample_format { SampleFormat::F32 => output_device.build_output_stream( @@ -196,7 +188,6 @@ impl DefaultAudioOutputDevice { Arc::clone(&client_streams), output_volume_receiver, user_volumes, - output_channels, ), err_fn, ), @@ -206,7 +197,6 @@ impl DefaultAudioOutputDevice { Arc::clone(&client_streams), output_volume_receiver, user_volumes, - output_channels, ), err_fn, ), @@ -216,7 +206,6 @@ impl DefaultAudioOutputDevice { Arc::clone(&client_streams), output_volume_receiver, user_volumes, - output_channels, ), err_fn, ), @@ -262,7 +251,6 @@ pub fn callback( user_bufs: Arc>, output_volume_receiver: watch::Receiver, user_volumes: Arc>>, - output_channels: opus::Channels, ) -> impl FnMut(&mut [T], &OutputCallbackInfo) + Send + 'static { move |data: &mut [T], _info: &OutputCallbackInfo| { for sample in data.iter_mut() { -- cgit v1.2.1