synthesizer 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/metronome.rb +55 -0
- data/examples/poly.rb +5 -5
- data/lib/audio_stream/audio_input_metronome.rb +55 -0
- data/lib/synthesizer.rb +2 -1
- data/lib/synthesizer/modulation/adsr.rb +3 -3
- data/lib/synthesizer/modulation/lfo.rb +2 -2
- data/lib/synthesizer/modulation_value.rb +1 -1
- data/lib/synthesizer/mono.rb +3 -3
- data/lib/synthesizer/oscillator.rb +1 -1
- data/lib/synthesizer/poly.rb +3 -3
- data/lib/synthesizer/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04ecefcdbf996dac3b8b38315ba0fa1c88ee9ce9a353ae13189c6f59d7ca764c
|
4
|
+
data.tar.gz: 5804b29acadece1016f420b85ee2c7fc43521e0cf14dc633240b09f2d80fa1f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd465c0efba7fdf5608297fbd85214370328a801a97074d37670a19681a96045b68f7cbb18cb9af5d809a2a63f33d2219ef3c27319c517bba3c2a9c11c1102bd
|
7
|
+
data.tar.gz: ee9e14bde33fbf7eff84b2b9c88afa4ff45ae8e73b6c170ef1e03fd95d0dda4562abecd58811da9a6f0e7dcf2cacfecab344624a4b0d2d4a5ba231697c460caa
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'synthesizer'
|
2
|
+
require 'audio_stream/core_ext'
|
3
|
+
|
4
|
+
include AudioStream
|
5
|
+
include AudioStream::Fx
|
6
|
+
|
7
|
+
|
8
|
+
soundinfo = SoundInfo.new(
|
9
|
+
channels: 2,
|
10
|
+
samplerate: 44100,
|
11
|
+
window_size: 1024,
|
12
|
+
format: RubyAudio::FORMAT_WAV|RubyAudio::FORMAT_PCM_16
|
13
|
+
)
|
14
|
+
|
15
|
+
|
16
|
+
# Track
|
17
|
+
|
18
|
+
track1 = AudioInputMetronome.new(
|
19
|
+
bpm: 120.0,
|
20
|
+
repeat: 1000,
|
21
|
+
soundinfo: soundinfo
|
22
|
+
)
|
23
|
+
|
24
|
+
|
25
|
+
# Audio FX
|
26
|
+
|
27
|
+
gain = AGain.new(level: 0.9)
|
28
|
+
|
29
|
+
|
30
|
+
# Bus
|
31
|
+
|
32
|
+
#stereo_out = AudioOutput.file("out.wav", soundinfo)
|
33
|
+
stereo_out = AudioOutput.device(soundinfo: soundinfo)
|
34
|
+
bus1 = AudioBus.new
|
35
|
+
|
36
|
+
|
37
|
+
# Mixer
|
38
|
+
|
39
|
+
track1
|
40
|
+
.stream
|
41
|
+
.fx(gain)
|
42
|
+
.send_to(bus1)
|
43
|
+
|
44
|
+
bus1
|
45
|
+
.send_to(stereo_out)
|
46
|
+
|
47
|
+
|
48
|
+
# start
|
49
|
+
|
50
|
+
conductor = Conductor.new(
|
51
|
+
input: track1,
|
52
|
+
output: stereo_out
|
53
|
+
)
|
54
|
+
conductor.connect
|
55
|
+
conductor.join
|
data/examples/poly.rb
CHANGED
@@ -11,28 +11,28 @@ soundinfo = SoundInfo.new(
|
|
11
11
|
)
|
12
12
|
|
13
13
|
synth = Synthesizer::Poly.new(
|
14
|
-
|
15
|
-
Synthesizer::
|
14
|
+
oscillators: [
|
15
|
+
Synthesizer::Oscillator.new(
|
16
16
|
shape: Synthesizer::Shape::SquareSawtooth,
|
17
17
|
uni_num: Synthesizer::ModulationValue.new(4)
|
18
18
|
.add(Synthesizer::Modulation::Lfo.new(
|
19
19
|
)),
|
20
20
|
uni_detune: 0.1,
|
21
21
|
),
|
22
|
-
#Synthesizer::
|
22
|
+
#Synthesizer::Oscillator.new(
|
23
23
|
# shape: Synthesizer::Shape::SquareSawtooth,
|
24
24
|
# tune_cents: 0.1,
|
25
25
|
# uni_num: 4,
|
26
26
|
# uni_detune: 0.1,
|
27
27
|
#),
|
28
|
-
#Synthesizer::
|
28
|
+
#Synthesizer::Oscillator.new(
|
29
29
|
# shape: Synthesizer::Shape::SquareSawtooth,
|
30
30
|
# tune_semis: -12,
|
31
31
|
# uni_num: 4,
|
32
32
|
# uni_detune: 0.1,
|
33
33
|
#),
|
34
34
|
],
|
35
|
-
|
35
|
+
amplifier: Synthesizer::Amplifier.new(
|
36
36
|
volume: Synthesizer::ModulationValue.new(1.0)
|
37
37
|
.add(Synthesizer::Modulation::Adsr.new(
|
38
38
|
attack: 0.05,
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module AudioStream
|
2
|
+
class AudioInputMetronome < Rx::Subject
|
3
|
+
include AudioInput
|
4
|
+
|
5
|
+
def initialize(bpm:, beat: 4, repeat: nil, soundinfo:)
|
6
|
+
super()
|
7
|
+
|
8
|
+
@bpm = bpm
|
9
|
+
@beat = beat.to_i
|
10
|
+
@repeat = repeat
|
11
|
+
|
12
|
+
@synth = Synthesizer::Poly.new(
|
13
|
+
oscillators: Synthesizer::Oscillator.new(
|
14
|
+
shape: Synthesizer::Shape::Sine,
|
15
|
+
phase: 0,
|
16
|
+
),
|
17
|
+
amplifier: Synthesizer::Amplifier.new(
|
18
|
+
volume: Synthesizer::ModulationValue.new(1.0)
|
19
|
+
.add(Synthesizer::Modulation::Adsr.new(
|
20
|
+
attack: 0.0,
|
21
|
+
hold: 0.05,
|
22
|
+
decay: 0.0,
|
23
|
+
sustain: 0.0,
|
24
|
+
release: 0.0
|
25
|
+
), depth: 1.0),
|
26
|
+
),
|
27
|
+
quality: Synthesizer::Quality::LOW,
|
28
|
+
soundinfo: soundinfo,
|
29
|
+
)
|
30
|
+
|
31
|
+
@soundinfo = soundinfo
|
32
|
+
end
|
33
|
+
|
34
|
+
def each(&block)
|
35
|
+
Enumerator.new do |y|
|
36
|
+
period = @soundinfo.samplerate.to_f / @soundinfo.window_size * 60.0 / @bpm
|
37
|
+
repeat_count = 0.0
|
38
|
+
beat_count = 0
|
39
|
+
|
40
|
+
Range.new(0, @repeat).each {|_|
|
41
|
+
if repeat_count<1
|
42
|
+
if beat_count==0
|
43
|
+
@synth.note_on(Synthesizer::Note.new(81))
|
44
|
+
else
|
45
|
+
@synth.note_on(Synthesizer::Note.new(69))
|
46
|
+
end
|
47
|
+
beat_count = (beat_count + 1) % @beat
|
48
|
+
end
|
49
|
+
y << @synth.next
|
50
|
+
repeat_count = (repeat_count + 1) % period
|
51
|
+
}
|
52
|
+
end.each(&block)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/synthesizer.rb
CHANGED
@@ -3,13 +3,13 @@ module Synthesizer
|
|
3
3
|
class Adsr
|
4
4
|
|
5
5
|
# @param attack [Float] attack sec (0.0~)
|
6
|
-
# @param attack_curve [
|
6
|
+
# @param attack_curve [Synthesizer::Curve]
|
7
7
|
# @param hold [Float] hold sec (0.0~)
|
8
8
|
# @param decay [Float] decay sec (0.0~)
|
9
|
-
# @param sustain_curve [
|
9
|
+
# @param sustain_curve [Synthesizer::Curve]
|
10
10
|
# @param sustain [Float] sustain sec (0.0~)
|
11
11
|
# @param release [Float] release sec (0.0~)
|
12
|
-
# @param release_curve [
|
12
|
+
# @param release_curve [Synthesizer::Curve]
|
13
13
|
def initialize(attack:, attack_curve: Curve::EaseOut, hold: 0.0, decay:, sustain_curve: Curve::EaseOut, sustain:, release:, release_curve: Curve::EaseOut)
|
14
14
|
@attack = attack
|
15
15
|
@attack_curve = attack_curve
|
@@ -2,10 +2,10 @@ module Synthesizer
|
|
2
2
|
module Modulation
|
3
3
|
class Lfo
|
4
4
|
|
5
|
-
# @param shape [
|
5
|
+
# @param shape [Synthesizer::Shape]
|
6
6
|
# @param delay [Float] delay sec (0.0~)
|
7
7
|
# @param attack [Float] attack sec (0.0~)
|
8
|
-
# @param attack_curve [
|
8
|
+
# @param attack_curve [Synthesizer::Curve]
|
9
9
|
# @param phase [Float] phase percent (0.0~1.0)
|
10
10
|
# @param rate [Float] wave freq (0.0~)
|
11
11
|
def initialize(shape: Shape::Sine, delay: 0.0, attack: 0.0, attack_curve: Curve::Straight, phase: 0.0, rate: 3.5)
|
data/lib/synthesizer/mono.rb
CHANGED
@@ -11,9 +11,9 @@ module Synthesizer
|
|
11
11
|
attr_reader :glide
|
12
12
|
attr_accessor :pitch_bend
|
13
13
|
|
14
|
-
# @param oscillators [Oscillator] oscillator
|
15
|
-
# @param amplifier [Amplifier] amplifier
|
16
|
-
# @param soundinfo [SoundInfo]
|
14
|
+
# @param oscillators [Synthesizer::Oscillator] oscillator
|
15
|
+
# @param amplifier [Synthesizer::Amplifier] amplifier
|
16
|
+
# @param soundinfo [AudioStream::SoundInfo]
|
17
17
|
def initialize(oscillators:, amplifier:, glide: 0.1, quality: Quality::LOW, soundinfo:)
|
18
18
|
@oscillators = [oscillators].flatten.compact
|
19
19
|
@amplifier = amplifier
|
@@ -12,7 +12,7 @@ module Synthesizer
|
|
12
12
|
attr_reader :uni_num
|
13
13
|
attr_reader :uni_detune
|
14
14
|
|
15
|
-
# @param shape [
|
15
|
+
# @param shape [Synthesizer::Shape] oscillator waveform shape
|
16
16
|
# @param volume [Float] oscillator volume. mute=0.0 max=1.0
|
17
17
|
# @param pan [Float] oscillator pan. left=-1.0 center=0.0 right=1.0 (-1.0~1.0)
|
18
18
|
# @param tune_semis [Integer] oscillator pitch semitone
|
data/lib/synthesizer/poly.rb
CHANGED
@@ -11,9 +11,9 @@ module Synthesizer
|
|
11
11
|
attr_reader :glide
|
12
12
|
attr_accessor :pitch_bend
|
13
13
|
|
14
|
-
# @param oscillators [Oscillator] Oscillator
|
15
|
-
# @param amplifier [Amplifier] amplifier
|
16
|
-
# @param soundinfo [SoundInfo]
|
14
|
+
# @param oscillators [Synthesizer::Oscillator] Oscillator
|
15
|
+
# @param amplifier [Synthesizer::Amplifier] amplifier
|
16
|
+
# @param soundinfo [AudioStream::SoundInfo]
|
17
17
|
def initialize(oscillators:, amplifier:, quality: Quality::LOW, soundinfo:)
|
18
18
|
@oscillators = [oscillators].flatten.compact
|
19
19
|
@amplifier = amplifier
|
data/lib/synthesizer/version.rb
CHANGED
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: 1.
|
4
|
+
version: 1.1.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-07-
|
11
|
+
date: 2019-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -153,9 +153,11 @@ files:
|
|
153
153
|
- bin/setup
|
154
154
|
- examples/adsr.ipynb
|
155
155
|
- examples/curves.ipynb
|
156
|
+
- examples/metronome.rb
|
156
157
|
- examples/mono.rb
|
157
158
|
- examples/poly.rb
|
158
159
|
- examples/shapes.ipynb
|
160
|
+
- lib/audio_stream/audio_input_metronome.rb
|
159
161
|
- lib/audio_stream/audio_input_synth.rb
|
160
162
|
- lib/synthesizer.rb
|
161
163
|
- lib/synthesizer/amplifier.rb
|