blob: 472c161bc2e7af72ae256f4afc651a7a81ada626 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
use cpal::{InputCallbackInfo, Sample};
use tokio::sync::watch;
use log::*;
pub fn callback<T: Sample>(
mut input_sender: futures_channel::mpsc::Sender<f32>,
input_volume_receiver: watch::Receiver<f32>,
) -> impl FnMut(&[T], &InputCallbackInfo) + Send + 'static {
move |data: &[T], _info: &InputCallbackInfo| {
let input_volume = *input_volume_receiver.borrow();
for sample in data
.iter()
.map(|e| e.to_f32())
.map(|e| e * input_volume) {
if let Err(_e) = input_sender.try_send(sample) {
warn!("Error sending audio: {}", _e);
}
}
}
}
|