fmod/
lib.rs

1//! Rust wrapper for FMOD 1.10.20
2
3#![feature(decl_macro)]
4
5#[macro_use] extern crate bitflags;
6
7extern crate num_traits;
8
9pub use num_traits::FromPrimitive;
10
11pub use fmod_sys as ll;
12
13#[cfg(target_os = "linux")]
14#[link(name = "fmod")] unsafe extern "C" {}
15
16#[cfg(target_os = "windows")]
17#[link(name = "fmod64_vc")] unsafe extern "C" {}
18
19////////////////////////////////////////////////////////////////////////////////
20//  modules                                                                   //
21////////////////////////////////////////////////////////////////////////////////
22
23pub mod channel;
24pub mod channel_control;
25pub mod channel_group;
26pub mod dsp;
27pub mod reverb3d;
28pub mod sound;
29pub mod sound_group;
30pub mod system;
31
32pub use self::channel::Channel;
33pub use self::channel_control::ChannelControl;
34pub use self::channel_group::{ChannelGroup, ChannelGroupRef};
35pub use self::dsp::{Dsp, DspRef};
36pub use self::reverb3d::Reverb3d;
37pub use self::sound::{Sound, SoundRef};
38pub use self::sound_group::SoundGroup;
39pub use self::system::System;
40// private modules
41mod types;
42pub use self::types::{Channelmask, CpuUsage, Delay, DebugFlags, DriverState,
43  Error, Guid, ListenerAttributes, Mode, PluginHandle, Plugintype, SoundRam,
44  Speaker, Speakermode, Timeunit};
45
46/// Version in FMOD headers used to generate bindings.
47///
48/// The version is a 32 bit hexadecimal value formated as 16:8:8, with the upper
49/// 16 bits being the product version, the middle 8 bits being the major version
50/// and the bottom 8 bits being the minor version.
51pub const FMOD_VERSION             : u32 = ll::FMOD_VERSION;
52pub const CODEC_WAVEFORMAT_VERSION : u32 = ll::FMOD_CODEC_WAVEFORMAT_VERSION;
53pub const MAX_CHANNEL_WIDTH        : u32 = ll::FMOD_MAX_CHANNEL_WIDTH;
54pub const MAX_SYSTEMS              : u32 = ll::FMOD_MAX_SYSTEMS;
55pub const MAX_LISTENERS            : u32 = ll::FMOD_MAX_LISTENERS;
56pub const OUTPUT_PLUGIN_VERSION    : u32 = ll::FMOD_OUTPUT_PLUGIN_VERSION;
57pub const PLUGIN_SDK_VERSION       : u32 = ll::FMOD_PLUGIN_SDK_VERSION;
58/// Version in FMOD headers used to generate bindings
59pub static FMOD_VERSION_STRING : std::sync::LazyLock <String> =
60  std::sync::LazyLock::new (|| version_string (FMOD_VERSION));
61
62pub (crate) macro fmod_result {
63  ($e:expr) => {{
64    match $e {
65      $crate::ll::FMOD_RESULT_FMOD_OK => Ok (()),
66      err => Err ($crate::Error::from_ll (err))
67    }
68  }}
69}
70
71pub mod vector {
72  use crate::ll;
73  pub const fn from_ll (vector : ll::FMOD_VECTOR) -> [f32; 3] {
74    [vector.x, vector.y, vector.z]
75  }
76  pub const fn to_ll (vector : [f32; 3]) -> ll::FMOD_VECTOR {
77    ll::FMOD_VECTOR { x: vector[0], y: vector[1], z: vector[2] }
78  }
79}
80
81pub (crate) fn version_string (fmod_version : u32) -> String {
82  format!("{:x}.{:x}.{:x}",
83    (fmod_version & 0xffff_0000) >> 16,
84    (fmod_version & 0x0000_ff00) >> 8,
85    (fmod_version & 0x0000_00ff))
86}