JPL Spatial
Sound spatialization and propagation library
Loading...
Searching...
No Matches
SpeedOfSound.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
22#include "Math/Math.h"
23
24namespace JPL
25{
26 //==========================================================================
29 {
30 public:
31 // Speed of sound at reference temperature (20C)
32 static constexpr float cReference = 343.2f;
33 static constexpr float cInvReference = 1.0f / cReference;
34
35 //======================================================================
38 [[nodiscard]] static constexpr float ForTemperature(float temperatureC)
39 {
40 // ISO 9613-1, Equation A.5
41 // Note: speed of sound changes with humidity up to 0.3%,
42 // which is considered negligible.
43
44 constexpr float zeroC_Kelvin = 273.15f;
45 constexpr float invReferenceTemp = 1.0f / (20.0f + zeroC_Kelvin);
47 }
48
49 // TODO: speed of sound in uncommon environments like liquids and space
50 };
51
52 // TODO: move JPL_SPEED_OF_SOUND here, or include this header in Math header where JPL_SPEED_OF_SOUND currently is
53
54} // namespace JPL
Speed of sound utility.
Definition SpeedOfSound.h:29
static constexpr float ForTemperature(float temperatureC)
Definition SpeedOfSound.h:38
static constexpr float cReference
Definition SpeedOfSound.h:32
static constexpr float cInvReference
Definition SpeedOfSound.h:33
JPL_INLINE constexpr T Sqrt(T x) noexcept
Definition Math.h:269
Definition AcousticMaterial.h:36
JPL_INLINE simd min(const simd &a, const simd &b) noexcept
Element-wise min.
Definition SIMD.h:1813