fmod/core/sound/data_reading.rs
1// Copyright (c) 2024 Lily 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 std::ffi::c_uint;
8
9use fmod_sys::*;
10
11use crate::{OpenState, Sound};
12
13impl Sound {
14 /// Retrieves the state a sound is in after being opened with the non blocking flag, or the current state of the streaming buffer.
15 ///
16 /// When a sound is opened with FMOD_NONBLOCKING, it is opened and prepared in the background, or asynchronously.
17 /// This allows the main application to execute without stalling on audio loads.
18 /// This function will describe the state of the asynchronous load routine i.e. whether it has succeeded, failed or is still in progress.
19 ///
20 /// If 'starving' is true, then you will most likely hear a stuttering/repeating sound as the decode buffer loops on itself and replays old data.
21 /// With the ability to detect stream starvation, muting the sound with ChannelControl::setMute will keep the stream quiet until it is not starving any more.
22 ///
23 /// #### Note: Always check [`OpenState`] to determine the state of the sound.
24 /// Do not assume that if this function returns [`Ok`] then the sound has finished loading.
25 pub fn get_open_state(&self) -> Result<(OpenState, c_uint, bool, bool)> {
26 let mut open_state = 0;
27 let mut percent_buffered = 0;
28 let mut starving = FMOD_BOOL::FALSE;
29 let mut disk_busy = FMOD_BOOL::FALSE;
30 let error = unsafe {
31 FMOD_Sound_GetOpenState(
32 self.inner,
33 &mut open_state,
34 &mut percent_buffered,
35 &mut starving,
36 &mut disk_busy,
37 )
38 .to_error()
39 };
40
41 let open_state = OpenState::try_from_ffi(open_state, error)?;
42 let starving = starving.into();
43 let disk_busy = disk_busy.into();
44 Ok((open_state, percent_buffered, starving, disk_busy))
45 }
46
47 // TODO read, seek, lock, unlock
48}