summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2013-09-29 15:45:18 -0500
committerDavid Barksdale <amatus@amatus.name>2013-09-29 15:45:18 -0500
commita211e8a0d53f02539518cf33cddbcf88a8585efe (patch)
tree082d1baf16ab22c138214f01bb8c2f427a3df7b8
parent2ba887beb5493f580c491934d8690677f13a71fb (diff)
Added command line arguments.
-rw-r--r--mp3lame.rs4
-rw-r--r--per.rs42
2 files changed, 39 insertions, 7 deletions
diff --git a/mp3lame.rs b/mp3lame.rs
index d26b667..1cfb0c6 100644
--- a/mp3lame.rs
+++ b/mp3lame.rs
@@ -74,6 +74,10 @@ impl LameContext {
unsafe { lame_set_out_samplerate(self.gfp, rate as c_int) };
}
#[fixed_stack_segment]
+ pub fn get_out_samplerate(&self) -> int {
+ unsafe { lame_get_out_samplerate(self.gfp) as int }
+ }
+ #[fixed_stack_segment]
pub fn set_num_channels(&self, channels: int) {
unsafe { lame_set_num_channels(self.gfp, channels as c_int) };
}
diff --git a/per.rs b/per.rs
index 1cb38e9..3b15eda 100644
--- a/per.rs
+++ b/per.rs
@@ -1,3 +1,6 @@
+extern mod extra;
+use extra::getopts::*;
+use std::os;
use std::path::Path;
use std::rt::io::io_error;
use std::task::{SingleThreaded, spawn_sched};
@@ -7,14 +10,35 @@ use mp3lame::*;
mod oss;
mod mp3lame;
-static DSP_FILES: &'static [&'static str] = &["/dev/dsp", "/dev/dsp1"];
-static DSP_SPEEDS: [int, ..2] = [44100i, 48000i];
#[fixed_stack_segment]
fn main() {
+ let args = os::args();
+ let opts = ~[
+ groups::optmulti("f", "file", "OSS device file", "/dev/dsp"),
+ groups::optmulti("r", "rate", "Sample rate in Hz", "44100"),
+ groups::optopt("s", "split",
+ "Number of minutes at which to split MP3 files", "60"),
+ groups::optflag("a",
+ "Align splits as if the first one happened midnight Jan. 1, 1970", "")
+ ];
+ let DSP_FILES = ~[~"/dev/dsp", ~"/dev/dsp1"];
+ let DSP_SPEEDS = ~[44100i, 48000i];
+ let matches = match groups::getopts(args.tail(), opts) {
+ Ok(m) => m,
+ Err(f) => {
+ println(f.to_err_msg());
+ print(groups::usage("Usage: per", opts));
+ return;
+ }
+ };
+ let dsp_files = match matches.opt_strs("f") {
+ [] => DSP_FILES,
+ f => f
+ };
let lame = LameContext::new();
let mut foo = None;
- for file_name in DSP_FILES.iter() {
+ for file_name in dsp_files.iter() {
match OssDevice::new(&Path(file_name.as_slice())) {
Some(x) => { foo = Some(x); break }
None => {}
@@ -28,9 +52,13 @@ fn main() {
dsp.set_format();
dsp.set_stereo();
lame.set_num_channels(2);
+ let dsp_speeds = match matches.opt_strs("r") {
+ [] => DSP_SPEEDS,
+ r => r.map(|x| { from_str::<int>(*x).unwrap() })
+ };
let mut speed: int = 0;
- for dsp_speed in DSP_SPEEDS.iter() {
- do io_error::cond.trap(|_| {speed = 0}).inside {
+ for dsp_speed in dsp_speeds.iter() {
+ do io_error::cond.trap(|_| {debug!("speed %d is a no go", *dsp_speed); speed = 0}).inside {
dsp.set_speed(*dsp_speed);
speed = *dsp_speed;
}
@@ -39,12 +67,12 @@ fn main() {
}
}
lame.set_in_samplerate(speed);
- lame.set_out_samplerate(speed);
- println(fmt!("Sample rate: %d Hz", speed));
lame.set_quality(2);
lame.set_bitrate(128);
lame.set_disable_reservoir(true);
lame.init_params();
+ println(fmt!("Recording sample rate: %d Hz", speed));
+ println(fmt!("Encoding sample rate: %d Hz", lame.get_out_samplerate()));
let (port, chan) = stream::<~[u8]>();
do spawn_sched(SingleThreaded) {
dsp.read_all(&chan);