qwac-sys 0.28.1

The FFI crates for QWAC
Documentation
#[derive(Clone, Copy, Hash, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[repr(u8)]
pub enum OscillatorType {
    Sine = 0,
    Square,
    Sawtooth,
    Triangle,
}

// /// Audio Buffers are initialized asynchronously, so we have to set them via a
// /// callback.
// /// The callback is given a negative code on error.  On a negative
// /// buffer, the error code is the bit-flipped number, which is `-1 - audio_buffer`.
// pub type AudioBufferCallback = extern "C" fn(audio_buffer: i32, user_data: *mut ());

// /// Audio Element streams are initialized asynchronously, so we have to set
// /// them via a callback.
// /// The callback is given a negative code on error.  On a negative
// /// buffer, the error code is the bit-flipped number, which is `-1 - audio_element`.
// pub type AudioElementCallback = extern "C" fn(audio_element: i32, user_data: *mut ());

#[link(wasm_import_module = "qwac_audio")]
extern "C" {
    // pub fn create_audio_buffer(
    //     source: *const u8,
    //     size: i32,
    //     callback: AudioBufferCallback,
    //     user_data: *mut (),
    // ) -> i32;

    // pub fn create_audio_element(
    //     source: *const u8,
    //     size: i32,
    //     mime_type: *const u8,
    //     mime_type_size: i32,
    //     callback: AudioElementCallback,
    //     user_data: *mut (),
    // ) -> i32;

    /// Creates an oscillator node
    pub fn create_oscillator_node(oscillator_type: OscillatorType) -> i32;
    pub fn create_gain_node(gain: f32) -> i32;
    pub fn create_delay_node(delay_time: f32, max_delay_time: f32) -> i32;
    // pub fn create_audio_buffer_source_node(audio_buffer: i32);
    // pub fn create_audio_element_source_node(audio_element: i32);

    // pub fn set_loop(audio_buffer_source: i32, enabled: i32);
    // pub fn set_loop_start(audio_buffer_source: i32, time: f32);
    // pub fn set_loop_end(audio_buffer_source: i32, time: f32);

    pub fn detune_param(audio_node: i32) -> i32;
    // pub fn playback_rate_param(audio_node: i32) -> i32;
    pub fn frequency_param(audio_node: i32) -> i32;
    pub fn gain_param(audio_node: i32) -> i32;
    pub fn delay_time_param(audio_node: i32) -> i32;

    pub fn param_cancel_and_hold_at_time(audio_param: i32, time: f32);
    pub fn param_cancel_scheduled_values(audio_param: i32, time: f32);
    pub fn param_set_value(audio_param: i32, value: f32);
    pub fn param_set_value_at_time(audio_param: i32, value: f32, time: f32);
    pub fn param_set_target_at_time(
        audio_param: i32,
        target: f32,
        start_time: f32,
        time_constant: f32,
    );
    pub fn param_linear_ramp_to_value_at_time(audio_param: i32, value: f32, end_time: f32);
    pub fn param_exponential_ramp_to_value_at_time(audio_param: i32, value: f32, end_time: f32);

    pub fn connect(source: i32, target: i32);

    // Disconnect the given target.  A negative target will disconnect all.
    pub fn disconnect(source: i32, target: i32);

    pub fn start(audio_node: i32, time: f32);
    pub fn stop(audio_node: i32, time: f32);

    pub fn drop(audio_slot: i32);
}