about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-08-25 09:36:22 +0000
committerEric Wong <normalperson@yhbt.net>2013-08-25 09:36:22 +0000
commit157b75aa71bb2d9e7140cd72f29451fa234a902a (patch)
treedd6c29146acbef5a0d8e4322507fc4b6ef5fd0f1
parent68ffa097e187da663fa3f537b430428ea5e8de2e (diff)
downloaddtas-157b75aa71bb2d9e7140cd72f29451fa234a902a.tar.gz
We'll be supporting reading the format from avprobe and ffprobe,
so we should avoid tying ourselves to soxi
-rw-r--r--lib/dtas/format.rb8
-rw-r--r--lib/dtas/source/sox.rb5
-rw-r--r--test/test_format.rb14
-rw-r--r--test/test_source_sox.rb13
4 files changed, 17 insertions, 23 deletions
diff --git a/lib/dtas/format.rb b/lib/dtas/format.rb
index a6e424b..8313796 100644
--- a/lib/dtas/format.rb
+++ b/lib/dtas/format.rb
@@ -75,14 +75,6 @@ class DTAS::Format # :nodoc:
     ivars_to_hash(SIVS)
   end
 
-  # FIXME, move to per-source (sox/avconv/ffmpeg)
-  def from_file(path)
-    @channels = qx(%W(soxi -c #{path})).to_i
-    @type = qx(%W(soxi -t #{path})).strip
-    @rate = qx(%W(soxi -r #{path})).to_i
-    # we don't need to care for bits, do we?
-  end
-
   # for the _decoded_ output
   def bits_per_sample
     return @bits if @bits
diff --git a/lib/dtas/source/sox.rb b/lib/dtas/source/sox.rb
index 44b5f17..64ce095 100644
--- a/lib/dtas/source/sox.rb
+++ b/lib/dtas/source/sox.rb
@@ -36,7 +36,10 @@ class DTAS::Source::Sox # :nodoc:
   def format
     @format ||= begin
       fmt = DTAS::Format.new
-      fmt.from_file(@infile)
+      path = @infile
+      fmt.channels = qx(%W(soxi -c #{path})).to_i
+      fmt.type = qx(%W(soxi -t #{path})).strip
+      fmt.rate = qx(%W(soxi -r #{path})).to_i
       fmt.bits ||= precision
       fmt
     end
diff --git a/test/test_format.rb b/test/test_format.rb
index ba039a7..00fb3e3 100644
--- a/test/test_format.rb
+++ b/test/test_format.rb
@@ -34,20 +34,6 @@ class TestFormat < Minitest::Unit::TestCase
     assert_nil hash["channels"]
   end
 
-  def test_from_file
-    Tempfile.open(%w(tmp .wav)) do |tmp|
-      # generate an empty file with 1s of audio
-      cmd = %W(sox -r 96000 -b 24 -c 2 -n #{tmp.path} trim 0 1)
-      system(*cmd)
-      assert $?.success?, "#{cmd.inspect} failed: #$?"
-      fmt = DTAS::Format.new
-      fmt.from_file tmp.path
-      assert_equal 96000, fmt.rate
-      assert_equal 2, fmt.channels
-      tmp.unlink
-    end
-  end
-
   def test_bytes_per_sample
     fmt = DTAS::Format.new
     assert_equal 4, fmt.bytes_per_sample
diff --git a/test/test_source_sox.rb b/test/test_source_sox.rb
index 6bf5071..f2e0699 100644
--- a/test/test_source_sox.rb
+++ b/test/test_source_sox.rb
@@ -99,4 +99,17 @@ class TestSource < Minitest::Unit::TestCase
     source = DTAS::Source::Sox.new(tmp.path, '1')
     assert_equal 1000000.0, source.offset_us
   end
+
+  def test_format_from_file
+    Tempfile.open(%w(tmp .wav)) do |tmp|
+      # generate an empty file with 1s of audio
+      cmd = %W(sox -r 96000 -b 24 -c 2 -n #{tmp.path} trim 0 1)
+      system(*cmd)
+      assert $?.success?, "#{cmd.inspect} failed: #$?"
+      fmt = DTAS::Source::Sox.new(tmp.path).format
+      assert_equal 96000, fmt.rate
+      assert_equal 2, fmt.channels
+      tmp.unlink
+    end
+  end
 end