Last active
March 1, 2016 13:47
-
-
Save lwrubel/dd9aec3a951337f06ee6 to your computer and use it in GitHub Desktop.
Cycling to work from Alexandria to Foggy Bottom, DC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cycling to work, in a brisk cold wind | |
# csv file has a heartrate and altitude measurement taken each second | |
# piano is the heartrate, higher note is higher heartrate | |
# underlying synth is altitude, higher pitch is higher altitude | |
require 'csv' | |
data = CSV.parse(File.read("/Users/lwrubel/projects/datasonify/20160222-cycle-to-work.csv")) | |
# using pentatonic scale for heartrate | |
heart_pitches = [:G1, :A1, :C2, :D2, :E2, :G2, :A2, :C3, :D3, :E3, :G3, :A3, :C4, :D4, :E4, :G4, :A4, :C5, :D5, :E5, :F5, :G5, :A5, :B5, :C6, :D6, | |
:E6, :G6, :A6, :C7, :D7, :E7, :G7, :A7] | |
# trying to not be too dissonant against heartrate | |
alt_pitches = [:C2, :E2, :G2, :A2, :C3, :E3, :G3, :A3, :C4, :E4, :G4, :A4, :C5, :E5, :G5, :A5, :C6, :E6, :G6, :A6] | |
count = 0 | |
data.each do |line| | |
puts count | |
if count % 8 == 0 # every eight heartrate measurement | |
heartrate = line[0] | |
heartsample = (heartrate.to_i / 4) - 18 | |
hpitch = heart_pitches[heartsample] | |
if count % 64 == 0 | |
boost = 1 | |
sample :ambi_soft_buzz, amp: 1 | |
else | |
boost = 0.5 | |
end | |
use_synth :piano | |
play hpitch, amp: boost | |
puts "heartrate: " + heartrate.to_s | |
sleep 0.2 | |
end | |
if count % 16 == 0 # every sixteenth altitude measurement | |
altitude = line[1].to_i | |
if altitude < 0 | |
altitude = 0 | |
end | |
apitch = alt_pitches[altitude] | |
use_synth :fm | |
play apitch, release: 1, amp: 0.5 | |
puts "altitude: " + altitude.to_s | |
end | |
if count % 32 == 0 | |
sample :bd_tek | |
end | |
count += 1 | |
end | |
sleep 1 | |
sample :ambi_soft_buzz, amp: 1 | |
sleep 2 | |
sample :ambi_soft_buzz, amp: 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment