synthesizer 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0abef47757011239dac5fe3bf5b746504491ba44eca05ce22fc6564fe00e390b
4
- data.tar.gz: f34263d9c956a57a096987824371ea1baf69f0a4cbc87fc40059101b07ce436c
3
+ metadata.gz: ed8a308cdf0bcb0baf27daffd40c86c4998c8ca5d49ee90d1c0a2aac7a69c64d
4
+ data.tar.gz: 46fbff7561bb5883dac304b083bed46bd6690e840096cd7c4b48f04d32542bac
5
5
  SHA512:
6
- metadata.gz: 60974d1c179a679d67cd5c044378f64b31b000a83baf2c989937969165fd7d317b3ef2f8747734a75fad24d40fb1cd1de02137dd1f1ffff5e6b758968e5e9626
7
- data.tar.gz: 97c4177887836a7a0d48165e6b6181eefe9e7993b53dd451f176e427620b42f8aed431d3b24e7fe33399a5e15c1e8479426054f21355001f5cd64898e5100896
6
+ metadata.gz: 9e9444d9132322cb3382e809a77a4803e895f5dd5aedf4de86272f616e27abc525734124d915cd1dd47f24e98e7b9d31716c88783337bc18f47e1b09d4e12ea3
7
+ data.tar.gz: 2141b9541d1700616b9d131887218727284210b28488dd9007d08adfd05190320993099145d016b0c84b75cf19a61e74c3bcdf8b0f19249d260d7c05b7e6697d
@@ -6,19 +6,17 @@ module Synthesizer
6
6
  @bandwidth = ModulationValue.create(bandwidth)
7
7
  end
8
8
 
9
- def generator(note_perform, framerate, &block)
10
- Enumerator.new do |y|
11
- soundinfo = note_perform.synth.soundinfo
12
- filter = AudioStream::Fx::BandPassFilter.new(soundinfo)
9
+ def generator(note_perform, framerate)
10
+ soundinfo = note_perform.synth.soundinfo
11
+ filter = AudioStream::Fx::BandPassFilter.new(soundinfo)
13
12
 
14
- freq_mod = ModulationValue.balance_generator(note_perform, framerate, @freq)
15
- bandwidth_mod = ModulationValue.balance_generator(note_perform, framerate, @bandwidth)
13
+ freq_mod = ModulationValue.balance_generator(note_perform, framerate, @freq)
14
+ bandwidth_mod = ModulationValue.balance_generator(note_perform, framerate, @bandwidth)
16
15
 
17
- loop {
18
- filter.update_coef(freq: freq_mod.next, bandwidth: bandwidth_mod.next)
19
- y << filter
20
- }
21
- end.each(&block)
16
+ -> {
17
+ filter.update_coef(freq: freq_mod[], bandwidth: bandwidth_mod[])
18
+ filter
19
+ }
22
20
  end
23
21
  end
24
22
  end
@@ -6,19 +6,17 @@ module Synthesizer
6
6
  @q = ModulationValue.create(q)
7
7
  end
8
8
 
9
- def generator(note_perform, framerate, &block)
10
- Enumerator.new do |y|
11
- soundinfo = note_perform.synth.soundinfo
12
- filter = AudioStream::Fx::HighPassFilter.new(soundinfo)
9
+ def generator(note_perform, framerate)
10
+ soundinfo = note_perform.synth.soundinfo
11
+ filter = AudioStream::Fx::HighPassFilter.new(soundinfo)
13
12
 
14
- freq_mod = ModulationValue.balance_generator(note_perform, framerate, @freq)
15
- q_mod = ModulationValue.balance_generator(note_perform, framerate, @q)
13
+ freq_mod = ModulationValue.balance_generator(note_perform, framerate, @freq)
14
+ q_mod = ModulationValue.balance_generator(note_perform, framerate, @q)
16
15
 
17
- loop {
18
- filter.update_coef(freq: freq_mod.next, q: q_mod.next)
19
- y << filter
20
- }
21
- end.each(&block)
16
+ -> {
17
+ filter.update_coef(freq: freq_mod[], q: q_mod[])
18
+ filter
19
+ }
22
20
  end
