audio_stream 1.1.0 → 1.2.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 +4 -4
- data/examples/distortion.rb +1 -1
- data/examples/lpf.rb +40 -0
- data/lib/audio_stream/audio_output.rb +2 -2
- data/lib/audio_stream/fx/band_pass_filter.rb +10 -12
- data/lib/audio_stream/fx/biquad_filter.rb +7 -2
- data/lib/audio_stream/fx/equalizer_2band.rb +2 -2
- data/lib/audio_stream/fx/equalizer_3band.rb +3 -3
- data/lib/audio_stream/fx/high_pass_filter.rb +12 -12
- data/lib/audio_stream/fx/high_shelf_filter.rb +14 -15
- data/lib/audio_stream/fx/low_pass_filter.rb +12 -12
- data/lib/audio_stream/fx/low_shelf_filter.rb +14 -15
- data/lib/audio_stream/fx/peaking_filter.rb +11 -14
- data/lib/audio_stream/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5bcb3b9d97e49748ebdcca6bef4ef5288dfb0dd8a1211826ee529692928df52f
|
|
4
|
+
data.tar.gz: c508e385ac5a131734f6b4493132b926329d2cea39aa4feed9da79e837889cef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78ac5a990115889d5a067bfdd3fa11273b57aacb6e8b90cf5c8e332af92c260a21a5d5ed3563c92c67ebe3b65deedd21884509eae7eb29a23c5117d2b553e13e
|
|
7
|
+
data.tar.gz: 17f43c4fdbdd178b749ce873e4a933d23ada7b4b845c07c038c43cdceb6ba4be83ef455c47f20b18dadfce3693d4ae56ad346273eaffab7574210b2cc94a9f7e
|
data/examples/distortion.rb
CHANGED
data/examples/lpf.rb
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require_relative 'example_options'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# Track
|
|
5
|
+
|
|
6
|
+
track1 = $input
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# Fx
|
|
10
|
+
|
|
11
|
+
lpf = LowPassFilter.create($soundinfo, freq: 440.0, q: nil)
|
|
12
|
+
hpf = HighPassFilter.create($soundinfo, freq: 440.0, q: nil)
|
|
13
|
+
bpf = BandPassFilter.create($soundinfo, freq: 440.0, bandwidth: 10.0)
|
|
14
|
+
lsf = LowShelfFilter.create($soundinfo, freq: 440.0, q: nil, gain: 1.0)
|
|
15
|
+
hsf = HighShelfFilter.create($soundinfo, freq: 440.0, q: nil, gain: 1.0)
|
|
16
|
+
eq_2band = Equalizer2band.new($soundinfo, lowgain: -15.0, highgain: 15.0)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Bus
|
|
20
|
+
|
|
21
|
+
stereo_out = AudioOutput.device(soundinfo: $soundinfo)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# Mixer
|
|
25
|
+
|
|
26
|
+
track1
|
|
27
|
+
.stream
|
|
28
|
+
.fx(StereoToMono.new)
|
|
29
|
+
.fx(lpf)
|
|
30
|
+
.send_to(stereo_out)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# start
|
|
34
|
+
|
|
35
|
+
conductor = Conductor.new(
|
|
36
|
+
input: track1,
|
|
37
|
+
output: stereo_out
|
|
38
|
+
)
|
|
39
|
+
conductor.connect
|
|
40
|
+
conductor.join
|
|
@@ -10,8 +10,8 @@ module AudioStream
|
|
|
10
10
|
AudioOutputFile.new(fname, soundinfo: soundinfo)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def self.device(
|
|
14
|
-
AudioOutputDevice.default_device(
|
|
13
|
+
def self.device(soundinfo:)
|
|
14
|
+
AudioOutputDevice.default_device(soundinfo: soundinfo)
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
end
|
|
@@ -2,18 +2,9 @@ module AudioStream
|
|
|
2
2
|
module Fx
|
|
3
3
|
class BandPassFilter < BiquadFilter
|
|
4
4
|
|
|
5
|
-
def
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@freq = freq
|
|
9
|
-
@bandwidth = bandwidth
|
|
10
|
-
|
|
11
|
-
filter_coef
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def filter_coef
|
|
15
|
-
omega = 2.0 * Math::PI * @freq / @samplerate
|
|
16
|
-
alpha = Math.sin(omega) * Math.sinh(Math.log(2.0) / 2.0 * @bandwidth * omega / Math.sin(omega))
|
|
5
|
+
def update_coef(freq:, bandwidth:)
|
|
6
|
+
omega = 2.0 * Math::PI * freq / @samplerate
|
|
7
|
+
alpha = Math.sin(omega) * Math.sinh(Math.log(2.0) / 2.0 * bandwidth * omega / Math.sin(omega))
|
|
17
8
|
|
|
18
9
|
a0 = 1.0 + alpha
|
|
19
10
|
a1 = -2.0 * Math.cos(omega)
|
|
@@ -24,6 +15,13 @@ module AudioStream
|
|
|
24
15
|
|
|
25
16
|
@filter_coef = FilterCoef.new(a0, a1, a2, b0, b1, b2)
|
|
26
17
|
end
|
|
18
|
+
|
|
19
|
+
def self.create(soundinfo, freq:, bandwidth: 1.0)
|
|
20
|
+
filter = new(soundinfo)
|
|
21
|
+
filter.update_coef(freq: freq, bandwidth: bandwidth)
|
|
22
|
+
|
|
23
|
+
filter
|
|
24
|
+
end
|
|
27
25
|
end
|
|
28
26
|
end
|
|
29
27
|
end
|
|
@@ -11,11 +11,16 @@ module AudioStream
|
|
|
11
11
|
|
|
12
12
|
FilterCoef = Struct.new("FilterCoef", :a0, :a1, :a2, :b0, :b1, :b2)
|
|
13
13
|
|
|
14
|
-
def initialize
|
|
14
|
+
def initialize(soundinfo)
|
|
15
|
+
@samplerate = soundinfo.samplerate.to_f
|
|
16
|
+
init_buffer
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def init_buffer
|
|
15
20
|
@filter_bufs = [FilterBuffer.create, FilterBuffer.create]
|
|
16
21
|
end
|
|
17
22
|
|
|
18
|
-
def
|
|
23
|
+
def update_coef(*args, **kwargs)
|
|
19
24
|
raise Error, "#{self.class.name}.filter_coef is not implemented"
|
|
20
25
|
end
|
|
21
26
|
|
|
@@ -10,8 +10,8 @@ module AudioStream
|
|
|
10
10
|
@highfreq = 4000.0
|
|
11
11
|
@highgain = highgain
|
|
12
12
|
|
|
13
|
-
@low_filter = LowShelfFilter.
|
|
14
|
-
@high_filter = HighShelfFilter.
|
|
13
|
+
@low_filter = LowShelfFilter.create(soundinfo, freq: @lowfreq, q: 1.0/Math.sqrt(2.0), gain: @lowgain)
|
|
14
|
+
@high_filter = HighShelfFilter.create(soundinfo, freq: @highfreq, q: 1.0/Math.sqrt(2.0), gain: @highgain)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def process!(input)
|
|
@@ -13,9 +13,9 @@ module AudioStream
|
|
|
13
13
|
@highfreq = 4000.0
|
|
14
14
|
@highgain = highgain
|
|
15
15
|
|
|
16
|
-
@low_filter = LowShelfFilter.
|
|
17
|
-
@mid_filter = PeakingFilter.
|
|
18
|
-
@high_filter = HighShelfFilter.
|
|
16
|
+
@low_filter = LowShelfFilter.create(soundinfo, freq: @lowfreq, q: 1.0/Math.sqrt(2.0), gain: @lowgain)
|
|
17
|
+
@mid_filter = PeakingFilter.create(soundinfo, freq: @midfreq, bandwidth: 1.0/Math.sqrt(2.0), gain: @midgain)
|
|
18
|
+
@high_filter = HighShelfFilter.create(soundinfo, freq: @highfreq, q: 1.0/Math.sqrt(2.0), gain: @highgain)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def process!(input)
|
|
@@ -2,18 +2,9 @@ module AudioStream
|
|
|
2
2
|
module Fx
|
|
3
3
|
class HighPassFilter < BiquadFilter
|
|
4
4
|
|
|
5
|
-
def
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@freq = freq
|
|
9
|
-
@q = q || 1.0 / Math.sqrt(2)
|
|
10
|
-
|
|
11
|
-
filter_coef
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def filter_coef
|
|
15
|
-
omega = 2.0 * Math::PI * @freq / @samplerate
|
|
16
|
-
alpha = Math.sin(omega) / (2.0 * @q)
|
|
5
|
+
def update_coef(freq:, q:)
|
|
6
|
+
omega = 2.0 * Math::PI * freq / @samplerate
|
|
7
|
+
alpha = Math.sin(omega) / (2.0 * q)
|
|
17
8
|
|
|
18
9
|
a0 = 1.0 + alpha
|
|
19
10
|
a1 = -2.0 * Math.cos(omega)
|
|
@@ -24,6 +15,15 @@ module AudioStream
|
|
|
24
15
|
|
|
25
16
|
@filter_coef = FilterCoef.new(a0, a1, a2, b0, b1, b2)
|
|
26
17
|
end
|
|
18
|
+
|
|
19
|
+
def self.create(soundinfo, freq:, q: nil)
|
|
20
|
+
q ||= 1.0 / Math.sqrt(2)
|
|
21
|
+
|
|
22
|
+
filter = new(soundinfo)
|
|
23
|
+
filter.update_coef(freq: freq, q: q)
|
|
24
|
+
|
|
25
|
+
filter
|
|
26
|
+
end
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -2,21 +2,11 @@ module AudioStream
|
|
|
2
2
|
module Fx
|
|
3
3
|
class HighShelfFilter < BiquadFilter
|
|
4
4
|
|
|
5
|
-
def
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@gain = gain
|
|
11
|
-
|
|
12
|
-
filter_coef
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def filter_coef
|
|
16
|
-
omega = 2.0 * Math::PI * @freq / @samplerate
|
|
17
|
-
alpha = Math.sin(omega) / (2.0 * @q)
|
|
18
|
-
a = 10.0 ** (@gain / 40.0)
|
|
19
|
-
beta = Math.sqrt(a) / @q
|
|
5
|
+
def update_coef(freq:, q:, gain:)
|
|
6
|
+
omega = 2.0 * Math::PI * freq / @samplerate
|
|
7
|
+
alpha = Math.sin(omega) / (2.0 * q)
|
|
8
|
+
a = 10.0 ** (gain / 40.0)
|
|
9
|
+
beta = Math.sqrt(a) / q
|
|
20
10
|
|
|
21
11
|
a0 = (a+1) - (a-1) * Math.cos(omega) + beta * Math.sin(omega)
|
|
22
12
|
a1 = 2.0 * ((a-1) - (a+1) * Math.cos(omega))
|
|
@@ -27,6 +17,15 @@ module AudioStream
|
|
|
27
17
|
|
|
28
18
|
@filter_coef = FilterCoef.new(a0, a1, a2, b0, b1, b2)
|
|
29
19
|
end
|
|
20
|
+
|
|
21
|
+
def self.create(soundinfo, freq:, q: nil, gain: 1.0)
|
|
22
|
+
q ||= 1.0 / Math.sqrt(2)
|
|
23
|
+
|
|
24
|
+
filter = new(soundinfo)
|
|
25
|
+
filter.update_coef(freq: freq, q: q, gain: gain)
|
|
26
|
+
|
|
27
|
+
filter
|
|
28
|
+
end
|
|
30
29
|
end
|
|
31
30
|
end
|
|
32
31
|
end
|
|
@@ -2,18 +2,9 @@ module AudioStream
|
|
|
2
2
|
module Fx
|
|
3
3
|
class LowPassFilter < BiquadFilter
|
|
4
4
|
|
|
5
|
-
def
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@freq = freq
|
|
9
|
-
@q = q || 1.0 / Math.sqrt(2)
|
|
10
|
-
|
|
11
|
-
filter_coef
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def filter_coef
|
|
15
|
-
omega = 2.0 * Math::PI * @freq / @samplerate
|
|
16
|
-
alpha = Math.sin(omega) / (2.0 * @q)
|
|
5
|
+
def update_coef(freq:, q:)
|
|
6
|
+
omega = 2.0 * Math::PI * freq / @samplerate
|
|
7
|
+
alpha = Math.sin(omega) / (2.0 * q)
|
|
17
8
|
|
|
18
9
|
a0 = 1.0 + alpha
|
|
19
10
|
a1 = -2.0 * Math.cos(omega)
|
|
@@ -24,6 +15,15 @@ module AudioStream
|
|
|
24
15
|
|
|
25
16
|
@filter_coef = FilterCoef.new(a0, a1, a2, b0, b1, b2)
|
|
26
17
|
end
|
|
18
|
+
|
|
19
|
+
def self.create(soundinfo, freq:, q: nil)
|
|
20
|
+
q ||= 1.0 / Math.sqrt(2)
|
|
21
|
+
|
|
22
|
+
filter = new(soundinfo)
|
|
23
|
+
filter.update_coef(freq: freq, q: q)
|
|
24
|
+
|
|
25
|
+
filter
|
|
26
|
+
end
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -2,21 +2,11 @@ module AudioStream
|
|
|
2
2
|
module Fx
|
|
3
3
|
class LowShelfFilter < BiquadFilter
|
|
4
4
|
|
|
5
|
-
def
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@gain = gain
|
|
11
|
-
|
|
12
|
-
filter_coef
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def filter_coef
|
|
16
|
-
omega = 2.0 * Math::PI * @freq / @samplerate
|
|
17
|
-
alpha = Math.sin(omega) / (2.0 * @q)
|
|
18
|
-
a = 10.0 ** (@gain / 40.0)
|
|
19
|
-
beta = Math.sqrt(a) / @q
|
|
5
|
+
def update_coef(freq:, q:, gain:)
|
|
6
|
+
omega = 2.0 * Math::PI * freq / @samplerate
|
|
7
|
+
alpha = Math.sin(omega) / (2.0 * q)
|
|
8
|
+
a = 10.0 ** (gain / 40.0)
|
|
9
|
+
beta = Math.sqrt(a) / q
|
|
20
10
|
|
|
21
11
|
a0 = (a+1) + (a-1) * Math.cos(omega) + beta * Math.sin(omega)
|
|
22
12
|
a1 = -2.0 * ((a-1) + (a+1) * Math.cos(omega))
|
|
@@ -27,6 +17,15 @@ module AudioStream
|
|
|
27
17
|
|
|
28
18
|
@filter_coef = FilterCoef.new(a0, a1, a2, b0, b1, b2)
|
|
29
19
|
end
|
|
20
|
+
|
|
21
|
+
def self.create(soundinfo, freq:, q: nil, gain: 1.0)
|
|
22
|
+
q ||= 1.0 / Math.sqrt(2)
|
|
23
|
+
|
|
24
|
+
filter = new(soundinfo)
|
|
25
|
+
filter.update_coef(freq: freq, q: q, gain: gain)
|
|
26
|
+
|
|
27
|
+
filter
|
|
28
|
+
end
|
|
30
29
|
end
|
|
31
30
|
end
|
|
32
31
|
end
|
|
@@ -2,20 +2,10 @@ module AudioStream
|
|
|
2
2
|
module Fx
|
|
3
3
|
class PeakingFilter < BiquadFilter
|
|
4
4
|
|
|
5
|
-
def
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@bandwidth = bandwidth
|
|
10
|
-
@gain = gain
|
|
11
|
-
|
|
12
|
-
filter_coef
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def filter_coef
|
|
16
|
-
omega = 2.0 * Math::PI * @freq / @samplerate
|
|
17
|
-
alpha = Math.sin(omega) * Math.sinh(Math.log(2.0) / 2.0 * @bandwidth * omega / Math.sin(omega))
|
|
18
|
-
a = 10.0 ** (@gain / 40.0)
|
|
5
|
+
def update_coef(freq:, bandwidth:, gain:)
|
|
6
|
+
omega = 2.0 * Math::PI * freq / @samplerate
|
|
7
|
+
alpha = Math.sin(omega) * Math.sinh(Math.log(2.0) / 2.0 * bandwidth * omega / Math.sin(omega))
|
|
8
|
+
a = 10.0 ** (gain / 40.0)
|
|
19
9
|
|
|
20
10
|
a0 = 1.0 + alpha / a
|
|
21
11
|
a1 = -2.0 * Math.cos(omega)
|
|
@@ -26,6 +16,13 @@ module AudioStream
|
|
|
26
16
|
|
|
27
17
|
@filter_coef = FilterCoef.new(a0, a1, a2, b0, b1, b2)
|
|
28
18
|
end
|
|
19
|
+
|
|
20
|
+
def self.create(soundinfo, freq:, bandwidth: 1.0, gain: 40.0)
|
|
21
|
+
filter = new(soundinfo)
|
|
22
|
+
filter.update_coef(freq: freq, bandwidth: bandwidth, gain: gain)
|
|
23
|
+
|
|
24
|
+
filter
|
|
25
|
+
end
|
|
29
26
|
end
|
|
30
27
|
end
|
|
31
28
|
end
|
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.2.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-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -142,6 +142,7 @@ files:
|
|
|
142
142
|
- examples/chorus.rb
|
|
143
143
|
- examples/distortion.rb
|
|
144
144
|
- examples/example_options.rb
|
|
145
|
+
- examples/lpf.rb
|
|
145
146
|
- examples/rec.rb
|
|
146
147
|
- examples/tremolo.rb
|
|
147
148
|
- examples/tuner.rb
|