Skip to content

Commit

Permalink
FMOD: Ability to switch between panning and binaural
Browse files Browse the repository at this point in the history
  • Loading branch information
GitGhillie committed Oct 17, 2024
1 parent cc748ad commit 6014c18
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 43 deletions.
13 changes: 7 additions & 6 deletions crates/phonon-fmod/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
30 changes: 19 additions & 11 deletions crates/phonon-fmod/src/parameter_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
},
Expand Down Expand Up @@ -154,15 +155,20 @@ pub(crate) fn init_parameters() -> Vec<DspParameterDesc> {
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",
Expand All @@ -178,6 +184,7 @@ pub(crate) fn init_parameters() -> Vec<DspParameterDesc> {
let param_direct_binaural = create_param_bool(
"DirectBinaural",
"Apply HRTF to direct path.",
true,
["Off", "On"],
);

Expand All @@ -189,8 +196,9 @@ pub(crate) fn init_parameters() -> Vec<DspParameterDesc> {
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,
Expand Down
53 changes: 27 additions & 26 deletions crates/phonon-fmod/src/parameter_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
*
Expand Down

0 comments on commit 6014c18

Please sign in to comment.