diff options
author | David Barksdale <amatus@amatus.name> | 2013-09-28 17:16:27 -0500 |
---|---|---|
committer | David Barksdale <amatus@amatus.name> | 2013-09-28 17:16:27 -0500 |
commit | 2ba887beb5493f580c491934d8690677f13a71fb (patch) | |
tree | e9d65fa9bf6261fbb08aec905b2f0296787822a0 /mp3lame.rs | |
parent | 60fbeeae8f13256504dc0a0bde4237e81af20cbd (diff) |
Do the mp3 encoding.
Diffstat (limited to 'mp3lame.rs')
-rw-r--r-- | mp3lame.rs | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -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 { |