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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f45da04dde77d57f659a2be426c7128d6da179afb23be0c9a247e88079d9d6b
4
- data.tar.gz: 564028cc062f4327a17d3384e2d9acf9ed69b4827768349fe3a6101b0cb3d0e2
3
+ metadata.gz: 04ecefcdbf996dac3b8b38315ba0fa1c88ee9ce9a353ae13189c6f59d7ca764c
4
+ data.tar.gz: 5804b29acadece1016f420b85ee2c7fc43521e0cf14dc633240b09f2d80fa1f5
5
5
  SHA512:
6
- metadata.gz: 6ea8c7397ed25c859d27e1eb68d7ed7551070ab5df1d94015bdc25a10e407b1a986a64c4f0d1be9bc2878d957299df50a75bfffd5230dfaa293a192e4286dff4
7
- data.tar.gz: 5b3e73218fa8f402ff6e5b966734217cbd33a182b114fedeab4cff9c3d0c1484078220496826cd0682d6195a3209d1f051ddaee27aaefd67c63263f3f66fcb97
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
@@ -11,28 +11,28 @@ soundinfo = SoundInfo.new(
11
11
  )
12
12
 
13
13
  synth = Synthesizer::Poly.new(
14
- oscs: [
15
- Synthesizer::Osc.new(
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::Osc.new(
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::Osc.new(
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
- amp: Synthesizer::Amp.new(
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
@@ -1,7 +1,8 @@
1
- require "synthesizer/version"
1
+ require 'synthesizer/version'
2
2
 
3
3
  require 'audio_stream'
4
4
  require 'audio_stream/audio_input_synth.rb'
5
+ require 'audio_stream/audio_input_metronome.rb'
5
6
 
6
7
  require 'synthesizer/poly'
7
8
  require 'synthesizer/mono'
@@ -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 [Synth::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 [Synth::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 [Synth::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 [Synth::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 [Synth::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)
@@ -13,7 +13,7 @@ module Synthesizer
13
13
  }
14
14
  end
15
15
 
16
- # @param mod [Synth::Modulation]
16
+ # @param mod [Synthesizer::Modulation]
17
17
  # @param depth [Float] (-1.0~1.0)
18
18
  def add(mod, depth: 1.0)
19
19
  depth ||= 1.0
@@ -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 [Synth::Shape] oscillator waveform 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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Synthesizer
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  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: 1.0.0
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-16 00:00:00.000000000 Z
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