From 60fbeeae8f13256504dc0a0bde4237e81af20cbd Mon Sep 17 00:00:00 2001 From: David Barksdale Date: Sat, 28 Sep 2013 15:23:14 -0500 Subject: Initializing lame parameters. --- mp3lame.rs | 28 ++++++++++++++++++++++++++++ per.rs | 11 ++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/mp3lame.rs b/mp3lame.rs index eb7d572..627a50f 100644 --- a/mp3lame.rs +++ b/mp3lame.rs @@ -64,6 +64,34 @@ impl LameContext { pub fn new() -> LameContext { LameContext { gfp: unsafe { lame_init() }} } + #[fixed_stack_segment] + pub fn set_in_samplerate(&self, rate: int) { + unsafe { lame_set_in_samplerate(self.gfp, rate as c_int) }; + } + #[fixed_stack_segment] + pub fn set_out_samplerate(&self, rate: int) { + unsafe { lame_set_out_samplerate(self.gfp, rate as c_int) }; + } + #[fixed_stack_segment] + pub fn set_num_channels(&self, channels: int) { + unsafe { lame_set_num_channels(self.gfp, channels as c_int) }; + } + #[fixed_stack_segment] + pub fn set_quality(&self, quality: int) { + unsafe { lame_set_quality(self.gfp, quality as c_int) }; + } + #[fixed_stack_segment] + pub fn set_bitrate(&self, rate: int) { + unsafe { lame_set_brate(self.gfp, rate as c_int) }; + } + #[fixed_stack_segment] + pub fn set_disable_reservoir(&self, disable: bool) { + unsafe { lame_set_disable_reservoir(self.gfp, disable as c_int) }; + } + #[fixed_stack_segment] + pub fn init_params(&self) { + unsafe { lame_init_params(self.gfp) }; + } } impl Drop for LameContext { diff --git a/per.rs b/per.rs index 6435978..1caf622 100644 --- a/per.rs +++ b/per.rs @@ -3,16 +3,16 @@ use std::rt::io::io_error; use std::task::{SingleThreaded, spawn_sched}; use oss::*; -//use mp3lame::*; +use mp3lame::*; mod oss; -//mod mp3lame; +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 ctx = LameContext::new(); + let lame = LameContext::new(); let mut foo = None; for file_name in DSP_FILES.iter() { match OssDevice::new(&Path(file_name.as_slice())) { @@ -27,6 +27,7 @@ fn main() { dsp.reset(); dsp.set_format(); dsp.set_stereo(); + lame.set_num_channels(2); let mut speed: int = 0; for dsp_speed in DSP_SPEEDS.iter() { do io_error::cond.trap(|_| {speed = 0}).inside { @@ -37,7 +38,11 @@ fn main() { break; } } + 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); let (port, chan) = stream::<~[u8]>(); do spawn_sched(SingleThreaded) { dsp.read_all(&chan); -- cgit v1.2.3-18-g5258