mirror of
https://github.com/mii443/maudio-router.git
synced 2025-08-22 16:05:35 +00:00
wip
This commit is contained in:
18
local_test.yaml
Normal file
18
local_test.yaml
Normal file
@ -0,0 +1,18 @@
|
||||
virtual_devices:
|
||||
- name: "mic"
|
||||
channels: 2
|
||||
sample_rate: 96000
|
||||
routes:
|
||||
input:
|
||||
- name: "Mic"
|
||||
virtual_device: "mic"
|
||||
device:
|
||||
local:
|
||||
name: "VoiceMeeter Output (VB-Audio VoiceMeeter VAIO)"
|
||||
output:
|
||||
- name: "Speaker"
|
||||
input:
|
||||
virtual_device: "mic"
|
||||
device:
|
||||
local:
|
||||
name: "VoiceMeeter Input (VB-Audio VoiceMeeter VAIO)"
|
@ -1,5 +1,7 @@
|
||||
use std::io::Read;
|
||||
|
||||
use cpal::{traits::{DeviceTrait, HostTrait}, Device};
|
||||
|
||||
use crate::args::Run;
|
||||
|
||||
pub fn run(run: Run) {
|
||||
@ -22,5 +24,76 @@ pub fn run(run: Run) {
|
||||
|
||||
let config: crate::config::Config = serde_yaml::from_str(&buf).unwrap();
|
||||
|
||||
println!("{:?}", config);
|
||||
let host = cpal::default_host();
|
||||
let input_devices: Vec<Device> = host.input_devices().unwrap().collect();
|
||||
let output_devices: Vec<Device> = host.output_devices().unwrap().collect();
|
||||
|
||||
// create virtual devices
|
||||
let mut virtual_devices = Vec::new();
|
||||
for virtual_device in config.virtual_devices {
|
||||
let device = crate::device::virtual_device::VirtualDevice::new(virtual_device.name, virtual_device.channels, virtual_device.sample_rate);
|
||||
virtual_devices.push(device);
|
||||
}
|
||||
|
||||
for input_route in config.routes.input {
|
||||
println!("Input: {}", input_route.name);
|
||||
println!(" Virtual device: {}", input_route.virtual_device);
|
||||
if virtual_devices.iter().any(|device| device.name == input_route.virtual_device) {
|
||||
println!(" Found");
|
||||
} else {
|
||||
println!(" Not found");
|
||||
}
|
||||
|
||||
match input_route.device {
|
||||
crate::config::Device::Local { local } => {
|
||||
println!(" Local device: {}", local.name);
|
||||
if input_devices
|
||||
.iter()
|
||||
.any(|device| device.name().unwrap() == local.name)
|
||||
{
|
||||
println!(" Found");
|
||||
} else {
|
||||
println!(" Not found");
|
||||
}
|
||||
}
|
||||
crate::config::Device::Remote { remote } => {
|
||||
println!(" Remote device: {}", remote.address);
|
||||
println!(" Port: {}", remote.port);
|
||||
println!(" Protocol: {}", remote.protocol);
|
||||
println!(" Buffer: {}", remote.buffer);
|
||||
println!(" Channels: {}", remote.channels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for output_route in config.routes.output {
|
||||
println!("Output: {}", output_route.name);
|
||||
println!(" Virtual device: {}", output_route.input.virtual_device);
|
||||
if virtual_devices.iter().any(|device| device.name == output_route.input.virtual_device) {
|
||||
println!(" Found");
|
||||
} else {
|
||||
println!(" Not found");
|
||||
}
|
||||
|
||||
match output_route.device {
|
||||
crate::config::Device::Local { local } => {
|
||||
println!(" Local device: {}", local.name);
|
||||
if output_devices
|
||||
.iter()
|
||||
.any(|device| device.name().unwrap() == local.name)
|
||||
{
|
||||
println!(" Found");
|
||||
} else {
|
||||
println!(" Not found");
|
||||
}
|
||||
}
|
||||
crate::config::Device::Remote { remote } => {
|
||||
println!(" Remote device: {}", remote.address);
|
||||
println!(" Port: {}", remote.port);
|
||||
println!(" Protocol: {}", remote.protocol);
|
||||
println!(" Buffer: {}", remote.buffer);
|
||||
println!(" Channels: {}", remote.channels);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,17 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub virtual_devices: Vec<VirtualDevice>,
|
||||
pub routes: Routes,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct VirtualDevice {
|
||||
pub name: String,
|
||||
pub channels: u8,
|
||||
pub sample_rate: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Routes {
|
||||
pub input: Vec<Input>,
|
||||
|
@ -1,8 +1,5 @@
|
||||
pub struct VirtualDevice {
|
||||
pub name: String,
|
||||
pub id: String,
|
||||
pub is_input: bool,
|
||||
pub is_output: bool,
|
||||
pub channels: u8,
|
||||
pub sample_rate: u32,
|
||||
output_index: Vec<usize>,
|
||||
@ -10,12 +7,9 @@ pub struct VirtualDevice {
|
||||
}
|
||||
|
||||
impl VirtualDevice {
|
||||
pub fn new(name: String, id: String, is_input: bool, is_output: bool, channels: u8, sample_rate: u32) -> Self {
|
||||
pub fn new(name: String, channels: u8, sample_rate: u32) -> Self {
|
||||
VirtualDevice {
|
||||
name,
|
||||
id,
|
||||
is_input,
|
||||
is_output,
|
||||
channels,
|
||||
sample_rate,
|
||||
output_index: Vec::new(),
|
||||
|
Reference in New Issue
Block a user