about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-09-10 09:21:17 +0000
committerEric Wong <normalperson@yhbt.net>2013-09-10 10:10:17 +0000
commit699a1217fbfa06b0cde58e4430a35825c384167f (patch)
tree1dba4fdcaf4f12f55456db95774218c6f918815a
parenta910d2ce86fa2cee0bed31e801173a981330fac1 (diff)
downloaddtas-699a1217fbfa06b0cde58e4430a35825c384167f.tar.gz
These are common output targets, at least for my workflow.
-rw-r--r--lib/dtas/format.rb11
-rw-r--r--lib/dtas/splitfx.rb27
-rw-r--r--test/test_splitfx.rb36
3 files changed, 70 insertions, 4 deletions
diff --git a/lib/dtas/format.rb b/lib/dtas/format.rb
index 690a21f..e9da16f 100644
--- a/lib/dtas/format.rb
+++ b/lib/dtas/format.rb
@@ -59,6 +59,16 @@ class DTAS::Format # :nodoc:
     end
   end
 
+  # returns 1 or 0 depending on endianess
+  def endian_opusenc
+    case e = @endian || NATIVE_ENDIAN
+    when "big" then "1"
+    when "little" then "0"
+    else
+      raise"unsupported endian=#{e}"
+    end
+  end
+
   def to_eca_arg
     %W(-f #{@type}_#{endian2},#@channels,#@rate)
   end
@@ -92,6 +102,7 @@ class DTAS::Format # :nodoc:
       "SOXFMT" => to_sox_arg.join(' '),
       "ECAFMT" => to_eca_arg.join(' '),
       "ENDIAN2" => endian2,
+      "ENDIAN_OPUSENC" => endian_opusenc,
     }
     begin # don't set these if we can't get them, SOX_FILETYPE may be enough
       rv["BITS_PER_SAMPLE"] = bits_per_sample.to_s
diff --git a/lib/dtas/splitfx.rb b/lib/dtas/splitfx.rb
index aa1665d..f7f8c39 100644
--- a/lib/dtas/splitfx.rb
+++ b/lib/dtas/splitfx.rb
@@ -42,7 +42,32 @@ class DTAS::SplitFX # :nodoc:
     @track_zpad = true
     @t2s = method(:t2s)
     @infile = nil
-    @targets = {}
+    @targets = {
+      "flac-cdda" => {
+        "command" => CMD,
+        "format" => {
+          "bits" => 16,
+          "rate" => 44100,
+          "type" => "flac",
+          "channels" => 2,
+        },
+      },
+      "opus" => {
+        "command" => 'sox "$INFILE" $COMMENTS $OUTFMT - ' \
+           '$TRIMFX $RATEFX $DITHERFX | opusenc --music ' \
+           '--raw-bits $BITS_PER_SAMPLE ' \
+           '$OPUSENC_BITRATE --raw-rate $RATE --raw-chan $CHANNELS ' \
+           '--raw-endianness $ENDIAN_OPUSENC ' \
+           '$OPUSENC_COMMENTS ' \
+           '- $TRACKNUMBER.opus',
+        "format" => {
+          "bits" => 16,
+          "rate" => 48000,
+          "type" => "s16",
+          "channels" => 2,
+        },
+      },
+    }
     @tracks = []
     @infmt = nil # wait until input is assigned
   end
diff --git a/test/test_splitfx.rb b/test/test_splitfx.rb
index 9408f66..9ba4664 100644
--- a/test/test_splitfx.rb
+++ b/test/test_splitfx.rb
@@ -27,12 +27,13 @@ class TestSplitfx < Testcase
         assert system(cmd), cmd.inspect
         sfx.import(hash, {})
         opts = { jobs: nil, silent: true }
-        WAIT_ALL_MTX.synchronize do
-          sfx.run("flac", opts)
-        end
+
+        # ensure default FLAC target works
+        WAIT_ALL_MTX.synchronize { sfx.run("flac", opts) }
         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 = fork { exec res_cmd }
         exp_cmd = "sox foo.flac -ts32 -c2 -r44100 expect.s32 trim 4"
@@ -43,6 +44,35 @@ class TestSplitfx < Testcase
         assert s.success?, "#{exp_cmd}: #{s.inspect}"
         cmp = "cmp result.s32 expect.s32"
         assert system(cmp), cmp
+
+        # try Ogg Opus, use opusenc/opusdec for now since that's available
+        # in Debian 7.0 (sox.git currently has opusfile support, but that
+        # 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("opus", opts) }
+          ensure
+            $stderr.reopen(err)
+          end
+
+          # ensure opus lengths match flac ones, we decode using opusdec
+          # since sox does not yet have opus support in Debian 7.0
+          %w(1 2).each do |nr|
+            cmd = "opusdec #{nr}.opus #{nr}.wav 2>/dev/null"
+            assert system(cmd), cmd
+            assert_equal `soxi -D #{nr}.flac`, `soxi -D #{nr}.wav`
+          end
+        end
+
+        # ensure 16/44.1kHz FLAC works (CDDA-like)
+        File.unlink('1.flac', '2.flac')
+        WAIT_ALL_MTX.synchronize { sfx.run("flac-cdda", opts) }
+        %w(1 2).each do |nr|
+          assert_equal `soxi -D #{nr}.flac`, `soxi -D #{nr}.wav`
+        end
       end
     end
   end