f fis g gis) FREQUENCIES = { d4:-7, dis4:-6, e4:-5, f4: -4, fis4:-3, g4:-2, gis4:-1, a4: 0, ais4: 1, b4: 2, c5: 3, cis5: 4, d5: 5 } # get the frequency of the pitch def frequency_of(step) 440.0*(2**(step.to_f/12.0)) end sample_rate = 44100.0 # 44100 Hz duration = 1 # 1 sec stream = [] # data stream for left and right channels frequency = frequency_of(FREQUENCIES[:a4]) # for the duration of 1 sec, step every 1/44100 times and # write the value (0.0..duration.to_f).step(1/sample_rate) do |i| x = (10000 * Math.sin(2 * Math::PI * frequency * i)).to_i stream << [x,x] end Monday, 24 June, 13
Math::PI * input * 2) end # for the duration of 1 sec, step every 1/44100 times and # write the value (0.0..duration.to_f).step(1/sample_rate) do |i| x = (10000 * harmonics(frequency * i)).to_i stream << [x,x] end Monday, 24 June, 13
Math::PI * input * 2) end # for the duration of 1 sec, step every 1/44100 times and # write the value (0.0..duration.to_f).step(1/sample_rate) do |i| x = (10000 * harmonics(frequency * i)).to_i stream << [x,x] end Monday, 24 June, 13
f fis g gis) FREQUENCIES = { d4:-7, dis4:-6, e4:-5, f4:-4, fis4:-3, g4:-2, gis4:-1, a4: 0, ais4: 1, b4: 2, c5: 3, cis5: 4, d5: 5 } # get the frequency of the pitch def frequency_of(step) 440.0*(2**(step.to_f/12.0)) end sample_rate = 44100.0 # 44100 Hz duration = 1 # 1 sec stream = [] # data stream for left and right channels frequency = frequency_of(FREQUENCIES[:a4]) # for the duration of 1 sec, step every 1/44100 times and # write the value (0.0..duration.to_f).step(1/sample_rate) do |i| x = (10000 * Math.sin(2 * Math::PI * frequency * i)).to_i stream << [x,x] end wav_file = Wav.new('sine.wav') wav_file.write(stream) wav_file.close Monday, 24 June, 13
name.to_s if name.start_with? *NOTES ... end end end require "muse" include Muse Song.record 'hotel_california', harmonic: 'guitar', bpm: 100 do ... bar(3).notes { a3_d4_fis4; fis4; fis4 b:0.5;} ... end Monday, 24 June, 13
{ 0 => %w(c d e f g a b c d), 1 => %w(g a b c d e fis g a), 2 => %w(d e fis g a b cis d e), 3 => %w(a b cis d e fis gis a b), 4 => %w(e fis gis a b cis dis e fis), 5 => %w(b cis dis e fis gis ais b cis), 6 => %w(fis gis ais b cis dis f fis gis) } num_of_sharps = most_frequent_7_notes.inject(0) { |memo, obj| obj.end_with? ("is") ? memo + 1 : memo } scale = MAJOR[num_of_sharps] Monday, 24 June, 13