23
21
  end
24
22
  end
@@ -7,20 +7,18 @@ module Synthesizer
7
7
  @gain = ModulationValue.create(gain)
8
8
  end
9
9
 
10
- def generator(note_perform, framerate, &block)
11
- Enumerator.new do |y|
12
- soundinfo = note_perform.synth.soundinfo
13
- filter = AudioStream::Fx::HighShelfFilter.new(soundinfo)
10
+ def generator(note_perform, framerate)
11
+ soundinfo = note_perform.synth.soundinfo
12
+ filter = AudioStream::Fx::HighShelfFilter.new(soundinfo)
14
13
 
15
- freq_mod = ModulationValue.balance_generator(note_perform, framerate, @freq)
16
- q_mod = ModulationValue.balance_generator(note_perform, framerate, @q)
17
- gain_mod = ModulationValue.balance_generator(note_perform, framerate, @gain)
14
+ freq_mod = ModulationValue.balance_generator(note_perform, framerate, @freq)
15
+ q_mod = ModulationValue.balance_generator(note_perform, framerate, @q)
16
+ gain_mod = ModulationValue.balance_generator(note_perform, framerate, @gain)
18
17
 
19
- loop {
20
- filter.update_coef(freq: freq_mod.next, q: q_mod.next, gain: gain_mod.next)
21
- y << filter
22
- }
23
- end.each(&block)
18
+ -> {
19
+ filter.update_coef(freq: freq_mod[], q: q_mod[], gain: gain_mod[])
20
+ filter
21
+ }
24
22
  end
25
23
  end
26
24
  end
@@ -6,19 +6,17 @@ module Synthesizer
6
6
  @q = ModulationValue.create(q)
7
7
  end
8
8
 
9
- def generator(note_perform, framerate, &block)
10
- Enumerator.new do |y|
11
- soundinfo = note_perform.synth.soundinfo
12
- filter = AudioStream::Fx::LowPassFilter.new(soundinfo)
9
+ def generator(note_perform, framerate)
10
+ soundinfo = note_perform.synth.soundinfo
11
+ filter = AudioStream::Fx::LowPassFilter.new(soundinfo)
13
12
 
14
- freq_mod = ModulationValue.balance_generator(note_perform, framerate, @freq)
15
- q_mod = ModulationValue.balance_generator(note_perform, framerate, @q)
13
+ freq_mod = ModulationValue.balance_generator(note_perform, framerate, @freq)
14
+ q_mod = ModulationValue.balance_generator(note_perform, framerate, @q)
16
15
 
17
- loop {
18
- filter.update_coef(freq: freq_mod.next, q: q_mod.next)
19
- y << filter
20
- }
21
- end.each(&block)
16
+ -> {
17
+ filter.update_coef(freq: freq_mod[], q: q_mod[])
18
+ filter
19
+ }
22
20
  end
23
21
  end
24
22
  end
@@ -7,20 +7,18 @@ module Synthesizer
7
7
  @gain = ModulationValue.create(gain)
8
8
  end
9
9
 
10
- def generator(note_perform, framerate, &block)
11
- Enumerator.new do |y|
12
- soundinfo = note_perform.synth.soundinfo
13
- filter = AudioStream::Fx::LowShelfFilter.new(soundinfo)
10
+ def generator(note_perform, framerate)
11
+ soundinfo = note_perform.synth.soundinfo
12
+ filter = AudioStream::Fx::LowShelfFilter.new(soundinfo)
14
13
 
15
- freq_mod = ModulationValue.balance_generator(note_perform, framerate, @freq)
16
- q_mod = ModulationValue.balance_generator(note_perform, framerate, @q)
17
- gain_mod = ModulationValue.balance_generator(note_perform, framerate, @gain)
14
+ freq_mod = ModulationValue.balance_generator(note_perform, framerate, @freq)
15
+ q_mod = ModulationValue.balance_generator(note_perform, framerate, @q)
16
+ gain_mod = ModulationValue.balance_generator(note_perform, framerate, @gain)
18
17
 
