qwac_sys/audio.rs
1#[derive(Clone, Copy, Hash, Debug, Eq, PartialEq, Ord, PartialOrd)]
2#[repr(u8)]
3pub enum OscillatorType {
4 Sine = 0,
5 Square,
6 Sawtooth,
7 Triangle,
8}
9
10// /// Audio Buffers are initialized asynchronously, so we have to set them via a
11// /// callback.
12// /// The callback is given a negative code on error. On a negative
13// /// buffer, the error code is the bit-flipped number, which is `-1 - audio_buffer`.
14// pub type AudioBufferCallback = extern "C" fn(audio_buffer: i32, user_data: *mut ());
15
16// /// Audio Element streams are initialized asynchronously, so we have to set
17// /// them via a callback.
18// /// The callback is given a negative code on error. On a negative
19// /// buffer, the error code is the bit-flipped number, which is `-1 - audio_element`.
20// pub type AudioElementCallback = extern "C" fn(audio_element: i32, user_data: *mut ());
21
22#[link(wasm_import_module = "qwac_audio")]
23extern "C" {
24 // pub fn create_audio_buffer(
25 // source: *const u8,
26 // size: i32,
27 // callback: AudioBufferCallback,
28 // user_data: *mut (),
29 // ) -> i32;
30
31 // pub fn create_audio_element(
32 // source: *const u8,
33 // size: i32,
34 // mime_type: *const u8,
35 // mime_type_size: i32,
36 // callback: AudioElementCallback,
37 // user_data: *mut (),
38 // ) -> i32;
39
40 /// Creates an oscillator node
41 pub fn create_oscillator_node(oscillator_type: OscillatorType) -> i32;
42 pub fn create_gain_node(gain: f32) -> i32;
43 pub fn create_delay_node(delay_time: f32, max_delay_time: f32) -> i32;
44 // pub fn create_audio_buffer_source_node(audio_buffer: i32);
45 // pub fn create_audio_element_source_node(audio_element: i32);
46
47 // pub fn set_loop(audio_buffer_source: i32, enabled: i32);
48 // pub fn set_loop_start(audio_buffer_source: i32, time: f32);
49 // pub fn set_loop_end(audio_buffer_source: i32, time: f32);
50
51 pub fn detune_param(audio_node: i32) -> i32;
52 // pub fn playback_rate_param(audio_node: i32) -> i32;
53 pub fn frequency_param(audio_node: i32) -> i32;
54 pub fn gain_param(audio_node: i32) -> i32;
55 pub fn delay_time_param(audio_node: i32) -> i32;
56
57 pub fn param_cancel_and_hold_at_time(audio_param: i32, time: f32);
58 pub fn param_cancel_scheduled_values(audio_param: i32, time: f32);
59 pub fn param_set_value(audio_param: i32, value: f32);
60 pub fn param_set_value_at_time(audio_param: i32, value: f32, time: f32);
61 pub fn param_set_target_at_time(
62 audio_param: i32,
63 target: f32,
64 start_time: f32,
65 time_constant: f32,
66 );
67 pub fn param_linear_ramp_to_value_at_time(audio_param: i32, value: f32, end_time: f32);
68 pub fn param_exponential_ramp_to_value_at_time(audio_param: i32, value: f32, end_time: f32);
69
70 pub fn connect(source: i32, target: i32);
71
72 // Disconnect the given target. A negative target will disconnect all.
73 pub fn disconnect(source: i32, target: i32);
74
75 pub fn start(audio_node: i32, time: f32);
76 pub fn stop(audio_node: i32, time: f32);
77
78 pub fn drop(audio_slot: i32);
79}