was missing a few things
This commit is contained in:
parent
6b059d0992
commit
fd5a815896
|
@ -1,8 +1,12 @@
|
|||
use tokio::io::{self, AsyncReadExt,AsyncWriteExt};
|
||||
use tokio::net::TcpListener;
|
||||
use alsa::pcm;
|
||||
use std::str;
|
||||
|
||||
use alsa::{Direction, ValueOr};
|
||||
use alsa::pcm::{PCM, HwParams, Format, Access, State,};
|
||||
|
||||
use std::str;
|
||||
use std::ffi::CStr;
|
||||
use std::io::Read;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
|
@ -22,14 +26,31 @@ async fn main() -> io::Result<()> {
|
|||
}; */
|
||||
//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();
|
||||
|
||||
|
||||
|
||||
// Open default playback device
|
||||
let pcm = PCM::new("default", Direction::Playback, false).unwrap();
|
||||
|
||||
// Set hardware parameters: 44100 Hz / Mono / 16 bit
|
||||
let hwp = HwParams::any(&pcm).unwrap();
|
||||
hwp.set_channels(1).unwrap();
|
||||
hwp.set_rate(44100, ValueOr::Nearest).unwrap();
|
||||
hwp.set_format(Format::s16()).unwrap();
|
||||
hwp.set_access(Access::RWInterleaved).unwrap();
|
||||
pcm.hw_params(&hwp).unwrap();
|
||||
let mut io = pcm.io_i16().unwrap();
|
||||
|
||||
// Make sure we don't start the stream too early
|
||||
let hwp = pcm.hw_params_current().unwrap();
|
||||
let swp = pcm.sw_params_current().unwrap();
|
||||
swp.set_start_threshold(hwp.get_buffer_size().unwrap()).unwrap();
|
||||
pcm.sw_params(&swp).unwrap();
|
||||
|
||||
|
||||
|
||||
loop {
|
||||
let (mut socket, addr) = listener.accept().await?;
|
||||
pcm.read(&mut buffer).unwrap();
|
||||
io.read(&mut buffer).unwrap();
|
||||
let msg = socket.read(&mut buffer[..]).await?;
|
||||
println!("{}: {:?}",addr,str::from_utf8(&buffer[..msg]));
|
||||
socket.write_all(&buffer[..msg]).await?;
|
||||
|
|
Loading…
Reference in a new issue