diff options
author | David Barksdale <amatus@amatus.name> | 2013-09-30 21:33:49 -0500 |
---|---|---|
committer | David Barksdale <amatus@amatus.name> | 2013-09-30 21:33:49 -0500 |
commit | 692a845e55fc7c07ef3681525885a07a2c3fc749 (patch) | |
tree | abc39514efbcd636616c76fed15363ac67067f5c | |
parent | 0e7aecc0fba231f4efc4f16e71f8d1b3952660ff (diff) |
Added output MP3 file writing.
-rw-r--r-- | mp3lame.rs | 14 | ||||
-rw-r--r-- | per.rs | 18 |
2 files changed, 27 insertions, 5 deletions
@@ -118,6 +118,20 @@ impl LameContext { mp3buf } } + #[fixed_stack_segment] + pub fn encode_flush_nogap(&self) -> ~[u8] { + unsafe { + let mut mp3buf: ~[u8] = vec::with_capacity(7200); + let length = lame_encode_flush_nogap(self.gfp, + vec::raw::to_mut_ptr(mp3buf) as *c_uchar, + 7200); + if length < 0 { + return ~[]; + } + vec::raw::set_len(&mut mp3buf, length as uint); + mp3buf + } + } } impl Drop for LameContext { @@ -3,11 +3,12 @@ use extra::getopts::*; use extra::time::*; use std::os; use std::path::Path; -use std::rt::io::io_error; +use std::rt::io::{Create, io_error, Open, Write, Writer}; +use std::rt::io::file::open; use std::task::{SingleThreaded, spawn_sched}; -use oss::*; -use mp3lame::*; +use oss::OssDevice; +use mp3lame::LameContext; mod oss; mod mp3lame; @@ -59,7 +60,7 @@ fn main() { }; let mut speed: int = 0; for dsp_speed in dsp_speeds.iter() { - do io_error::cond.trap(|_| {debug!("speed %d is a no go", *dsp_speed); speed = 0}).inside { + do io_error::cond.trap(|_| {speed = 0}).inside { dsp.set_speed(*dsp_speed); speed = *dsp_speed; } @@ -84,13 +85,19 @@ fn main() { } else { get_time() }; + let mut out_file = open(&Path("/dev/null"), Open, Write).unwrap(); let (port, chan) = stream::<~[u8]>(); do spawn_sched(SingleThreaded) { dsp.read_all(&chan); } loop { - if next_split <= get_time() { + let now = get_time(); + if next_split <= now { debug!("split!"); + out_file.write(lame.encode_flush_nogap()); + out_file.flush(); + out_file = open(&Path(at(now).rfc3339() + ".mp3"), Create, Write) + .unwrap(); let Timespec { sec, nsec } = next_split; next_split = Timespec::new(sec + split as i64, nsec); } @@ -98,5 +105,6 @@ fn main() { debug!("Read buffer of length %u", buffer.len()); let mp3buf = lame.encode_buffer_interleaved(buffer); debug!("Encoded buffer of length %u", mp3buf.len()); + out_file.write(mp3buf); } } |