Some cleanup in outputdefault test prog
This commit is contained in:
parent
52eb0206eb
commit
93c7f71d1c
@ -6,14 +6,15 @@ use std::io;
|
||||
use std::{thread, time};
|
||||
// use
|
||||
|
||||
fn spawn_stdin_channel() -> Receiver<String> {
|
||||
/// Spawns a thread and waits for a single line, pushes it to the receiver and returns
|
||||
fn stdin_channel_wait_for_return() -> Receiver<String> {
|
||||
|
||||
let (tx, rx) = unbounded();
|
||||
thread::spawn(move || 'tt: loop {
|
||||
thread::spawn(move || {
|
||||
let mut buffer = String::new();
|
||||
io::stdin().read_line(&mut buffer).unwrap();
|
||||
if tx.send(buffer).is_err() {
|
||||
break 'tt;
|
||||
}
|
||||
// Do not care whether we succeed here.
|
||||
let _ = tx.send(buffer);
|
||||
});
|
||||
rx
|
||||
}
|
||||
@ -24,42 +25,42 @@ fn sleep(millis: u64) {
|
||||
fn main() -> Result<()> {
|
||||
let mut smgr = StreamMgr::new();
|
||||
|
||||
println!("Starting stream...");
|
||||
smgr.startDefaultOutputStream()?;
|
||||
let stdin_channel = spawn_stdin_channel();
|
||||
let stdin_channel = stdin_channel_wait_for_return();
|
||||
|
||||
println!("Creating signal generator...");
|
||||
let mut siggen = Siggen::newSineWave(2, 100.);
|
||||
siggen.setDCOffset(&[0.1, 0.]);
|
||||
// let mut siggen = Siggen::newWhiteNoise(2);
|
||||
let mut siggen = Siggen::newSineWave(2, 432.);
|
||||
|
||||
// Some things that can be done
|
||||
// siggen.setDCOffset(&[0.1, 0.]);
|
||||
|
||||
// Reduce all gains a bit...
|
||||
siggen.setAllGains(0.1);
|
||||
// siggen.setMute(&[true, true]);
|
||||
// siggen.setMute(&[true, false]);
|
||||
// siggen.setAllMute(false);
|
||||
|
||||
// Apply signal generator
|
||||
smgr.setSiggen(siggen)?;
|
||||
|
||||
println!("Starting stream...");
|
||||
smgr.startDefaultOutputStream()?;
|
||||
|
||||
println!("Press <enter> key to quit...");
|
||||
'infy: loop {
|
||||
match stdin_channel.try_recv() {
|
||||
Ok(_key) => break 'infy,
|
||||
Err(TryRecvError::Empty) => {}
|
||||
Err(TryRecvError::Disconnected) => panic!("Channel disconnected"),
|
||||
}
|
||||
sleep(1000);
|
||||
sleep(100);
|
||||
match smgr.getStatus(StreamType::Output) {
|
||||
StreamStatus::NotRunning => {
|
||||
println!("Stream is not running?");
|
||||
break 'infy;
|
||||
}
|
||||
StreamStatus::Running => {
|
||||
println!("Stream is running...");
|
||||
}
|
||||
StreamStatus::Running => {}
|
||||
StreamStatus::Error(e) => {
|
||||
println!("Stream error: {}", e);
|
||||
break 'infy;
|
||||
}
|
||||
}
|
||||
|
||||
// let stat = smgr.
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user