fmod/
lib.rs

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