1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use super::misc::DEFAULT_LISTENING_ROOM_RT60_S;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
/// Room dimensions for automatic Schroeder frequency calculation
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct RoomDimensions {
/// Length in meters
pub length: f64,
/// Width in meters
pub width: f64,
/// Height in meters
pub height: f64,
}
impl RoomDimensions {
/// Calculate the Schroeder frequency from room dimensions using a
/// default RT60 assumption of [`DEFAULT_LISTENING_ROOM_RT60_S`].
///
/// See [`Self::schroeder_frequency_with_rt60`] for the underlying
/// formula and the meaning of the Schroeder frequency. The previous
/// implementation of this function used `11885 / √V`, which is
/// equivalent to the correct formula `2000 · √(RT60 / V)` with an
/// implicit RT60 of ~35 s — a value appropriate to a cathedral,
/// not a listening room. That bug inflated the computed Schroeder
/// frequency by roughly an order of magnitude for every small-room
/// caller.
pub fn schroeder_frequency(&self) -> f64 {
self.schroeder_frequency_with_rt60(DEFAULT_LISTENING_ROOM_RT60_S)
}
/// Calculate the Schroeder frequency from room dimensions and a
/// known RT60 (reverberation time to −60 dB, in seconds).
///
/// Uses Schroeder's engineering formula
/// `f_S ≈ 2000 · √(RT60 / V)` where V is the room volume in m³
/// and the result is in Hz. This is the canonical crossover
/// between the modal region (discrete resonances, where narrow EQ
/// cuts are effective and boosts cannot fill nulls) and the
/// diffuse region (statistical mode overlap, where broadband
/// correction works).
pub fn schroeder_frequency_with_rt60(&self, rt60_seconds: f64) -> f64 {
let volume = self.length * self.width * self.height;
if volume <= 0.0 || rt60_seconds <= 0.0 {
return 0.0;
}
2000.0 * (rt60_seconds / volume).sqrt()
}
}