mirror of
https://github.com/mii443/maudio-router.git
synced 2025-08-22 16:05:35 +00:00
Refactor input_callback function and remove unused code
This commit is contained in:
@ -1,5 +1,4 @@
|
|||||||
use num::Complex;
|
use num::Complex;
|
||||||
use rubato::{FastFixedIn, PolynomialDegree, Resampler};
|
|
||||||
use rustfft::FftPlanner;
|
use rustfft::FftPlanner;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -153,7 +153,6 @@ pub fn run(run: Run) {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let config = device.default_input_config().unwrap();
|
let config = device.default_input_config().unwrap();
|
||||||
let channels = config.channels();
|
let channels = config.channels();
|
||||||
let sample_rate = config.sample_rate().0;
|
|
||||||
|
|
||||||
let virtual_devices = virtual_devices
|
let virtual_devices = virtual_devices
|
||||||
.iter()
|
.iter()
|
||||||
@ -167,12 +166,7 @@ pub fn run(run: Run) {
|
|||||||
&config.into(),
|
&config.into(),
|
||||||
{
|
{
|
||||||
move |data: &[i8], _| {
|
move |data: &[i8], _| {
|
||||||
input_callback(
|
input_callback(data, channels.into(), virtual_devices.clone())
|
||||||
data,
|
|
||||||
channels.into(),
|
|
||||||
sample_rate,
|
|
||||||
virtual_devices.clone(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
move |err| eprintln!("An error occurred on the input stream: {}", err),
|
move |err| eprintln!("An error occurred on the input stream: {}", err),
|
||||||
@ -182,12 +176,7 @@ pub fn run(run: Run) {
|
|||||||
&config.into(),
|
&config.into(),
|
||||||
{
|
{
|
||||||
move |data: &[i16], _| {
|
move |data: &[i16], _| {
|
||||||
input_callback(
|
input_callback(data, channels.into(), virtual_devices.clone())
|
||||||
data,
|
|
||||||
channels.into(),
|
|
||||||
sample_rate,
|
|
||||||
virtual_devices.clone(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
move |err| eprintln!("An error occurred on the input stream: {}", err),
|
move |err| eprintln!("An error occurred on the input stream: {}", err),
|
||||||
@ -197,12 +186,7 @@ pub fn run(run: Run) {
|
|||||||
&config.into(),
|
&config.into(),
|
||||||
{
|
{
|
||||||
move |data: &[i32], _| {
|
move |data: &[i32], _| {
|
||||||
input_callback(
|
input_callback(data, channels.into(), virtual_devices.clone())
|
||||||
data,
|
|
||||||
channels.into(),
|
|
||||||
sample_rate,
|
|
||||||
virtual_devices.clone(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
move |err| eprintln!("An error occurred on the input stream: {}", err),
|
move |err| eprintln!("An error occurred on the input stream: {}", err),
|
||||||
@ -212,12 +196,7 @@ pub fn run(run: Run) {
|
|||||||
&config.into(),
|
&config.into(),
|
||||||
{
|
{
|
||||||
move |data: &[f32], _| {
|
move |data: &[f32], _| {
|
||||||
input_callback(
|
input_callback(data, channels.into(), virtual_devices.clone())
|
||||||
data,
|
|
||||||
channels.into(),
|
|
||||||
sample_rate,
|
|
||||||
virtual_devices.clone(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
move |err| eprintln!("An error occurred on the input stream: {}", err),
|
move |err| eprintln!("An error occurred on the input stream: {}", err),
|
||||||
@ -250,8 +229,6 @@ pub fn run(run: Run) {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let config = device.default_output_config().unwrap();
|
let config = device.default_output_config().unwrap();
|
||||||
|
|
||||||
let sample_rate = config.sample_rate().0;
|
|
||||||
|
|
||||||
let virtual_device = virtual_devices
|
let virtual_device = virtual_devices
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|device| {
|
.filter(|device| {
|
||||||
@ -370,12 +347,8 @@ fn create_virtual_device_input_stream(
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn input_callback<T>(
|
fn input_callback<T>(data: &[T], channels: usize, virtual_device: Arc<Mutex<VirtualDevice>>)
|
||||||
data: &[T],
|
where
|
||||||
channels: usize,
|
|
||||||
sample_rate: u32,
|
|
||||||
virtual_device: Arc<Mutex<VirtualDevice>>,
|
|
||||||
) where
|
|
||||||
T: Clone + num::cast::ToPrimitive,
|
T: Clone + num::cast::ToPrimitive,
|
||||||
{
|
{
|
||||||
let data: Vec<f32> = data.iter().map(|d| d.to_f32().unwrap()).collect();
|
let data: Vec<f32> = data.iter().map(|d| d.to_f32().unwrap()).collect();
|
||||||
|
@ -9,7 +9,6 @@ pub struct VirtualDevice {
|
|||||||
|
|
||||||
output_index: HashMap<u32, Vec<usize>>,
|
output_index: HashMap<u32, Vec<usize>>,
|
||||||
output_buffer: HashMap<u32, Vec<Vec<f32>>>,
|
output_buffer: HashMap<u32, Vec<Vec<f32>>>,
|
||||||
simple_buffer: Vec<Vec<f32>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualDevice {
|
impl VirtualDevice {
|
||||||
@ -20,7 +19,6 @@ impl VirtualDevice {
|
|||||||
sample_rate,
|
sample_rate,
|
||||||
output_index: HashMap::new(),
|
output_index: HashMap::new(),
|
||||||
output_buffer: HashMap::new(),
|
output_buffer: HashMap::new(),
|
||||||
simple_buffer: vec![vec![]; channels as usize],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user