about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-01-06 10:48:39 +0000
committerEric Wong <e@80x24.org>2017-01-06 11:12:53 +0000
commitbe14891fd17aa9c4c8e8b18c6c761c79cac99b05 (patch)
tree57322611ab01021ee37a3ca745164ffe296b1ec5
parentee92073d8d2d48eb7f070a8542430a7d5177e6bd (diff)
downloaddtas-be14891fd17aa9c4c8e8b18c6c761c79cac99b05.tar.gz
Seeing tiny (or zero) values for the "gain" effect is an eyesore
in process table output, and a waste of CPU cycles in sox.  So
stop using the "gain" effect for imperceptible changes in volume.

While we're at it, remove the pointless knobs for setting this,
too.  They were never documented and I doubt anybody would want
to tweak them at runtime.
-rw-r--r--lib/dtas/player/client_handler.rb3
-rw-r--r--lib/dtas/rg_state.rb11
-rw-r--r--test/test_rg_integration.rb2
-rw-r--r--test/test_rg_state.rb6
4 files changed, 11 insertions, 11 deletions
diff --git a/lib/dtas/player/client_handler.rb b/lib/dtas/player/client_handler.rb
index 05704c0..b17e90b 100644
--- a/lib/dtas/player/client_handler.rb
+++ b/lib/dtas/player/client_handler.rb
@@ -274,8 +274,7 @@ module DTAS::Player::ClientHandler # :nodoc:
       when "fallback_track"
         rv = set_bool(io, kv, v) { |b| @rg.fallback_track = b }
         rv == true or return rv
-      when %r{(?:gain_threshold|norm_threshold|
-              preamp|norm_level|fallback_gain|volume)[+-]?\z}x
+      when %r{(?:preamp|norm_level|fallback_gain|volume)[+-]?\z}x
         rv = adjust_numeric(io, @rg, k, v)
         rv == true or return rv
       end
diff --git a/lib/dtas/rg_state.rb b/lib/dtas/rg_state.rb
index 1452158..7af67e1 100644
--- a/lib/dtas/rg_state.rb
+++ b/lib/dtas/rg_state.rb
@@ -22,8 +22,6 @@ class DTAS::RGState # :nodoc:
   RG_DEFAULT = {
     "volume" => 1.0,
     # skip the effect if the adjustment is too small to be noticeable
-    "gain_threshold" => 0.00000001, # in dB
-    "norm_threshold" => 0.00000001,
 
     "preamp" => 0, # no extra adjustment
     # "mode" => "album_gain", # nil: off
@@ -73,23 +71,21 @@ class DTAS::RGState # :nodoc:
     when -1 then return 'gain -192'
     when 1 then return 'gain 192'
     else
-      sprintf('gain %0.8g', val).freeze
+      val.abs <= 0.00000001 and return
+      sprintf('gain %0.8f', val).freeze
     end
   end
 
   # returns a dB argument to the "gain" effect, nil if nothing found
   def rg_vol_gain(val)
     val = val.to_f + @preamp + vol_db
-    return if val.abs < @gain_threshold
     to_sox_gain(val)
   end
 
   # returns a DB argument to the "gain" effect
   def rg_vol_norm(val)
     n = @norm_level == 1.0 ? @volume : @norm_level
-    diff = n - val.to_f
-    return if (n - diff).abs < @norm_threshold
-    diff += n
+    diff = n * 2 - val.to_f
     to_sox_gain(linear_to_db(diff))
   end
 
@@ -99,7 +95,6 @@ class DTAS::RGState # :nodoc:
   # tag slips into the queue
   def rg_fallback_effect(reason)
     val = (@fallback_gain || 0) + @preamp + vol_db
-    return if val.abs < @gain_threshold
     warn(reason) if $DEBUG
     to_sox_gain(val)
   end
diff --git a/test/test_rg_integration.rb b/test/test_rg_integration.rb
index a932720..29dd29b 100644
--- a/test/test_rg_integration.rb
+++ b/test/test_rg_integration.rb
@@ -63,7 +63,7 @@ class TestRgIntegration < Testcase
 
     check_gain.call(%r{gain -3}, "album_gain")
     check_gain.call(%r{gain -2}, "track_gain")
-    check_gain.call(%r{gain 0\.0}, "album_peak")
+    check_gain.call(%r{gain 0\.}, "album_peak")
     check_gain.call(%r{gain 2\.5}, "track_peak")
 
     s.req_ok("rg preamp+=1")
diff --git a/test/test_rg_state.rb b/test/test_rg_state.rb
index 3a84216..59061a2 100644
--- a/test/test_rg_state.rb
+++ b/test/test_rg_state.rb
@@ -20,6 +20,12 @@ class TestRGState < Testcase
     assert_equal({"preamp" => 0.666}, rg.to_hsh)
   end
 
+  def test_rg_vol_norm
+    rg = DTAS::RGState.new
+    assert_nil rg.rg_vol_norm(0.999999999)
+    assert_match(%r{\Again 0.827}, rg.rg_vol_norm(0.9))
+  end
+
   def test_mode_set
     rg = DTAS::RGState.new
     orig = rg.mode