audio_stream 1.2.4 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/audio_stream.gemspec +0 -1
- data/examples/buffer.ipynb +2 -2
- data/examples/chorus.rb +1 -2
- data/examples/distortion.rb +0 -1
- data/examples/example_options.rb +2 -2
- data/examples/lpf.rb +1 -2
- data/examples/rec.rb +2 -4
- data/examples/tuner.rb +1 -1
- data/lib/audio_stream.rb +5 -1
- data/lib/audio_stream/audio_bus.rb +52 -12
- data/lib/audio_stream/audio_input.rb +20 -13
- data/lib/audio_stream/audio_input_buffer.rb +12 -0
- data/lib/audio_stream/audio_input_device.rb +11 -5
- data/lib/audio_stream/audio_input_file.rb +14 -4
- data/lib/audio_stream/audio_notification.rb +17 -0
- data/lib/audio_stream/audio_observable.rb +29 -0
- data/lib/audio_stream/audio_observable_fx.rb +25 -0
- data/lib/audio_stream/audio_observer.rb +13 -0
- data/lib/audio_stream/audio_output_device.rb +2 -2
- data/lib/audio_stream/buffer.rb +1 -1
- data/lib/audio_stream/conductor.rb +7 -5
- data/lib/audio_stream/fx/hanning_window.rb +1 -0
- data/lib/audio_stream/fx/mono_to_stereo.rb +2 -0
- data/lib/audio_stream/fx/noise_gate.rb +1 -1
- data/lib/audio_stream/fx/stereo_to_mono.rb +2 -0
- data/lib/audio_stream/fx/tuner.rb +2 -2
- data/lib/audio_stream/plot.rb +1 -1
- data/lib/audio_stream/version.rb +1 -1
- metadata +6 -17
- data/lib/audio_stream/core_ext.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e44fc50ce5993f26948cf0429df83eb1dac15556dbc89f7db605fa398a79f928
|
4
|
+
data.tar.gz: 8a4f2bcb04ca5d26b2574ac0b960211769d9d8f1f3474dcfb9823780ec0c90d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3e1ac2bde745775aa261b02fa130f98720e3c549ed67d0ff1237e7ca5815a74fb3608f87fb020a03ea8af933bd0c3c78488b5d879310e8cd9d0df845b8fc8d3
|
7
|
+
data.tar.gz: 79502696e497e3307f35867cbcc8f585a977530b7f2bf1c2223aed6e84323467ee11e9a9e5cdbe4af7e40cbe77aa3a40a3eccfce1fd20cdb8365145389be5703
|
data/audio_stream.gemspec
CHANGED
@@ -33,6 +33,5 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_dependency "ruby-audio", ">= 1.6.1"
|
34
34
|
spec.add_dependency "coreaudio", ">= 0.0.12"
|
35
35
|
spec.add_dependency "ruby-fftw3", ">= 1.0.2"
|
36
|
-
spec.add_dependency "rx", ">= 0.0.3"
|
37
36
|
spec.add_dependency "rbplotly", ">= 0.1.2"
|
38
37
|
end
|
data/examples/buffer.ipynb
CHANGED
@@ -51,7 +51,7 @@
|
|
51
51
|
],
|
52
52
|
"source": [
|
53
53
|
"$LOAD_PATH << File.dirname(__FILE__) + \"/../lib\"\n",
|
54
|
-
"require 'audio_stream
|
54
|
+
"require 'audio_stream'\n",
|
55
55
|
"\n",
|
56
56
|
"include AudioStream\n",
|
57
57
|
"include AudioStream::Fx\n",
|
@@ -118,7 +118,7 @@
|
|
118
118
|
],
|
119
119
|
"source": [
|
120
120
|
"$LOAD_PATH << File.dirname(__FILE__) + \"/../lib\"\n",
|
121
|
-
"require 'audio_stream
|
121
|
+
"require 'audio_stream'\n",
|
122
122
|
"\n",
|
123
123
|
"include AudioStream\n",
|
124
124
|
"include AudioStream::Fx\n",
|
data/examples/chorus.rb
CHANGED
data/examples/distortion.rb
CHANGED
data/examples/example_options.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'audio_stream
|
1
|
+
require 'audio_stream'
|
2
2
|
require 'optparse'
|
3
3
|
|
4
4
|
include AudioStream
|
@@ -6,7 +6,7 @@ include AudioStream::Fx
|
|
6
6
|
|
7
7
|
|
8
8
|
$soundinfo = SoundInfo.new(
|
9
|
-
channels:
|
9
|
+
channels: 2,
|
10
10
|
samplerate: 44100,
|
11
11
|
window_size: 1024,
|
12
12
|
format: RubyAudio::FORMAT_WAV|RubyAudio::FORMAT_PCM_16
|
data/examples/lpf.rb
CHANGED
data/examples/rec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'audio_stream
|
1
|
+
require 'audio_stream'
|
2
2
|
|
3
3
|
include AudioStream
|
4
4
|
include AudioStream::Fx
|
@@ -6,7 +6,7 @@ include AudioStream::Fx
|
|
6
6
|
soundinfo = SoundInfo.new(
|
7
7
|
channels: 2,
|
8
8
|
samplerate: 44100,
|
9
|
-
window_size: 1024
|
9
|
+
window_size: 1024,
|
10
10
|
format: RubyAudio::FORMAT_WAV|RubyAudio::FORMAT_PCM_16
|
11
11
|
)
|
12
12
|
|
@@ -31,7 +31,6 @@ stereo_out = AudioOutput.device(soundinfo: soundinfo)
|
|
31
31
|
# Mixer
|
32
32
|
|
33
33
|
track1
|
34
|
-
.stream
|
35
34
|
.send_to(file_out)
|
36
35
|
.send_to(bus1)
|
37
36
|
|
@@ -39,7 +38,6 @@ bus1
|
|
39
38
|
.send_to(stereo_out, gain: 0.5)
|
40
39
|
|
41
40
|
track2
|
42
|
-
.stream
|
43
41
|
.send_to(stereo_out)
|
44
42
|
|
45
43
|
|
data/examples/tuner.rb
CHANGED
data/lib/audio_stream.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'ruby-audio'
|
2
2
|
require 'coreaudio'
|
3
3
|
require 'numru/fftw3'
|
4
|
-
require 'rx'
|
5
4
|
require 'rbplotly'
|
5
|
+
require 'singleton'
|
6
6
|
|
7
7
|
require 'audio_stream/version'
|
8
8
|
require 'audio_stream/error'
|
@@ -11,6 +11,10 @@ require 'audio_stream/buffer'
|
|
11
11
|
require 'audio_stream/ring_buffer'
|
12
12
|
require 'audio_stream/sync'
|
13
13
|
require 'audio_stream/conductor'
|
14
|
+
require 'audio_stream/audio_observer'
|
15
|
+
require 'audio_stream/audio_observable'
|
16
|
+
require 'audio_stream/audio_observable_fx'
|
17
|
+
require 'audio_stream/audio_notification'
|
14
18
|
require 'audio_stream/audio_input'
|
15
19
|
require 'audio_stream/audio_input_file'
|
16
20
|
require 'audio_stream/audio_input_device'
|
@@ -1,28 +1,68 @@
|
|
1
1
|
module AudioStream
|
2
|
-
class AudioBus
|
2
|
+
class AudioBus
|
3
|
+
include AudioObserver
|
4
|
+
include AudioObservable
|
5
|
+
|
3
6
|
def initialize
|
4
|
-
|
5
|
-
@
|
6
|
-
@
|
7
|
-
@detach = nil
|
7
|
+
@mutex = Mutex.new
|
8
|
+
@callers = Set[]
|
9
|
+
@notifications = {}
|
8
10
|
end
|
9
11
|
|
10
12
|
def add(observable, gain:, pan:)
|
11
13
|
if gain && gain!=1.0
|
12
|
-
observable = observable.
|
14
|
+
observable = observable.fx(Fx::AGain.new(level: gain))
|
13
15
|
end
|
14
16
|
|
15
17
|
if pan && pan!=0.0
|
16
|
-
observable = observable.
|
18
|
+
observable = observable.fx(Fx::Panning.new(pan: pan))
|
17
19
|
end
|
18
20
|
|
19
|
-
@
|
20
|
-
|
21
|
-
|
21
|
+
@mutex.synchronize {
|
22
|
+
@callers << observable
|
23
|
+
observable.add_observer(self)
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def update(notification)
|
28
|
+
do_notify = false
|
29
|
+
next_notifications = nil
|
30
|
+
|
31
|
+
@mutex.synchronize {
|
32
|
+
@notifications[notification.caller_obj] = notification
|
33
|
+
|
34
|
+
if @callers.length==@notifications.length
|
35
|
+
next_notifications = []
|
36
|
+
@notifications.each {|caller_obj, notification|
|
37
|
+
case notification.stat
|
38
|
+
when AudioNotification::STAT_NEXT
|
39
|
+
next_notifications << notification
|
40
|
+
when AudioNotification::STAT_COMPLETE
|
41
|
+
@callers.delete(caller_obj)
|
42
|
+
end
|
43
|
+
}
|
44
|
+
|
45
|
+
do_notify = true
|
46
|
+
@notifications.clear
|
47
|
+
end
|
48
|
+
}
|
49
|
+
|
50
|
+
if do_notify
|
51
|
+
if 0<next_notifications.length
|
52
|
+
output = next_notifications.map(&:input).inject(:+)
|
53
|
+
on_next(output)
|
54
|
+
else
|
55
|
+
on_complete
|
56
|
+
end
|
22
57
|
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def on_next(input)
|
61
|
+
notify_next(input)
|
62
|
+
end
|
23
63
|
|
24
|
-
|
25
|
-
|
64
|
+
def on_complete
|
65
|
+
notify_complete
|
26
66
|
end
|
27
67
|
end
|
28
68
|
end
|
@@ -2,6 +2,7 @@ module AudioStream
|
|
2
2
|
|
3
3
|
module AudioInput
|
4
4
|
include Enumerable
|
5
|
+
include AudioObservable
|
5
6
|
|
6
7
|
attr_reader :connection
|
7
8
|
|
@@ -9,13 +10,24 @@ module AudioStream
|
|
9
10
|
@sync ||= Sync.new
|
10
11
|
end
|
11
12
|
|
12
|
-
def
|
13
|
+
def publish
|
13
14
|
@connection = Thread.start {
|
14
|
-
|
15
|
+
each {|input|
|
16
|
+
sync.resume_wait
|
17
|
+
notify_next(input)
|
18
|
+
sync.yield
|
19
|
+
}
|
20
|
+
sync.resume_wait
|
21
|
+
notify_complete
|
22
|
+
sync.finish
|
15
23
|
}
|
16
24
|
self
|
17
25
|
end
|
18
26
|
|
27
|
+
def connect
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
19
31
|
def disconnect
|
20
32
|
if @connection
|
21
33
|
@connection.kill
|
@@ -24,17 +36,12 @@ module AudioStream
|
|
24
36
|
self
|
25
37
|
end
|
26
38
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
34
|
-
sync.resume_wait
|
35
|
-
sync.finish
|
36
|
-
observer.on_completed
|
37
|
-
end.publish
|
39
|
+
def connected?
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def published?
|
44
|
+
!!@connection
|
38
45
|
end
|
39
46
|
|
40
47
|
|
@@ -14,22 +14,28 @@ module AudioStream
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def connect
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
if !connected?
|
18
|
+
@inbuf = @dev.input_buffer(@soundinfo.window_size)
|
19
|
+
@inbuf.start
|
20
|
+
end
|
21
|
+
self
|
20
22
|
end
|
21
23
|
|
22
24
|
def disconnect
|
23
|
-
if
|
25
|
+
if connected?
|
24
26
|
@inbuf.stop
|
25
27
|
@inbuf = nil
|
26
28
|
end
|
27
29
|
super
|
28
30
|
end
|
29
31
|
|
32
|
+
def connected?
|
33
|
+
!!@inbuf
|
34
|
+
end
|
35
|
+
|
30
36
|
def each(&block)
|
31
37
|
Enumerator.new do |y|
|
32
|
-
if
|
38
|
+
if !connected?
|
33
39
|
raise Error, "Device is not connected. You need to exec #{self.class.name}.connect: #{name}"
|
34
40
|
end
|
35
41
|
|
@@ -10,25 +10,35 @@ module AudioStream
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def connect
|
13
|
-
|
14
|
-
|
13
|
+
if !connected?
|
14
|
+
@sound = RubyAudio::Sound.open(@path)
|
15
|
+
end
|
16
|
+
self
|
15
17
|
end
|
16
18
|
|
17
19
|
def disconnect
|
18
|
-
if
|
20
|
+
if connected?
|
19
21
|
@sound.close
|
20
22
|
end
|
21
23
|
super
|
22
24
|
end
|
23
25
|
|
26
|
+
def connected?
|
27
|
+
@sound && !@sound.closed?
|
28
|
+
end
|
29
|
+
|
24
30
|
def seek(frames, whence=IO::SEEK_SET)
|
31
|
+
if !connected?
|
32
|
+
raise Error, "File is not opened. You need to exec #{self.class.name}.connect: #{@path}"
|
33
|
+
end
|
34
|
+
|
25
35
|
@sound.seek(frames, whence)
|
26
36
|
self
|
27
37
|
end
|
28
38
|
|
29
39
|
def each(&block)
|
30
40
|
Enumerator.new do |y|
|
31
|
-
if
|
41
|
+
if !connected?
|
32
42
|
raise Error, "File is not opened. You need to exec #{self.class.name}.connect: #{@path}"
|
33
43
|
end
|
34
44
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AudioStream
|
2
|
+
|
3
|
+
class AudioNotification
|
4
|
+
STAT_NEXT = :next
|
5
|
+
STAT_COMPLETE = :complete
|
6
|
+
|
7
|
+
attr_reader :stat
|
8
|
+
attr_reader :input
|
9
|
+
attr_reader :caller_obj
|
10
|
+
|
11
|
+
def initialize(stat, input, caller_obj)
|
12
|
+
@stat = stat
|
13
|
+
@input = input
|
14
|
+
@caller_obj = caller_obj
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'observer'
|
2
|
+
|
3
|
+
module AudioStream
|
4
|
+
|
5
|
+
module AudioObservable
|
6
|
+
include Observable
|
7
|
+
|
8
|
+
def notify_next(input)
|
9
|
+
changed
|
10
|
+
notify_observers(AudioNotification.new(AudioNotification::STAT_NEXT, input, self))
|
11
|
+
end
|
12
|
+
|
13
|
+
def notify_complete
|
14
|
+
changed
|
15
|
+
notify_observers(AudioNotification.new(AudioNotification::STAT_COMPLETE, nil, self))
|
16
|
+
end
|
17
|
+
|
18
|
+
def fx(effector)
|
19
|
+
observer = AudioObservableFx.new(effector)
|
20
|
+
add_observer(observer)
|
21
|
+
observer
|
22
|
+
end
|
23
|
+
|
24
|
+
def send_to(bus, gain: nil, pan: nil)
|
25
|
+
bus.add(self, gain: gain, pan: pan)
|
26
|
+
self
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module AudioStream
|
2
|
+
|
3
|
+
class AudioObservableFx
|
4
|
+
include AudioObserver
|
5
|
+
include AudioObservable
|
6
|
+
|
7
|
+
def initialize(effector)
|
8
|
+
@effector = effector
|
9
|
+
end
|
10
|
+
|
11
|
+
def on_next(input)
|
12
|
+
if Fx::BangProcess===input
|
13
|
+
@effector.process!(input)
|
14
|
+
output = input
|
15
|
+
else
|
16
|
+
output = @effector.process(input)
|
17
|
+
end
|
18
|
+
notify_next(output)
|
19
|
+
end
|
20
|
+
|
21
|
+
def on_complete
|
22
|
+
notify_complete
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -23,9 +23,9 @@ module AudioStream
|
|
23
23
|
|
24
24
|
case @channels
|
25
25
|
when 1
|
26
|
-
input = Fx::StereoToMono.
|
26
|
+
input = Fx::StereoToMono.instance.process(input)
|
27
27
|
when 2
|
28
|
-
input = Fx::MonoToStereo.
|
28
|
+
input = Fx::MonoToStereo.instance.process(input)
|
29
29
|
end
|
30
30
|
|
31
31
|
sint_a = input.to_a.flatten.map{|f| (f*0x7FFF).round}
|
data/lib/audio_stream/buffer.rb
CHANGED
@@ -8,18 +8,20 @@ module AudioStream
|
|
8
8
|
def connect
|
9
9
|
@outputs.map(&:connect)
|
10
10
|
@inputs.map(&:connect)
|
11
|
+
@inputs.map(&:publish)
|
11
12
|
|
12
13
|
@sync_thread = Thread.start {
|
13
14
|
catch :break do
|
14
15
|
loop {
|
15
|
-
@inputs.each {|
|
16
|
-
|
16
|
+
@inputs.each {|input|
|
17
|
+
input.sync.resume
|
17
18
|
}
|
18
19
|
|
19
|
-
@inputs.each {|
|
20
|
-
stat =
|
20
|
+
@inputs.each {|input|
|
21
|
+
stat = input.sync.yield_wait
|
21
22
|
if stat==Sync::COMPLETED
|
22
|
-
|
23
|
+
@inputs.delete(input)
|
24
|
+
#throw :break
|
23
25
|
end
|
24
26
|
}
|
25
27
|
|
@@ -15,14 +15,14 @@ module AudioStream
|
|
15
15
|
|
16
16
|
def initialize(soundinfo, window: nil)
|
17
17
|
@samplerate = soundinfo.samplerate.to_f
|
18
|
-
@window = window || HanningWindow.
|
18
|
+
@window = window || HanningWindow.instance
|
19
19
|
end
|
20
20
|
|
21
21
|
def process(input)
|
22
22
|
window_size = input.size
|
23
23
|
|
24
24
|
# mono window
|
25
|
-
input = StereoToMono.
|
25
|
+
input = StereoToMono.instance.process(input)
|
26
26
|
@window.process!(input)
|
27
27
|
|
28
28
|
gain = input.to_a.flatten.max
|
data/lib/audio_stream/plot.rb
CHANGED
data/lib/audio_stream/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: audio_stream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.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-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 1.0.2
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rx
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 0.0.3
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 0.0.3
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: rbplotly
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,12 +138,15 @@ files:
|
|
152
138
|
- lib/audio_stream/audio_input_buffer.rb
|
153
139
|
- lib/audio_stream/audio_input_device.rb
|
154
140
|
- lib/audio_stream/audio_input_file.rb
|
141
|
+
- lib/audio_stream/audio_notification.rb
|
142
|
+
- lib/audio_stream/audio_observable.rb
|
143
|
+
- lib/audio_stream/audio_observable_fx.rb
|
144
|
+
- lib/audio_stream/audio_observer.rb
|
155
145
|
- lib/audio_stream/audio_output.rb
|
156
146
|
- lib/audio_stream/audio_output_device.rb
|
157
147
|
- lib/audio_stream/audio_output_file.rb
|
158
148
|
- lib/audio_stream/buffer.rb
|
159
149
|
- lib/audio_stream/conductor.rb
|
160
|
-
- lib/audio_stream/core_ext.rb
|
161
150
|
- lib/audio_stream/error.rb
|
162
151
|
- lib/audio_stream/fx.rb
|
163
152
|
- lib/audio_stream/fx/a_gain.rb
|