Skip to content

Commit 224a8bd

Browse files
committed
expand sound library examples
1 parent c8043d7 commit 224a8bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1277
-428
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
### README
2+
Remember you need to install processing sound library, either using processing ide or to `~/.jruby_art/libraries`.
23

3-
You can use processing-3.0+ to install the sound library from processing.org. This sound library has been adopted by processing.org, although the minim library is still available to install from the processing ide.
4+
To use processing ide installed libraries then set `processing_ide: true` in `./jruby_art.config.yml` else set `processing_ide: false` in `./jruby_art.config.yml` for k9 or manually installed libraries.
Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1-
# Simple demo Rakefile to autorun samples in current directory
2-
# adjust path to rp5 executable, and or opts as required
1+
# -*- encoding: utf-8 -*-
32

4-
SAMPLES_DIR = './'
3+
PRWD = File.expand_path(__dir__)
54

65
desc 'run demo'
7-
task default: [:demo]
6+
task :default => [:all]
87

9-
desc 'demo'
10-
task :demo do
11-
samples_list.shuffle.each { |sample| run_sample sample }
8+
desc 'autorun all samples'
9+
task :all do
10+
Rake::Task[:soundfile].execute
11+
Rake::Task[:oscillators].execute
12+
Rake::Task[:noise].execute
13+
Rake::Task[:effects].execute
1214
end
1315

14-
def samples_list
15-
files = []
16-
Dir.chdir(SAMPLES_DIR)
17-
Dir.glob('*.rb').each do |file|
18-
files << File.join(SAMPLES_DIR, file)
19-
end
20-
return files
16+
desc 'run soundfile samples'
17+
task :soundfile do
18+
sh "cd #{PRWD}/soundfile && rake"
2119
end
2220

23-
def run_sample(sample_name)
24-
puts "Running #{sample_name}...quit to run next sample"
25-
open("|k9 -r #{sample_name}", 'r') do |io|
26-
while l = io.gets
27-
puts(l.chop)
28-
end
29-
end
21+
desc 'oscillators'
22+
task :oscillators do
23+
sh "cd #{PRWD}/oscillators && rake"
24+
end
25+
26+
desc 'noise'
27+
task :noise do
28+
sh "cd #{PRWD}/noise && rake"
29+
end
30+
31+
desc 'effects'
32+
task :effects do
33+
sh "cd #{PRWD}/effects && rake"
3034
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Simple demo Rakefile to autorun samples in current directory
2+
# adjust path to rp5 executable, and or opts as required
3+
4+
SAMPLES_DIR = './'
5+
6+
desc 'run demo'
7+
task default: [:demo]
8+
9+
desc 'demo'
10+
task :demo do
11+
samples_list.shuffle.each { |sample| run_sample sample }
12+
end
13+
14+
def samples_list
15+
files = []
16+
Dir.chdir(SAMPLES_DIR)
17+
Dir.glob('*.rb').each do |file|
18+
files << File.join(SAMPLES_DIR, file)
19+
end
20+
return files
21+
end
22+
23+
def run_sample(sample_name)
24+
puts "Running #{sample_name}...quit to run next sample"
25+
open("|k9 - r #{sample_name}", 'r') do |io|
26+
while l = io.gets
27+
puts(l.chop)
28+
end
29+
end
30+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
# Play a sound sample and pass it through a tape delay, changing the delay
4+
# parameters based on the mouse position.
5+
6+
load_library :sound
7+
java_import 'processing.sound.Waveform'
8+
java_import 'processing.sound.SoundFile'
9+
10+
attr_reader :waveform, :sample
11+
SAMPLES = 100
12+
def settings
13+
size(640, 360)
14+
end
15+
16+
def setup
17+
sketch_title 'Waveform Analyser'
18+
# Load and play a soundfile and loop it
19+
@sample = SoundFile.new(self, data_path('beat.aiff'))
20+
sample.loop
21+
# Create and patch the waveform tracker
22+
@waveform = Waveform.new(self, SAMPLES)
23+
waveform.input(sample)
24+
end
25+
26+
def draw
27+
# Set background color, noFill and stroke style
28+
background(0)
29+
stroke(255)
30+
strokeWeight(2)
31+
noFill
32+
33+
# Perform the analysis
34+
waveform.analyze
35+
36+
begin_shape
37+
SAMPLES.times do |i|
38+
# Draw current data of the waveform
39+
# Each sample in the data array is between -1 and +1
40+
vertex(
41+
map1d(i, 0..SAMPLES, 0..width),
42+
map1d(waveform.data[i], -1..1, 0..height)
43+
)
44+
end
45+
end_shape
46+
end
File renamed without changes.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
# Play a sound sample and pass it through a tape delay, changing the delay
4+
# parameters based on the mouse position.
5+
load_library :sound
6+
java_import 'processing.sound.FFT'
7+
java_import 'processing.sound.SoundFile'
8+
9+
attr_reader :fft, :sample, :sum, :bar_width
10+
SMOOTHING_FACTOR = 0.25
11+
BANDS = 128
12+
SCALE = 5
13+
def settings
14+
size(640, 360)
15+
end
16+
17+
def setup
18+
sketch_title 'FFT Spectrum'
19+
@bar_width = width / BANDS.to_f
20+
# Load and play a soundfile and loop it
21+
@sample = SoundFile.new(self, data_path('beat.aiff'))
22+
sample.loop
23+
# Create and patch the fft tracker
24+
@fft = FFT.new(self)
25+
fft.input(sample)
26+
@sum = Array.new(BANDS, 0.0)
27+
end
28+
29+
def draw
30+
# Set background color, noStroke and fill color
31+
background(125, 255, 125)
32+
noStroke
33+
fill(255, 0, 150)
34+
fft.analyze
35+
BANDS.times do |i|
36+
# Smooth the FFT spectrum data by smoothing factor
37+
sum[i] += (fft.spectrum[i] - sum[i]) * SMOOTHING_FACTOR
38+
rect(i * bar_width, height, bar_width, -sum[i] * height * SCALE)
39+
end
40+
end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
# Play a sound sample and pass it through a tape delay, changing the delay
4+
# parameters based on the mouse position.
5+
load_library :sound
6+
java_import 'processing.sound.Amplitude'
7+
java_import 'processing.sound.SoundFile'
8+
9+
attr_reader :rms, :sample, :sum
10+
SMOOTHING_FACTOR = 0.25
11+
def settings
12+
size(640, 360)
13+
end
14+
15+
def setup
16+
sketch_title 'Peak Amplitude'
17+
# Load and play a soundfile and loop it
18+
@sample = SoundFile.new(self, data_path('beat.aiff'))
19+
sample.loop
20+
# Create and patch the rms tracker
21+
@rms = Amplitude.new(self)
22+
rms.input(sample)
23+
@sum = 0
24+
end
25+
26+
def draw
27+
# Set background color, noStroke and fill color
28+
background(125, 255, 125)
29+
noStroke
30+
fill(255, 0, 150)
31+
32+
# smooth the rms data by smoothing factor
33+
@sum += (rms.analyze - sum) * SMOOTHING_FACTOR
34+
35+
# rms.analyze() return a value between 0 and 1. Its
36+
# scaled to height/2 and then multiplied by a fixed scale factor
37+
rms_scaled = sum * (height / 2) * 5
38+
39+
# We draw a circle whose size is coupled to the audio analysis
40+
ellipse(width / 2, height / 2, rms_scaled, rms_scaled)
41+
end

