Add a default noise floor. #13

Merged
liamwarfield merged 5 commits from feature/stop-sending-when-quiet into main 2026-01-19 22:07:06 +00:00
Showing only changes of commit 95c7981632 - Show all commits
+17 -27
View File
@@ -3,7 +3,6 @@ use crate::effects::{AudioProcessor, AudioProcessorSender, TransmitState};
use color_eyre::eyre::{bail, eyre, Error};
use crossbeam::atomic::AtomicCell;
use dioxus::prelude::*;
use std::sync::Arc;
use futures::{AsyncRead, AsyncWrite};
use gloo_timers::future::TimeoutFuture;
use js_sys::Float32Array;
@@ -11,6 +10,7 @@ use mumble_protocol::control::ClientControlCodec;
use mumble_web2_common::{ClientConfig, ServerStatus};
use reqwest::Url;
use std::future::Future;
use std::sync::Arc;
use std::time::Duration;
use tracing::level_filters::LevelFilter;
use tracing::{debug, error, info, instrument};
@@ -120,7 +120,10 @@ impl AudioSystem {
self.processors.store(Some(processor))
}
pub fn start_recording(&mut self, each: impl FnMut(Vec<u8>, bool) + 'static) -> Result<(), Error> {
pub fn start_recording(
&mut self,
each: impl FnMut(Vec<u8>, bool) + 'static,
) -> Result<(), Error> {
let audio_context_worklet = self.webctx.clone();
let processors = self.processors.clone();
spawn(async move {
@@ -312,34 +315,21 @@ async fn run_encoder_worklet(
// Don't encode or send anything
return;
}
liamwarfield marked this conversation as resolved Outdated
Outdated
Review

This logic is duplicated in both Transmitting and Terminator? Could we possibly pull this match statement up a level out of imp and have encode_and_send be the platform specific code boundary?

This logic is duplicated in both `Transmitting` and `Terminator`? Could we possibly pull this match statement up a level out of `imp` and have `encode_and_send` be the platform specific code boundary?
Outdated
Review

I was able to pull that code out of the match and run it bellow. As for the refactoring things out of imp, I don't think that's a good idea due to how everything has to eventually end up in audio encoding worklet for the web impl. That's why I have to wrap the terminator logic in a arc with pending_terminator.store(true);.

I was able to pull that code out of the match and run it bellow. As for the refactoring things out of `imp`, I don't think that's a good idea due to how everything has to eventually end up in audio encoding worklet for the web impl. That's why I have to wrap the terminator logic in a arc with `pending_terminator.store(true);`.
TransmitState::Transmitting => {
// Normal transmission
match AudioData::new(frame.unchecked_ref()) {
Ok(data) => {
let _ = audio_encoder.encode(&data);
}
Err(err) => {
error!(
"error creating AudioData object {:?} during event {:?}",
err, event,
);
}
}
}
TransmitState::Transmitting => (), // Normal transmission
TransmitState::Terminator => {
// Mark this as a terminator before encoding
pending_terminator.store(true);
match AudioData::new(frame.unchecked_ref()) {
Ok(data) => {
let _ = audio_encoder.encode(&data);
}
Err(err) => {
error!(
"error creating AudioData object {:?} during event {:?}",
err, event,
);
}
}
}
}
match AudioData::new(frame.unchecked_ref()) {
Ok(data) => {
let _ = audio_encoder.encode(&data);
}
Err(err) => {
error!(
"error creating AudioData object {:?} during event {:?}",
err, event,
);
}
}
});