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=-2.4 required=3.0 tests=AWL,BAYES_00,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 9D32663381C for ; Mon, 29 Dec 2014 04:26:21 +0000 (UTC) Received: from localhost ([::1]:60141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5RuP-0002L1-0w for dtas-all@80x24.org; Sun, 28 Dec 2014 23:26:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5RuK-0002KD-9o for dtas-all@nongnu.org; Sun, 28 Dec 2014 23:26:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y5RuG-0007ew-Qi for dtas-all@nongnu.org; Sun, 28 Dec 2014 23:26:16 -0500 Received: from dcvr.yhbt.net ([64.71.152.64]:60652) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5RuG-0007ek-L0 for dtas-all@nongnu.org; Sun, 28 Dec 2014 23:26:12 -0500 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 5D6D963381B for ; Mon, 29 Dec 2014 04:26:10 +0000 (UTC) From: Eric Wong To: Subject: [PATCH] splitfx: use $FX env consistently in targets, too Date: Mon, 29 Dec 2014 04:26:08 +0000 Message-Id: <1419827169-20555-3-git-send-email-e@80x24.org> X-Mailer: git-send-email 2.2.1.202.g55b961f X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.71.152.64 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 While we're at it, document the splitfx manpage and make the example suitable for tests. --- Documentation/dtas-splitfx.txt | 5 +++- examples/splitfx.sample.yml | 9 ++++--- lib/dtas/splitfx.rb | 4 ++-- test/test_splitfx.rb | 53 ++++++++++++++++++++++++++++++++---------- 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/Documentation/dtas-splitfx.txt b/Documentation/dtas-splitfx.txt index 70c812a..5aa3086 100644 --- a/Documentation/dtas-splitfx.txt +++ b/Documentation/dtas-splitfx.txt @@ -39,6 +39,8 @@ to use ecasound(1), too. * infile - string, the pathname of the original audio file * env - hash of environment variables to set for all commands + env: + FX: vol +3dB stats * comments - hash of common tags for all audio (e.g. ARTIST, ALBUM, YEAR) comments: ARTIST: John Smith @@ -52,6 +54,7 @@ to use ecasound(1), too. highest-numbered track (default: true) * tracks - array, see "TRACKS" section * targets - hash, see "TARGETS" section +* command - used only by dtas-player(1) # TRACKS @@ -168,4 +171,4 @@ License: GPLv3 or later # SEE ALSO -sox(1), ecasound(1), flac(1), opusenc(1) +sox(1), ecasound(1), flac(1), opusenc(1), dtas-player(1) diff --git a/examples/splitfx.sample.yml b/examples/splitfx.sample.yml index 5d32a6c..d7ee06b 100644 --- a/examples/splitfx.sample.yml +++ b/examples/splitfx.sample.yml @@ -4,9 +4,6 @@ # test_splitfx.rb relies on this. --- infile: foo.flac -env: - PATH: $PATH - SOX_OPTS: $SOX_OPTS -R comments: ARTIST: John Smith ALBUM: Hello World @@ -15,10 +12,12 @@ comments: # specify this as it is the default: # command: exec sox "$INFILE" $SOXFMT - $TRIMFX $RGFX $FX env: + PATH: $PATH # these effects may be used in any command in this file, including targets + SOX_OPTS: $SOX_OPTS -R FX: - highpass -1 120 highpass 40 highpass 40 - vol +1.5dB + # highpass -1 120 highpass 40 highpass 40 + # vol +1.5dB stats track_start: 1 # 0 for pregap/intro tracks cdda_align: true diff --git a/lib/dtas/splitfx.rb b/lib/dtas/splitfx.rb index 9af3faf..36cdf9f 100644 --- a/lib/dtas/splitfx.rb +++ b/lib/dtas/splitfx.rb @@ -9,7 +9,7 @@ require_relative 'xs' require 'tempfile' class DTAS::SplitFX # :nodoc: CMD = 'sox "$INFILE" $COMMENTS $OUTFMT "$TRACKNUMBER.$SUFFIX" '\ - '$TRIMFX $RATEFX $DITHERFX' + '$TRIMFX $FX $RATEFX $DITHERFX' include DTAS::Process include DTAS::XS attr_reader :infile, :env @@ -61,7 +61,7 @@ class DTAS::SplitFX # :nodoc: }, "opusenc" => { "command" => 'sox "$INFILE" $COMMENTS $OUTFMT - ' \ - '$TRIMFX $RATEFX $DITHERFX | opusenc --music ' \ + '$TRIMFX $FX $RATEFX $DITHERFX | opusenc --music ' \ '--raw-bits $BITS_PER_SAMPLE ' \ '$OPUSENC_BITRATE --raw-rate $RATE --raw-chan $CHANNELS ' \ '--raw-endianness $ENDIAN_OPUSENC ' \ diff --git a/test/test_splitfx.rb b/test/test_splitfx.rb index ab0dcd2..ea170ce 100644 --- a/test/test_splitfx.rb +++ b/test/test_splitfx.rb @@ -6,6 +6,18 @@ require 'thread' require_relative 'helper' class TestSplitfx < Testcase + + def tmp_err(path) + err = $stderr.dup + $stderr.reopen(path, 'a') + begin + yield + ensure + $stderr.reopen(err) + err.close + end + end + def test_t2s sfx = DTAS::SplitFX.new sfx.instance_eval do @@ -15,6 +27,17 @@ class TestSplitfx < Testcase assert_equal 118554030, sfx.t2s('44:48.3') end + def assert_contains_stats(file) + buf = File.read(file) + [ 'DC offset', 'Min level', 'Max level', 'Pk lev dB', + 'RMS lev dB', 'RMS Pk dB', 'RMS Tr dB', 'Crest factor', 'Flat factor', + 'Pk count', 'Bit-depth', 'Num samples', + 'Length s', 'Scale max', 'Window s' + ].each do |re| + assert_match(/^#{re}/, buf, buf) + end + end + def test_example hash = YAML.load(File.read("examples/splitfx.sample.yml")) sfx = DTAS::SplitFX.new @@ -25,19 +48,25 @@ class TestSplitfx < Testcase opts = { jobs: nil, silent: true } # ensure default FLAC target works - WAIT_ALL_MTX.synchronize { sfx.run("flac", opts) } + WAIT_ALL_MTX.synchronize do + tmp_err('err.txt') { sfx.run("flac", opts) } + end expect = %w(1.flac 2.flac foo.flac) assert_equal expect, Dir["*.flac"].sort # compare results with expected output - res_cmd = "sox 1.flac 2.flac -ts32 -c2 -r44100 result.s32" - res_pid = Process.spawn(res_cmd) - exp_cmd = "sox foo.flac -ts32 -c2 -r44100 expect.s32 trim 4" - exp_pid = Process.spawn(exp_cmd) + res_cmd = "sox 1.flac 2.flac -ts32 -c2 -r44100 result.s32 stats" + res_pid = Process.spawn(res_cmd, err: 'b.txt') + exp_cmd = "sox foo.flac -ts32 -c2 -r44100 expect.s32 trim 4 stats" + exp_pid = Process.spawn(exp_cmd, err: 'a.txt') _, s = Process.waitpid2(res_pid) assert s.success?, "#{res_cmd}: #{s.inspect}" _, s = Process.waitpid2(exp_pid) assert s.success?, "#{exp_cmd}: #{s.inspect}" + assert_equal File.read('a.txt'), File.read('b.txt') + + assert_contains_stats('err.txt') + cmp = "cmp result.s32 expect.s32" assert system(cmp), cmp @@ -46,13 +75,10 @@ class TestSplitfx < Testcase # hasn't made it into Debian, yet) if `which opusenc 2>/dev/null`.size > 0 && `which opusdec 2>/dev/null`.size > 0 - err = $stderr.dup - begin - $stderr.reopen("/dev/null", "a") - WAIT_ALL_MTX.synchronize { sfx.run("opusenc", opts) } - ensure - $stderr.reopen(err) + WAIT_ALL_MTX.synchronize do + tmp_err('opus.err.txt') { sfx.run("opusenc", opts) } end + assert_contains_stats('opus.err.txt') # ensure opus lengths match flac ones, we decode using opusdec # since sox does not yet have opus support in Debian 7.0 @@ -64,7 +90,10 @@ class TestSplitfx < Testcase # ensure 16/44.1kHz FLAC works (CDDA-like) File.unlink('1.flac', '2.flac') - WAIT_ALL_MTX.synchronize { sfx.run("flac-cdda", opts) } + WAIT_ALL_MTX.synchronize do + tmp_err('flac-cdda.err.txt') { sfx.run("flac-cdda", opts) } + end + assert_contains_stats('flac-cdda.err.txt') %w(1 2).each do |nr| assert_equal `soxi -D #{nr}.flac`, `soxi -D #{nr}.wav` end -- EW