fmod/core/flags.rs
1// Copyright (c) 2024 Melody Madeline Lyons
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7use fmod_sys::*;
8
9bitflags::bitflags! {
10 /// Configuration flags used when initializing the System object.
11 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
12 pub struct InitFlags: FMOD_INITFLAGS {
13 /// Initialize normally
14 const NORMAL = FMOD_INIT_NORMAL;
15 /// No stream thread is created internally.
16 /// Streams are driven from [`System::update`]. Mainly used with non-realtime outputs.
17 const STREAM_FROM_UPDATE = FMOD_INIT_STREAM_FROM_UPDATE;
18 /// No mixer thread is created internally.
19 /// Mixing is driven from [`System::update`].
20 /// Only applies to polling based output modes such as [`FMOD_OUTPUTTYPE_NOSOUND`], [`FMOD_OUTPUTTYPE_WAVWRITER`].
21 const MIX_FROM_UPDATE = FMOD_INIT_MIX_FROM_UPDATE;
22 /// 3D calculations will be performed in right-handed coordinates, instead of the default of left-handed coordinates.
23 /// See the Handedness section of the Glossary for more information.
24 const RIGHTHANDED_3D = FMOD_INIT_3D_RIGHTHANDED;
25 /// Enables hard clipping of output values greater than 1.0f or less than -1.0f.
26 const CLIP_OUTPUT = FMOD_INIT_CLIP_OUTPUT;
27 /// Enables usage of [`ChannelControl::setLowPassGain`],
28 /// [`ChannelControl::set3DOcclusion`], or automatic usage by the Geometry API.
29 ///
30 /// All voices will add a software lowpass filter effect into the DSP chain which is idle unless one of the previous
31 /// functions/features are used.
32 const CHANNEL_LOWPASS = FMOD_INIT_CHANNEL_LOWPASS;
33 /// All [`FMOD_3D`] based voices add a software low pass and highpass filter effect into the DSP chain,
34 /// which acts as a distance-automated bandpass filter.
35 ///
36 /// Use [`System::setAdvancedSettings`] to adjust the center frequency.
37 const CHANNEL_DISTANCE_FILTER = FMOD_INIT_CHANNEL_DISTANCEFILTER;
38 /// Enable TCP/IP based host which allows FMOD Studio or FMOD Profiler to connect to it,
39 /// and view memory, CPU and the DSP graph in real-time.
40 const PROFILE_ENABLE = FMOD_INIT_PROFILE_ENABLE;
41 /// Any sounds that are 0 volume will go virtual and not be processed except for having their positions updated virtually.
42 ///
43 /// Use [`System::setAdvancedSettings`] to adjust what volume besides zero to switch to virtual at.
44 const VOL_0_BECOMES_VIRTUAL = FMOD_INIT_VOL0_BECOMES_VIRTUAL;
45 /// With the geometry engine, only process the closest polygon rather than accumulating all polygons the sound to listener line intersects.
46 const GEOMETRY_USE_CLOSEST = FMOD_INIT_GEOMETRY_USECLOSEST;
47 /// When using [`FMOD_SPEAKERMODE_5POINT1`] with a stereo output device,
48 /// use the Dolby Pro Logic II downmix algorithm instead of the default stereo downmix algorithm.
49 const PREFER_DOLBY_DOWNMIX = FMOD_INIT_PREFER_DOLBY_DOWNMIX;
50 /// This flag cannot be used normally as this crate has guardrails preventing it.
51 /// It is still here for completeness' sake, though.
52 const THREAD_UNSAFE = FMOD_INIT_THREAD_UNSAFE;
53 /// Slower, but adds level metering for every single DSP unit in the graph.
54 /// Use [`DSP::setMeteringEnabled`] to turn meters off individually.
55 ///
56 /// Setting this flag implies [`PROFILE_ENABLE`].
57 const PROFILE_METER_ALL = FMOD_INIT_PROFILE_METER_ALL;
58 /// Enables memory allocation tracking.
59 /// Currently this is only useful when using the Studio API.
60 /// Increases memory footprint and reduces performance.
61 ///
62 /// This flag is implied by [`FMOD_STUDIO_INIT_MEMORY_TRACKING`].
63 const MEMORY_TRACKING = FMOD_INIT_MEMORY_TRACKING;
64 }
65}
66
67impl From<FMOD_INITFLAGS> for InitFlags {
68 fn from(value: FMOD_INITFLAGS) -> Self {
69 InitFlags::from_bits_truncate(value)
70 }
71}
72
73impl From<InitFlags> for FMOD_INITFLAGS {
74 fn from(value: InitFlags) -> Self {
75 value.bits()
76 }
77}
78
79bitflags::bitflags! {
80 /// Bitfield for specifying the CPU core a given thread runs on.
81 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
82 pub struct ThreadAffinity: FMOD_THREAD_AFFINITY {
83 /// For a given thread use the default listed below, i.e. [`FMOD_THREAD_TYPE_MIXER`] uses [`FMOD_THREAD_AFFINITY_MIXER`].
84 const GROUP_DEFAULT = FMOD_THREAD_AFFINITY_GROUP_DEFAULT as FMOD_THREAD_AFFINITY;
85 /// Grouping A is recommended to isolate the mixer thread [`FMOD_THREAD_TYPE_MIXER`].
86 const GROUP_A = FMOD_THREAD_AFFINITY_GROUP_A as FMOD_THREAD_AFFINITY;
87 /// Grouping B is recommended to isolate the Studio update thread [`FMOD_THREAD_TYPE_STUDIO_UPDATE`].
88 const GROUP_B = FMOD_THREAD_AFFINITY_GROUP_B as FMOD_THREAD_AFFINITY;
89 /// Grouping C is recommended for all remaining threads.
90 const GROUP_C = FMOD_THREAD_AFFINITY_GROUP_C as FMOD_THREAD_AFFINITY;
91 /// Default affinity for [`FMOD_THREAD_TYPE_MIXER`].
92 const MIXER = FMOD_THREAD_AFFINITY_MIXER as FMOD_THREAD_AFFINITY;
93 /// Default affinity for [`FMOD_THREAD_TYPE_FEEDER`].
94 const FEEDER = FMOD_THREAD_AFFINITY_FEEDER as FMOD_THREAD_AFFINITY;
95 /// Default affinity for [`FMOD_THREAD_TYPE_STREAM`].
96 const STREAM = FMOD_THREAD_AFFINITY_STREAM as FMOD_THREAD_AFFINITY;
97 /// Default affinity for [`FMOD_THREAD_TYPE_FILE`].
98 const FILE = FMOD_THREAD_AFFINITY_FILE as FMOD_THREAD_AFFINITY;
99 /// Default affinity for [`FMOD_THREAD_TYPE_NONBLOCKING`].
100 const NONBLOCKING = FMOD_THREAD_AFFINITY_NONBLOCKING as FMOD_THREAD_AFFINITY;
101 /// Default affinity for [`FMOD_THREAD_TYPE_RECORD`].
102 const RECORD = FMOD_THREAD_AFFINITY_RECORD as FMOD_THREAD_AFFINITY;
103 /// Default affinity for [`FMOD_THREAD_TYPE_GEOMETRY`].
104 const GEOMETRY = FMOD_THREAD_AFFINITY_GEOMETRY as FMOD_THREAD_AFFINITY;
105 /// Default affinity for [`FMOD_THREAD_TYPE_PROFILER`].
106 const PROFILER = FMOD_THREAD_AFFINITY_PROFILER as FMOD_THREAD_AFFINITY;
107 /// Default affinity for [`FMOD_THREAD_TYPE_STUDIO_UPDATE`].
108 const STUDIO_UPDATE = FMOD_THREAD_AFFINITY_STUDIO_UPDATE as FMOD_THREAD_AFFINITY;
109 /// Default affinity for [`FMOD_THREAD_TYPE_STUDIO_LOAD_BANK`].
110 const STUDIO_LOAD_BANK = FMOD_THREAD_AFFINITY_STUDIO_LOAD_BANK as FMOD_THREAD_AFFINITY;
111 /// Default affinity for [`FMOD_THREAD_TYPE_STUDIO_LOAD_SAMPLE`].
112 const STUDIO_LOAD_SAMPLE = FMOD_THREAD_AFFINITY_STUDIO_LOAD_SAMPLE as FMOD_THREAD_AFFINITY;
113 /// Default affinity for [`FMOD_THREAD_TYPE_CONVOLUTION1`].
114 const CONVOLUTION_1 = FMOD_THREAD_AFFINITY_CONVOLUTION1 as FMOD_THREAD_AFFINITY;
115 /// Default affinity for [`FMOD_THREAD_TYPE_CONVOLUTION2`].
116 const CONVOLUTION_2 = FMOD_THREAD_AFFINITY_CONVOLUTION2 as FMOD_THREAD_AFFINITY;
117 /// Assign to all cores.
118 const CORE_ALL = FMOD_THREAD_AFFINITY_CORE_ALL as FMOD_THREAD_AFFINITY;
119 /// Assign to core 0.
120 const CORE_0 = FMOD_THREAD_AFFINITY_CORE_0 as FMOD_THREAD_AFFINITY;
121 /// Assign to core 1.
122 const CORE_1 = FMOD_THREAD_AFFINITY_CORE_1 as FMOD_THREAD_AFFINITY;
123 /// Assign to core 2.
124 const CORE_2 = FMOD_THREAD_AFFINITY_CORE_2 as FMOD_THREAD_AFFINITY;
125 /// Assign to core 3.
126 const CORE_3 = FMOD_THREAD_AFFINITY_CORE_3 as FMOD_THREAD_AFFINITY;
127 /// Assign to core 4.
128 const CORE_4 = FMOD_THREAD_AFFINITY_CORE_4 as FMOD_THREAD_AFFINITY;
129 /// Assign to core 5.
130 const CORE_5 = FMOD_THREAD_AFFINITY_CORE_5 as FMOD_THREAD_AFFINITY;
131 /// Assign to core 6.
132 const CORE_6 = FMOD_THREAD_AFFINITY_CORE_6 as FMOD_THREAD_AFFINITY;
133 /// Assign to core 7.
134 const CORE_7 = FMOD_THREAD_AFFINITY_CORE_7 as FMOD_THREAD_AFFINITY;
135 /// Assign to core 8.
136 const CORE_8 = FMOD_THREAD_AFFINITY_CORE_8 as FMOD_THREAD_AFFINITY;
137 /// Assign to core 9.
138 const CORE_9 = FMOD_THREAD_AFFINITY_CORE_9 as FMOD_THREAD_AFFINITY;
139 /// Assign to core 10.
140 const CORE_10 = FMOD_THREAD_AFFINITY_CORE_10 as FMOD_THREAD_AFFINITY;
141 /// Assign to core 11.
142 const CORE_11 = FMOD_THREAD_AFFINITY_CORE_11 as FMOD_THREAD_AFFINITY;
143 /// Assign to core 12.
144 const CORE_12 = FMOD_THREAD_AFFINITY_CORE_12 as FMOD_THREAD_AFFINITY;
145 /// Assign to core 13.
146 const CORE_13 = FMOD_THREAD_AFFINITY_CORE_13 as FMOD_THREAD_AFFINITY;
147 /// Assign to core 14.
148 const CORE_14 = FMOD_THREAD_AFFINITY_CORE_14 as FMOD_THREAD_AFFINITY;
149 /// Assign to core 15.
150 const CORE_15 = FMOD_THREAD_AFFINITY_CORE_15 as FMOD_THREAD_AFFINITY;
151 }
152}
153
154impl From<FMOD_THREAD_AFFINITY> for ThreadAffinity {
155 fn from(value: FMOD_THREAD_AFFINITY) -> Self {
156 ThreadAffinity::from_bits_truncate(value)
157 }
158}
159
160impl From<ThreadAffinity> for FMOD_THREAD_AFFINITY {
161 fn from(value: ThreadAffinity) -> Self {
162 value.bits()
163 }
164}
165
166bitflags::bitflags! {
167 /// [`Sound`] description bitfields.
168 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
169 pub struct Mode: FMOD_MODE {
170 /// Default for all modes listed below.
171 const DEFAULT = FMOD_DEFAULT;
172 /// For non looping [`Sound`]s. (Default)
173 ///
174 /// Overrides [`LOOP_NORMAL`] / [`LOOP_BIDI`].
175 const LOOP_OFF = FMOD_LOOP_OFF;
176 /// For forward looping [`Sound`]s.
177 const LOOP_NORMAL = FMOD_LOOP_NORMAL;
178 /// For bidirectional looping [`Sound`]s. (only works on non-streaming, real voices).
179 const LOOP_BIDI = FMOD_LOOP_BIDI;
180 /// Ignores any 3d processing. (Default)
181 const D2 = FMOD_2D;
182 /// Makes the [`Sound`] positionable in 3D. Overrides [`D2`].
183 const D3 = FMOD_3D;
184 /// Decompress at runtime,
185 /// streaming from the source provided (ie from disk).
186 /// Overrides [`FMOD_CREATESAMPLE`] and [`FMOD_CREATECOMPRESSEDSAMPLE`].
187 /// Note a stream can only be played once at a time due to a stream only having 1 stream buffer and file handle.
188 /// Open multiple streams to have them play concurrently.
189 const CREATE_STREAM = FMOD_CREATESTREAM;
190 /// Decompress at loadtime,
191 /// decompressing or decoding whole file into memory as the target sample format (ie PCM).
192 /// Fastest for playback and most flexible.
193 const CREATE_SAMPLE = FMOD_CREATESAMPLE;
194 /// Load MP2/MP3/FADPCM/IMAADPCM/Vorbis/AT9 or XMA into memory and leave it compressed.
195 /// Vorbis/AT9/FADPCM encoding only supported in the .FSB container format.
196 /// During playback the FMOD software mixer will decode it in realtime as a 'compressed sample'.
197 /// Overrides [`FMOD_CREATESAMPLE`].
198 /// If the sound data is not one of the supported formats,
199 /// it will behave as if it was created with [`FMOD_CREATESAMPLE`] and decode the sound into PCM.
200 const CREATE_COMPRESSED_SAMPLE = FMOD_CREATECOMPRESSEDSAMPLE;
201 /// Opens a user-created static sample or stream.
202 const OPEN_USER = FMOD_OPENUSER;
203 /// Opens a sound with a pointer to memory.
204 /// Duplicates the pointer into its own buffer.
205 const OPEN_MEMORY = FMOD_OPENMEMORY;
206 /// Opens a sound with a pointer to memory.
207 const OPEN_MEMORY_POINT = FMOD_OPENMEMORY_POINT;
208 /// Will ignore file format and treat as raw pcm.
209 const OPEN_RAW = FMOD_OPENRAW;
210 /// Just open the file, don't prebuffer or read.
211 /// Good for fast opens for info, or when [`Sound::readData`] is to be used.
212 const OPEN_ONLY = FMOD_OPENONLY;
213 /// For [`System::create_sound`] - for accurate [`Sound::get_length`] / [`Channel::set_position`] on VBR MP3,
214 /// and MOD/S3M/XM/IT/MIDI files.
215 /// Scans file first, so takes longer to open.
216 /// [`FMOD_OPENONLY`] does not affect this.
217 const ACCURATE_TIME = FMOD_ACCURATETIME;
218 /// For corrupted / bad MP3 files.
219 /// This will search all the way through the file until it hits a valid MPEG header.
220 /// Normally only searches for 4k.
221 const MPEG_SEARCH = FMOD_MPEGSEARCH;
222 /// For opening [`Sound`]s and getting streamed subsounds (seeking) asynchronously.
223 /// Use [`Sound::get_open_state`] to poll the state of the [`Sound`] as it opens or retrieves the subsound in the background.
224 const NONBLOCKING = FMOD_NONBLOCKING;
225 /// Unique [`Sound`], can only be played one at a time.
226 const UNIQUE = FMOD_UNIQUE;
227 /// Make the [`Sound`]'s position, velocity and orientation relative to the listener.
228 const HEADRELATIVE_3D = FMOD_3D_HEADRELATIVE;
229 /// Make the [`Sound`]'s position, velocity and orientation absolute (relative to the world). (Default)
230 const WORLDRELATIVE_3D = FMOD_3D_WORLDRELATIVE;
231 /// This sound follows an inverse roll-off model.
232 /// Below mindistance, the volume is unattenuated; as distance increases above mindistance,
233 /// the volume attenuates using mindistance/distance as the gradient until it reaches maxdistance,
234 /// where it stops attenuating.
235 /// For this roll-off mode, distance values greater than mindistance are scaled according to the rolloffscale.
236 /// This roll-off mode accurately models the way sounds attenuate over distance in the real world. (Default)
237 const INVERSE_ROLLOFF_3D = FMOD_3D_INVERSEROLLOFF;
238 /// This sound follows a linear roll-off model.
239 /// Below mindistance, the volume is unattenuated; as distance increases from mindistance to maxdistance,
240 /// the volume attenuates to silence using a linear gradient.
241 /// For this roll-off mode, distance values greater than mindistance are scaled according to the rolloffscale.
242 /// While this roll-off mode is not as realistic as inverse roll-off mode, it is easier to comprehend.
243 const LINEAR_ROLLOFF_3D = FMOD_3D_LINEARROLLOFF;
244 /// This sound follows a linear-square roll-off model.
245 /// Below mindistance, the volume is unattenuated; as distance increases from mindistance to maxdistance,
246 /// the volume attenuates to silence according to a linear squared gradient.
247 /// For this roll-off mode, distance values greater than mindistance are scaled according to the rolloffscale.
248 /// This roll-off mode provides steeper volume ramping close to the mindistance,
249 /// and more gradual ramping close to the maxdistance, than linear roll-off mode.
250 const LINEAR_SQUARE_ROLLOFF_3D = FMOD_3D_LINEARSQUAREROLLOFF;
251 /// This sound follows a combination of the inverse and linear-square roll-off models.
252 /// At short distances where inverse roll-off would provide greater attenuation,
253 /// it functions as inverse roll-off mode; then at greater distances where linear-square roll-off mode would provide greater attenuation,
254 /// it uses that roll-off mode instead.
255 /// For this roll-off mode, distance values greater than mindistance are scaled according to the rolloffscale.
256 /// Inverse tapered roll-off mode approximates realistic behavior while still guaranteeing the sound attenuates to silence at maxdistance.
257 const INVERSE_TAPERED_ROLLOFF_3D = FMOD_3D_INVERSETAPEREDROLLOFF;
258 /// This sound follow a roll-off model defined by [`Sound::set3DCustomRolloff`] / [`ChannelControl::set3DCustomRolloff`].
259 /// This roll-off mode provides greater freedom and flexibility than any other, but must be defined manually.
260 const CUSTOM_ROLLOFF_3D = FMOD_3D_CUSTOMROLLOFF;
261 /// Is not affected by geometry occlusion.
262 /// If not specified in [`Sound::setMode`], or [`ChannelControl::setMode`],
263 /// the flag is cleared and it is affected by geometry again.
264 const IGNORE_GEOMETRY_3D = FMOD_3D_IGNOREGEOMETRY;
265 /// Skips id3v2/asf/etc tag checks when opening a Sound, to reduce seek/read overhead when opening files.
266 const IGNORE_TAGS = FMOD_IGNORETAGS;
267 /// Removes some features from samples to give a lower memory overhead, like [`Sound::getName`].
268 const LOWMEM = FMOD_LOWMEM;
269 /// For Channels that start virtual (due to being quiet or low importance),
270 /// instead of swapping back to audible,
271 /// and playing at the correct offset according to time, this flag makes the Channel play from the start.
272 const VIRTUAL_PLAYFROM_START = FMOD_VIRTUAL_PLAYFROMSTART;
273 }
274}
275
276impl From<FMOD_MODE> for Mode {
277 fn from(value: FMOD_MODE) -> Self {
278 Mode::from_bits_truncate(value)
279 }
280}
281
282impl From<Mode> for FMOD_MODE {
283 fn from(value: Mode) -> Self {
284 value.bits()
285 }
286}
287
288bitflags::bitflags! {
289 /// Flags that describe the speakers present in a given signal.
290 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
291 pub struct ChannelMask: FMOD_CHANNELMASK {
292 /// Front left channel.
293 const FRONT_LEFT = FMOD_CHANNELMASK_FRONT_LEFT;
294 /// Front right channel.
295 const FRONT_RIGHT = FMOD_CHANNELMASK_FRONT_RIGHT;
296 /// Front center channel.
297 const FRONT_CENTER = FMOD_CHANNELMASK_FRONT_CENTER;
298 /// Low frequency channel.
299 const LOW_FREQUENCY = FMOD_CHANNELMASK_LOW_FREQUENCY;
300 /// Surround left channel.
301 const SURROUND_LEFT = FMOD_CHANNELMASK_SURROUND_LEFT;
302 /// Surround right channel.
303 const SURROUND_RIGHT = FMOD_CHANNELMASK_SURROUND_RIGHT;
304 /// Back left channel.
305 const BACK_LEFT = FMOD_CHANNELMASK_BACK_LEFT;
306 /// Back right channel.
307 const BACK_RIGHT = FMOD_CHANNELMASK_BACK_RIGHT;
308 /// Back center channel, not represented in any [`FMOD_SPEAKERMODE`].
309 const BACK_CENTER = FMOD_CHANNELMASK_BACK_CENTER;
310 /// Mono channel mask.
311 const MONO = FMOD_CHANNELMASK_MONO;
312 /// Stereo channel mask.
313 const STEREO = FMOD_CHANNELMASK_STEREO;
314 /// Left / right / center channel mask.
315 const LRC = FMOD_CHANNELMASK_LRC;
316 /// Quadphonic channel mask.
317 const QUAD = FMOD_CHANNELMASK_QUAD;
318 /// 5.0 surround sound channel mask.
319 const SURROUND = FMOD_CHANNELMASK_SURROUND;
320 /// 5.1 surround sound channel mask.
321 const _5POINT1 = FMOD_CHANNELMASK_5POINT1;
322 /// 5.1 surround sound channel mask, using rears instead of surrounds.
323 const _5POINT1_REARS = FMOD_CHANNELMASK_5POINT1_REARS;
324 /// 7.0 surround sound channel mask.
325 const _7POINT0 = FMOD_CHANNELMASK_7POINT0;
326 /// 7.1 surround sound channel mask.
327 const _7POINT1 = FMOD_CHANNELMASK_7POINT1;
328 }
329}
330
331impl From<FMOD_CHANNELMASK> for ChannelMask {
332 fn from(value: FMOD_CHANNELMASK) -> Self {
333 ChannelMask::from_bits_truncate(value)
334 }
335}
336
337impl From<ChannelMask> for FMOD_CHANNELMASK {
338 fn from(value: ChannelMask) -> Self {
339 value.bits()
340 }
341}
342
343bitflags::bitflags! {
344 /// Flags that provide additional information about a particular driver.
345 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
346 pub struct DriverState: FMOD_DRIVER_STATE {
347 /// Device is currently plugged in.
348 const CONNECTED = FMOD_DRIVER_STATE_CONNECTED;
349 /// Device is the users preferred choice.
350 const DEFAULT = FMOD_DRIVER_STATE_DEFAULT;
351 }
352}
353
354impl From<FMOD_DRIVER_STATE> for DriverState {
355 fn from(value: FMOD_DRIVER_STATE) -> Self {
356 DriverState::from_bits_truncate(value)
357 }
358}
359
360impl From<DriverState> for FMOD_DRIVER_STATE {
361 fn from(value: DriverState) -> Self {
362 value.bits()
363 }
364}