Skip to content

Instantly share code, notes, and snippets.

@julik
Created January 27, 2010 15:20
Show Gist options
  • Save julik/287920 to your computer and use it in GitHub Desktop.
Save julik/287920 to your computer and use it in GitHub Desktop.
require "rubygems"
require "tracksperanto"
class Unwarp < Tracksperanto::Import::FlameStabilizer
def parse(io)
extract_channels_from_stream(io)
end
end
file_path = ARGV.shift
p = Unwarp.new
channels = p.parse(File.open(file_path))
# Do a simple linear interpolxion. The function will yield
# the interim X and Y, one tuple per whole value between the set points,
# and return the last tuple (so you can return-assign from it in a loop)
def lerp(last_x, last_y, x, y) #:yields: interp_x, interp_y
if last_x.nil?
yield(x, y)
else
gap_size = x - last_x
increment = (y.to_f - last_y) / gap_size.to_f
(1..gap_size).each do | index |
yield(last_x + index, last_y + (increment * index))
end
end
return [x, y]
end
channels.each do | ch |
File.open("%s_%s.chan" % [file_path, ch.name], "wb" ) do | chan_file |
last_at, last_value = nil, nil
ch.each do | at, value |
last_at, last_value = lerp(last_at, last_value, at, value) do | interp_at, interp_value |
chan_file.puts("%d\t%.5f" % [interp_at, interp_value])
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment