1use std::{self, rc::Rc};
2use log;
3use crate::{ll, fmod_result, vector, Error, System};
4
5#[derive(Clone, Debug, PartialEq)]
6pub struct Reverb3d {
7 inner : Rc <Inner>,
8 system : System
9}
10
11#[derive(PartialEq)]
12struct Inner (*mut ll::FMOD_REVERB3D);
13
14#[derive(Clone, Debug, PartialEq)]
16pub struct Attributes {
17 pub position : [f32; 3],
18 pub mindistance : f32,
19 pub maxdistance : f32
20}
21
22pub mod presets;
23pub use presets::*;
24
25#[derive(Clone, Debug, PartialEq)]
33pub struct Properties {
34 pub decay_time : f32,
35 pub early_delay : f32,
36 pub late_delay : f32,
37 pub hf_reference : f32,
38 pub hf_decay_ratio : f32,
39 pub diffusion : f32,
40 pub density : f32,
41 pub low_shelf_frequency : f32,
42 pub low_shelf_gain : f32,
43 pub high_cut : f32,
44 pub early_late_mix : f32,
45 pub wet_level : f32
46}
47
48impl Reverb3d {
49 #[inline]
50 pub fn from_raw_parts (raw : *mut ll::FMOD_REVERB3D, system : System)
51 -> Self
52 {
53 let inner = Rc::new (Inner (raw));
54 Reverb3d { inner, system }
55 }
56
57 #[inline]
58 fn raw (&self) -> *mut ll::FMOD_REVERB3D {
59 self.inner.0
60 }
61
62 #[inline]
63 pub fn get_3d_attributes (&self) -> Result <Attributes, Error> {
64 let mut position = vector::to_ll ([0.0; 3]);
65 let mut mindistance = 0.0;
66 let mut maxdistance = 0.0;
67 unsafe {
68 fmod_result!(ll::FMOD_Reverb3D_Get3DAttributes (self.raw(),
69 &mut position, &mut mindistance, &mut maxdistance
70 ))?;
71 }
72 let attributes = Attributes {
73 position: [position.x, position.y, position.z],
74 mindistance,
75 maxdistance
76 };
77 Ok (attributes)
78 }
79
80 #[inline]
81 pub fn get_active (&self) -> Result <bool, Error> {
82 let mut active = 0;
83 unsafe {
84 fmod_result!(ll::FMOD_Reverb3D_GetActive (self.raw(), &mut active))?;
85 }
86 Ok (active != 0)
87 }
88
89 #[inline]
90 pub fn get_properties (&self) -> Result <Properties, Error> {
91 let mut properties = ll::FMOD_REVERB_PROPERTIES {
92 DecayTime: 0.0,
93 EarlyDelay: 0.0,
94 LateDelay: 0.0,
95 HFReference: 0.0,
96 HFDecayRatio: 0.0,
97 Diffusion: 0.0,
98 Density: 0.0,
99 LowShelfFrequency: 0.0,
100 LowShelfGain: 0.0,
101 HighCut: 0.0,
102 EarlyLateMix: 0.0,
103 WetLevel: 0.0
104 };
105 unsafe {
106 fmod_result!(
107 ll::FMOD_Reverb3D_GetProperties (self.raw(), &mut properties)
108 )?;
109 }
110 let properties = Properties::from_ll (&properties);
111 Ok (properties)
112 }
113
114}
115
116impl Properties {
117 #[inline]
118 pub const fn from_ll (properties : &ll::FMOD_REVERB_PROPERTIES) -> Self {
119 Properties {
120 decay_time: properties.DecayTime,
121 early_delay: properties.EarlyDelay,
122 late_delay: properties.LateDelay,
123 hf_reference: properties.HFReference,
124 hf_decay_ratio: properties.HFDecayRatio,
125 diffusion: properties.Diffusion,
126 density: properties.Density,
127 low_shelf_frequency: properties.LowShelfFrequency,
128 low_shelf_gain: properties.LowShelfGain,
129 high_cut: properties.HighCut,
130 early_late_mix: properties.EarlyLateMix,
131 wet_level: properties.WetLevel
132 }
133 }
134 #[inline]
135 pub const fn to_ll (&self) -> ll::FMOD_REVERB_PROPERTIES {
136 ll::FMOD_REVERB_PROPERTIES {
137 DecayTime: self.decay_time,
138 EarlyDelay: self.early_delay,
139 LateDelay: self.late_delay,
140 HFReference: self.hf_reference,
141 HFDecayRatio: self.hf_decay_ratio,
142 Diffusion: self.diffusion,
143 Density: self.density,
144 LowShelfFrequency: self.low_shelf_frequency,
145 LowShelfGain: self.low_shelf_gain,
146 HighCut: self.high_cut,
147 EarlyLateMix: self.early_late_mix,
148 WetLevel: self.wet_level
149 }
150 }
151}
152
153impl Default for Properties {
154 fn default() -> Self {
155 GENERIC.clone()
156 }
157}
158
159impl std::fmt::Debug for Inner {
160 fn fmt (&self, f : &mut std::fmt::Formatter) -> std::fmt::Result {
161 write!(f, "{:p}", self.0)
162 }
163}
164
165impl Drop for Inner {
166 fn drop (&mut self) {
167 unsafe {
168 let _ = fmod_result!(ll::FMOD_Reverb3D_Release (self.0)).map_err (
169 |err| log::error!("error releasing FMOD Reverb3D@{:p}: {:?}", self.0, err));
170 }
171 }
172}