52 if (multiplier == 0.)
return DB_FLOOR;
53 else if (multiplier < 0.)
return multiplier_to_dB(-multiplier);
54 double dB = 10 * log10(multiplier);
61 if (dB == DB_FLOOR)
return 0.;
62 double m = pow(10., dB / 10.);
74 }
else if (db < -60.0f) {
75 def = (db + 70.0f) * 0.25f;
76 }
else if (db < -50.0f) {
77 def = (db + 60.0f) * 0.5f + 2.5f;
78 }
else if (db < -40.0f) {
79 def = (db + 50.0f) * 0.75f + 7.5f;
80 }
else if (db < -30.0f) {
81 def = (db + 40.0f) * 1.5f + 15.0f;
82 }
else if (db < -20.0f) {
83 def = (db + 30.0f) * 2.0f + 30.0f;
85 def = (db + 20.0f) * 2.5f + 50.0f;
96 db = (def - 50.0f) / 2.5f - 20.0f;
97 }
else if (def >= 30.0f) {
98 db = (def - 30.0f) / 2.0f - 30.0f;
99 }
else if (def >= 15.0f) {
100 db = (def - 15.0f) / 1.5f - 40.0f;
101 }
else if (def >= 7.5f) {
102 db = (def - 7.5f) / 0.75f - 50.0f;
103 }
else if (def >= 2.5f) {
104 db = (def - 2.5f) / 0.5f - 60.0f;
106 db = (def / 0.25f) - 70.0f;
115 if (level == 0)
return DB_FLOOR;
117 if (type == IEC268Meter || type == IEC268LongMeter) {
120 double percent = double(level) * maxPercent / double(maxLevel);
126 int zeroLevel = int(round(maxLevel * faderTypes[type].
zeroPoint));
128 if (level >= zeroLevel) {
130 double value = level - zeroLevel;
131 double scale = (maxLevel - zeroLevel) /
132 sqrt(faderTypes[type].
maxDb);
134 double dB = pow(value, 2.);
139 double value = zeroLevel - level;
140 double scale = zeroLevel / sqrt(0. - faderTypes[type].
minDb);
142 double dB = pow(value, 2.);
152 if (dB == DB_FLOOR)
return 0;
154 if (type == IEC268Meter || type == IEC268LongMeter) {
163 int faderLevel = int((maxLevel * percent) / maxPercent + 0.01f);
165 if (faderLevel < 0) faderLevel = 0;
166 if (faderLevel > maxLevel) faderLevel = maxLevel;
171 int zeroLevel = int(round(maxLevel * faderTypes[type].
zeroPoint));
175 if (faderTypes[type].
maxDb <= 0.) {
181 double value = sqrt(dB);
182 double scale = (maxLevel - zeroLevel) / sqrt(faderTypes[type].
maxDb);
184 int level = int(value + 0.01f) + zeroLevel;
185 if (level > maxLevel) level = maxLevel;
192 double value = sqrt(dB);
193 double scale = zeroLevel / sqrt(0. - faderTypes[type].
minDb);
195 int level = zeroLevel - int(value + 0.01f);
196 if (level < 0) level = 0;
206 if (level == 0)
return 0.;
207 return dB_to_multiplier(fader_to_dB(level, maxLevel, type));
213 if (multiplier == 0.)
return 0;
214 double dB = multiplier_to_dB(multiplier);
215 int fader = dB_to_fader(dB, maxLevel, type);
223 return multiplier_to_fader(m, levels, PreviewLevel);
230 return fader_to_multiplier(level, levels, PreviewLevel);
static double preview_to_multiplier(int level, int levels)
static double fader_to_multiplier(int level, int maxLevel, FaderType type)
static double multiplier_to_dB(double multiplier)
static int multiplier_to_preview(double multiplier, int levels)
static const double DB_FLOOR
static const FaderDescription faderTypes[]
static int multiplier_to_fader(double multiplier, int maxFaderLevel, FaderType type)
static double iec_dB_to_fader(double db)
FaderDescription(double _minDb, double _maxDb, double _zeroPoint)
static double iec_fader_to_dB(double def)
static int dB_to_fader(double dB, int maxFaderLevel, FaderType type)
static double fader_to_dB(int level, int maxLevel, FaderType type)
static double dB_to_multiplier(double dB)