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
//! Audio module entrypoints
//!
//! Audio modules only get an entry point, no API functions, so not much needed here
//! other than necessary type definitions.

use bytemuck::Pod;
use bytemuck::Zeroable;

/// `ark_audio_render` - Render an audio frame from a set of source instances
pub type AudioRenderFn = fn(
    render_info_ptr: *const AudioRenderInfo,
    source_info_ptr: *const AudioSourceInfo,
    source_info_len: u32,
);
pub const AUDIO_RENDER: &str = "ark_audio_render";

bitflags! {
    #[repr(C)]
    #[derive(Pod, Zeroable)]
    pub struct AudioSourceFlags : u32 {
        const STARTED = 0b0000_0001;
        const REMOVED = 0b0000_0010;
    }
}
/// Raw struct, abstracted away by the impl macro so not accessed directly by user code.
#[derive(Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct AudioSourceInfo {
    pub object_to_world: [f32; 16],

    // Plain parameters copied from the component, can be interpreted how you like
    pub rate: f32,
    pub flags: AudioSourceFlags,

    pub static_data_ptr: u32,
    pub static_data_len: u32,

    pub dynamic_data_ptr: u32,
    pub dynamic_data_len: u32,

    pub out_buffer_ptr: u32,
    pub out_buffer_len: u32,

    /// Stable instance ID for identifying an instance across frames.
    pub cache_id: u64,

    /// Unlike in AudioRenderInfo, we need to reserve space here for any future expansion
    /// because we pass as slice of `AudioSourceInfo` to the module so the size is fixed.
    pub reserved: [u32; 16],
}

/// General information about the current frame.
#[derive(Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct AudioRenderInfo {
    pub view_to_world: [f32; 16],
    pub sample_rate_hz: f32,
    pub channels: u32,
    // Can safely be (strictly) expanded without breaking ABI.
}