fmod/core/channel_control/
dsp.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_int;
8
9use fmod_sys::*;
10
11use crate::{ChannelControl, Dsp};
12
13impl ChannelControl {
14    pub const DSP_HEAD: FMOD_CHANNELCONTROL_DSP_INDEX = FMOD_CHANNELCONTROL_DSP_HEAD;
15    pub const DSP_TAIL: FMOD_CHANNELCONTROL_DSP_INDEX = FMOD_CHANNELCONTROL_DSP_TAIL;
16    pub const DSP_FADER: FMOD_CHANNELCONTROL_DSP_INDEX = FMOD_CHANNELCONTROL_DSP_FADER;
17
18    /// Adds a DSP unit to the specified index in the DSP chain.
19    ///
20    /// If dsp is already added to an existing object it will be removed and then added to this object.
21    ///
22    /// For detailed information on FMOD's DSP network, read the DSP Architecture and Usage white paper.
23    pub fn add_dsp(&self, index: c_int, dsp: Dsp) -> Result<()> {
24        unsafe { FMOD_ChannelControl_AddDSP(self.inner, index, dsp.inner).to_result() }
25    }
26
27    /// Removes the specified DSP unit from the DSP chain.
28    pub fn remove_dsp(&self, dsp: Dsp) -> Result<()> {
29        unsafe { FMOD_ChannelControl_RemoveDSP(self.inner, dsp.inner).to_result() }
30    }
31
32    /// Retrieves the number of DSP units in the DSP chain.
33    pub fn get_dsp_count(&self) -> Result<c_int> {
34        let mut count = 0;
35        unsafe {
36            FMOD_ChannelControl_GetNumDSPs(self.inner, &mut count).to_result()?;
37        }
38        Ok(count)
39    }
40
41    /// Retrieves the DSP unit at the specified index in the DSP chain.
42    pub fn get_dsp(&self, index: c_int) -> Result<Dsp> {
43        let mut dsp = std::ptr::null_mut();
44        unsafe {
45            FMOD_ChannelControl_GetDSP(self.inner, index, &mut dsp).to_result()?;
46        }
47        Ok(Dsp { inner: dsp })
48    }
49
50    /// Sets the index in the DSP chain of the specified DSP.
51    ///
52    /// This will move a DSP already in the DSP chain to a new offset.
53    pub fn set_dsp_index(&self, dsp: Dsp, index: c_int) -> Result<()> {
54        unsafe { FMOD_ChannelControl_SetDSPIndex(self.inner, dsp.inner, index).to_result() }
55    }
56
57    /// Retrieves the index of a DSP inside the Channel or ChannelGroup's DSP chain.
58    pub fn get_dsp_index(&self, dsp: Dsp) -> Result<c_int> {
59        let mut index = 0;
60        unsafe {
61            FMOD_ChannelControl_GetDSPIndex(self.inner, dsp.inner, &mut index).to_result()?;
62        }
63        Ok(index)
64    }
65}