diff options
author | David Barksdale <amatus@amatus.name> | 2013-09-28 14:44:22 -0500 |
---|---|---|
committer | David Barksdale <amatus@amatus.name> | 2013-09-28 14:44:22 -0500 |
commit | 91f8e289c7ed3df1339848f2de9f07d33b35902a (patch) | |
tree | 572a70d2ce045aef68b6009b7bd278263435a4d6 /mp3lame.rs |
Initial commit now that things are taking shape.
Diffstat (limited to 'mp3lame.rs')
-rw-r--r-- | mp3lame.rs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/mp3lame.rs b/mp3lame.rs new file mode 100644 index 0000000..eb7d572 --- /dev/null +++ b/mp3lame.rs @@ -0,0 +1,74 @@ +use std::libc::{c_float, c_int, c_short, c_uchar, c_ulong, c_void}; + +type GlobalFlags_ = *c_void; + +enum MpegMode { + Stereo = 0, + JointStereo, + DualChannel, + Mono, + NotSet, + MaxIndicator +} + +#[link_args = "-lmp3lame"] + +extern { + fn lame_init() -> GlobalFlags_; + fn lame_set_num_samples(gfp: GlobalFlags_, samples: c_ulong) -> c_int; + fn lame_get_num_samples(gfp: GlobalFlags_) -> c_ulong; + fn lame_set_in_samplerate(gfp: GlobalFlags_, rate: c_int) -> c_int; + fn lame_get_in_samplerate(gfp: GlobalFlags_) -> c_int; + fn lame_set_num_channels(gfp: GlobalFlags_, channels: c_int) -> c_int; + fn lame_get_num_channels(gfp: GlobalFlags_) -> c_int; + fn lame_set_scale(gfp: GlobalFlags_, scale: c_float) -> c_int; + fn lame_get_scale(gfp: GlobalFlags_) -> c_float; + fn lame_set_scale_left(gfp: GlobalFlags_, scale: c_float) -> c_int; + fn lame_get_scale_left(gfp: GlobalFlags_) -> c_float; + fn lame_set_scale_right(gfp: GlobalFlags_, scale: c_float) -> c_int; + fn lame_get_scale_right(gfp: GlobalFlags_) -> c_float; + fn lame_set_out_samplerate(gfp: GlobalFlags_, rate: c_int) -> c_int; + fn lame_get_out_samplerate(gfp: GlobalFlags_) -> c_int; + fn lame_set_analysis(gfp: GlobalFlags_, analysis: c_int) -> c_int; + fn lame_get_analysis(gfp: GlobalFlags_) -> c_int; + fn lame_set_bWriteVbrTag(gfp: GlobalFlags_, write_tag: c_int) -> c_int; + fn lame_get_bWriteVbrTag(gfp: GlobalFlags_) -> c_int; + fn lame_set_decode_only(gfp: GlobalFlags_, decode: c_int) -> c_int; + fn lame_get_decode_only(gfp: GlobalFlags_) -> c_int; + fn lame_set_quality(gfp: GlobalFlags_, quality: c_int) -> c_int; + fn lame_get_quality(gfp: GlobalFlags_) -> c_int; + fn lame_set_mode(gfp: GlobalFlags_, mode: MpegMode) -> c_int; + fn lame_get_mode(gfp: GlobalFlags_) -> MpegMode; + fn lame_set_brate(gfp: GlobalFlags_, rate: c_int) -> c_int; + fn lame_get_brate(gfp: GlobalFlags_) -> c_int; + fn lame_set_disable_reservoir(gfp: GlobalFlags_, disable: c_int) -> c_int; + fn lame_get_disable_reservoir(gfp: GlobalFlags_) -> c_int; + fn lame_init_params(gfp: GlobalFlags_) -> c_int; + fn lame_close(gfp: GlobalFlags_) -> c_int; + fn lame_encode_buffer_interleaved(gfp: GlobalFlags_, + pcm: *c_short, + num_samples:c_int, + mp3buf: *c_uchar, + mp3buf_size: c_int) -> c_int; + fn lame_encode_flush_nogap(gfp: GlobalFlags_, + mp3buf: *c_uchar, + size: c_int) -> c_int; +} + +pub struct LameContext { + gfp: GlobalFlags_ +} + +impl LameContext { + #[fixed_stack_segment] + pub fn new() -> LameContext { + LameContext { gfp: unsafe { lame_init() }} + } +} + +impl Drop for LameContext { + #[fixed_stack_segment] + fn drop(&mut self) { + unsafe { lame_close(self.gfp) }; + } +} |