fmod/core/dsp/
processing.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::ffi::c_float;
9
10use crate::Dsp;
11
12impl Dsp {
13    /// Sets the processing active state.
14    ///
15    /// If active is false, processing of this unit and its inputs are stopped.
16    ///
17    /// When created a [`Dsp`] is inactive. If ChannelControl::addDSP is used it will automatically be activated, otherwise it must be set to active manually.
18    pub fn set_active(&self, active: bool) -> Result<()> {
19        unsafe { FMOD_DSP_SetActive(self.inner, active.into()).to_result() }
20    }
21
22    /// Retrieves the processing active state.
23    ///
24    /// If active is False, processing of this unit and its inputs are stopped.
25    ///
26    /// When created a [`Dsp`] is inactive.
27    /// If ChannelControl::addDSP is used it will automatically be activated, otherwise it must be set to active manually.
28    pub fn get_active(&self) -> Result<bool> {
29        let mut active = FMOD_BOOL::FALSE;
30        unsafe { FMOD_DSP_GetActive(self.inner, &mut active).to_result()? };
31        Ok(active.into())
32    }
33
34    /// Sets the processing bypass state.
35    ///
36    /// If `bypass` is true, processing of this unit is skipped but it continues to process its inputs.
37    pub fn set_bypass(&self, bypass: bool) -> Result<()> {
38        unsafe { FMOD_DSP_SetBypass(self.inner, bypass.into()).to_result() }
39    }
40
41    /// Retrieves the processing bypass state.
42    ///
43    /// If `bypass` is true, processing of this unit is skipped but it continues to process its inputs.
44    pub fn get_bypass(&self) -> Result<bool> {
45        let mut bypass = FMOD_BOOL::FALSE;
46        unsafe { FMOD_DSP_GetBypass(self.inner, &mut bypass).to_result()? };
47        Ok(bypass.into())
48    }
49
50    /// Sets the scale of the wet and dry signal components.
51    ///
52    /// The dry signal path is silent by default, because dsp effects transform the input and pass the newly processed result to the output.
53    pub fn set_wet_dry_mix(&self, pre_wet: c_float, post_wet: c_float, dry: c_float) -> Result<()> {
54        unsafe { FMOD_DSP_SetWetDryMix(self.inner, pre_wet, post_wet, dry).to_result() }
55    }
56
57    /// Retrieves the scale of the wet and dry signal components.
58    pub fn get_wet_dry_mix(&self) -> Result<(c_float, c_float, c_float)> {
59        let mut pre_wet = 0.0;
60        let mut post_wet = 0.0;
61        let mut dry = 0.0;
62        unsafe {
63            FMOD_DSP_GetWetDryMix(self.inner, &mut pre_wet, &mut post_wet, &mut dry).to_result()?;
64        }
65        Ok((pre_wet, post_wet, dry))
66    }
67
68    /// Retrieves the idle state.
69    ///
70    /// A [`Dsp`] is considered idle when it stops receiving input signal and all internal processing of stored input has been exhausted.
71    ///
72    /// Each [`Dsp`] type has the potential to have differing idle behaviour based on the type of effect.
73    /// A reverb or echo may take a longer time to go idle after it stops receiving a valid signal, compared to an effect with a shorter tail length like an EQ filter.
74    pub fn get_idle(&self) -> Result<bool> {
75        let mut idle = FMOD_BOOL::FALSE;
76        unsafe { FMOD_DSP_GetIdle(self.inner, &mut idle).to_result()? };
77        Ok(idle.into())
78    }
79}