require 'digest'
root=ARGV[0]||Dir.pwd;rate=22050;frames=66150;f0=440*2**((60-69)/12.0)
[['vibrato-steady-c4',0],['vibrato-35cents-5hz',35]].each do |name,depth|
 phase=0.0;a=frames.times.map do |i|
  t=i.fdiv(rate);value=(Math.sin(phase)*0.25*[t/0.02,1].min*[(3-t)/0.08,1].min*32767).round
  f=f0*2**((depth*Math.sin(2*Math::PI*5*t))/1200.0);phase+=2*Math::PI*f/rate;value
 end
 pcm=a.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.binwrite(File.join(root,name+'.wav'),wav);puts "#{name}.wav #{wav.bytesize} bytes SHA256 #{Digest::SHA256.hexdigest(wav)}"
end
