Class: Synthesizer::Unison
- Inherits:
-
Object
- Object
- Synthesizer::Unison
- Defined in:
- lib/synthesizer/unison.rb
Constant Summary collapse
- UNI_NUM_MAX =
16
Instance Method Summary collapse
-
#initialize(note_perform, source, phase) ⇒ Unison
constructor
A new instance of Unison.
- #next(uni_num, uni_detune, uni_stereo, volume, pan, tune_semis, tune_cents, sym, sync) ⇒ Object
Constructor Details
#initialize(note_perform, source, phase) ⇒ Unison
Returns a new instance of Unison.
5 6 7 8 9 10 11 12 13 |
# File 'lib/synthesizer/unison.rb', line 5 def initialize(note_perform, source, phase) synth = note_perform.synth @note_perform = note_perform @source = source @source_contexts = UNI_NUM_MAX.times.map {|i| source.generate_context(synth.soundinfo, note_perform, phase.value) } end |
Instance Method Details
#next(uni_num, uni_detune, uni_stereo, volume, pan, tune_semis, tune_cents, sym, sync) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/synthesizer/unison.rb', line 15 def next(uni_num, uni_detune, uni_stereo, volume, pan, tune_semis, tune_cents, sym, sync) if uni_num<1.0 uni_num = 1.0 elsif UNI_NUM_MAX<uni_num uni_num = UNI_NUM_MAX end if uni_num==1.0 context = @source_contexts[0] l_gain, r_gain = Utils.panning(pan) hz = @note_perform.note.hz(semis: tune_semis, cents: tune_cents) buffer = @source.next(context, AudioStream::Rate.freq(hz), sym, sync, l_gain, r_gain) else buffer = uni_num.ceil.times.map {|i| context = @source_contexts[i] uni_volume = 1.0 if uni_num<i uni_volume = uni_num % 1.0 end sign = i.even? ? 1 : -1 diff = sign * (i + 1.0) / (uni_num + 1.0) detune_cents = uni_detune * diff * 100 diff_pan = uni_stereo * diff l_gain, r_gain = Utils.panning(pan + diff_pan) hz = @note_perform.note.hz(semis: tune_semis, cents: tune_cents + detune_cents) @source.next(context, AudioStream::Rate.freq(hz), sym, sync, l_gain * uni_volume / uni_num, r_gain * uni_volume / uni_num) }.inject(:+) end AudioStream::Buffer.new(*buffer.streams.map {|stream| stream * volume }) end |