From 0e7aecc0fba231f4efc4f16e71f8d1b3952660ff Mon Sep 17 00:00:00 2001 From: David Barksdale Date: Sun, 29 Sep 2013 17:02:27 -0500 Subject: Added split logic. --- per.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'per.rs') diff --git a/per.rs b/per.rs index 3b15eda..f4f2a1e 100644 --- a/per.rs +++ b/per.rs @@ -1,5 +1,6 @@ extern mod extra; use extra::getopts::*; +use extra::time::*; use std::os; use std::path::Path; use std::rt::io::io_error; @@ -73,11 +74,26 @@ fn main() { lame.init_params(); println(fmt!("Recording sample rate: %d Hz", speed)); println(fmt!("Encoding sample rate: %d Hz", lame.get_out_samplerate())); + let split = match matches.opt_str("s") { + Some(s) => from_str::(s).unwrap() * 60, + None => 3600 + }; + let mut next_split = if matches.opt_present("a") { + let Timespec { sec, _ } = get_time(); + Timespec::new(sec - sec % split as i64, 0) + } else { + get_time() + }; let (port, chan) = stream::<~[u8]>(); do spawn_sched(SingleThreaded) { dsp.read_all(&chan); } loop { + if next_split <= get_time() { + debug!("split!"); + let Timespec { sec, nsec } = next_split; + next_split = Timespec::new(sec + split as i64, nsec); + } let buffer = port.recv(); debug!("Read buffer of length %u", buffer.len()); let mp3buf = lame.encode_buffer_interleaved(buffer); -- cgit v1.2.3-18-g5258