19
- loop {
20
- filter.update_coef(freq: freq_mod.next, q: q_mod.next, gain: gain_mod.next)
21
- y << filter
22
- }
23
- end.each(&block)
18
+ -> {
19
+ filter.update_coef(freq: freq_mod[], q: q_mod[], gain: gain_mod[])
20
+ filter
21
+ }
24
22
  end
25
23
  end
26
24
  end
@@ -5,17 +5,15 @@ module Synthesizer
5
5
  @filters = filters
6
6
  end
7
7
 
8
- def generator(note_perform, framerate, &block)
9
- Enumerator.new do |y|
10
- filter_mods = @filters.map {|filter|
11
- filter.generator(note_perform, framerate)
12
- }
8
+ def generator(note_perform, framerate)
9
+ filter_mods = @filters.map {|filter|
10
+ filter.generator(note_perform, framerate)
11
+ }
13
12
 
14
- loop {
15
- fxs = filter_mods.map(&:next)
16
- y << Fx.new(fxs)
17
- }
18
- end.each(&block)
13
+ -> {
14
+ fxs = filter_mods.map(&:[])
15
+ Fx.new(fxs)
16
+ }
19
17
  end
20
18
 
21
19
  class Fx
@@ -7,20 +7,18 @@ module Synthesizer
7
7
  @gain = ModulationValue.create(gain)
8
8
  end
9
9
 
10
- def generator(note_perform, framerate, &block)
11
- Enumerator.new do |y|
12
- soundinfo = note_perform.synth.soundinfo
13
- filter = AudioStream::Fx::LowShelfFilter.new(soundinfo)
10
+ def generator(note_perform, framerate)
11
+ soundinfo = note_perform.synth.soundinfo
12
+ filter = AudioStream::Fx::LowShelfFilter.new(soundinfo)
14
13
 
15
- freq_mod = ModulationValue.balance_generator(note_perform, framerate, @freq)
16
- bandwidth_mod = ModulationValue.balance_generator(note_perform, framerate, @bandwidth)
17
- gain_mod = ModulationValue.balance_generator(note_perform, framerate, @gain)
14
+ freq_mod = ModulationValue.balance_generator(note_perform, framerate, @freq)
15
+ bandwidth_mod = ModulationValue.balance_generator(note_perform, framerate, @bandwidth)
16
+ gain_mod = ModulationValue.balance_generator(note_perform, framerate, @gain)
18
17
 
19
- loop {
20
- filter.update_coef(freq: freq_mod.next, bandwidth: bandwidth_mod.next, gain: gain_mod.next)
21
- y << filter
22
- }
23
- end.each(&block)
18
+ -> {
19
+ filter.update_coef(freq: freq_mod[], bandwidth: bandwidth_mod[], gain: gain_mod[])
20
+ filter
21
+ }
24
22
  end
25
23
  end
26
24
  end
@@ -5,17 +5,15 @@ module Synthesizer
5
5
  @filters = filters
6
6
  end
7
7
 
8
- def generator(note_perform, framerate, &block)
9
- Enumerator.new do |y|
10
- filter_mods = @filters.map {|filter|
11
- filter.generator(note_perform, framerate)
12
- }
8
+ def generator(note_perform, framerate)
9
+ filter_mods = @filters.map {|filter|
10
+ filter.generator(note_perform, framerate)
11
+ }
13
12
 
14
- loop {
15
- fxs = filter_mods.map(&:next)
16
- y << Fx.new(fxs)
17
- }
18
- end.each(&block)
13
+ -> {
14
+ fxs = filter_mods.map(&:[])
15
+ Fx.new(fxs)
16
+ }
19
17
  end
20
18
 
21
19
  class Fx
@@ -73,36 +73,36 @@ module Synthesizer
73
73
  end.each(&block)
74
74
  end
75
75
 
