require 'digest'
require 'json'
root=ARGV[0] || Dir.pwd
rate=22050;frames=66150;f0=440.0*2**((60-69)/12.0)
files=%w[steady-c4 rising-two-semitones].map do |kind|
 phase=0.0
 pcm=frames.times.map do |i|
  t=i.to_f/rate;cents=kind=='steady-c4' ? 0.0 : 200.0*[t/2.8,1].min
  sample=(Math.sin(phase)*0.32*[t/0.02,1].min*[(3.0-t)/0.08,1].min*32767).round
  phase+=2*Math::PI*f0*2**(cents/1200.0)/rate
  sample
 end.pack('s<*')
 wav='RIFF'+[36+pcm.bytesize].pack('V')+'WAVEfmt '+[16,1,1,rate,rate*2,2,16].pack('VvvVVvv')+'data'+[pcm.bytesize].pack('V')+pcm
 file=File.join(root,'glide-'+kind+'.wav');File.binwrite(file,wav)
 {file:file,bytes:wav.bytesize,sha256:Digest::SHA256.hexdigest(wav)}
end
puts JSON.pretty_generate(files)
