Class: DTAS::Source::Sox

Inherits:
Object
  • Object
show all
Extended by:
XS
Includes:
File, XS
Defined in:
lib/dtas/source/sox.rb

Overview

this is usually one input file

Direct Known Subclasses

SplitFX

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

Process::PIDS

Constants included from Command

Command::COMMAND_DEFAULTS

Instance Attribute Summary

Attributes included from File

#infile, #offset, #tryorder

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

Methods included from XS

xs

Methods included from File

#__file_init, #__offset_samples, #comments, #cuebreakpoints, #load!, #offset_samples, #offset_us, #replaygain, #samples!, #source_file_dup, #to_hash, #to_source_cat, #to_state_hash, #trimfx

Methods included from Mp3gain

#__mp3gain_peak, #mp3gain_comments

Methods included from Process

#dtas_spawn, #env_expand, #qx, reaper

Methods included from DTAS::SpawnFix

#spawn

Methods included from Common

#dst_assoc

Methods included from Command

#command_init, #command_string, #on_death

Methods included from DTAS::Serialize

#ivars_to_hash

Constructor Details

#initializeSox

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_commentsObject

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

#formatObject



50
51
52
# File 'lib/dtas/source/sox.rb', line 50

def format
  @format ||= DTAS::Format.from_file(@env, @infile)
end

#samplesObject

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.message
  0
end

#source_defaultsObject



95
96
97
# File 'lib/dtas/source/sox.rb', line 95

def source_defaults
  SOX_DEFAULTS
end

#src_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 src_spawn(player_format, rg_state, opts)
  raise "BUG: #{self.inspect}#src_spawn called twice" if @to_io
  e = @env.merge!(player_format.to_env)
  e["INFILE"] = xs(@infile)

  # make sure these are visible to the "current" command...
  e["TRIMFX"] = trimfx
  e["RGFX"] = rg_state.effect(self) || nil
  e.merge!(@rg.to_env) if @rg

  @pid = dtas_spawn(e, command_string, opts)
end

#to_hshObject



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, trim = nil) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/dtas/source/sox.rb', line 41

def try(infile, offset = nil, trim = 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, trim)
end