summaryrefslogtreecommitdiff
path: root/mp3lame.rs
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2013-09-28 17:16:27 -0500
committerDavid Barksdale <amatus@amatus.name>2013-09-28 17:16:27 -0500
commit2ba887beb5493f580c491934d8690677f13a71fb (patch)
treee9d65fa9bf6261fbb08aec905b2f0296787822a0 /mp3lame.rs
parent60fbeeae8f13256504dc0a0bde4237e81af20cbd (diff)
Do the mp3 encoding.
Diffstat (limited to 'mp3lame.rs')
-rw-r--r--mp3lame.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/mp3lame.rs b/mp3lame.rs
index 627a50f..d26b667 100644
--- a/mp3lame.rs
+++ b/mp3lame.rs
@@ -1,4 +1,5 @@
use std::libc::{c_float, c_int, c_short, c_uchar, c_ulong, c_void};
+use std::vec;
type GlobalFlags_ = *c_void;
@@ -92,6 +93,27 @@ impl LameContext {
pub fn init_params(&self) {
unsafe { lame_init_params(self.gfp) };
}
+ #[fixed_stack_segment]
+ pub fn encode_buffer_interleaved(&self, pcm: &[u8]) -> ~[u8] {
+ if pcm.len() % 4 != 0 {
+ return ~[];
+ }
+ let num_samples = pcm.len() / 4;
+ let mp3buf_size = (1.25 * num_samples as float + 7200.0) as uint;
+ unsafe {
+ let mut mp3buf: ~[u8] = vec::with_capacity(mp3buf_size);
+ let length = lame_encode_buffer_interleaved(self.gfp,
+ vec::raw::to_ptr(pcm) as *c_short,
+ num_samples as c_int,
+ vec::raw::to_mut_ptr(mp3buf) as *c_uchar,
+ mp3buf_size as c_int);
+ if length < 0 {
+ return ~[];
+ }
+ vec::raw::set_len(&mut mp3buf, length as uint);
+ mp3buf
+ }
+ }
}
impl Drop for LameContext {