The processing sound library in JRubyArt
Since processing-3.0 does not include the minim sound library. Instead the processing guys have created their own sound library, but even that is only available as a separate install, but usage in JRubyArt is the same as other libraries ie you can use the JRubyArt load_library
, load_libraries
utility, but note that as with other java imports to use the classes you need to include_package
to use a java package without full qualification.
Brown noise generator
# This is a simple brownian noise generator. It can be started with .play(amp).
# In this example it is started and stopped by clicking into the renderer window.
load_library :sound
include_package 'processing.sound'
attr_reader :amp, :noise
def settings
size(640, 360)
end
def setup
sketch_title 'Brown Noise'
background(255)
@amp = 0.0
# Create the noise generator
@noise = BrownNoise.new(self)
noise.play(amp)
end
def draw
# Map mouseX from 0.0 to 1.0 for amplitude
noise.amp(map1d(mouse_x, (0..width), (0.0..1.0)))
# Map mouseY from -1.0 to 1.0 for left to right
noise.pan(map1d(mouse_y, (0..height), (-1.0..1.0)))
end
Pink noise generator
# This is a simple pink noise generator. It can be started with .play(amp).
# In this example it is started and stopped by clicking into the renderer window.
load_library :sound
include_package 'processing.sound'
attr_reader :amp, :noise
def settings
size(640, 360)
end
def setup
sketch_title 'Pink Noise'
background(255)
@amp = 0.0
# Create the noise generator
@noise = PinkNoise.new(self)
noise.play(amp)
end
def draw
# Map mouseX from 0.0 to 1.0 for amplitude
noise.amp(map1d(mouse_x, (0..width), (0.0..1.0)))
# Map mouseY from -1.0 to 1.0 for left to right
noise.pan(map1d(mouse_y, (0..height), (-1.0..1.0)))
end
White noise generator
# This is a simple white noise generator. It can be started with .play(amp).
# In this example it is started and stopped by clicking into the renderer window.
load_library :sound
include_package 'processing.sound'
attr_reader :amp, :noise
def settings
size(640, 360)
end
def setup
sketch_title 'White Noise'
background(255)
@amp = 0.0
# Create the noise generator
@noise = WhiteNoise.new(self)
noise.play(amp)
end
def draw
# Map mouseX from 0.0 to 1.0 for amplitude
noise.amp(map1d(mouse_x, (width..0), (0.0..1.0))) # reversed for fun
# Map mouseY from -1.0 to 1.0 for left to right
noise.pan(map1d(mouse_y, (0..height), (-1.0..1.0)))
end