Class: DTAS::Source::Sox
- Inherits:
-
Object
- Object
- DTAS::Source::Sox
- Extended by:
- XS
- Defined in:
- lib/dtas/source/sox.rb
Overview
this is usually one input file
Constant Summary collapse
- SOX_DEFAULTS =
COMMAND_DEFAULTS.merge( "command" => 'exec sox "$INFILE" $SOXFMT - $TRIMFX $RGFX', "tryorder" => 0, )
Constants included from File
File::FILE_SIVS, File::SRC_SIVS
Constants included from Process
Constants included from Command
Instance Attribute Summary
Attributes included from File
Attributes included from Common
#dst, #dst_zero_byte, #requeued
Attributes included from Command
#command, #env, #pid, #spawn_at, #to_io
Class Method Summary collapse
Instance Method Summary collapse
-
#__load_comments ⇒ Object
just run soxi -a.
- #format ⇒ Object
-
#initialize ⇒ Sox
constructor
A new instance of Sox.
-
#samples ⇒ Object
This is the number of samples according to the samples in the source file itself, not the decoded output.
- #source_defaults ⇒ Object
- #spawn(player_format, rg_state, opts) ⇒ Object
- #to_hsh ⇒ Object
- #try(infile, offset = nil) ⇒ Object
Methods included from XS
Methods included from File
#__file_init, #comments, #cuebreakpoints, #load!, #offset_samples, #offset_us, #replaygain, #samples!, #source_file_dup, #to_hash, #to_source_cat, #to_state_hash
Methods included from Mp3gain
#__mp3gain_peak, #mp3gain_comments
Methods included from Process
#dtas_spawn, #env_expand, #qx, reaper
Methods included from Common
Methods included from Command
#command_init, #command_string, #on_death
Methods included from DTAS::Serialize
Constructor Details
#initialize ⇒ Sox
Returns a new instance of Sox.
37 38 39 |
# File 'lib/dtas/source/sox.rb', line 37 def initialize command_init(SOX_DEFAULTS) end |
Class Method Details
.try_to_fail_harder(infile, s, cmd) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dtas/source/sox.rb', line 23 def self.try_to_fail_harder(infile, s, cmd) msg = nil case s when %r{\A0\s*\z} then msg = "detected zero samples" when Process::Status then msg = "failed with #{s.exitstatus}" end if msg return if @last_failed == infile @last_failed = infile return warn("`#{xs(cmd)}' #{msg}") end true end |
Instance Method Details
#__load_comments ⇒ Object
just run soxi -a
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/dtas/source/sox.rb', line 64 def __load_comments tmp = {} case @infile when String qx(@env, %W(soxi -a #@infile)).split(/\n/n).each do |line| key, value = line.split(/=/n, 2) key && value or next # TODO: multi-line/multi-value/repeated tags tmp[key.upcase] = value end end tmp end |
#format ⇒ Object
50 51 52 |
# File 'lib/dtas/source/sox.rb', line 50 def format @format ||= DTAS::Format.from_file(@env, @infile) end |
#samples ⇒ Object
This is the number of samples according to the samples in the source file itself, not the decoded output
56 57 58 59 60 61 |
# File 'lib/dtas/source/sox.rb', line 56 def samples @samples ||= qx(@env, %W(soxi -s #@infile)).to_i rescue => e warn e. 0 end |
#source_defaults ⇒ Object
95 96 97 |
# File 'lib/dtas/source/sox.rb', line 95 def source_defaults SOX_DEFAULTS end |
#spawn(player_format, rg_state, opts) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dtas/source/sox.rb', line 78 def spawn(player_format, rg_state, opts) raise "BUG: #{self.inspect}#spawn called twice" if @to_io e = @env.merge!(player_format.to_env) e["INFILE"] = @infile # make sure these are visible to the "current" command... e["TRIMFX"] = @offset ? "trim #@offset" : nil e["RGFX"] = rg_state.effect(self) || nil e.merge!(@rg.to_env) if @rg @pid = dtas_spawn(e, command_string, opts) end |
#to_hsh ⇒ Object
91 92 93 |
# File 'lib/dtas/source/sox.rb', line 91 def to_hsh to_hash.delete_if { |k,v| v == SOX_DEFAULTS[k] } end |
#try(infile, offset = nil) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/dtas/source/sox.rb', line 41 def try(infile, offset = nil) err = "" cmd = %W(soxi -s #{infile}) s = qx(@env.dup, cmd, err_str: err, no_raise: true) return if err =~ /soxi FAIL formats:/ self.class.try_to_fail_harder(infile, s, cmd) or return source_file_dup(infile, offset) end |