76
- def generator(note_perform, framerate, release_sustain:, &block)
77
- Enumerator.new do |y|
78
- note_on = note_on_envelope(framerate, sustain: true)
79
- note_off = note_off_envelope(framerate, sustain: release_sustain)
80
- last = 0.0
81
-
82
- loop {
83
- if note_perform.note_on?
84
- last = note_on.next
85
- y << last
86
- else
87
- y << note_off.next * last
88
- end
89
- }
90
- end.each(&block)
76
+ def generator(note_perform, framerate, release_sustain:)
77
+ note_on = note_on_envelope(framerate, sustain: true)
78
+ note_off = note_off_envelope(framerate, sustain: release_sustain)
79
+ last = 0.0
80
+
81
+ -> {
82
+ if note_perform.note_on?
83
+ last = note_on.next
84
+ else
85
+ note_off.next * last
86
+ end
87
+ }
91
88
  end
92
89
 
93
90
 
94
91
  def amp_generator(note_perform, framerate, depth, &block)
95
92
  bottom = 1.0 - depth
93
+ gen = generator(note_perform, framerate, release_sustain: 0.0<bottom)
96
94
 
97
- generator(note_perform, framerate, release_sustain: 0.0<bottom).lazy.map {|val|
98
- val * depth + bottom
99
- }.each(&block)
95
+ -> {
96
+ gen[] * depth + bottom
97
+ }
100
98
  end
101
99
 
102
100
  def balance_generator(note_perform, framerate, depth, &block)
103
- generator(note_perform, framerate, release_sustain: true).lazy.map {|val|
104
- val * depth
105
- }.each(&block)
101
+ gen = generator(note_perform, framerate, release_sustain: true)
102
+
103
+ -> {
104
+ gen[] * depth
105
+ }
106
106
  end
107
107
 
108
108
  def plot_data(framerate: 44100)
@@ -26,42 +26,46 @@ module Synthesizer
26
26
  @diff = target - @current
27
27
  end
28
28
 
29
- def generator(note_perform, samplerate, &block)
30
- Enumerator.new do |yld|
31
- rate = @time * samplerate
29
+ def generator(note_perform, samplerate)
30
+ rate = @time * samplerate
32
31
 
33
- loop {
34
- if note_perform.note_on?
35
- # Note On
36
- if 0<@time && @target!=@current
37
- # Gliding
38
- x = @diff / rate
39
- if x.abs<(@target-@current).abs
40
- @current += x
41
- else
42
- @current = @target
43
- end
32
+ -> {
33
+ ret = nil
44
34
 
45
- yld << @current - @base
35
+ if note_perform.note_on?
36
+ # Note On
37
+ if 0<@time && @target!=@current
38
+ # Gliding
39
+ x = @diff / rate
40
+ if x.abs<(@target-@current).abs
41
+ @current += x
46
42
  else
47
- # Stay
48
- yld << @target - @base
43
+ @current = @target
49
44
  end
45
+
46
+ ret = @current - @base
50
47
  else
51
- # Note Off
52
- @current = 0.0
53
- @target = 0.0
54
- @diff = 0.0
55
- yld << 0.0
48
+ # Stay
49
+ ret = @target - @base
56
50
  end
57
- }
58
- end.each(&block)
51
+ else
52
+ # Note Off
53
+ @current = 0.0
54
+ @target = 0.0
55
+ @diff = 0.0
56
+ ret = 0.0
57
+ end
58
+
59
+ ret
60
+ }
59
61
  end
60
62
 
61
- def balance_generator(note_perform, samplerate, depth, &block)
62
- generator(note_perform, samplerate).lazy.map {|val|
63
- val * depth
64
- }.each(&block)
63
+ def balance_generator(note_perform, samplerate, depth)
64
+ gen = generator(note_perform, samplerate)
65
+
66
+ -> {
67
+ gen[] * depth
68
+ }
65
69
  end
66
70
 
67
71
  def to_modval
@@ -47,17 +47,20 @@ module Synthesizer
47
47
 
48
48
  def amp_generator(note_perform, framerate, depth, &block)
49
49
  bottom = 1.0 - depth
50
+ gen = generator(note_perform, framerate)
50
51
 
51
- generator(note_perform, framerate).lazy.map {|val|
52
- val = (val + 1) / 2
52
+ -> {
53
+ val = (gen.next + 1) / 2
53
54
  val * depth + bottom
54
- }.each(&block)
55
+ }
55
56
  end
56
57
 
57
58
  def balance_generator(note_perform, framerate, depth, &block)
