fmod/core/dsp/
callback.rs1use fmod_sys::*;
8use std::ffi::c_void;
9
10use crate::panic_wrapper;
11
12use super::Dsp;
13use crate::{FmodResultExt, Result};
14
15pub trait DspCallback {
19 fn data_parameter_release(dsp: Dsp, info: FMOD_DSP_DATA_PARAMETER_INFO) -> Result<()>;
22}
23
24unsafe extern "C" fn callback_impl<C: DspCallback>(
25 dsp: *mut FMOD_DSP,
26 kind: FMOD_DSP_CALLBACK_TYPE,
27 data: *mut c_void,
28) -> FMOD_RESULT {
29 panic_wrapper(|| {
30 let dsp = unsafe { Dsp::from_ffi(dsp) };
31 #[allow(clippy::single_match_else)]
33 let result = match kind {
34 FMOD_DSP_CALLBACK_DATAPARAMETERRELEASE => {
35 let info = unsafe { std::ptr::read(data.cast()) };
36 C::data_parameter_release(dsp, info)
37 }
38 _ => {
39 eprintln!("warning: unknown dsp callback type {kind}");
40 return FMOD_RESULT::FMOD_OK;
41 }
42 };
43 FMOD_RESULT::from_result(result)
44 })
45}
46
47impl Dsp {
48 pub fn set_callback<C: DspCallback>(&self) -> Result<()> {
50 unsafe { FMOD_DSP_SetCallback(self.inner.as_ptr(), Some(callback_impl::<C>)).to_result() }
51 }
52}