Skip to content

Commit fd1f412

Browse files
committed
sound samples
1 parent 4047c60 commit fd1f412

File tree

13 files changed

+279
-7
lines changed

13 files changed

+279
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
### README
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
4+
# This is a simple brownian noise generator. It can be started with .play(amp).
5+
# In this example it is started and stopped by clicking into the renderer window.
6+
class BrownNoiseApp < Propane::App
7+
load_library :sound
8+
include_package 'processing.sound'
9+
10+
attr_reader :amp, :noise
11+
12+
def settings
13+
size(640, 360)
14+
end
15+
16+
def setup
17+
sketch_title 'Brown Noise'
18+
background(255)
19+
@amp = 0.0
20+
# Create the noise generator
21+
@noise = BrownNoise.new(self)
22+
noise.play(amp)
23+
end
24+
25+
def draw
26+
# Map mouseX from 0.0 to 1.0 for amplitude
27+
noise.amp(map1d(mouse_x, (0..width), (0.0..1.0)))
28+
# Map mouseY from -1.0 to 1.0 for left to right
29+
noise.pan(map1d(mouse_y, (0..height), (-1.0..1.0)))
30+
end
31+
end
32+
33+
BrownNoiseApp.new
130 KB
Binary file not shown.
113 KB
Binary file not shown.
160 KB
Binary file not shown.
150 KB
Binary file not shown.
123 KB
Binary file not shown.
4.71 MB
Binary file not shown.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
4+
# This example shows how to make a simple sampler and sequencer with the Sound
5+
# library. In this sketch 5 different short samples are loaded and played back
6+
# at different pitches, in this when 5 different octaves. The sequencer
7+
# triggers and event every 200-1000 mSecs randomly. Each time a sound is
8+
# played a colored rect with a random color is displayed.
9+
class Keyboard < Propane::App
10+
load_library :sound
11+
include_package 'processing.sound'
12+
# Define the number of samples
13+
NUM_SOUNDS = 5
14+
attr_reader :device, :file, :value
15+
16+
def setup
17+
sketch_title 'Keyboard'
18+
background(255)
19+
# Create a Sound renderer and an array of empty soundfiles
20+
@device = AudioDevice.new(self, 48_000, 32)
21+
@file = []
22+
@value = Array.new(3, 0)
23+
# Load 5 soundfiles from a folder in a for loop. By naming the files 1., 2.,
24+
# 3., n.aif it is easy to iterate through the folder and load all files in
25+
# one line of code.
26+
NUM_SOUNDS.times do |i|
27+
file << SoundFile.new(self, data_path(format('%d.aif', (i + 1))))
28+
end
29+
end
30+
31+
def draw
32+
background(*value) # splat array values
33+
end
34+
35+
def key_pressed
36+
defined = true
37+
case key
38+
when 'a'
39+
file[0].play(0.5, 1.0)
40+
when 's'
41+
file[1].play(0.5, 1.0)
42+
when 'd'
43+
file[2].play(0.5, 1.0)
44+
when 'f'
45+
file[3].play(0.5, 1.0)
46+
when 'g'
47+
file[4].play(0.5, 1.0)
48+
when 'h'
49+
file[0].play(1.0, 1.0)
50+
when 'j'
51+
file[1].play(1.0, 1.0)
52+
when 'k'
53+
file[2].play(1.0, 1.0)
54+
when 'l'
55+
file[3].play(1.0, 1.0)
56+
when 'ö'
57+
file[4].play(1.0, 1.0)
58+
when 'ä'
59+
file[0].play(2.0, 1.0)
60+
when 'q'
61+
file[1].play(2.0, 1.0)
62+
when 'w'
63+
file[2].play(2.0, 1.0)
64+
when 'e'
65+
file[3].play(2.0, 1.0)
66+
when 'r'
67+
file[4].play(2.0, 1.0)
68+
when 't'
69+
file[0].play(3.0, 1.0)
70+
when 'z'
71+
file[1].play(3.0, 1.0)
72+
when 'u'
73+
file[2].play(3.0, 1.0)
74+
when 'i'
75+
file[3].play(3.0, 1.0)
76+
when 'o'
77+
file[4].play(3.0, 1.0)
78+
when 'p'
79+
file[0].play(4.0, 1.0)
80+
when 'ü'
81+
file[1].play(4.0, 1.0)
82+
else
83+
defined = false # only set background color value, if key is defined
84+
end
85+
@value = [rand(0..255), rand(0..255), rand(0..255)] if defined
86+
end
87+
88+
def settings
89+
size 640, 360, P2D
90+
end
91+
end
92+
93+
Keyboard.new

processing_app/library/sound/pink_noise.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
# This is a simple pink noise generator. It can be started with .play(amp).
2-
# In this example it is started and stopped by clicking into the renderer window.
1+
#!/usr/bin/env jruby
32
require 'propane'
43

4+
# This is a simple pink noise generator. It can be started with .play(amp).
5+
# In this example it is started and stopped by clicking into the renderer window.
56
class PinkNoiseApp < Propane::App
67
load_library :sound
78
include_package 'processing.sound'
8-
9+
910
attr_reader :amp, :noise
10-
11+
1112
def settings
1213
size(640, 360)
1314
end
14-
15+
1516
def setup
1617
sketch_title 'Pink Noise'
1718
background(255)
1819
@amp = 0.0
1920
# Create the noise generator
2021
@noise = PinkNoise.new(self)
2122
noise.play(amp)
22-
end
23-
23+
end
24+
2425
def draw
2526
# Map mouseX from 0.0 to 1.0 for amplitude
2627
noise.amp(map1d(mouse_x, (0..width), (0.0..1.0)))

0 commit comments

Comments
 (0)