Skip to content

Commit

Permalink
Harmonizer#samples does its own work
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmacphersonmusic committed May 15, 2015
1 parent 51c5792 commit 4a58068
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/music_theory/harmonize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@
module MusicTheory
class Harmonize
include MusicTheory::Output
attr_accessor :samples

def initialize(*things_to_flatten)
max_sample_array_length = things_to_flatten.map(&:length).max
@things_to_flatten = things_to_flatten
end

def samples
max_sample_array_length = @things_to_flatten.map(&:length).max
@samples = Array.new(max_sample_array_length, 0)

things_to_flatten.each do |group|
@things_to_flatten.each do |group|
group.each_with_index do |value, i|
@samples[i] += value
end
end

max = @samples.map {|s| s.abs }.max
multiplier = 1.0 / max
@samples.map!{ |s| multiplier * s }
max = @samples.map {|s| s.abs }.max
multiplier = 1.0 / max
@samples.map!{ |s| multiplier * s }
end
end
end

0 comments on commit 4a58068

Please sign in to comment.