Skip to content

Commit

Permalink
audio: fix errors and add more attrs for BiquadFilter and StereoPanner
Browse files Browse the repository at this point in the history
merongivian committed Sep 23, 2015
1 parent 0802970 commit 1360b71
Showing 2 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions opal/browser/audio.rb
Original file line number Diff line number Diff line change
@@ -24,8 +24,8 @@ def oscillator
Node::Oscillator.new(self)
end

def delay
Node::Delay.new(self)
def delay(max_time)
Node::Delay.new(self, max_time)
end

def dynamics_compressor
24 changes: 22 additions & 2 deletions opal/browser/audio/node.rb
Original file line number Diff line number Diff line change
@@ -77,8 +77,8 @@ class Delay
include Native
include Pluggable

def initialize(audio_context, max_time)
super `#{audio_context.to_n}.createDelay(max_time || 1)`
def initialize(audio_context, max_time = 1)
super `#{audio_context.to_n}.createDelay(max_time)`
end

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

alias_native :reduction

def initialize(audio_context)
super `#{audio_context.to_n}.createDynamicsCompressor()`
end

def treshold=(treshold)
`#@native.treshold.value = treshold`
end
@@ -138,13 +142,27 @@ def release
end

class BiquadFilter
TYPES = %i(lowpass highpass bandpass lowshelf highshelf peaking notch allpass)

include Native
include Pluggable

def initialize(audio_context)
super `#{audio_context.to_n}.createBiquadFilter()`
end

def type=(type)
unless TYPES.include?(type)
raise ArgumentError, "type #{type} doesn't exists"
end

`#@native.type = type`
end

def type
`#@native.type`
end

def detune=(detune)
`#@native.detune.value = #{@detune = detune}`
end
@@ -170,6 +188,8 @@ class StereoPanner
include Native
include Pluggable

alias_native :normalize

def initialize(audio_context)
super `#{audio_context.to_n}.createStereoPanner()`
end

0 comments on commit 1360b71

Please sign in to comment.