summaryrefslogtreecommitdiff
path: root/mp3lame.rs
blob: eb7d572e2ceb77a7b6ea6b17d03532e2b37d6f57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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) };
  }
}