From 53c3abbbb222e3ab84c565498b8461009a3059c0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 26 Dec 2016 22:43:32 +0000 Subject: format.from_file: reduce soxi invocations 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. --- lib/dtas/format.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/dtas') 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 -- cgit v1.2.3-24-ge0c7