diff options
Diffstat (limited to 'src/devices/machine/rescap.h')
-rw-r--r-- | src/devices/machine/rescap.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/devices/machine/rescap.h b/src/devices/machine/rescap.h index 71b9cd55216..b558f2d3a0c 100644 --- a/src/devices/machine/rescap.h +++ b/src/devices/machine/rescap.h @@ -26,6 +26,24 @@ constexpr double RES_VOLTAGE_DIVIDER(double r1, double r2) { return r2 / (r1 + r #define RES_2_SERIAL(r1,r2) ((r1)+(r2)) +// Audio taper (aka "logarithmic") potentiometer law. +// `x` should be in the range 0-1, and so is the return value. +inline double RES_AUDIO_POT_LAW(double x) +{ + // The implementation is that of an ideal log potentiometer, based on: + // https://electronics.stackexchange.com/questions/304692/formula-for-logarithmic-audio-taper-pot + + // Note that most audio potentiometers are not ideal, but they try to + // approximate this curve. + + // The 10% midpoint ("A2" potentiometer curve) is typical for audio + // applications. See any datasheet for a log potentiometer. + constexpr const double MIDPOINT = 0.1; + constexpr const double B = (1.0 / MIDPOINT - 1.0) * (1.0 / MIDPOINT - 1.0); // pow(1.0 / MIDPOINT - 1.0, 2); + constexpr const double A = 1.0 / (B - 1.0); + return A * pow(B, x) - A; +} + // macro for the RC time constant on a 74LS123 with C > 1000pF // R is in ohms, C is in farads constexpr double TIME_OF_74LS123(double r, double c) { return 0.45 * r * c; } |