-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeirdSounds.pde
126 lines (108 loc) · 4.22 KB
/
WeirdSounds.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import io.github.daveho.funwithsound.*;
import net.beadsproject.beads.core.*;
import net.beadsproject.beads.data.*;
FunWithSound fws = new FunWithSound(this) {
protected Player createPlayer() {
Player player = super.createPlayer();
registerCustomInstruments(player);
return player;
}
};
class MyComp extends Composer {
void create() {
tempo(200, 8); // 200 beats per minute, 8 beats per measure
// Metronome instrument for keeping time
Instrument metronome = percussion();
// Set up the custom instrument that will be used for notes played live
Instrument synth = custom(0); // <-- change this to select among the custom instruments
//addfx(synth, new AddReverb()); // <-- uncomment this line to add reverb
v(synth, 0.2); // reduce the volume
// Metronome pattern: plays a closed hihat every 2 beats
Rhythm metr = rr(p(0,101), 2, 4);
Figure metf = pf(metr, 42, metronome);
// Add 8 measures of the metronome pattern
add1(gf(metf));
add1(gf(metf));
add1(gf(metf));
add1(gf(metf));
add1(gf(metf));
add1(gf(metf));
add1(gf(metf));
add1(gf(metf));
// Play live using the custom instrument
audition(synth);
}
}
MyComp c = new MyComp();
void setup() {
size(600,200);
textSize(32);
fill(0);
text("Click to start playing", 125, 140);
c.create();
}
void draw() {
}
void mouseClicked() {
fws.play(c);
}
void registerCustomInstruments(Player player) {
// The code below defines the characteristics of the custom instruments.
// Comments indicate where you can make changes.
CustomInstrumentFactory factory = new CustomInstrumentFactoryImpl(
// Custom instrument 0: plays simple wave forms with a single frequency,
// using a simple on/off envelope
0, new CustomInstrumentFactoryImpl.CreateCustomInstrument() {
public RealizedInstrument create(AudioContext ac) {
DataBead params = Defaults.monosynthDefaults();
params.put(ParamNames.GLIDE_TIME_MS, 0.0f);
SynthToolkit tk = SynthToolkitBuilder.start()
.withWaveVoice(Buffer.SINE) // <-- try Buffer.SQUARE, Buffer.SAW, Buffer.TRIANGLE
.withOnOffNoteEnvelope()
.getTk();
MonoSynthUGen2 u = new MonoSynthUGen2(ac, tk, params,
new double[]{ 1.0 },
new double[]{ 1.0 }
);
return new RealizedInstrument(u, ac);
}
},
// Custom instrument 1: simple waveforms with a single frequency,
// but with an attack/sustain/release envelope
1, new CustomInstrumentFactoryImpl.CreateCustomInstrument() {
public RealizedInstrument create(AudioContext ac) {
DataBead params = Defaults.monosynthDefaults();
params.put(ParamNames.GLIDE_TIME_MS, 0.0); // <-- try increasing this for portamento
params.put(ParamNames.ATTACK_TIME_MS, 10.0); // <-- change the attack time
params.put(ParamNames.RELEASE_TIME_MS, 80.0); // <-- change the release time
SynthToolkit tk = SynthToolkitBuilder.start()
.withWaveVoice(Buffer.SINE) // <-- try Buffer.SQUARE, Buffer.SAW, Buffer.TRIANGLE
.withASRNoteEnvelope()
.getTk();
MonoSynthUGen2 u = new MonoSynthUGen2(ac, tk, params,
new double[]{ 1.0 },
new double[]{ 1.0 }
);
return new RealizedInstrument(u, ac);
}
},
// Custom instrument 2: simple wave forms with multiple frequencies,
// with attack/sustain/release envelope
2, new CustomInstrumentFactoryImpl.CreateCustomInstrument() {
public RealizedInstrument create(AudioContext ac) {
DataBead params = Defaults.monosynthDefaults();
params.put(ParamNames.GLIDE_TIME_MS, 40.0);
SynthToolkit tk = SynthToolkitBuilder.start()
.withWaveVoice(Buffer.SINE) // <-- try Buffer.SQUARE, Buffer.SAW, Buffer.TRIANGLE
.withASRNoteEnvelope()
.getTk();
MonoSynthUGen2 u = new MonoSynthUGen2(ac, tk, params,
new double[]{ 1.0, 1.5, 2.0 }, // <-- try changing the multiples, adding new multiples
new double[]{ 1.0, 0.5, 0.25 } // <-- try changing the gains (volumes)
);
return new RealizedInstrument(u, ac);
}
}
);
player.setCustomInstrumentFactory(factory);
}