From 3ce3983c3cb958fa0c7f946c331914134b5c43b7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 29 Dec 2014 06:35:09 +0000 Subject: trimfx: require audio format at initialization This makes things easier for scheduling/expansion since we won't have to deal with floating point numbers when we work directly with with sample counts (like the rest of dtas). --- test/test_trimfx.rb | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'test/test_trimfx.rb') diff --git a/test/test_trimfx.rb b/test/test_trimfx.rb index a8fd902..a59ad73 100644 --- a/test/test_trimfx.rb +++ b/test/test_trimfx.rb @@ -6,6 +6,10 @@ require 'dtas/format' require 'yaml' class TestTrimFX < Testcase + def rate + 44100 + end + def test_example ex = YAML.load(File.read("examples/trimfx.sample.yml")) effects = [] @@ -14,8 +18,8 @@ class TestTrimFX < Testcase case words[0] when "trim" tfx = DTAS::TrimFX.new(words) - assert_equal 52.0, tfx.tbeg - assert_equal 1.0, tfx.tlen + assert_equal 52 * rate, tfx.tbeg + assert_equal rate, tfx.tlen effects << tfx end end @@ -26,21 +30,21 @@ class TestTrimFX < Testcase tfx = DTAS::TrimFX.new(%w(all)) assert_equal 0, tfx.tbeg assert_nil tfx.tlen - assert_equal [], tfx.to_sox_arg(DTAS::Format.new) + assert_equal [], tfx.to_sox_arg end def test_time tfx = DTAS::TrimFX.new(%w(trim 2:30 3.1)) - assert_equal 150, tfx.tbeg - assert_equal 3.1, tfx.tlen + assert_equal 150 * rate, tfx.tbeg + assert_equal((3.1 * rate).round, tfx.tlen) end def test_to_sox_arg tfx = DTAS::TrimFX.new(%w(trim 1 0.5)) - assert_equal %w(trim 44100s 22050s), tfx.to_sox_arg(DTAS::Format.new) + assert_equal %w(trim 44100s 22050s), tfx.to_sox_arg tfx = DTAS::TrimFX.new(%w(trim 1 sox vol -1dB)) - assert_equal %w(trim 44100s), tfx.to_sox_arg(DTAS::Format.new) + assert_equal %w(trim 44100s), tfx.to_sox_arg end def test_tfx_effects @@ -56,8 +60,8 @@ class TestTrimFX < Testcase ].shuffle ary = DTAS::TrimFX.schedule(fx) assert_operator 1, :==, ary.size - assert_equal [ 0.5, 1, 2 ], ary[0].map(&:tbeg) - assert_equal [ 0.5, 0.3, 0.2 ], ary[0].map(&:tlen) + assert_equal [ 22050, 44100, 88200 ], ary[0].map(&:tbeg) + assert_equal [ 22050, 13230, 8820 ], ary[0].map(&:tlen) end def test_schedule_overlaps @@ -68,10 +72,10 @@ class TestTrimFX < Testcase ] ary = DTAS::TrimFX.schedule(fx) assert_equal 2, ary.size - assert_equal [ 0.5, 1 ], ary[0].map(&:tbeg) - assert_equal [ 1.1 ], ary[1].map(&:tbeg) + assert_equal [ 22050, 44100 ], ary[0].map(&:tbeg) + assert_equal [ 48510 ], ary[1].map(&:tbeg) - ex = DTAS::TrimFX.expand(fx, 10) + ex = DTAS::TrimFX.expand(fx, 10 * rate) assert_equal 2, ex.size assert_equal 0, ex[0][0].tbeg assert_equal 3, ex[0].size -- cgit v1.2.3-24-ge0c7