From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 208.118.235.0/24 X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,URIBL_BLOCKED shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: dtas-all@80x24.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 0185D1F733 for ; Thu, 7 May 2015 08:41:50 +0000 (UTC) Received: from localhost ([::1]:49487 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqHNO-0003l9-5J for dtas-all@80x24.org; Thu, 07 May 2015 04:41:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqHMy-0003HE-Ka for dtas-all@nongnu.org; Thu, 07 May 2015 04:41:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YqHMv-0003F2-8M for dtas-all@nongnu.org; Thu, 07 May 2015 04:41:24 -0400 Received: from dcvr.yhbt.net ([64.71.152.64]:39673) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqHMv-0003El-2a for dtas-all@nongnu.org; Thu, 07 May 2015 04:41:21 -0400 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 754501F725; Thu, 7 May 2015 08:41:19 +0000 (UTC) From: Eric Wong To: Subject: [PATCH] replaygain uses the "gain" effect instead of "vol" Date: Thu, 7 May 2015 08:41:17 +0000 Message-Id: <1430988077-940-1-git-send-email-e@80x24.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.71.152.64 Cc: Eric Wong X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+dtas-all=80x24.org@nongnu.org Sender: dtas-all-bounces+dtas-all=80x24.org@nongnu.org The `gain' effect seems superior as it can "see" across the effects chain to take into account extra/lost headroom. For example, this allows me to add the the "gain -h" effect at the start of my effects chain before the RGFX placeholder in my source command, so when I play a file requiring a -6dB ReplayGain adjustment, I will only need an additional -4dB of headroom to accomodate the 10dB boost at 20Hz I use (for listening through headphones): Before: RGFX='vol -6dB' sox "$INFILE" $SOXFMT - $TRIMFX $RGFX vol -10dB equalizer 20 0.7071q 10 After: RGFX='gain -6' sox "$INFILE" $SOXFMT - $TRIMFX gain -h $RGFX equalizer 20 0.7071q 10 --- lib/dtas/rg_state.rb | 12 +++++++----- test/test_rg_integration.rb | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/dtas/rg_state.rb b/lib/dtas/rg_state.rb index 6ab31b9..b124098 100644 --- a/lib/dtas/rg_state.rb +++ b/lib/dtas/rg_state.rb @@ -5,8 +5,10 @@ # MAYBE: account for non-standard reference loudness (89.0 dB is standard) require_relative '../dtas' require_relative 'serialize' +require_relative 'util' class DTAS::RGState # :nodoc: include DTAS::Serialize + include DTAS::Util RG_MODE = { # attribute name => method to use @@ -53,19 +55,19 @@ class DTAS::RGState # :nodoc: to_hash.delete_if { |k,v| RG_DEFAULT[k] == v } end - # returns a dB argument to the "vol" effect, nil if nothing found + # returns a dB argument to the "gain" effect, nil if nothing found def rg_vol_gain(val) val = val.to_f + @preamp return if val.abs < @gain_threshold - sprintf('vol %0.8gdB', val) + sprintf('gain %0.8g', val) end - # returns a linear argument to the "vol" effect + # returns a DB argument to the "gain" effect def rg_vol_norm(val) diff = @norm_level - val.to_f return if (@norm_level - diff).abs < @norm_threshold diff += @norm_level - sprintf('vol %0.8g', diff) + sprintf('gain %0.8g', linear_to_db(diff)) end # The ReplayGain fallback adjustment value (in dB), in case a file is @@ -77,7 +79,7 @@ class DTAS::RGState # :nodoc: val = @fallback_gain + @preamp return if val.abs < @gain_threshold warn(reason) if $DEBUG - "vol #{val}dB" + "gain #{val}" end # returns an array (for command-line argument) for the effect needed diff --git a/test/test_rg_integration.rb b/test/test_rg_integration.rb index f8e81c2..efc8f97 100644 --- a/test/test_rg_integration.rb +++ b/test/test_rg_integration.rb @@ -1,8 +1,10 @@ # Copyright (C) 2013-2015 all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) require './test/player_integration' +require 'dtas/util' class TestRgIntegration < Testcase include PlayerIntegration + include DTAS::Util def tmp_pluck(len = 5) pluck = Tempfile.open(%w(pluck .flac)) @@ -58,10 +60,10 @@ class TestRgIntegration < Testcase assert_match expect, cur["current"]["env"]["RGFX"] end - check_gain.call(%r{vol -3dB}, "album_gain") - check_gain.call(%r{vol -2dB}, "track_gain") - check_gain.call(%r{vol 1\.3}, "track_peak") - check_gain.call(%r{vol 1\.0}, "album_peak") + 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 2\.5}, "track_peak") s.req_ok("rg preamp+=1") rg = YAML.load(yaml = s.req("rg")) -- EW