39 lines
1.7 KiB
C++
39 lines
1.7 KiB
C++
// master_gain.h — dB<->linear<->knob-taper math for the post-mixer master gain.
|
|
// One shared formula so the drawn needle, the persisted value, and the audio-thread
|
|
// multiply can't drift. Norm 0 = true zero gain (not an epsilon); persisted value is
|
|
// linear gain, the dB taper is a UI-side view of it. Unity (0 dB) sits at ~0.714 norm.
|
|
// RT: the processor applies the linear gain as one multiply over the summed output;
|
|
// these functions themselves run on UI/state threads only.
|
|
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
|
|
namespace reasampler::instrument::engine {
|
|
|
|
// norm 0 is -inf (true zero); norm just above 0 starts at the finite floor kMasterGainMinDb
|
|
// and sweeps linearly in dB to kMasterGainMaxDb at norm 1.
|
|
inline constexpr double kMasterGainMinDb = -60.0;
|
|
inline constexpr double kMasterGainMaxDb = 24.0;
|
|
|
|
// Largest linear gain the control can produce (kMasterGainMaxDb as a ratio, ~15.849).
|
|
double masterGainMaxLinear();
|
|
|
|
double masterGainDbFromNorm(double norm);
|
|
|
|
// Anything at or below kMasterGainMinDb (including -inf) collapses to norm 0 — the finite
|
|
// sweep only covers the range above the floor.
|
|
double masterGainNormFromDb(double db);
|
|
|
|
double masterGainLinearFromNorm(double norm);
|
|
|
|
// linear <= 0, or at/below the kMasterGainMinDb floor, collapses to norm 0 — values between
|
|
// true-zero and the floor aren't representable on the knob. Out-of-range/non-finite clamps.
|
|
double masterGainNormFromLinear(double linear);
|
|
|
|
// "-inf" at the bottom, else a signed one-decimal dB string ("-12.0dB", "+2.4dB").
|
|
// Writes at most `len` bytes including the terminator.
|
|
void formatMasterGainLabel(double norm, char* buf, std::size_t len);
|
|
|
|
} // namespace reasampler::instrument::engine
|