feat: remote mixer part 4

This commit is contained in:
Ahmet Kaan Gümüş 2025-05-20 05:44:00 +03:00
parent 50917c09d5
commit 35ebb58698
6 changed files with 64 additions and 145 deletions

View file

@ -8,7 +8,7 @@ use iced::{
Element, Task, Theme,
widget::{button, column, row},
};
use protocol::{BUFFER_LENGTH, Error};
use protocol::Error;
use tokio::{
sync::{
broadcast::{self},
@ -17,7 +17,7 @@ use tokio::{
time::sleep,
};
use crate::{ClientConfig, stream::connect, voice::record};
use crate::{ClientConfig, MICROPHONE_BUFFER_LENGHT, stream::connect, voice::record};
#[derive(Debug, Default)]
struct Signal {
@ -59,7 +59,7 @@ struct Channel {
impl Channel {
fn new() -> Self {
Self {
microphone: broadcast::channel(BUFFER_LENGTH).0.into(),
microphone: broadcast::channel(MICROPHONE_BUFFER_LENGHT / 4).0.into(),
// speaker: broadcast::channel(BUFFER_LENGTH),
}
}

View file

@ -2,6 +2,9 @@ pub mod gui;
pub mod stream;
pub mod voice;
const MICROPHONE_BUFFER_LENGHT: usize = 1024 * 16;
const SPEAKER_BUFFER_LENGHT: usize = 1024 * 16 * 4;
#[derive(Debug)]
pub struct ClientConfig {
certificate_path: String,

View file

@ -1,6 +1,6 @@
use std::{net::SocketAddr, path::Path, sync::Arc};
use protocol::{BUFFER_LENGTH, Error};
use protocol::Error;
use s2n_quic::{
Client,
client::Connect,
@ -11,7 +11,7 @@ use tokio::{
sync::{broadcast, oneshot},
};
use crate::{ClientConfig, voice::play};
use crate::{ClientConfig, SPEAKER_BUFFER_LENGHT, voice::play};
pub async fn connect(
connection_stop_signal_receiver: oneshot::Receiver<bool>,
@ -51,7 +51,7 @@ pub async fn connect(
.await
.map_err(|err_val| Error::ConnectionSetup(err_val.to_string()))?;
let (receive_stream, send_stream) = stream.split();
let (speaker_sender, speaker_receiver) = broadcast::channel(BUFFER_LENGTH);
let (speaker_sender, speaker_receiver) = broadcast::channel(SPEAKER_BUFFER_LENGHT);
let (speaker_stop_signal_sender, speaker_stop_signal_receiver) = oneshot::channel();
tokio::spawn(play(speaker_receiver, speaker_stop_signal_receiver));
let receive_voice_data_task = tokio::spawn(receive_audio_data(receive_stream, speaker_sender));

View file

@ -11,6 +11,7 @@ pub async fn record(
let host = cpal::default_host();
let input_device = host.default_input_device().unwrap();
let config = input_device.default_input_config().unwrap().into();
println!("Recorder Stream Config = {:#?}", config);
let input = move |data: &[f32], _: &cpal::InputCallbackInfo| {
for &sample in data {
@ -50,6 +51,7 @@ pub async fn play(
let host = cpal::default_host();
let output_device = host.default_output_device().unwrap();
let config = output_device.default_output_config().unwrap().into();
println!("Speaker Stream Config = {:#?}", config);
let output = move |data: &mut [f32], _: &cpal::OutputCallbackInfo| {
for sample in data {