Class: Zerbo::Waveform

Inherits:
Packet
  • Object
show all
Defined in:
lib/zerbo.rb

Instance Attribute Summary

Attributes inherited from Packet

#data, #owner, #sequence, #type

Instance Method Summary collapse

Methods inherited from Packet

#guess_length, inherited, #initialize, #name, #to_i

Constructor Details

This class inherits a constructor from Zerbo::Packet

Instance Method Details

#filteredObject



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/zerbo.rb', line 166

def filtered
  unless @filtered
    # blindly stolen from the Python library.
    filter = [
      0.0056, 0.0190, 0.0113, -0.0106, 0.0029, 0.0041,
      -0.0082, 0.0089, -0.0062, 0.0006, 0.0066, -0.0129,
      0.0157, -0.0127, 0.0035, 0.0102, -0.0244, 0.0336,
      -0.0323, 0.0168, 0.0136, -0.0555, 0.1020, -0.1446,
      0.1743, 0.8150, 0.1743, -0.1446, 0.1020, -0.0555,
      0.0136, 0.0168, -0.0323, 0.0336, -0.0244, 0.0102,
      0.0035, -0.0127, 0.0157, -0.0129, 0.0066, 0.0006,
      -0.0062, 0.0089, -0.0082, 0.0041, 0.0029, -0.0106,
      0.0113, 0.0190, 0.0056
    ]
    p = raw.length
    q = filter.length
    n = p + q - 1
    @filtered = []
    n.times do |k|
      t = 0
      lower = [0, k-(q-1)].max
      upper = [p-1, k].min
      lower.upto(upper) do |i|
        t = t + raw[i] * filter[k-i]
      end
      @filtered << (t*1e6).round/1e6
    end
  end
  @filtered
end

#inspectObject



201
202
203
# File 'lib/zerbo.rb', line 201

def inspect
  format_inspect(raw.inspect[1..-2])
end

#rawObject



160
161
162
163
164
# File 'lib/zerbo.rb', line 160

def raw
  data.unpack('v128').map do |v|
    v > 0x7fff ? -0x10000 ^ v : v
  end
end

#to_aObject



197
198
199
# File 'lib/zerbo.rb', line 197

def to_a
  filtered[90...218]
end