From c2adfc88f8aeb4bbdb417897b0cbf44b5b9f7b2c Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Fri, 12 Feb 2021 00:00:34 +0100 Subject: fix audio buffer overflowing --- mumd/src/audio/input.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'mumd/src/audio/input.rs') diff --git a/mumd/src/audio/input.rs b/mumd/src/audio/input.rs index deb0fb8..7769ec1 100644 --- a/mumd/src/audio/input.rs +++ b/mumd/src/audio/input.rs @@ -2,11 +2,17 @@ use cpal::{InputCallbackInfo, Sample}; use tokio::sync::watch; use log::*; +use crate::state::StatePhase; + pub fn callback( mut input_sender: futures::channel::mpsc::Sender, input_volume_receiver: watch::Receiver, + phase_watcher: watch::Receiver, ) -> impl FnMut(&[T], &InputCallbackInfo) + Send + 'static { move |data: &[T], _info: &InputCallbackInfo| { + if !matches!(&*phase_watcher.borrow(), StatePhase::Connected(_)) { + return; + } let input_volume = *input_volume_receiver.borrow(); for sample in data .iter() -- cgit v1.2.1