Rise
The Vieneo Province
Loading...
Searching...
No Matches
RcsAudio.h
Go to the documentation of this file.
1#pragma once
2
4
5namespace RcsAudio
6{
7 // rumble1.wav was linearly normalized by +10.913 dB to -0.10 dBTP
8 // (8x reconstruction). Undo that gain only inside the cockpit.
9 constexpr float RecordingGain = 3.5127828006f;
10 constexpr float CockpitGain = 1.f / RecordingGain;
11
12 inline float Level(float output, float limit)
13 {
14 if (!std::isfinite(output) || !std::isfinite(limit) || limit <= 0.f)
15 return 0.f;
16 return std::clamp(output / limit, 0.f, 1.f);
17 }
18
19 // Exterior mix only: keep the established cockpit rumble in propulsion.
20 // Positive Y is F9's downward exhaust (lift), negative Y is F8's upper set.
22 float downLimit, float upLimit, float lateralLimit, float bellyDepthKm, float roofHeightKm,
23 const RiseMath::Vector3& cameraFromVehicle, float yaw, float pitch, float roll,
24 const RiseMath::Matrix& bodyToCameraFrame)
25 {
26 float gain = 0.f, pan = 0.f;
27 const auto addSource = [&](float level, const RiseMath::Vector3& bodyPosition,
28 float referenceDistanceKm, bool downwardExhaust)
29 {
30 if (level <= 0.f) return;
31 RiseMath::Vector3 position;
32 RiseMath::Vec3TransformNormal(&position, &bodyPosition, &bodyToCameraFrame);
33 const auto relative = cameraFromVehicle - position;
34 const auto spatial = VehicleSoundSpatial::Calculate(relative, yaw, pitch, roll, referenceDistanceKm);
35 if (spatial.gain <= 0.f) return;
36 float directivity = 1.f;
37 const float distance = RiseMath::Vec3Length(&relative);
38 if (downwardExhaust && distance > .000001f)
39 {
40 const RiseMath::Vector3 down{0.f, -1.f, 0.f};
41 RiseMath::Vector3 exhaust;
42 RiseMath::Vec3TransformNormal(&exhaust, &down, &bodyToCameraFrame);
43 const float facing = std::clamp(RiseMath::Vec3Dot(&relative, &exhaust) / distance, -1.f, 1.f);
44 // Full level below the belly; the hull shields listeners above it.
45 // Camera look direction affects stereo pan, never exhaust loudness.
46 directivity += .6f * std::min(facing, 0.f);
47 }
48 const float audible = level * spatial.gain * directivity;
49 gain += audible;
50 pan += audible * spatial.pan;
51 };
52
53 // Hull dimensions provide a representative source, not an authored nozzle.
54 // Dustoff carries like the main rockets. Maneuvering jets stay local and
55 // peak at one quarter of its amplitude per axis (mix tuning, not SPL).
56 addSource(Level(output.y, downLimit), {0.f, -bellyDepthKm, 0.f}, .100f, true);
57 addSource(.25f * Level(-output.y, upLimit), {0.f, roofHeightKm, 0.f}, .005f, false);
58 addSource(.25f * Level(std::fabs(output.x), lateralLimit), {}, .005f, false);
59 // Fine longitudinal input is 0.002 km/s^2, independent of main throttle.
60 addSource(.25f * Level(std::fabs(output.z), .002f), {}, .005f, false);
61 return {std::min(gain, 1.f), gain > 0.f ? pan / gain : 0.f};
62 }
63}
VehicleSoundSpatial::Mix CalculateExterior(const RiseMath::Vector3 &output, float downLimit, float upLimit, float lateralLimit, float bellyDepthKm, float roofHeightKm, const RiseMath::Vector3 &cameraFromVehicle, float yaw, float pitch, float roll, const RiseMath::Matrix &bodyToCameraFrame)
Definition RcsAudio.h:21
constexpr float CockpitGain
Definition RcsAudio.h:10
float Level(float output, float limit)
Definition RcsAudio.h:12
constexpr float RecordingGain
Definition RcsAudio.h:9
float Vec3Length(const Vector3 *a)
Definition ClientMath.h:95
Vector3 * Vec3TransformNormal(Vector3 *out, const Vector3 *a, const Matrix *m)
Definition ClientMath.h:107
float Vec3Dot(const Vector3 *a, const Vector3 *b)
Definition ClientMath.h:93
Mix Calculate(const RiseMath::Vector3 &cameraFromVehicle, float yaw, float pitch, float roll, float referenceDistanceKm=.005f)