Skip to content

Commit 1360b71

Browse files
committed
audio: fix errors and add more attrs for BiquadFilter and StereoPanner
1 parent 0802970 commit 1360b71

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

opal/browser/audio.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def oscillator
2424
Node::Oscillator.new(self)
2525
end
2626

27-
def delay
28-
Node::Delay.new(self)
27+
def delay(max_time)
28+
Node::Delay.new(self, max_time)
2929
end
3030

3131
def dynamics_compressor

opal/browser/audio/node.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class Delay
7777
include Native
7878
include Pluggable
7979

80-
def initialize(audio_context, max_time)
81-
super `#{audio_context.to_n}.createDelay(max_time || 1)`
80+
def initialize(audio_context, max_time = 1)
81+
super `#{audio_context.to_n}.createDelay(max_time)`
8282
end
8383

8484
def time=(time)
@@ -96,6 +96,10 @@ class DynamicsCompressor
9696

9797
alias_native :reduction
9898

99+
def initialize(audio_context)
100+
super `#{audio_context.to_n}.createDynamicsCompressor()`
101+
end
102+
99103
def treshold=(treshold)
100104
`#@native.treshold.value = treshold`
101105
end
@@ -138,13 +142,27 @@ def release
138142
end
139143

140144
class BiquadFilter
145+
TYPES = %i(lowpass highpass bandpass lowshelf highshelf peaking notch allpass)
146+
141147
include Native
142148
include Pluggable
143149

144150
def initialize(audio_context)
145151
super `#{audio_context.to_n}.createBiquadFilter()`
146152
end
147153

154+
def type=(type)
155+
unless TYPES.include?(type)
156+
raise ArgumentError, "type #{type} doesn't exists"
157+
end
158+
159+
`#@native.type = type`
160+
end
161+
162+
def type
163+
`#@native.type`
164+
end
165+
148166
def detune=(detune)
149167
`#@native.detune.value = #{@detune = detune}`
150168
end
@@ -170,6 +188,8 @@ class StereoPanner
170188
include Native
171189
include Pluggable
172190

191+
alias_native :normalize
192+
173193
def initialize(audio_context)
174194
super `#{audio_context.to_n}.createStereoPanner()`
175195
end

0 commit comments

Comments
 (0)