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