processing_app/library/sound/brown_noise.rb

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Simple demo Rakefile to autorun samples in current directory
2+
# adjust path to rp5 executable, and or opts as required
3+
4+
SAMPLES_DIR = './'
5+
6+
desc 'run demo'
7+
task default: [:demo]
8+
9+
desc 'demo'
10+
task :demo do
11+
samples_list.shuffle.each { |sample| run_sample sample }
12+
end
13+
14+
def samples_list
15+
files = []
16+
Dir.chdir(SAMPLES_DIR)
17+
Dir.glob('*.rb').each do |file|
18+
files << File.join(SAMPLES_DIR, file)
19+
end
20+
return files
21+
end
22+
23+
def run_sample(sample_name)
24+
puts "Running #{sample_name}...quit to run next sample"
25+
open("|k9 - r #{sample_name}", 'r') do |io|
26+
while l = io.gets
27+
puts(l.chop)
28+
end
29+
end
30+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
# Play a sound sample and pass it through a tape source, changing the source
4+
# parameters based on the mouse position.
5+
load_library :sound
6+
java_import 'processing.sound.WhiteNoise'
7+
java_import 'processing.sound.BandPass'
8+
9+
attr_reader :filter, :source
10+
11+
def settings
12+
size(640, 360)
13+
end
14+
15+
def setup
16+
background(255)
17+
sketch_title 'Band Pass Filter'
18+
# Create the noise generator + filter
19+
@filter = BandPass.new(self)
20+
@source = WhiteNoise.new(self)
21+
# Connect the filter to the source unit
22+
source.play
23+
filter.process(source)
24+
end
25+
26+
def draw
27+
# Map the left/right mouse position to a cutoff frequency between 20 and 10000 Hz
28+
frequency = map1d(mouseX, 0..width, 20..10_000)
29+
# And the vertical mouse position to the width of the band to be passed through
30+
bandwidth = map1d(mouseY, 0..height, 1_000..100)
31+
filter.freq(frequency)
32+
filter.bw(bandwidth)
33+
# Draw a circle indicating the position + width of the frequency window
34+
# that is allowed to pass through
35+
background(125, 255, 125)
36+
no_stroke
37+
fill(255, 0, 150)
38+
end

0 commit comments

Comments
 (0)