fmod/core/dsp/
metering.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::*;
8use std::mem::MaybeUninit;
9
10use crate::{Dsp, DspMeteringInfo};
11use crate::{FmodResultExt, Result};
12
13impl Dsp {
14    /// Retrieve the signal metering information.
15    ///
16    /// Requesting metering information when it hasn't been enabled will result in [`FMOD_RESULT::FMOD_ERR_BADCOMMAND`].
17    ///
18    /// `FMOD_INIT_PROFILE_METER_ALL` with `SystemBuilder::build` will automatically enable metering for all [`Dsp`] units.
19    pub fn get_metering_info(&self) -> Result<(DspMeteringInfo, DspMeteringInfo)> {
20        let mut input = MaybeUninit::zeroed();
21        let mut output = MaybeUninit::zeroed();
22        unsafe {
23            FMOD_DSP_GetMeteringInfo(self.inner.as_ptr(), input.as_mut_ptr(), output.as_mut_ptr())
24                .to_result()?;
25            let input = input.assume_init().into();
26            let output = output.assume_init().into();
27            Ok((input, output))
28        }
29    }
30
31    /// Sets the input and output signal metering enabled states.
32    ///
33    /// Input metering is pre processing, while output metering is post processing.
34    ///
35    /// Enabled metering allows [`Dsp::get_metering_info`] to return metering information and allows FMOD profiling tools to visualize the levels.
36    ///
37    /// `FMOD_INIT_PROFILE_METER_ALL` with `SystemBuilder::build` will automatically turn on metering for all [`Dsp`] units inside the mixer graph.
38    ///
39    /// This function must have inputEnabled and outputEnabled set to true if being used by the FMOD Studio API,
40    /// such as in the Unity or Unreal Engine integrations, in order to avoid conflict with FMOD Studio's live update feature.
41    pub fn set_metering_enabled(&self, input_enabled: bool, output_enabled: bool) -> Result<()> {
42        unsafe {
43            FMOD_DSP_SetMeteringEnabled(
44                self.inner.as_ptr(),
45                input_enabled.into(),
46                output_enabled.into(),
47            )
48            .to_result()
49        }
50    }
51
52    /// Retrieves the input and output signal metering enabled states.
53    ///
54    /// Input metering is pre processing, while output metering is post processing.
55    ///
56    /// Enabled metering allows [`Dsp::get_metering_info`] to return metering information and allows FMOD profiling tools to visualize the levels.
57    ///
58    /// `FMOD_INIT_PROFILE_METER_ALL` with `SystemBuilder::build` will automatically turn on metering for all [`Dsp`] units inside the mixer graph.
59    pub fn get_metering_enabled(&self) -> Result<(bool, bool)> {
60        let mut input_enabled = FMOD_BOOL::FALSE;
61        let mut output_enabled = FMOD_BOOL::FALSE;
62        unsafe {
63            FMOD_DSP_GetMeteringEnabled(
64                self.inner.as_ptr(),
65                &raw mut input_enabled,
66                &raw mut output_enabled,
67            )
68            .to_result()?;
69        }
70        Ok((input_enabled.into(), output_enabled.into()))
71    }
72}