JPL Spatial
Sound spatialization and propagation library
Loading...
Searching...
No Matches
ReverbUtilities.h
Go to the documentation of this file.
1//
2// ██╗██████╗ ██╗ ██╗██████╗ ███████╗
3// ██║██╔══██╗ ██║ ██║██╔══██╗██╔════╝ ** JPL Spatial **
4// ██║██████╔╝ ██║ ██║██████╔╝███████╗
5// ██ ██║██╔═══╝ ██║ ██║██╔══██╗╚════██║ https://github.com/Jaytheway/JPLSpatial
6// ╚█████╔╝██║ ███████╗██║██████╔╝███████║
7// ╚════╝ ╚═╝ ╚══════╝╚═╝╚═════╝ ╚══════╝
8//
9// Copyright 2026 Jaroslav Pevno, JPL Spatial is offered under the terms of the ISC license:
10//
11// Permission to use, copy, modify, and/or distribute this software for any purpose with or
12// without fee is hereby granted, provided that the above copyright notice and this permission
13// notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
14// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
16// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20#pragma once
21#include "JPLSpatial/Core.h"
26
27#include <cmath>
28#include <numbers>
29#include <span>
30#include <vector>
31
32namespace JPL
33{
34
35 //======================================================================
39 [[nosiscard]] JPL_INLINE simd EstimateRT60_Sabine(float w, float l, float h, const simd& avgAbsorption);
40
42 [[nosiscard]] JPL_INLINE simd EstimateRT60_Sabine(float w, float l, float h, const simd& avgAbsorption, const simd& airAttenuation_dB);
43
44 // Note: we keep Sabine estimator for material workflows/measures,
45 // because absorption coefficients found online often assume Sabine measure.
46
50 [[nosiscard]] JPL_INLINE simd EstimateRT60_Eyring(float w, float l, float h, const simd& avgAbsorption);
51
53 [[nosiscard]] JPL_INLINE simd EstimateRT60_Eyring(float w, float l, float h, const simd& avgAbsorption, const simd& airAttenuation_dB);
54
55} // namespace JPL
56
57//==============================================================================
58//
59// Code beyond this point is implementation detail...
60//
61//==============================================================================
62
63namespace JPL
64{
65
66 //======================================================================
67 namespace Impl
68 {
69 struct Sabine
70 {
72 {
73 return surface * avgAbsorption;
74 }
75 };
76
77 struct Eyring
78 {
80 {
81 return -surface * log(simd(1.0f) - avgAbsorption);
82 }
83 };
84
86 {
87 // Air attenuation as reciprocal meters (1/m).
88 // I.e. dB converted to Nepers
89 static const float napersCoeff = 1.0f / (10.0f * ::log10(std::numbers::e_v<float>));
91 return 4.0f * m * volume;
92 }
93
94 template<class SurfaceFactor>
95 [[nodiscard]] JPL_INLINE simd EstimateRT60(float w, float l, float h, const simd& avgAbsorption)
96 {
97 static const simd K(0.161f); // room constant
98 const float surface = 2.0f * (l * w + l * h + w * h);
99 const float volume = w * l * h;
100 return simd(K * volume) / SurfaceFactor::Compute(surface, avgAbsorption);
101 }
102
103 template<class SurfaceFactor>
105 {
106 static const simd K(0.161f); // room constant
107 const float surface = 2.0f * (l * w + l * h + w * h);
108 const float volume = w * l * h;
109 return simd(K * volume) /
111 }
112
113 } // namespace Impl
114
115
117 {
118 return Impl::EstimateRT60<Impl::Sabine>(w, l, h, avgAbsorption);
119 }
120
122 {
123 return Impl::EstimateRT60<Impl::Sabine>(w, l, h, avgAbsorption, airAttenuation_dB);
124
125 }
126
128 {
129 return Impl::EstimateRT60<Impl::Eyring>(w, l, h, avgAbsorption);
130 }
131
133 {
134 return Impl::EstimateRT60<Impl::Eyring>(w, l, h, avgAbsorption, airAttenuation_dB);
135 }
136
137} // namespace JPL
JPL_INLINE simd ComputeAirAbsorptionFactor(float volume, const simd &airAttenuation_dB)
Definition ReverbUtilities.h:85
JPL_INLINE simd EstimateRT60(float w, float l, float h, const simd &avgAbsorption)
Definition ReverbUtilities.h:95
Definition AcousticMaterial.h:36
JPL_INLINE simd EstimateRT60_Sabine(float w, float l, float h, const simd &avgAbsorption)
Definition ReverbUtilities.h:116
JPL_INLINE simd EstimateRT60_Eyring(float w, float l, float h, const simd &avgAbsorption)
Definition ReverbUtilities.h:127
simd log(simd x) noexcept
Definition SIMDMath.h:191
JPL_INLINE simd min(const simd &a, const simd &b) noexcept
Element-wise min.
Definition SIMD.h:1813
JPL_INLINE simd log10(const simd &vec) noexcept
log10 for 4-wide 32-bit float vector
Definition SIMDMath.h:241
Definition ReverbUtilities.h:78
static JPL_INLINE simd Compute(float surface, const simd &avgAbsorption)
Definition ReverbUtilities.h:79
Definition ReverbUtilities.h:70
static JPL_INLINE simd Compute(float surface, const simd &avgAbsorption)
Definition ReverbUtilities.h:71
Minimal 4-wide 32-bit float vector implementation for SIMD.
Definition SIMD.h:60