use super::types::*;
use crate::Position3D;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RoomSimulationSettings {
pub enabled: bool,
pub virtual_room: VirtualRoomParameters,
pub acoustic_matching: AcousticMatchingSettings,
pub cross_room_interaction: CrossRoomSettings,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VirtualRoomParameters {
pub dimensions: (f32, f32, f32),
pub materials: RoomMaterials,
pub layout: RoomLayout,
pub acoustic_properties: AcousticProperties,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RoomMaterials {
pub walls: Vec<MaterialProperties>,
pub floor: MaterialProperties,
pub ceiling: MaterialProperties,
pub objects: Vec<ObjectMaterial>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MaterialProperties {
pub name: String,
pub absorption: Vec<(f32, f32)>,
pub scattering: Vec<(f32, f32)>,
pub transmission: Vec<(f32, f32)>,
}
impl MaterialProperties {
pub fn default_wall() -> Self {
Self {
name: "Drywall".to_string(),
absorption: vec![
(125.0, 0.1),
(250.0, 0.05),
(500.0, 0.04),
(1000.0, 0.06),
(2000.0, 0.07),
(4000.0, 0.09),
],
scattering: vec![
(125.0, 0.1),
(250.0, 0.1),
(500.0, 0.1),
(1000.0, 0.1),
(2000.0, 0.1),
(4000.0, 0.1),
],
transmission: vec![
(125.0, 0.01),
(250.0, 0.005),
(500.0, 0.002),
(1000.0, 0.001),
(2000.0, 0.0005),
(4000.0, 0.0002),
],
}
}
pub fn default_floor() -> Self {
Self {
name: "Carpet".to_string(),
absorption: vec![
(125.0, 0.05),
(250.0, 0.1),
(500.0, 0.25),
(1000.0, 0.45),
(2000.0, 0.65),
(4000.0, 0.8),
],
scattering: vec![
(125.0, 0.2),
(250.0, 0.2),
(500.0, 0.2),
(1000.0, 0.2),
(2000.0, 0.2),
(4000.0, 0.2),
],
transmission: vec![
(125.0, 0.01),
(250.0, 0.01),
(500.0, 0.01),
(1000.0, 0.01),
(2000.0, 0.01),
(4000.0, 0.01),
],
}
}
pub fn default_ceiling() -> Self {
Self {
name: "Acoustic Tile".to_string(),
absorption: vec![
(125.0, 0.2),
(250.0, 0.3),
(500.0, 0.5),
(1000.0, 0.7),
(2000.0, 0.8),
(4000.0, 0.85),
],
scattering: vec![
(125.0, 0.15),
(250.0, 0.15),
(500.0, 0.15),
(1000.0, 0.15),
(2000.0, 0.15),
(4000.0, 0.15),
],
transmission: vec![
(125.0, 0.05),
(250.0, 0.03),
(500.0, 0.02),
(1000.0, 0.01),
(2000.0, 0.005),
(4000.0, 0.002),
],
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ObjectMaterial {
pub object_id: String,
pub position: Position3D,
pub dimensions: (f32, f32, f32),
pub material: MaterialProperties,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RoomLayout {
pub shape: RoomShape,
pub openings: Vec<Opening>,
pub furniture: Vec<FurnitureItem>,
pub user_positions: Vec<super::spatial::UserPosition>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Opening {
pub id: String,
pub opening_type: OpeningType,
pub geometry: OpeningGeometry,
pub acoustic_properties: OpeningAcoustics,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OpeningGeometry {
pub position: Position3D,
pub width: f32,
pub height: f32,
pub depth: f32,
pub orientation: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OpeningAcoustics {
pub open_state: f32,
pub transmission_coefficient: f32,
pub diffraction_coefficient: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FurnitureItem {
pub id: String,
pub furniture_type: FurnitureType,
pub geometry: FurnitureGeometry,
pub acoustic_impact: FurnitureAcoustics,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FurnitureGeometry {
pub position: Position3D,
pub dimensions: (f32, f32, f32),
pub rotation: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FurnitureAcoustics {
pub absorption: f32,
pub scattering: f32,
pub occlusion_factor: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AcousticProperties {
pub reverb_time: f32,
pub early_decay_time: f32,
pub clarity: f32,
pub definition: f32,
pub intimacy_time: f32,
pub background_noise: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AcousticMatchingSettings {
pub enabled: bool,
pub algorithm: AcousticMatchingAlgorithm,
pub strength: f32,
pub real_time_adaptation: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CrossRoomSettings {
pub enabled: bool,
pub inter_room_attenuation: f32,
pub isolation_level: f32,
pub shared_spaces: Vec<SharedSpace>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SharedSpace {
pub id: String,
pub space_type: SharedSpaceType,
pub connected_rooms: Vec<String>,
pub acoustic_properties: AcousticProperties,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DistanceModelingSettings {
pub enabled: bool,
pub attenuation_model: AttenuationModel,
pub air_absorption: AirAbsorptionSettings,
pub max_distance: f32,
pub near_field_compensation: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AirAbsorptionSettings {
pub enabled: bool,
pub temperature: f32,
pub humidity: f32,
pub pressure: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DopplerEffectsSettings {
pub enabled: bool,
pub factor_scaling: f32,
pub max_shift: f32,
pub smoothing: f32,
}
impl Default for RoomSimulationSettings {
fn default() -> Self {
Self {
enabled: true,
virtual_room: VirtualRoomParameters::default(),
acoustic_matching: AcousticMatchingSettings::default(),
cross_room_interaction: CrossRoomSettings::default(),
}
}
}
impl Default for VirtualRoomParameters {
fn default() -> Self {
Self {
dimensions: (8.0, 3.0, 6.0), materials: RoomMaterials::default(),
layout: RoomLayout::default(),
acoustic_properties: AcousticProperties::default(),
}
}
}
impl Default for RoomMaterials {
fn default() -> Self {
Self {
walls: vec![MaterialProperties::default_wall()],
floor: MaterialProperties::default_floor(),
ceiling: MaterialProperties::default_ceiling(),
objects: vec![],
}
}
}
impl Default for RoomLayout {
fn default() -> Self {
Self {
shape: RoomShape::Rectangular,
openings: vec![],
furniture: vec![],
user_positions: vec![],
}
}
}
impl Default for AcousticProperties {
fn default() -> Self {
Self {
reverb_time: 0.6, early_decay_time: 0.15,
clarity: 5.0,
definition: 0.7,
intimacy_time: 20.0,
background_noise: -45.0, }
}
}
impl Default for AcousticMatchingSettings {
fn default() -> Self {
Self {
enabled: false,
algorithm: AcousticMatchingAlgorithm::Direct,
strength: 0.7,
real_time_adaptation: false,
}
}
}
impl Default for CrossRoomSettings {
fn default() -> Self {
Self {
enabled: false,
inter_room_attenuation: 20.0, isolation_level: 0.8,
shared_spaces: vec![],
}
}
}
impl Default for DistanceModelingSettings {
fn default() -> Self {
Self {
enabled: true,
attenuation_model: AttenuationModel::InverseSquare,
air_absorption: AirAbsorptionSettings::default(),
max_distance: 50.0, near_field_compensation: true,
}
}
}
impl Default for AirAbsorptionSettings {
fn default() -> Self {
Self {
enabled: true,
temperature: 20.0, humidity: 50.0, pressure: 101325.0, }
}
}
impl Default for DopplerEffectsSettings {
fn default() -> Self {
Self {
enabled: true,
factor_scaling: 1.0,
max_shift: 500.0, smoothing: 0.8,
}
}
}