diff options
author | Ben Loftis <ben@harrisonconsoles.com> | 2015-03-25 16:47:25 -0500 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2015-04-22 00:22:43 +0200 |
commit | 46f97e8d92241c94d12d81ea182a9172df98e61e (patch) | |
tree | f757e7014aa6260b7d927b35bcf1fd221e2d40e4 /libs/ardour/amp.cc | |
parent | 187ddb3bad70088f901ed1ea5e1402519fd393b4 (diff) |
Initial Gain Coefficient tweaks
1) Disambiguate 1.0 to GAIN_COEFF_UNITY, and 0.0 to GAIN_COEFF_ZERO
2) Add GAIN_COEFF_SMALL which replaces SMALL_SIGNAL (-140dB)
3) GAIN_COEFF_SMALL can used to avoid interpolating towards -inf on a db scale
4) GAIN_COEFF_SMALL is used to detect very small (denormal?) gains and memset to zero
Diffstat (limited to 'libs/ardour/amp.cc')
-rw-r--r-- | libs/ardour/amp.cc | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/libs/ardour/amp.cc b/libs/ardour/amp.cc index 523b538359..ac970fc581 100644 --- a/libs/ardour/amp.cc +++ b/libs/ardour/amp.cc @@ -40,7 +40,7 @@ Amp::Amp (Session& s) : Processor(s, "Amp") , _apply_gain(true) , _apply_gain_automation(false) - , _current_gain(1.0) + , _current_gain(GAIN_COEFF_UNITY) , _current_automation_frame (INT64_MAX) , _gain_automation_buffer(0) { @@ -115,7 +115,7 @@ Amp::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /*end_frame*/, _current_gain = Amp::apply_gain (bufs, _session.nominal_frame_rate(), nframes, _current_gain, dg); - } else if (_current_gain != 1.0f) { + } else if (_current_gain != GAIN_COEFF_UNITY) { /* gain has not changed, but its non-unity */ @@ -221,11 +221,11 @@ Amp::declick (BufferSet& bufs, framecnt_t nframes, int dir) if (dir < 0) { /* fade out: remove more and more of delta from initial */ delta = -1.0; - initial = 1.0; + initial = GAIN_COEFF_UNITY; } else { /* fade in: add more and more of delta from initial */ delta = 1.0; - initial = 0.0; + initial = GAIN_COEFF_ZERO; } /* Audio Gain */ @@ -275,15 +275,15 @@ Amp::apply_gain (AudioBuffer& buf, framecnt_t sample_rate, framecnt_t nframes, g lpf += a * (target - lpf); } - if (lpf < 1e-10) return 0; - if (fabsf(lpf - 1.0) < 1e-10) return 1.0; + if (lpf < 1e-10) return 0; // TODO use GAIN_COEFF_TINY or _DENORMAL + if (fabsf(lpf - GAIN_COEFF_UNITY) < 1e-10) return GAIN_COEFF_UNITY; return lpf; } void Amp::apply_simple_gain (BufferSet& bufs, framecnt_t nframes, gain_t target) { - if (target == 0.0) { + if (target < GAIN_COEFF_SMALL) { for (BufferSet::midi_iterator i = bufs.midi_begin(); i != bufs.midi_end(); ++i) { MidiBuffer& mb (*i); @@ -300,7 +300,7 @@ Amp::apply_simple_gain (BufferSet& bufs, framecnt_t nframes, gain_t target) memset (i->data(), 0, sizeof (Sample) * nframes); } - } else if (target != 1.0) { + } else if (target != GAIN_COEFF_UNITY) { for (BufferSet::midi_iterator i = bufs.midi_begin(); i != bufs.midi_end(); ++i) { MidiBuffer& mb (*i); @@ -322,9 +322,9 @@ Amp::apply_simple_gain (BufferSet& bufs, framecnt_t nframes, gain_t target) void Amp::apply_simple_gain (AudioBuffer& buf, framecnt_t nframes, gain_t target) { - if (target == 0.0) { + if (target < GAIN_COEFF_SMALL) { memset (buf.data(), 0, sizeof (Sample) * nframes); - } else if (target != 1.0) { + } else if (target != GAIN_COEFF_UNITY) { apply_gain_to_buffer (buf.data(), nframes, target); } } @@ -334,7 +334,7 @@ Amp::inc_gain (gain_t factor, void *src) { float desired_gain = _gain_control->user_double(); - if (desired_gain == 0.0f) { + if (desired_gain < GAIN_COEFF_SMALL) { set_gain (0.000001f + (0.000001f * factor), src); } else { set_gain (desired_gain + (desired_gain * factor), src); |