Skip to content

Commit

Permalink
Integrate the DirectEffect with the FMOD plugin (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
GitGhillie authored Sep 8, 2024
1 parent 48d7cef commit 74d7ef0
Show file tree
Hide file tree
Showing 14 changed files with 1,143 additions and 404 deletions.
8 changes: 5 additions & 3 deletions crates/phonon-fmod/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ repository = "https://github.com/GitGhillie/phonon_rs"
crate-type = ["cdylib", "lib"]

[dependencies]
libfmod = "~2.222.3"
#libfmod = { path = "../../../libfmod/libfmod" }
phonon = { path = "../phonon" }
libfmod = "~2.222.4"
glam = "0.27" # todo how do we ensure the same version is used accross the different crates in the workspace?
strum = { version = "0.26", features = ["derive"] }

[[example]]
name = "manual_registration"

[[example]]
name = "create_dsp"
name = "create_dsp"
55 changes: 46 additions & 9 deletions crates/phonon-fmod/examples/create_dsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
// Mostly copied from libfmod's examples

use libfmod::ffi::{
FMOD_3D_ATTRIBUTES, FMOD_DSP_PARAMETER_3DATTRIBUTES, FMOD_INIT_NORMAL, FMOD_LOOP_NORMAL,
FMOD_VECTOR,
};
use libfmod::{Error, System};
use phonon::direct_simulator::DirectSoundPath;
use phonon_fmod::create_dsp_description;
use std::io;
use std::io::BufRead;

use libfmod::ffi::{FMOD_INIT_NORMAL, FMOD_LOOP_NORMAL};
use libfmod::{DspDescription, Error, System};
use phonon_fmod::create_dsp_description;
use std::os::raw::c_void;

fn main() -> Result<(), Error> {
let system = System::create()?;
Expand All @@ -18,7 +22,7 @@ fn main() -> Result<(), Error> {
let sound = system.create_sound("./data/audio/windless_slopes.ogg", FMOD_LOOP_NORMAL, None)?;
system.play_sound(sound, None, false)?;

let desc = DspDescription::try_from(create_dsp_description())?;
let desc = create_dsp_description();
let mydsp = system.create_dsp(desc)?;
let mastergroup = system.get_master_channel_group()?;
mastergroup.add_dsp(0, mydsp)?;
Expand All @@ -32,17 +36,50 @@ fn main() -> Result<(), Error> {
mydsp.set_bypass(false)?;
}
3 => {
mydsp.set_parameter_float(0, 0.2)?;
//mydsp.set_parameter_float(0, 0.2)?;
let mut attributes = FMOD_DSP_PARAMETER_3DATTRIBUTES {
relative: FMOD_3D_ATTRIBUTES {
position: FMOD_VECTOR {
x: -20.0,
y: 0.0,
z: 0.0,
},
velocity: Default::default(),
forward: Default::default(),
up: Default::default(),
},
absolute: Default::default(),
};
let attributes_ptr = &mut attributes as *mut _ as *mut c_void;
let attributes_size = std::mem::size_of::<FMOD_DSP_PARAMETER_3DATTRIBUTES>();

let mut direct_sound_path = DirectSoundPath {
distance_attenuation: 0.5,
air_absorption: [1.0, 1.0, 1.0],
delay: 0.0,
occlusion: 1.0,
transmission: [1.0, 1.0, 1.0],
directivity: 0.0,
};
let sound_path_ptr = &mut direct_sound_path as *mut _ as *mut c_void;
let sound_path_size = std::mem::size_of::<DirectSoundPath>();

// set 3d attributes
mydsp.set_parameter_data(0, attributes_ptr, attributes_size as u32)?;
// enable/disable distance attenuation
mydsp.set_parameter_int(2, 1)?;
// set direct sound path
mydsp.set_parameter_data(10, sound_path_ptr, sound_path_size as u32)?
}
4 => {
let (value, _) = mydsp.get_parameter_float(0, 0)?;
println!("volume: {}", value);
//let (value, _) = mydsp.get_parameter_float(0, 0)?;
//println!("volume: {}", value);
}
_ => {}
}
}
let info = mydsp.get_parameter_info(0)?;
println!("default: {}", unsafe { info.union.floatdesc.defaultval });
//println!("default: {}", unsafe { info.union.floatdesc.defaultval });

println!("Press Enter to exit.");
let stdin = io::stdin();
Expand Down
4 changes: 2 additions & 2 deletions crates/phonon-fmod/examples/manual_registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ use std::io;
use std::io::BufRead;

use libfmod::ffi::FMOD_INIT_NORMAL;
use libfmod::{DspDescription, Error, System};
use libfmod::{Error, System};
use phonon_fmod::create_dsp_description;

fn main() -> Result<(), Error> {
let system = System::create()?;
system.init(32, FMOD_INIT_NORMAL, None)?;

let desc = DspDescription::try_from(create_dsp_description())?;
let desc = create_dsp_description();
system.register_dsp(desc)?;

println!("Press Enter to exit.");
Expand Down
Loading

0 comments on commit 74d7ef0

Please sign in to comment.