require 'digest'
root=ARGV[0]||Dir.pwd;rate=22050;frames=66150;f0=440*2**((60-69)/12.0);phase=0.0
carrier=frames.times.map do |i|
 t=i.fdiv(rate);v=Math.sin(phase)*0.25*[t/0.02,1].min*[(3-t)/0.08,1].min*32767
 phase+=2*Math::PI*f0/rate;v
end
[['tremolo-steady-c4',false],['tremolo-amplitude-4hz',true]].each do |name,mod|
 a=carrier.each_with_index.map{|v,i|(v*(mod ? 0.625+0.375*Math.sin(2*Math::PI*4*i/rate.to_f) : 1)).round};pcm=a.pack('s<*')
 b='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'),b);puts "#{name}.wav #{b.bytesize} bytes SHA256 #{Digest::SHA256.hexdigest(b)}"
end
