From 68ffa097e187da663fa3f537b430428ea5e8de2e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 25 Aug 2013 09:25:07 +0000 Subject: split out source handling to prepare for avconv/ffmpeg support We should've done this at the start, but we didn't. --- test/test_rg_integration.rb | 2 +- test/test_source.rb | 102 -------------------------------------------- test/test_source_sox.rb | 102 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 103 deletions(-) delete mode 100644 test/test_source.rb create mode 100644 test/test_source_sox.rb (limited to 'test') diff --git a/test/test_rg_integration.rb b/test/test_rg_integration.rb index 0d2ac09..79a6563 100644 --- a/test/test_rg_integration.rb +++ b/test/test_rg_integration.rb @@ -103,7 +103,7 @@ class TestRgIntegration < Minitest::Unit::TestCase s = client_socket s.req_ok("rg mode=album_gain") pluck, _ = tmp_pluck - cmd = DTAS::Source::SOURCE_DEFAULTS["command"] + cmd = DTAS::Source::Sox::SOX_DEFAULTS["command"] fifo = tmpfifo s.req_ok("source ed command='env > #{fifo}; #{cmd}'") s.req_ok("sink ed default command='cat >/dev/null' active=true") diff --git a/test/test_source.rb b/test/test_source.rb deleted file mode 100644 index 21a56ac..0000000 --- a/test/test_source.rb +++ /dev/null @@ -1,102 +0,0 @@ -# -*- encoding: binary -*- -# Copyright (C) 2013, Eric Wong -# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) -require './test/helper' -require 'dtas/source' -require 'tempfile' - -class TestSource < Minitest::Unit::TestCase - def teardown - @tempfiles.each { |tmp| tmp.close! } - end - - def setup - @tempfiles = [] - end - - def x(cmd) - system(*cmd) - assert $?.success?, cmd.inspect - end - - def new_file(suffix) - tmp = Tempfile.new(%W(tmp .#{suffix})) - @tempfiles << tmp - cmd = %W(sox -r 44100 -b 16 -c 2 -n #{tmp.path} trim 0 1) - return tmp if system(*cmd) - nil - end - - def test_flac - return if `which metaflac`.strip.size == 0 - tmp = new_file('flac') or return - - source = DTAS::Source.new(tmp.path) - x(%W(metaflac --set-tag=FOO=BAR #{tmp.path})) - x(%W(metaflac --add-replay-gain #{tmp.path})) - assert_equal source.comments["FOO"], "BAR" - rg = source.replaygain - assert_kind_of DTAS::ReplayGain, rg - assert_in_delta 0.0, rg.track_peak.to_f, 0.00000001 - assert_in_delta 0.0, rg.album_peak.to_f, 0.00000001 - assert_operator rg.album_gain.to_f, :>, 1 - assert_operator rg.track_gain.to_f, :>, 1 - end - - def test_mp3gain - return if `which mp3gain`.strip.size == 0 - a = new_file('mp3') or return - b = new_file('mp3') or return - - source = DTAS::Source.new(a.path) - - # redirect stdout to /dev/null temporarily, mp3gain is noisy - File.open("/dev/null", "w") do |null| - old_out = $stdout.dup - $stdout.reopen(null) - begin - x(%W(mp3gain -q #{a.path} #{b.path})) - ensure - $stdout.reopen(old_out) - old_out.close - end - end - - rg = source.replaygain - assert_kind_of DTAS::ReplayGain, rg - assert_in_delta 0.0, rg.track_peak.to_f, 0.00000001 - assert_in_delta 0.0, rg.album_peak.to_f, 0.00000001 - assert_operator rg.album_gain.to_f, :>, 1 - assert_operator rg.track_gain.to_f, :>, 1 - end - - def test_offset - tmp = new_file('sox') or return - source = DTAS::Source.new(*%W(#{tmp.path} 5s)) - assert_equal 5, source.offset_samples - - source = DTAS::Source.new(*%W(#{tmp.path} 1:00:00.5)) - expect = 1 * 60 * 60 * 44100 + (44100/2) - assert_equal expect, source.offset_samples - - source = DTAS::Source.new(*%W(#{tmp.path} 1:10.5)) - expect = 1 * 60 * 44100 + (10 * 44100) + (44100/2) - assert_equal expect, source.offset_samples - - source = DTAS::Source.new(*%W(#{tmp.path} 10.03)) - expect = (10 * 44100) + (44100 * 3/100.0) - assert_equal expect, source.offset_samples - end - - def test_offset_us - tmp = new_file('sox') or return - source = DTAS::Source.new(*%W(#{tmp.path} 441s)) - assert_equal 10000.0, source.offset_us - - source = DTAS::Source.new(*%W(#{tmp.path} 22050s)) - assert_equal 500000.0, source.offset_us - - source = DTAS::Source.new(tmp.path, '1') - assert_equal 1000000.0, source.offset_us - end -end diff --git a/test/test_source_sox.rb b/test/test_source_sox.rb new file mode 100644 index 0000000..6bf5071 --- /dev/null +++ b/test/test_source_sox.rb @@ -0,0 +1,102 @@ +# -*- encoding: binary -*- +# Copyright (C) 2013, Eric Wong +# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +require './test/helper' +require 'dtas/source/sox' +require 'tempfile' + +class TestSource < Minitest::Unit::TestCase + def teardown + @tempfiles.each { |tmp| tmp.close! } + end + + def setup + @tempfiles = [] + end + + def x(cmd) + system(*cmd) + assert $?.success?, cmd.inspect + end + + def new_file(suffix) + tmp = Tempfile.new(%W(tmp .#{suffix})) + @tempfiles << tmp + cmd = %W(sox -r 44100 -b 16 -c 2 -n #{tmp.path} trim 0 1) + return tmp if system(*cmd) + nil + end + + def test_flac + return if `which metaflac`.strip.size == 0 + tmp = new_file('flac') or return + + source = DTAS::Source::Sox.new(tmp.path) + x(%W(metaflac --set-tag=FOO=BAR #{tmp.path})) + x(%W(metaflac --add-replay-gain #{tmp.path})) + assert_equal source.comments["FOO"], "BAR" + rg = source.replaygain + assert_kind_of DTAS::ReplayGain, rg + assert_in_delta 0.0, rg.track_peak.to_f, 0.00000001 + assert_in_delta 0.0, rg.album_peak.to_f, 0.00000001 + assert_operator rg.album_gain.to_f, :>, 1 + assert_operator rg.track_gain.to_f, :>, 1 + end + + def test_mp3gain + return if `which mp3gain`.strip.size == 0 + a = new_file('mp3') or return + b = new_file('mp3') or return + + source = DTAS::Source::Sox.new(a.path) + + # redirect stdout to /dev/null temporarily, mp3gain is noisy + File.open("/dev/null", "w") do |null| + old_out = $stdout.dup + $stdout.reopen(null) + begin + x(%W(mp3gain -q #{a.path} #{b.path})) + ensure + $stdout.reopen(old_out) + old_out.close + end + end + + rg = source.replaygain + assert_kind_of DTAS::ReplayGain, rg + assert_in_delta 0.0, rg.track_peak.to_f, 0.00000001 + assert_in_delta 0.0, rg.album_peak.to_f, 0.00000001 + assert_operator rg.album_gain.to_f, :>, 1 + assert_operator rg.track_gain.to_f, :>, 1 + end + + def test_offset + tmp = new_file('sox') or return + source = DTAS::Source::Sox.new(*%W(#{tmp.path} 5s)) + assert_equal 5, source.offset_samples + + source = DTAS::Source::Sox.new(*%W(#{tmp.path} 1:00:00.5)) + expect = 1 * 60 * 60 * 44100 + (44100/2) + assert_equal expect, source.offset_samples + + source = DTAS::Source::Sox.new(*%W(#{tmp.path} 1:10.5)) + expect = 1 * 60 * 44100 + (10 * 44100) + (44100/2) + assert_equal expect, source.offset_samples + + source = DTAS::Source::Sox.new(*%W(#{tmp.path} 10.03)) + expect = (10 * 44100) + (44100 * 3/100.0) + assert_equal expect, source.offset_samples + end + + def test_offset_us + tmp = new_file('sox') or return + source = DTAS::Source::Sox.new(*%W(#{tmp.path} 441s)) + assert_equal 10000.0, source.offset_us + + source = DTAS::Source::Sox.new(*%W(#{tmp.path} 22050s)) + assert_equal 500000.0, source.offset_us + + source = DTAS::Source::Sox.new(tmp.path, '1') + assert_equal 1000000.0, source.offset_us + end +end -- cgit v1.2.3-24-ge0c7