blob: 517c9ce3994141ae8b774b57f2f37b4bb999d300 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
use cpal::{InputCallbackInfo, Sample};
use std::collections::VecDeque;
use std::sync::{Arc, Mutex};
use tokio::sync::watch;
use futures::Stream;
use std::pin::Pin;
use std::task::{Context, Poll};
use futures_util::task::Waker;
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)
}
}
}
}
|