58
- generator(note_perform, framerate).lazy.map {|val|
59
- val * depth
60
- }.each(&block)
59
+ gen = generator(note_perform, framerate)
60
+
61
+ -> {
62
+ gen.next * depth
63
+ }
61
64
  end
62
65
  end
63
66
  end
@@ -49,12 +49,10 @@ module Synthesizer
49
49
  }
50
50
  }
51
51
 
52
- Enumerator.new do |y|
53
- loop {
54
- depth = mods.map(&:next).inject(1.0, &:*)
55
- y << value * depth
56
- }
57
- end
52
+ -> {
53
+ depth = mods.map(&:[]).inject(1.0, &:*)
54
+ value * depth
55
+ }
58
56
  end
59
57
 
60
58
  def self.balance_generator(note_perform, framerate, *modvals, center: 0)
@@ -72,12 +70,10 @@ module Synthesizer
72
70
  }
73
71
  }
74
72
 
75
- Enumerator.new do |y|
76
- loop {
77
- depth = mods.map(&:next).sum
78
- y << value + depth
79
- }
80
- end
73
+ -> {
74
+ depth = mods.map(&:[]).sum
75
+ value + depth
76
+ }
81
77
  end
82
78
  end
83
79
  end
@@ -20,7 +20,7 @@ module Synthesizer
20
20
 
21
21
  def next
22
22
  begin
23
- @processors.map(&:next).inject(:+)
23
+ @processors.map(&:[]).inject(:+)
24
24
  rescue StopIteration => e
25
25
  @released = true
26
26
  nil
@@ -1,92 +1,90 @@
1
1
  module Synthesizer
2
2
  module Processor
3
3
  class High
