Class: DTAS::TFX
Overview
this will represent a trim section inside -splitfx for applying effects to only a part of the output
Defined Under Namespace
Classes: TFXSort
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#tbeg ⇒ Object
readonly
Returns the value of attribute tbeg.
-
#tlen ⇒ Object
readonly
Returns the value of attribute tlen.
Class Method Summary collapse
-
.expand(ary, total_samples) ⇒ Object
like schedule, but fills in the gaps with pass-through (no-op) TFX objs This does not change the number of epochs.
-
.schedule(ary) ⇒ Object
sorts and converts an array of TFX objects into non-overlapping arrays of epochs.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(args, format = DTAS::Format.new) ⇒ TFX
constructor
A new instance of TFX.
-
#parse_trim!(args) ⇒ Object
tries to interpret “trim” time args the same way the sox trim effect does This takes time arguments only, not sample counts; otherwise, deviations from sox are considered bugs in dtas.
- #tfx_eca(args) ⇒ Object
- #tfx_sox(args) ⇒ Object
- #to_sox_arg ⇒ Object
Methods included from ParseTime
Constructor Details
#initialize(args, format = DTAS::Format.new) ⇒ TFX
Returns a new instance of TFX.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dtas/tfx.rb', line 17 def initialize(args, format = DTAS::Format.new) @format = format args = args.dup case args.shift when :pad # [ :pad, start_time, end_time ] @tbeg = args.shift @tlen = args.shift - @tbeg when "trim" parse_trim!(args) when "all" @tbeg = 0 @tlen = nil else raise ArgumentError, "#{args.inspect} not understood" end case tmp = args.shift when "sh" then @cmd = args when "sox" then tfx_sox(args) when "eca" then tfx_eca(args) when nil @cmd = [] else raise ArgumentError, "unknown effect type: #{tmp}" end end |
Instance Attribute Details
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
15 16 17 |
# File 'lib/dtas/tfx.rb', line 15 def cmd @cmd end |
#tbeg ⇒ Object (readonly)
Returns the value of attribute tbeg.
13 14 15 |
# File 'lib/dtas/tfx.rb', line 13 def tbeg @tbeg end |
#tlen ⇒ Object (readonly)
Returns the value of attribute tlen.
14 15 16 |
# File 'lib/dtas/tfx.rb', line 14 def tlen @tlen end |
Class Method Details
.expand(ary, total_samples) ⇒ Object
like schedule, but fills in the gaps with pass-through (no-op) TFX objs This does not change the number of epochs.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/dtas/tfx.rb', line 144 def self.(ary, total_samples) rv = [] schedule(ary).each_with_index do |sary, epoch| tip = 0 dst = rv[epoch] = [] while tfx = sary.shift if tfx.tbeg > tip # fill in the previous gap nfx = new([:pad, tip, tfx.tbeg]) dst << nfx dst << tfx tip = tfx.tbeg + tfx.tlen end end if tip < total_samples # fill until the last chunk nfx = new([:pad, tip, total_samples]) dst << nfx end end rv end |
.schedule(ary) ⇒ Object
sorts and converts an array of TFX objects into non-overlapping arrays of epochs
input:
[ tfx1, tfx2, tfx3, ... ]
output:
[
[ tfx1 ], # first epoch
[ tfx2, tfx3 ], # second epoch
...
]
There are multiple epochs only if ranges overlap, There is only one epoch if there are no overlaps
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/dtas/tfx.rb', line 109 def self.schedule(ary) sorted = [] ary.each_with_index { |tfx, i| sorted << TFXSort[tfx, i] } sorted.sort! rv = [] epoch = 0 prev_end = 0 defer = [] begin while tfxsort = sorted.shift tfx = tfxsort.tfx if tfx.tbeg >= prev_end # great, no overlap, append to the current epoch prev_end = tfx.tbeg + tfx.tlen (rv[epoch] ||= []) << tfx else # overlapping region, we'll need a new epoch defer << tfxsort end end if defer[0] # do we need another epoch? epoch += 1 sorted = defer defer = [] prev_end = 0 end end while sorted[0] rv end |
Instance Method Details
#<=>(other) ⇒ Object
83 84 85 |
# File 'lib/dtas/tfx.rb', line 83 def <=>(other) tbeg <=> other.tbeg end |
#parse_trim!(args) ⇒ Object
tries to interpret “trim” time args the same way the sox trim effect does This takes time arguments only, not sample counts; otherwise, deviations from sox are considered bugs in dtas
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/dtas/tfx.rb', line 69 def parse_trim!(args) tbeg = parse_time(args.shift) if args[0] =~ /\A=?[\d\.]+\z/ tlen = args.shift is_stop_time = tlen.sub!(/\A=/, "") ? true : false tlen = parse_time(tlen) tlen = tlen - tbeg if is_stop_time @tlen = (tlen * @format.rate).round else @tlen = nil end @tbeg = (tbeg * @format.rate).round end |
#tfx_eca(args) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/dtas/tfx.rb', line 48 def tfx_eca(args) @cmd = %w(sox $SOXIN $SOX2ECA $TRIMFX) @cmd.concat(%w(| ecasound $ECAFMT -i stdin -o stdout)) @cmd.concat(args) @cmd.concat(%w(| sox $ECA2SOX - $SOXOUT)) end |
#tfx_sox(args) ⇒ Object
43 44 45 46 |
# File 'lib/dtas/tfx.rb', line 43 def tfx_sox(args) @cmd = %w(sox $SOXIN $SOXOUT $TRIMFX) @cmd.concat(args) end |
#to_sox_arg ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dtas/tfx.rb', line 55 def to_sox_arg if @tbeg && @tlen %W(trim #{@tbeg}s #{@tlen}s) elsif @tbeg return [] if @tbeg == 0 %W(trim #{@tbeg}s) else [] end end |