From 6014c181116a5f87836e564ae0ad8537a7298637 Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Thu, 17 Oct 2024 21:48:18 +0200 Subject: [PATCH] FMOD: Ability to switch between panning and binaural --- crates/phonon-fmod/src/lib.rs | 13 +++--- crates/phonon-fmod/src/parameter_init.rs | 30 +++++++++----- crates/phonon-fmod/src/parameter_spec.rs | 53 ++++++++++++------------ 3 files changed, 53 insertions(+), 43 deletions(-) diff --git a/crates/phonon-fmod/src/lib.rs b/crates/phonon-fmod/src/lib.rs index 9de7382..9339187 100644 --- a/crates/phonon-fmod/src/lib.rs +++ b/crates/phonon-fmod/src/lib.rs @@ -188,12 +188,13 @@ impl EffectState { self.direct_effect .apply(direct_params, &self.in_buffer_mono, &mut self.direct_buffer); - // todo ability to switch between panning and binaural - // self.panning_effect - // .apply(panning_params, &self.direct_buffer, &mut self.out_buffer); - - self.binaural_effect - .apply(binaural_params, &self.direct_buffer, &mut self.out_buffer); + if self.apply_hrtf { + self.binaural_effect + .apply(binaural_params, &self.direct_buffer, &mut self.out_buffer); + } else { + self.panning_effect + .apply(panning_params, &self.direct_buffer, &mut self.out_buffer); + } self.out_buffer.write_interleaved(out_buffer); } diff --git a/crates/phonon-fmod/src/parameter_init.rs b/crates/phonon-fmod/src/parameter_init.rs index fa3e784..36ac4ed 100644 --- a/crates/phonon-fmod/src/parameter_init.rs +++ b/crates/phonon-fmod/src/parameter_init.rs @@ -67,6 +67,7 @@ fn create_param_float( fn create_param_bool( name: &str, description: &'static str, + default: bool, value_names: [&'static str; 2], ) -> DspParameterDesc { let value_names_c: Vec<*mut c_char> = value_names @@ -85,7 +86,7 @@ fn create_param_bool( description: description.to_string(), union: FMOD_DSP_PARAMETER_DESC_UNION { booldesc: FMOD_DSP_PARAMETER_DESC_BOOL { - defaultval: 0, + defaultval: default as c_int, valuenames: Box::into_raw(value_names_c.into_boxed_slice()) as *const *const c_char, }, }, @@ -154,15 +155,20 @@ pub(crate) fn init_parameters() -> Vec { let param_apply_directivity = create_param_apply("ApplyDir", "Apply directivity."); let param_apply_occlusion = create_param_apply("ApplyOc", "Apply occlusion."); let param_apply_transmission = create_param_apply("ApplyTrans", "Apply transmission."); - // let param_apply_reflections = - // create_param_bool("ApplyReflections", "Apply reflections.", ["Off", "On"]); - // let param_apply_pathing = create_param_bool("ApplyPathing", "Apply pathing.", ["Off", "On"]); + let param_apply_reflections = create_param_bool( + "ApplyReflections", + "Apply reflections.", + true, + ["Off", "On"], + ); + let param_apply_pathing = + create_param_bool("ApplyPathing", "Apply pathing.", true, ["Off", "On"]); - // let param_hrtf_interpolation = create_param_int( - // "HrtfInterp", - // "HRTF Interpolation.", - // vec!["Nearest", "Bilinear"], - // ); + let param_hrtf_interpolation = create_param_int( + "HrtfInterp", + "HRTF Interpolation.", + vec!["Nearest", "Bilinear"], + ); let param_direct_sound_path = create_param_data( "DirectSoundPath", @@ -178,6 +184,7 @@ pub(crate) fn init_parameters() -> Vec { let param_direct_binaural = create_param_bool( "DirectBinaural", "Apply HRTF to direct path.", + true, ["Off", "On"], ); @@ -189,8 +196,9 @@ pub(crate) fn init_parameters() -> Vec { param_apply_directivity, param_apply_occlusion, param_apply_transmission, - //param_apply_reflections, - //param_apply_pathing, + param_apply_reflections, + param_apply_pathing, + param_hrtf_interpolation, param_direct_sound_path, param_directivity_dipole_weight, param_directivity_dipole_power, diff --git a/crates/phonon-fmod/src/parameter_spec.rs b/crates/phonon-fmod/src/parameter_spec.rs index 5258da4..bd39642 100644 --- a/crates/phonon-fmod/src/parameter_spec.rs +++ b/crates/phonon-fmod/src/parameter_spec.rs @@ -109,33 +109,34 @@ pub enum Params { */ ApplyTransmission, - // /** - // * **Type**: `FMOD_DSP_PARAMETER_TYPE_BOOL` - // * - // * If true, reflections are rendered, using the data calculated by the game engine using simulation, and provided - // * via the \c SimulationOutputs parameter. - // */ - // ApplyReflections, - // - // /** - // * **Type**: `FMOD_DSP_PARAMETER_TYPE_BOOL` - // * - // * If true, pathing is rendered, using the data calculated by the game engine using simulation, and provided - // * via the \c SimulationOutputs parameter. - // */ - // ApplyPathing, + /** + * **Type**: `FMOD_DSP_PARAMETER_TYPE_BOOL` + * + * If true, reflections are rendered, using the data calculated by the game engine using simulation, and provided + * via the \c SimulationOutputs parameter. + */ + ApplyReflections, + + /** + * **Type**: `FMOD_DSP_PARAMETER_TYPE_BOOL` + * + * If true, pathing is rendered, using the data calculated by the game engine using simulation, and provided + * via the \c SimulationOutputs parameter. + */ + ApplyPathing, + + /** + * **Type**: `FMOD_DSP_PARAMETER_TYPE_INT` + * + * **Range**: 0 to 1. + * + * Controls how HRTFs are interpolated when the source moves relative to the listener. + * + * - `0`: Nearest-neighbor interpolation. + * - `1`: Bilinear interpolation. + */ + HrtfInterpolation, - // /** - // * **Type**: `FMOD_DSP_PARAMETER_TYPE_INT` - // * - // * **Range**: 0 to 1. - // * - // * Controls how HRTFs are interpolated when the source moves relative to the listener. - // * - // * - `0`: Nearest-neighbor interpolation. - // * - `1`: Bilinear interpolation. - // */ - // HrtfInterpolation, /** * **Type**: `FMOD_DSP_PARAMETER_TYPE_DATA` *