trx/src/tx/main.rs
2022-08-21 06:33:48 -05:00

40 lines
1 KiB
Rust

use tokio::io::{self, AsyncReadExt,AsyncWriteExt};
use tokio::net::TcpListener;
use alsa::pcm;
use std::str;
#[tokio::main]
async fn main() -> io::Result<()> {
let listener: TcpListener = TcpListener::bind("127.0.0.1:8080").await?;
/*SupportedStreamConfig {
channels: 1,
sample_rate: SampleRate(384000),
buffer_size: Range { min: 3, max: 4194304 },
sample_format: I16 }
THIS IS NOT ENTIRELY CORRECT
*/
//init device config
/* let device_config = Spec {
format: Format::S16NE,
channels: 2,
rate: 44100,
}; */
//temp bc buffer size will be set in cpal
let mut buffer = [0u8; 1024];
let mut pcm = pcm::PCM::open(&"defaukt",pcm::Stream::Capture, false).unwrap();
loop {
let (mut socket, addr) = listener.accept().await?;
pcm.read(&mut buffer).unwrap();
let msg = socket.read(&mut buffer[..]).await?;
println!("{}: {:?}",addr,str::from_utf8(&buffer[..msg]));
socket.write_all(&buffer[..msg]).await?;
}
}