sphinxad_sys/lib.rs
1extern crate libc;
2use libc::{c_char,c_void};
3
4///Device
5#[repr(C)]
6pub struct ad_rec_t(c_void);
7
8///Uses for ad_open function
9pub const DEFAULT_SAMPLES_PER_SEC:i32 = 16000;
10
11
12pub const AD_OK:i32 = 0;
13pub const AD_EOF:i32 = -1;
14pub const AD_ERR_GEN:i32 = -1;
15pub const AD_ERR_NOT_OPEN:i32 = -2;
16pub const AD_ERR_WAVE:i32 = -3;
17
18#[link(name = "sphinxad")]
19extern {
20 ///Open a specific audio device with a given name and sampling rate.
21 ///
22 ///The device is opened in non-blocking mode and placed in idle state.
23 ///The return value to be used as the first argument to
24 ///other recording functions.
25 /// # Safety
26 ///
27 ///Return pointer to read-only ad_rec_t structure if successful, NULL
28 ///otherwise.
29 pub fn ad_open_dev(device_name: *const c_char, samples_per_sec: u32) -> *const ad_rec_t;
30
31 ///Open the default audio device with a given sampling rate.
32 ///
33 ///The device is opened in non-blocking mode and placed in idle state.
34 ///The return value to be used as the first argument to
35 ///other recording functions.
36 /// # Safety
37 ///
38 ///Return pointer to read-only ad_rec_t structure if successful, NULL
39 ///otherwise.
40 pub fn ad_open_sps(samples_per_sec:u32) -> *const ad_rec_t;
41
42 ///Open the default audio device.
43 ///
44 ///The device is opened in non-blocking mode and placed in idle state.
45 ///The return value to be used as the first argument to
46 ///other recording functions.
47 /// # Safety
48 ///
49 ///Return pointer to read-only ad_rec_t structure if successful, NULL
50 ///otherwise.
51 pub fn ad_open() -> *const ad_rec_t;
52
53 ///Start audio recording.
54 ///
55 /// # Safety
56 ///
57 ///Return 0(ReturnCode::Ok) if successful, <0 otherwise
58 pub fn ad_start_rec(dev: *const ad_rec_t) -> i32;
59
60 ///Stop audio recording.
61 ///
62 /// # Safety
63 ///
64 ///Return 0(ReturnCode::Ok) if successful, <0 otherwise
65 pub fn ad_stop_rec(dev: *const ad_rec_t) -> i32;
66
67 ///Close the recording device.
68 ///
69 /// # Safety
70 ///
71 ///Return 0(ReturnCode::Ok) if successful, <0 otherwise
72 pub fn ad_close(dev: *const ad_rec_t) -> i32;
73
74 ///Read next block of audio samples while recording; read upto max samples into buf.
75 ///
76 /// # Safety
77 ///
78 ///Return # samples actually read (could be 0 since non-blocking); AD_EOF if not
79 ///recording and no more samples remaining to be read from most recent recording.
80 pub fn ad_read(dev: *const ad_rec_t, buf:*mut i16, max:u32) -> i32;
81}