ark_api_ffi/entrypoints/
audio.rs

1//! Audio module entrypoints
2//!
3//! Audio modules only get an entry point, no API functions, so not much needed here
4//! other than necessary type definitions.
5
6use bytemuck::Pod;
7use bytemuck::Zeroable;
8
9/// `ark_audio_render` - Render an audio frame from a set of source instances
10pub type AudioRenderFn = fn(
11    render_info_ptr: *const AudioRenderInfo,
12    source_info_ptr: *const AudioSourceInfo,
13    source_info_len: u32,
14);
15pub const AUDIO_RENDER: &str = "ark_audio_render";
16
17bitflags! {
18    #[repr(C)]
19    #[derive(Pod, Zeroable)]
20    pub struct AudioSourceFlags : u32 {
21        const STARTED = 0b0000_0001;
22        const REMOVED = 0b0000_0010;
23    }
24}
25/// Raw struct, abstracted away by the impl macro so not accessed directly by user code.
26#[derive(Copy, Clone, Pod, Zeroable)]
27#[repr(C)]
28pub struct AudioSourceInfo {
29    pub object_to_world: [f32; 16],
30
31    // Plain parameters copied from the component, can be interpreted how you like
32    pub rate: f32,
33    pub flags: AudioSourceFlags,
34
35    pub static_data_ptr: u32,
36    pub static_data_len: u32,
37
38    pub dynamic_data_ptr: u32,
39    pub dynamic_data_len: u32,
40
41    pub out_buffer_ptr: u32,
42    pub out_buffer_len: u32,
43
44    /// Stable instance ID for identifying an instance across frames.
45    pub cache_id: u64,
46
47    /// Unlike in AudioRenderInfo, we need to reserve space here for any future expansion
48    /// because we pass as slice of `AudioSourceInfo` to the module so the size is fixed.
49    pub reserved: [u32; 16],
50}
51
52/// General information about the current frame.
53#[derive(Copy, Clone, Pod, Zeroable)]
54#[repr(C)]
55pub struct AudioRenderInfo {
56    pub view_to_world: [f32; 16],
57    pub sample_rate_hz: f32,
58    pub channels: u32,
59    // Can safely be (strictly) expanded without breaking ABI.
60}