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