about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-12-26 22:43:32 +0000
committerEric Wong <e@80x24.org>2016-12-26 22:43:32 +0000
commit53c3abbbb222e3ab84c565498b8461009a3059c0 (patch)
tree9f44c56e2e349f6862a4467c9b114fe4e6997108
parentf77befb947a41d9ce939ad4a624bd820eac6245a (diff)
downloaddtas-53c3abbbb222e3ab84c565498b8461009a3059c0.tar.gz
Spawning processes under Ruby on Linux is relatively cheap,
but may not be for other OSes and it's still cheaper to
spawn fewer processes.
-rw-r--r--lib/dtas/format.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/dtas/format.rb b/lib/dtas/format.rb
index f378f8e..d48d3ff 100644
--- a/lib/dtas/format.rb
+++ b/lib/dtas/format.rb
@@ -56,10 +56,14 @@ class DTAS::Format # :nodoc:
 
   def self.from_file(env, infile)
     fmt = new
-    fmt.channels = qx(env, %W(soxi -c #{infile})).to_i
-    fmt.type = qx(env, %W(soxi -t #{infile})).strip
-    fmt.rate = qx(env, %W(soxi -r #{infile})).to_i
-    fmt.bits ||= precision(env, infile)
+    out = qx(env, %W(soxi #{infile}), err: DTAS.null)
+    out =~ /^Channels\s*:\s*(\d+)/n
+    fmt.channels = $1.to_i
+    out =~ /^Sample Rate\s*:\s*(\d+)/n
+    fmt.rate = $1.to_i
+    out =~ /Precision\s*:\s*(\d+)-bit/n
+    fmt.bits = $1.to_i
+    fmt.type = qx(env, %W(soxi -t #{infile})).strip # ....
     fmt
   end