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.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dtas/tfx.rb', line 18 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.
16 17 18 |
# File 'lib/dtas/tfx.rb', line 16 def cmd @cmd end |
#tbeg ⇒ Object (readonly)
Returns the value of attribute tbeg.
14 15 16 |
# File 'lib/dtas/tfx.rb', line 14 def tbeg @tbeg end |
#tlen ⇒ Object (readonly)
Returns the value of attribute tlen.
15 16 17 |
# File 'lib/dtas/tfx.rb', line 15 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.
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/dtas/tfx.rb', line 145 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
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 141 |
# File 'lib/dtas/tfx.rb', line 110 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
84 85 86 |
# File 'lib/dtas/tfx.rb', line 84 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
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/dtas/tfx.rb', line 70 def parse_trim!(args) tbeg = parse_time(args.shift) if args[0] =~ /\A=?[\d\.]+\z/ tlen = args.shift.dup 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
49 50 51 52 53 54 |
# File 'lib/dtas/tfx.rb', line 49 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
44 45 46 47 |
# File 'lib/dtas/tfx.rb', line 44 def tfx_sox(args) @cmd = %w(sox $SOXIN $SOXOUT $TRIMFX) @cmd.concat(args) end |
#to_sox_arg ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/dtas/tfx.rb', line 56 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 |