fmod_sys/
lib.rs

1//! Low level bindings to the FMOD sound engine.
2//!
3//! Due to licensing restrictions, the FMOD API cannot be distributed with this crate.
4//! docs.rs documention is provided for the FMOD API but the actual API is not available without the FMOD library.
5//!
6//! Currently, this crate provides both core and studio bindings (no fsbank bindings).
7//!
8//! See [`fmod-oxide`](https://github.com/melody-rs/fmod-oxide/blob/main/README.md)'s README.md for more information on how this crate links to FMOD.
9//!
10//! # Feature flags
11#![doc = document_features::document_features!()]
12#![allow(non_upper_case_globals)]
13#![allow(non_camel_case_types)]
14#![allow(non_snake_case)]
15#![doc(html_favicon_url = "https://www.fmod.com/assets/fmod-logo.svg")]
16#![doc(html_logo_url = "https://www.fmod.com/assets/fmod-logo.svg")]
17
18#[cfg(any(docsrs, feature = "force-docs-bindings"))]
19include!("../docs/documentation.rs");
20
21#[cfg(not(any(docsrs, feature = "force-docs-bindings")))]
22include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
23
24pub const INSTALL_DIR: &str = env!("FMOD_DIR");
25pub const API_DIR: &str = env!("FMOD_API_DIR");
26
27impl From<FMOD_BOOL> for bool {
28    fn from(val: FMOD_BOOL) -> Self {
29        val.0 > 0
30    }
31}
32
33impl From<bool> for FMOD_BOOL {
34    fn from(value: bool) -> Self {
35        Self(value as _)
36    }
37}
38
39impl FMOD_BOOL {
40    pub const FALSE: Self = Self(0);
41    pub const TRUE: Self = Self(1);
42}
43
44#[allow(non_snake_case)]
45pub const fn error_code_to_str(result: FMOD_RESULT) -> &'static str {
46    match result {
47        FMOD_RESULT::FMOD_OK => "No errors.",
48        FMOD_RESULT::FMOD_ERR_BADCOMMAND => {
49            "Tried to call a function on a data type that does not allow this type of functionality (ie calling Sound::lock on a streaming sound)."
50        }
51        FMOD_RESULT::FMOD_ERR_CHANNEL_ALLOC => "Error trying to allocate a channel.",
52        FMOD_RESULT::FMOD_ERR_CHANNEL_STOLEN => {
53            "The specified channel has been reused to play another sound."
54        }
55        FMOD_RESULT::FMOD_ERR_DMA => "DMA Failure.  See debug output for more information.",
56        FMOD_RESULT::FMOD_ERR_DSP_CONNECTION => {
57            "DSP connection error.  Connection possibly caused a cyclic dependency or connected dsps with incompatible buffer counts."
58        }
59        FMOD_RESULT::FMOD_ERR_DSP_DONTPROCESS => {
60            "DSP  code from a DSP process query callback.  Tells mixer not to call the process callback and therefore not consume CPU.  Use this to optimize the DSP graph."
61        }
62        FMOD_RESULT::FMOD_ERR_DSP_FORMAT => {
63            "DSP Format error.  A DSP unit may have attempted to connect to this network with the wrong format, or a matrix may have been set with the wrong size if the target unit has a specified channel map."
64        }
65        FMOD_RESULT::FMOD_ERR_DSP_INUSE => {
66            "DSP is already in the mixer's DSP network. It must be removed before being reinserted or released."
67        }
68        FMOD_RESULT::FMOD_ERR_DSP_NOTFOUND => {
69            "DSP connection error.  Couldn't find the DSP unit specified."
70        }
71        FMOD_RESULT::FMOD_ERR_DSP_RESERVED => {
72            "DSP operation error.  Cannot perform operation on this DSP as it is reserved by the system."
73        }
74        FMOD_RESULT::FMOD_ERR_DSP_SILENCE => {
75            "DSP operation error.  Cannot perform operation on this DSP as it is reserved by the system."
76        }
77        FMOD_RESULT::FMOD_ERR_DSP_TYPE => {
78            "DSP operation cannot be performed on a DSP of this type."
79        }
80        FMOD_RESULT::FMOD_ERR_FILE_BAD => "Error loading file.",
81        FMOD_RESULT::FMOD_ERR_FILE_COULDNOTSEEK => {
82            "Couldn't perform seek operation.  This is a limitation of the medium (ie netstreams) or the file format."
83        }
84        FMOD_RESULT::FMOD_ERR_FILE_DISKEJECTED => "Media was ejected while reading.",
85        FMOD_RESULT::FMOD_ERR_FILE_EOF => {
86            "End of file unexpectedly reached while trying to read essential data (truncated?)."
87        }
88        FMOD_RESULT::FMOD_ERR_FILE_ENDOFDATA => {
89            "End of current chunk reached while trying to read data."
90        }
91        FMOD_RESULT::FMOD_ERR_FILE_NOTFOUND => "File not found.",
92        FMOD_RESULT::FMOD_ERR_FORMAT => "Unsupported file or audio format.",
93        FMOD_RESULT::FMOD_ERR_HEADER_MISMATCH => {
94            "There is a version mismatch between the FMOD header and either the FMOD Studio library or the FMOD Low Level library."
95        }
96        FMOD_RESULT::FMOD_ERR_HTTP => {
97            "A HTTP error occurred. This is a catch-all for HTTP errors not listed elsewhere."
98        }
99        FMOD_RESULT::FMOD_ERR_HTTP_ACCESS => {
100            "The specified resource requires authentication or is forbidden."
101        }
102        FMOD_RESULT::FMOD_ERR_HTTP_PROXY_AUTH => {
103            "Proxy authentication is required to access the specified resource."
104        }
105        FMOD_RESULT::FMOD_ERR_HTTP_SERVER_ERROR => "A HTTP server error occurred.",
106        FMOD_RESULT::FMOD_ERR_HTTP_TIMEOUT => "The HTTP request timed out.",
107        FMOD_RESULT::FMOD_ERR_INITIALIZATION => {
108            "FMOD was not initialized correctly to support this function."
109        }
110        FMOD_RESULT::FMOD_ERR_INITIALIZED => "Cannot call this command after System::init.",
111        FMOD_RESULT::FMOD_ERR_INTERNAL => {
112            "An error occured in the FMOD system. Use the logging version of FMOD for more information."
113        }
114        FMOD_RESULT::FMOD_ERR_INVALID_FLOAT => {
115            "Value passed in was a NaN, Inf or denormalized float."
116        }
117        FMOD_RESULT::FMOD_ERR_INVALID_HANDLE => "An invalid object handle was used.",
118        FMOD_RESULT::FMOD_ERR_INVALID_PARAM => "An invalid parameter was passed to this function.",
119        FMOD_RESULT::FMOD_ERR_INVALID_POSITION => {
120            "An invalid seek position was passed to this function."
121        }
122        FMOD_RESULT::FMOD_ERR_INVALID_SPEAKER => {
123            "An invalid speaker was passed to this function based on the current speaker mode."
124        }
125        FMOD_RESULT::FMOD_ERR_INVALID_SYNCPOINT => {
126            "The syncpoint did not come from this sound handle."
127        }
128        FMOD_RESULT::FMOD_ERR_INVALID_THREAD => {
129            "Tried to call a function on a thread that is not supported."
130        }
131        FMOD_RESULT::FMOD_ERR_INVALID_VECTOR => {
132            "The vectors passed in are not unit length, or perpendicular."
133        }
134        FMOD_RESULT::FMOD_ERR_MAXAUDIBLE => {
135            "Reached maximum audible playback count for this sound's soundgroup."
136        }
137        FMOD_RESULT::FMOD_ERR_MEMORY => "Not enough memory or resources.",
138        FMOD_RESULT::FMOD_ERR_MEMORY_CANTPOINT => {
139            "Can't use FMOD_OPENMEMORY_POINT on non PCM source data, or non mp3/xma/adpcm data if FMOD_CREATECOMPRESSEDSAMPLE was used."
140        }
141        FMOD_RESULT::FMOD_ERR_NEEDS3D => {
142            "Tried to call a command on a 2d sound when the command was meant for 3d sound."
143        }
144        FMOD_RESULT::FMOD_ERR_NEEDSHARDWARE => {
145            "Tried to use a feature that requires hardware support."
146        }
147        FMOD_RESULT::FMOD_ERR_NET_CONNECT => "Couldn't connect to the specified host.",
148        FMOD_RESULT::FMOD_ERR_NET_SOCKET_ERROR => {
149            "A socket error occurred.  This is a catch-all for socket-related errors not listed elsewhere."
150        }
151        FMOD_RESULT::FMOD_ERR_NET_URL => "The specified URL couldn't be resolved.",
152        FMOD_RESULT::FMOD_ERR_NET_WOULD_BLOCK => {
153            "Operation on a non-blocking socket could not complete immediately."
154        }
155        FMOD_RESULT::FMOD_ERR_NOTREADY => {
156            "Operation could not be performed because specified sound/DSP connection is not ready."
157        }
158        FMOD_RESULT::FMOD_ERR_OUTPUT_ALLOCATED => {
159            "Error initializing output device, but more specifically, the output device is already in use and cannot be reused."
160        }
161        FMOD_RESULT::FMOD_ERR_OUTPUT_CREATEBUFFER => "Error creating hardware sound buffer.",
162        FMOD_RESULT::FMOD_ERR_OUTPUT_DRIVERCALL => {
163            "A call to a standard soundcard driver failed, which could possibly mean a bug in the driver or resources were missing or exhausted."
164        }
165        FMOD_RESULT::FMOD_ERR_OUTPUT_FORMAT => "Soundcard does not support the specified format.",
166        FMOD_RESULT::FMOD_ERR_OUTPUT_INIT => "Error initializing output device.",
167        FMOD_RESULT::FMOD_ERR_OUTPUT_NODRIVERS => {
168            "The output device has no drivers installed.  If pre-init, FMOD_OUTPUT_NOSOUND is selected as the output mode.  If post-init, the function just fails."
169        }
170        FMOD_RESULT::FMOD_ERR_PLUGIN => "An unspecified error has been ed from a plugin.",
171        FMOD_RESULT::FMOD_ERR_PLUGIN_MISSING => {
172            "A requested output, dsp unit type or codec was not available."
173        }
174        FMOD_RESULT::FMOD_ERR_PLUGIN_RESOURCE => {
175            "A resource that the plugin requires cannot be allocated or found. (ie the DLS file for MIDI playback)"
176        }
177        FMOD_RESULT::FMOD_ERR_PLUGIN_VERSION => {
178            "A plugin was built with an unsupported SDK version."
179        }
180        FMOD_RESULT::FMOD_ERR_RECORD => {
181            "An error occurred trying to initialize the recording device."
182        }
183        FMOD_RESULT::FMOD_ERR_REVERB_CHANNELGROUP => {
184            "Reverb properties cannot be set on this channel because a parent channelgroup owns the reverb connection."
185        }
186        FMOD_RESULT::FMOD_ERR_REVERB_INSTANCE => {
187            "Specified instance in FMOD_REVERB_PROPERTIES couldn't be set. Most likely because it is an invalid instance number or the reverb doesn't exist."
188        }
189        FMOD_RESULT::FMOD_ERR_SUBSOUNDS => {
190            "The error occurred because the sound referenced contains subsounds when it shouldn't have, or it doesn't contain subsounds when it should have.  The operation may also not be able to be performed on a parent sound."
191        }
192        FMOD_RESULT::FMOD_ERR_SUBSOUND_ALLOCATED => {
193            "This subsound is already being used by another sound, you cannot have more than one parent to a sound.  Null out the other parent's entry first."
194        }
195        FMOD_RESULT::FMOD_ERR_SUBSOUND_CANTMOVE => {
196            "Shared subsounds cannot be replaced or moved from their parent stream, such as when the parent stream is an FSB file."
197        }
198        FMOD_RESULT::FMOD_ERR_TAGNOTFOUND => {
199            "The specified tag could not be found or there are no tags."
200        }
201        FMOD_RESULT::FMOD_ERR_TOOMANYCHANNELS => {
202            "The sound created exceeds the allowable input channel count.  This can be increased using the 'maxinputchannels' parameter in SystemBuilder::software_format."
203        }
204        FMOD_RESULT::FMOD_ERR_TRUNCATED => {
205            "The retrieved string is too long to fit in the supplied buffer and has been truncated."
206        }
207        FMOD_RESULT::FMOD_ERR_UNIMPLEMENTED => {
208            "Something in FMOD hasn't been implemented when it should be. Contact support."
209        }
210        FMOD_RESULT::FMOD_ERR_UNINITIALIZED => {
211            "This command failed because System::init or System::setDriver was not called."
212        }
213        FMOD_RESULT::FMOD_ERR_UNSUPPORTED => {
214            "A command issued was not supported by this object.  Possibly a plugin without certain callbacks specified."
215        }
216        FMOD_RESULT::FMOD_ERR_VERSION => "The version number of this file format is not supported.",
217        FMOD_RESULT::FMOD_ERR_EVENT_ALREADY_LOADED => "The specified bank has already been loaded.",
218        FMOD_RESULT::FMOD_ERR_EVENT_LIVEUPDATE_BUSY => {
219            "The live update connection failed due to the game already being connected."
220        }
221        FMOD_RESULT::FMOD_ERR_EVENT_LIVEUPDATE_MISMATCH => {
222            "The live update connection failed due to the game data being out of sync with the tool."
223        }
224        FMOD_RESULT::FMOD_ERR_EVENT_LIVEUPDATE_TIMEOUT => "The live update connection timed out.",
225        FMOD_RESULT::FMOD_ERR_EVENT_NOTFOUND => {
226            "The requested event, parameter, bus or vca could not be found."
227        }
228        FMOD_RESULT::FMOD_ERR_STUDIO_UNINITIALIZED => {
229            "The Studio::System object is not yet initialized."
230        }
231        FMOD_RESULT::FMOD_ERR_STUDIO_NOT_LOADED => {
232            "The specified resource is not loaded, so it can't be unloaded."
233        }
234        FMOD_RESULT::FMOD_ERR_INVALID_STRING => "An invalid string was passed to this function.",
235        FMOD_RESULT::FMOD_ERR_ALREADY_LOCKED => "The specified resource is already locked.",
236        FMOD_RESULT::FMOD_ERR_NOT_LOCKED => {
237            "The specified resource is not locked, so it can't be unlocked."
238        }
239        FMOD_RESULT::FMOD_ERR_RECORD_DISCONNECTED => {
240            "The specified recording driver has been disconnected."
241        }
242        FMOD_RESULT::FMOD_ERR_TOOMANYSAMPLES => "The length provided exceeds the allowable limit.",
243        _ => "Unknown error.",
244    }
245}