Class: Synthesizer::OscillatorSource::FormantVocoder
- Inherits:
-
Object
- Object
- Synthesizer::OscillatorSource::FormantVocoder
- Defined in:
- lib/synthesizer/oscillator_source/formant_vocoder.rb
Defined Under Namespace
Classes: Context
Constant Summary collapse
- @@f =
{ i: [110.0, 250.0, 2100.0, 2900.0, 3700.0], e: [160.0, 450.0, 1900.0, 2650.0, 3800.0], a: [110.0, 700.0, 1250.0, 2500.0, 3900.0], o: [110.0, 500.0, 1050.0, 2700.0, 3700.0], u: [110.0, 330.0, 1500.0, 2400.0, 3650.0], x: [110.0, 335.0, 1550.0, 2450.0, 3800.0], }
- @@gain =
[50.0, 70.0, 110.0, 200.0, 200.0].map {|x| Math::PI * x}
Instance Attribute Summary collapse
-
#pronunciation ⇒ Object
Returns the value of attribute pronunciation.
-
#vowels ⇒ Object
Returns the value of attribute vowels.
Instance Method Summary collapse
- #generate_context(soundinfo, note_perform, init_phase) ⇒ Object
-
#initialize(vowels: [:i, :e, :a, :o, :u], pronunciation: 0) ⇒ FormantVocoder
constructor
A new instance of FormantVocoder.
- #next(context, rate, sym, sync, l_gain, r_gain) ⇒ Object
- #resfil(x, v, a, w, dt, len) ⇒ Object
Constructor Details
#initialize(vowels: [:i, :e, :a, :o, :u], pronunciation: 0) ⇒ FormantVocoder
Returns a new instance of FormantVocoder.
17 18 19 20 21 |
# File 'lib/synthesizer/oscillator_source/formant_vocoder.rb', line 17 def initialize(vowels: [:i, :e, :a, :o, :u], pronunciation: 0) self.vowels = vowels self.pronunciation = pronunciation @pulse = Pulse.instance end |
Instance Attribute Details
#pronunciation ⇒ Object
Returns the value of attribute pronunciation.
5 6 7 |
# File 'lib/synthesizer/oscillator_source/formant_vocoder.rb', line 5 def pronunciation @pronunciation end |
#vowels ⇒ Object
Returns the value of attribute vowels.
4 5 6 |
# File 'lib/synthesizer/oscillator_source/formant_vocoder.rb', line 4 def vowels @vowels end |
Instance Method Details
#generate_context(soundinfo, note_perform, init_phase) ⇒ Object
95 96 97 |
# File 'lib/synthesizer/oscillator_source/formant_vocoder.rb', line 95 def generate_context(soundinfo, note_perform, init_phase) Context.new(soundinfo, note_perform, init_phase, @pronunciation) end |
#next(context, rate, sym, sync, l_gain, r_gain) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/synthesizer/oscillator_source/formant_vocoder.rb', line 33 def next(context, rate, sym, sync, l_gain, r_gain) soundinfo = context.soundinfo channels = context.channels window_size = context.window_size samplerate = context.samplerate tmpbufs = context.tmpbufs pronunciation_mod = context.pronunciation_mod pulse_context = context.pulse_context pulse = Pulse.instance.next(pulse_context, rate, sym, sync, 0.5, 0.5).streams[0] notediff = Math.log2(rate.freq(soundinfo) / 440.0) * 12 + 69 - 36 if notediff<0.0 notediff = 0.0 end notediff = Math.sqrt(notediff) vowels = @vowels.map {|vowel| vowel.map{|f| f * (ShapePos::SEMITONE_RATIO ** notediff)} } r_index = pronunciation_mod[] index = r_index.to_i dst = 5.times.map {|i| #dst = (1...5).each.map {|i| tmpbuf = tmpbufs[i] freq = vowels[index % @vowels_len][i]+(vowels[(index+1) % @vowels_len][i]-vowels[index % @vowels_len][i])*(r_index-index) w = Math::PI * 2 * freq resfil(pulse, tmpbufs[i], @@gain[i], w, 1.0/samplerate, window_size) }.inject(:+) case channels when 1 Buffer.new(dst * l_gain) when 2 Buffer.new(dst * l_gain, dst * r_gain) end end |
#resfil(x, v, a, w, dt, len) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/synthesizer/oscillator_source/formant_vocoder.rb', line 72 def resfil(x, v, a, w, dt, len) b = 2.0 * (Math::E ** (-a*dt)) * Math.cos(w*dt) c = Math::E ** (-2.0 * a * dt) d = ((a*a+w*w)/w) * (Math::E ** (-a*dt)) * Math.sin(w*dt) #v[0] = v[len-2] #v[1] = v[len-1] #v[0] += 1.0 #Vdsp::UnsafeDouble.vsmsma(v, 1, 1, b, v, 0, 1, -c, v, 2, 1, len) #v * (d / 25000.to_f) v[0] = v[len-2] v[1] = v[len-1] y = len.times.map {|i| v[i+2] = b * v[i+1] - c * v[i] + x[i] v[i+1] * (d / 25000.to_f) } Vdsp::DoubleArray.create(y) end |