4
- def generator(osc, note_perform, &block)
5
- Enumerator.new do |y|
6
- synth = note_perform.synth
7
- filter = synth.filter
8
- amp = synth.amplifier
9
- channels = synth.soundinfo.channels
10
- window_size = synth.soundinfo.window_size
11
- framerate = synth.soundinfo.samplerate
12
-
13
- # Oscillator, Amplifier
14
- volume_mod = ModulationValue.amp_generator(note_perform, framerate, osc.volume, amp.volume)
15
- pan_mod = ModulationValue.balance_generator(note_perform, framerate, osc.pan, amp.pan)
16
- tune_semis_mod = ModulationValue.balance_generator(note_perform, framerate, osc.tune_semis, amp.tune_semis, synth.glide&.to_modval)
17
- tune_cents_mod = ModulationValue.balance_generator(note_perform, framerate, osc.tune_cents, amp.tune_cents)
18
-
19
- uni_num_mod = ModulationValue.balance_generator(note_perform, framerate, osc.uni_num, amp.uni_num, center: 1.0)
20
- uni_detune_mod = ModulationValue.balance_generator(note_perform, framerate, osc.uni_detune, amp.uni_detune)
21
- unison = Unison.new(note_perform, osc.shape, osc.phase)
22
-
23
- # Filter
24
- filter_mod = nil
25
- if filter
26
- filter_mod = filter.generator(note_perform, framerate)
27
- end
28
-
29
- case channels
30
- when 1
31
- loop {
32
- buf = AudioStream::Buffer.create_mono(window_size)
33
- dst0 = buf.streams[0]
34
-
35
- window_size.times.each {|i|
36
- # Oscillator, Amplifier
37
- volume = volume_mod.next * note_perform.velocity
38
- tune_semis = tune_semis_mod.next + synth.pitch_bend
39
- tune_cents = tune_cents_mod.next
40
-
41
- uni_num = uni_num_mod.next
42
- uni_detune = uni_detune_mod.next
43
-
44
- sval = unison.next(uni_num, uni_detune, volume, 0.0, tune_semis, tune_cents)
45
- mval = (sval[0] + sval[1]) / 2.0
46
-
47
- # Filter
48
- if filter_mod
49
- filter_fx = filter_mod.next
50
- mval = filter_fx.process_mono(mval)
51
- end
52
-
53
- dst0[i] = mval
54
- }
55
-
56
- y << buf
4
+ def generator(osc, note_perform)
5
+ synth = note_perform.synth
6
+ filter = synth.filter
7
+ amp = synth.amplifier
8
+ channels = synth.soundinfo.channels
9
+ window_size = synth.soundinfo.window_size
10
+ framerate = synth.soundinfo.samplerate.to_f
11
+
12
+ # Oscillator, Amplifier
13
+ volume_mod = ModulationValue.amp_generator(note_perform, framerate, osc.volume, amp.volume)
14
+ pan_mod = ModulationValue.balance_generator(note_perform, framerate, osc.pan, amp.pan)
15
+ tune_semis_mod = ModulationValue.balance_generator(note_perform, framerate, osc.tune_semis, amp.tune_semis, synth.glide&.to_modval)
16
+ tune_cents_mod = ModulationValue.balance_generator(note_perform, framerate, osc.tune_cents, amp.tune_cents)
17
+
18
+ uni_num_mod = ModulationValue.balance_generator(note_perform, framerate, osc.uni_num, amp.uni_num, center: 1.0)
19
+ uni_detune_mod = ModulationValue.balance_generator(note_perform, framerate, osc.uni_detune, amp.uni_detune)
20
+ unison = Unison.new(note_perform, osc.shape, osc.phase)
21
+
22
+ # Filter
23
+ filter_mod = nil
24
+ if filter
25
+ filter_mod = filter.generator(note_perform, framerate / window_size)
26
+ end
27
+
28
+ case channels
29
+ when 1
30
+ -> {
31
+ buf = AudioStream::Buffer.create_mono(window_size)
32
+ dst0 = buf.streams[0]
33
+
34
+ window_size.times.each {|i|
35
+ # Oscillator, Amplifier
36
+ volume = volume_mod[] * note_perform.velocity
37
+ tune_semis = tune_semis_mod[] + synth.pitch_bend
38
+ tune_cents = tune_cents_mod[]
39
+
40
+ uni_num = uni_num_mod[]
41
+ uni_detune = uni_detune_mod[]
42
+
43
+ sval = unison.next(uni_num, uni_detune, volume, 0.0, tune_semis, tune_cents)
44
+ mval = (sval[0] + sval[1]) / 2.0
45
+
46
+ dst0[i] = mval
57
47
  }
58
- when 2
59
- loop {
60
- buf = AudioStream::Buffer.create_stereo(window_size)
61
- dst0 = buf.streams[0]
62
- dst1 = buf.streams[1]
63
-
64
- window_size.times.each {|i|
65
- # Oscillator, Amplifier
66
- volume = volume_mod.next * note_perform.velocity
67
- pan = pan_mod.next
68
- tune_semis = tune_semis_mod.next + synth.pitch_bend
69
- tune_cents = tune_cents_mod.next
70
-
71
- uni_num = uni_num_mod.next
72
- uni_detune = uni_detune_mod.next
73
-
74
- sval = unison.next(uni_num, uni_detune, volume, pan, tune_semis, tune_cents)
75
-
76
- # Filter
77
- if filter_mod
78
- filter_fx = filter_mod.next
79
- sval = filter_fx.process_stereo(sval)
80
- end
81
-
82
- dst0[i] = sval[0]
83
- dst1[i] = sval[1]
84
- }
85
-
86
- y << buf
48
+
49
+ # Filter
50
+ if filter_mod
51
+ filter_fx = filter_mod[]
52
+ buf = filter_fx.process(buf)
53
+ end
54
+
55
+ buf
56
+ }
57
+ when 2
58
+ -> {
59
+ buf = AudioStream::Buffer.create_stereo(window_size)
60
+ dst0 = buf.streams[0]
61
+ dst1 = buf.streams[1]
62
+
63
+ window_size.times.each {|i|
64
+ # Oscillator, Amplifier
65
+ volume = volume_mod[] * note_perform.velocity
66
+ pan = pan_mod[]
67
+ tune_semis = tune_semis_mod[] + synth.pitch_bend
68
+ tune_cents = tune_cents_mod[]
69
+
70
+ uni_num = uni_num_mod[]
71
+ uni_detune = uni_detune_mod[]
72
+
73
+ sval = unison.next(uni_num, uni_detune, volume, pan, tune_semis, tune_cents)
74
+
75
+ dst0[i] = sval[0]
76
+ dst1[i] = sval[1]
87
77
  }
88
- end
89
- end.each(&block)
78
+
79
+ # Filter
80
+ if filter_mod
81
+ filter_fx = filter_mod[]
82
+ buf = filter_fx.process(buf)
83
+ end
84
+
85
+ buf
86
+ }
87
+ end
90
88
  end
91
89
  end
92
90
  end
@@ -1,89 +1,87 @@
1
1
  module Synthesizer
2
2
  module Processor
3
3
  class Low
4
- def generator(osc, note_perform, &block)
5
- Enumerator.new do |y|
6
- synth = note_perform.synth
7
- filter = synth.filter
8
- amp = synth.amplifier
9
- channels = synth.soundinfo.channels
10
- window_size = synth.soundinfo.window_size
11
- framerate = synth.soundinfo.samplerate.to_f / window_size
4
+ def generator(osc, note_perform)
5
+ synth = note_perform.synth
6
+ filter = synth.filter
7
+ amp = synth.amplifier
8
+ channels = synth.soundinfo.channels
9
+ window_size = synth.soundinfo.window_size
10
+ framerate = synth.soundinfo.samplerate.to_f / window_size
12
11
 
13
- # Oscillator, Amplifier
14
- volume_mod = ModulationValue.amp_generator(note_perform, framerate, osc.volume, amp.volume)
15
- pan_mod = ModulationValue.balance_generator(note_perform, framerate, osc.pan, amp.pan)
16
- tune_semis_mod = ModulationValue.balance_generator(note_perform, framerate, osc.tune_semis, amp.tune_semis, synth.glide&.to_modval)
17
- tune_cents_mod = ModulationValue.balance_generator(note_perform, framerate, osc.tune_cents, amp.tune_cents)
12
+ # Oscillator, Amplifier
13
+ volume_mod = ModulationValue.amp_generator(note_perform, framerate, osc.volume, amp.volume)
14
+ pan_mod = ModulationValue.balance_generator(note_perform, framerate, osc.pan, amp.pan)
15
+ tune_semis_mod = ModulationValue.balance_generator(note_perform, framerate, osc.tune_semis, amp.tune_semis, synth.glide&.to_modval)
16
+ tune_cents_mod = ModulationValue.balance_generator(note_perform, framerate, osc.tune_cents, amp.tune_cents)
18
17
 
19
- uni_num_mod = ModulationValue.balance_generator(note_perform, framerate, osc.uni_num, amp.uni_num, center: 1.0)
20
- uni_detune_mod = ModulationValue.balance_generator(note_perform, framerate, osc.uni_detune, amp.uni_detune)
21
- unison = Unison.new(note_perform, osc.shape, osc.phase)
18
+ uni_num_mod = ModulationValue.balance_generator(note_perform, framerate, osc.uni_num, amp.uni_num, center: 1.0)
19
+ uni_detune_mod = ModulationValue.balance_generator(note_perform, framerate, osc.uni_detune, amp.uni_detune)
20
+ unison = Unison.new(note_perform, osc.shape, osc.phase)
22
21
 
23
- # Filter
24
- filter_mod = nil
25
- if filter
26
- filter_mod = filter.generator(note_perform, framerate)
27
- end
22
+ # Filter
23
+ filter_mod = nil
24
+ if filter
25
+ filter_mod = filter.generator(note_perform, framerate)
26
+ end
28
27
 
29
- case channels
30
- when 1
31
- loop {
32
- buf = AudioStream::Buffer.create_mono(window_size)
33
- dst0 = buf.streams[0]
28
+ case channels
29
+ when 1
30
+ -> {
31
+ buf = AudioStream::Buffer.create_mono(window_size)
32
+ dst0 = buf.streams[0]
34
33
 
35
- # Oscillator, Amplifier
36
- volume = volume_mod.next * note_perform.velocity
37
- tune_semis = tune_semis_mod.next + synth.pitch_bend
38
- tune_cents = tune_cents_mod.next
34
+ # Oscillator, Amplifier
35
+ volume = volume_mod[] * note_perform.velocity
36
+ tune_semis = tune_semis_mod[] + synth.pitch_bend
37
+ tune_cents = tune_cents_mod[]
39
38
 
40
- uni_num = uni_num_mod.next
41
- uni_detune = uni_detune_mod.next
39
+ uni_num = uni_num_mod[]
40
+ uni_detune = uni_detune_mod[]
42
41
 
43
- window_size.times.each {|i|
44
- val = unison.next(uni_num, uni_detune, volume, 0.0, tune_semis, tune_cents)
45
- dst0[i] = (val[0] + val[1]) / 2.0
46
- }
47
-
48
- # Filter
49
- if filter_mod
50
- filter_fx = filter_mod.next
51
- buf = filter_fx.process(buf)
52
- end
53
-
54
- y << buf
42
+ window_size.times.each {|i|
43
+ val = unison.next(uni_num, uni_detune, volume, 0.0, tune_semis, tune_cents)
44
+ dst0[i] = (val[0] + val[1]) / 2.0
55
45
  }
56
- when 2
57
- loop {
58
- buf = AudioStream::Buffer.create_stereo(window_size)
59
- dst0 = buf.streams[0]
60
- dst1 = buf.streams[1]
61
46
 
62
- # Oscillator, Amplifier
63
- volume = volume_mod.next * note_perform.velocity
64
- pan = pan_mod.next
65
- tune_semis = tune_semis_mod.next + synth.pitch_bend
66
- tune_cents = tune_cents_mod.next
47
+ # Filter
48
+ if filter_mod
49
+ filter_fx = filter_mod[]
50
+ buf = filter_fx.process(buf)
51
+ end
67
52
 
68
- uni_num = uni_num_mod.next
69
- uni_detune = uni_detune_mod.next
53
+ buf
54
+ }
55
+ when 2
56
+ -> {
57
+ buf = AudioStream::Buffer.create_stereo(window_size)
58
+ dst0 = buf.streams[0]
59
+ dst1 = buf.streams[1]
70
60
 
71
- window_size.times.each {|i|
72
- val = unison.next(uni_num, uni_detune, volume, pan, tune_semis, tune_cents)
73
- dst0[i] = val[0]
74
- dst1[i] = val[1]
75
- }
61
+ # Oscillator, Amplifier
62
+ volume = volume_mod[] * note_perform.velocity
63
+ pan = pan_mod[]
64
+ tune_semis = tune_semis_mod[] + synth.pitch_bend
65
+ tune_cents = tune_cents_mod[]
76
66
 
77
- # Filter
78
- if filter_mod
79
- filter_fx = filter_mod.next
80
- buf = filter_fx.process(buf)
81
- end
67
+ uni_num = uni_num_mod[]
68
+ uni_detune = uni_detune_mod[]
82
69
 
83
- y << buf
70
+ window_size.times.each {|i|
71
+ val = unison.next(uni_num, uni_detune, volume, pan, tune_semis, tune_cents)
72
+ dst0[i] = val[0]
73
+ dst1[i] = val[1]
84
74
  }
85
- end
86
- end.each(&block)
75
+
76
+ # Filter
77
+ if filter_mod
78
+ filter_fx = filter_mod[]
79
+ buf = filter_fx.process(buf)
80
+ end
81
+
82
+ buf
83
+ }
84
+ end
87
85
  end
88
86
  end
89
87
  end
@@ -1,3 +1,3 @@
1
1
  module Synthesizer
2
- VERSION = "2.0.0"
2
+ VERSION = "3.0.0"
3
3
  end
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "rake", "~> 12.0"
31
31
  spec.add_development_dependency "minitest", "~> 5.0"
32
32
 
33
- spec.add_dependency "audio_stream", ">= 2.0.0"
33
+ spec.add_dependency "audio_stream", ">= 3.0.0"
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synthesizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshida Tetsuya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-11 00:00:00.000000000 Z
11
+ date: 2019-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 2.0.0
61
+ version: 3.0.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 2.0.0
68
+ version: 3.0.0
69
69
  description: Synthesizer implemented in Ruby.
70
70
  email:
71
71
  - yoshida.eth0@gmail.com