summaryrefslogtreecommitdiff
path: root/per.rs
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2013-09-29 17:02:27 -0500
committerDavid Barksdale <amatus@amatus.name>2013-09-29 17:02:27 -0500
commit0e7aecc0fba231f4efc4f16e71f8d1b3952660ff (patch)
tree1c53f68258b220b689eb812d44f175fac1fbdb0f /per.rs
parenta211e8a0d53f02539518cf33cddbcf88a8585efe (diff)
Added split logic.
Diffstat (limited to 'per.rs')
-rw-r--r--per.rs16
1 files changed, 16 insertions, 0 deletions
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::<int>(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);