fmod/core/dsp/
mod.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 std::ptr::NonNull;
8
9use fmod_sys::*;
10
11mod callback;
12mod channel_format;
13mod connections;
14mod data_parameters;
15pub mod effects;
16mod general;
17mod metering;
18mod parameter_traits;
19mod parameters;
20mod processing;
21
22pub use callback::DspCallback;
23pub use data_parameters::*;
24pub use parameter_traits::*;
25
26#[cfg(doc)]
27use crate::System;
28
29/// A digital signal processor is one node within a graph that transforms input audio signals into an output stream.
30///
31/// Create with [`System::create_dsp`], [`System::create_dsp_by_type`] or [`System::create_dsp_by_plugin`].
32#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
33#[repr(transparent)] // so we can transmute between types
34pub struct Dsp {
35    pub(crate) inner: NonNull<FMOD_DSP>,
36}
37
38#[cfg(not(feature = "thread-unsafe"))]
39unsafe impl Send for Dsp {}
40#[cfg(not(feature = "thread-unsafe"))]
41unsafe impl Sync for Dsp {}
42
43impl Dsp {
44    /// # Safety
45    ///
46    /// `value` must be a valid pointer either aquired from [`Self::as_ptr`] or FMOD.
47    ///
48    /// # Panics
49    ///
50    /// Panics if `value` is null.
51    pub unsafe fn from_ffi(value: *mut FMOD_DSP) -> Self {
52        let inner = NonNull::new(value).unwrap();
53        Dsp { inner }
54    }
55
56    /// Converts `self` into its raw representation.
57    pub fn as_ptr(self) -> *mut FMOD_DSP {
58        self.inner.as_ptr()
59    }
60}
61
62impl From<Dsp> for *mut FMOD_DSP {
63    fn from(value: Dsp) -> Self {
64        value.inner.as_ptr()
65    }
66}