propagate volume threshold
This commit is contained in:
parent
2fb5a5709f
commit
e352c5b048
4 changed files with 20 additions and 11 deletions
7
interface/Cargo.lock
generated
7
interface/Cargo.lock
generated
|
@ -434,6 +434,12 @@ version = "1.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "atomic_float"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "628d228f918ac3b82fe590352cc719d30664a0c13ca3a60266fe02c7132d480a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atspi"
|
name = "atspi"
|
||||||
version = "0.22.0"
|
version = "0.22.0"
|
||||||
|
@ -1883,6 +1889,7 @@ name = "interface"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"atomic_float",
|
||||||
"common",
|
"common",
|
||||||
"cpal",
|
"cpal",
|
||||||
"eframe",
|
"eframe",
|
||||||
|
|
|
@ -18,3 +18,4 @@ eframe = { version = "0.30", features = ["persistence"] }
|
||||||
egui_extras = { version = "0.30", features = ["default", "image"] }
|
egui_extras = { version = "0.30", features = ["default", "image"] }
|
||||||
egui-toast = "0.16.0"
|
egui-toast = "0.16.0"
|
||||||
home = "0.5.11"
|
home = "0.5.11"
|
||||||
|
atomic_float = "1.1.0"
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
|
|
||||||
use std::{cell::OnceCell, path::PathBuf, time::Duration};
|
use std::{cell::OnceCell, path::PathBuf, sync::atomic::Ordering, time::Duration};
|
||||||
|
|
||||||
use common::{ControlPacket, TelemetryPacket};
|
use common::{ControlPacket, TelemetryPacket};
|
||||||
use eframe::{egui::{self, containers, Align2, Checkbox, Context, Id, Label}, Storage};
|
use eframe::{egui::{self, containers, Align2, Checkbox, Context, Id, Label}, Storage};
|
||||||
use tokio::{runtime::Runtime, sync::{mpsc, watch::Receiver}};
|
use tokio::{runtime::Runtime, sync::{mpsc, watch::Receiver}};
|
||||||
use egui_toast::{Toast, Toasts};
|
use egui_toast::{Toast, Toasts};
|
||||||
|
|
||||||
use crate::storage_dir::storage_dir;
|
use crate::{storage_dir::storage_dir, POWER_THRESHOLD};
|
||||||
|
|
||||||
pub const GUI: OnceCell<Context> = OnceCell::new();
|
pub const GUI: OnceCell<Context> = OnceCell::new();
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ pub struct GUIData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
const DEFAULT_VOLUME_THRESHOLD: f32 = 5.0;
|
pub const DEFAULT_VOLUME_THRESHOLD: f32 = 5.0;
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
const DEFAULT_VOLUME_THRESHOLD: f32 = 1.0;
|
pub const DEFAULT_VOLUME_THRESHOLD: f32 = 1.0;
|
||||||
const DEFAULT_TURN_GAIN: f32 = 0.3;
|
const DEFAULT_TURN_GAIN: f32 = 0.3;
|
||||||
const DEFAULT_FIRE_DISTANCE: f32 = 55.0;
|
const DEFAULT_FIRE_DISTANCE: f32 = 55.0;
|
||||||
|
|
||||||
|
@ -96,6 +96,8 @@ impl eframe::App for GUI {
|
||||||
storage.set_string("auto_turn_gain", format!("{}",self.auto_turn_gain));
|
storage.set_string("auto_turn_gain", format!("{}",self.auto_turn_gain));
|
||||||
storage.set_string("auto_fire_distance", format!("{}",self.auto_fire_distance));
|
storage.set_string("auto_fire_distance", format!("{}",self.auto_fire_distance));
|
||||||
storage.set_string("selected_auto", format!("{}",self.selected_auto));
|
storage.set_string("selected_auto", format!("{}",self.selected_auto));
|
||||||
|
|
||||||
|
POWER_THRESHOLD.store(self.volume_threshold, Ordering::Relaxed);
|
||||||
});
|
});
|
||||||
|
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#![feature(iter_collect_into)]
|
#![feature(iter_collect_into)]
|
||||||
use std::{fmt::format, ops::ControlFlow, result, sync::Arc, thread::{self, sleep}, time::Duration};
|
use std::{fmt::format, ops::ControlFlow, result, sync::{atomic::Ordering, Arc}, thread::{self, sleep}, time::Duration};
|
||||||
|
|
||||||
use anyhow::{Context, Ok, Result};
|
use anyhow::{Context, Ok, Result};
|
||||||
|
use atomic_float::AtomicF32;
|
||||||
use common::{ControlPacket, TelemetryPacket};
|
use common::{ControlPacket, TelemetryPacket};
|
||||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||||
use egui_toast::{Toast, ToastKind};
|
use egui_toast::{Toast, ToastKind};
|
||||||
use gui::{gui, GUIData, GUI};
|
use gui::{gui, GUIData, DEFAULT_VOLUME_THRESHOLD, GUI};
|
||||||
use pitch_detection::{detector::{mcleod::McLeodDetector, PitchDetector}, utils};
|
use pitch_detection::{detector::{mcleod::McLeodDetector, PitchDetector}, utils};
|
||||||
use rust_music_theory::note::{Note, NoteLetter, Pitch, Tuning};
|
use rust_music_theory::note::{Note, NoteLetter, Pitch, Tuning};
|
||||||
use tokio::{io::{AsyncReadExt, AsyncWriteExt, BufWriter, WriteHalf}, net::{tcp::{OwnedReadHalf, OwnedWriteHalf}, TcpStream}, spawn, sync::{self, broadcast, mpsc, watch, RwLock}, time::timeout};
|
use tokio::{io::{AsyncReadExt, AsyncWriteExt, BufWriter, WriteHalf}, net::{tcp::{OwnedReadHalf, OwnedWriteHalf}, TcpStream}, spawn, sync::{self, broadcast, mpsc, watch, RwLock}, time::timeout};
|
||||||
|
@ -13,6 +14,8 @@ use tokio::{io::{AsyncReadExt, AsyncWriteExt, BufWriter, WriteHalf}, net::{tcp::
|
||||||
mod gui;
|
mod gui;
|
||||||
mod storage_dir;
|
mod storage_dir;
|
||||||
|
|
||||||
|
pub const POWER_THRESHOLD: AtomicF32 = AtomicF32::new(DEFAULT_VOLUME_THRESHOLD);
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
// assumes pulseaudio system with f32 samples and 2204 sample packets
|
// assumes pulseaudio system with f32 samples and 2204 sample packets
|
||||||
dbg!(cpal::available_hosts());
|
dbg!(cpal::available_hosts());
|
||||||
|
@ -32,10 +35,6 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
let (sender, notes) = broadcast::channel(2);
|
let (sender, notes) = broadcast::channel(2);
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
const POWER_THRESHOLD: f32 = 5.0;
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
const POWER_THRESHOLD: f32 = 1.0;
|
|
||||||
const CLARITY_THRESHOLD: f32 = 0.85;
|
const CLARITY_THRESHOLD: f32 = 0.85;
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
const PACKET_LEN: usize = 2204;
|
const PACKET_LEN: usize = 2204;
|
||||||
|
@ -66,7 +65,7 @@ fn main() -> Result<()> {
|
||||||
// reinitialized every packet as it is not thread safe
|
// reinitialized every packet as it is not thread safe
|
||||||
let mut detctor = McLeodDetector::new(PACKET_LEN, PACKET_LEN/2);
|
let mut detctor = McLeodDetector::new(PACKET_LEN, PACKET_LEN/2);
|
||||||
let vol = utils::buffer::square_sum(data);
|
let vol = utils::buffer::square_sum(data);
|
||||||
if let Err(e) = sender.send((detctor.get_pitch(data, rate.0 as usize, POWER_THRESHOLD, CLARITY_THRESHOLD).map(|p|p.frequency),vol)) {
|
if let Err(e) = sender.send((detctor.get_pitch(data, rate.0 as usize, POWER_THRESHOLD.load(Ordering::Relaxed), CLARITY_THRESHOLD).map(|p|p.frequency),vol)) {
|
||||||
println!("channel: {e}");
|
println!("channel: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue