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/input.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'mumd/src/audio/input.rs') diff --git a/mumd/src/audio/input.rs b/mumd/src/audio/input.rs index a1227e3..10aea91 100644 --- a/mumd/src/audio/input.rs +++ b/mumd/src/audio/input.rs @@ -1,3 +1,4 @@ +//! Listens to the microphone and sends it to the networking. use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use cpal::{InputCallbackInfo, Sample, SampleFormat, SampleRate, StreamConfig}; use log::*; @@ -8,6 +9,7 @@ use crate::audio::transformers::{NoiseGate, Transformer}; use crate::error::{AudioError, AudioStream}; use crate::state::StatePhase; +/// Generates a callback that receives [Sample]s and sends them as floats to a [futures_channel::mpsc::Sender]. pub fn callback( mut input_sender: futures_channel::mpsc::Sender>, mut transformers: Vec>, @@ -44,10 +46,15 @@ pub fn callback( } pub trait AudioInputDevice { + /// Starts the device. fn play(&self) -> Result<(), AudioError>; + /// Stops the device. fn pause(&self) -> Result<(), AudioError>; + /// Sets the input volume of the device. fn set_volume(&self, volume: f32); + /// Returns a receiver to this device's values. fn sample_receiver(&mut self) -> Option>>; + /// The amount of channels this device has. fn num_channels(&self) -> usize; } @@ -59,6 +66,7 @@ pub struct DefaultAudioInputDevice { } impl DefaultAudioInputDevice { + /// Initializes the default audio input. pub fn new( input_volume: f32, phase_watcher: watch::Receiver, @@ -162,17 +170,21 @@ impl AudioInputDevice for DefaultAudioInputDevice { .play() .map_err(|e| AudioError::InputPlayError(e)) } + fn pause(&self) -> Result<(), AudioError> { self.stream .pause() .map_err(|e| AudioError::InputPauseError(e)) } + fn set_volume(&self, volume: f32) { self.volume_sender.send(volume).unwrap(); } + fn sample_receiver(&mut self) -> Option>> { self.sample_receiver.take() } + fn num_channels(&self) -> usize { self.channels as usize } -- cgit v1.2.1 From bc270b506270a17fe830cc1a41426708fedcbdb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 15 Jun 2021 13:21:37 +0200 Subject: doc trait audioinputdevice --- mumd/src/audio/input.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mumd/src/audio/input.rs') diff --git a/mumd/src/audio/input.rs b/mumd/src/audio/input.rs index 10aea91..5721996 100644 --- a/mumd/src/audio/input.rs +++ b/mumd/src/audio/input.rs @@ -45,6 +45,9 @@ pub fn callback( } } +/// Something that can listen to audio and send it somewhere. +/// +/// One sample is assumed to be an encoded opus frame. See [opus::Encoder]. pub trait AudioInputDevice { /// Starts the device. fn play(&self) -> Result<(), AudioError>; -- cgit v1.2.1