Skip to content

Commit ccfcb7e

Browse files
committed
deleted old example files and data, added new examples
1 parent b046322 commit ccfcb7e

19 files changed

+296
-447
lines changed

examples/data/bwv806d.mid

-6.41 KB
Binary file not shown.

examples/data/demo.mid

-4.1 KB
Binary file not shown.

examples/data/sonata01-1.mid

-23 KB
Binary file not shown.

examples/data/test1_poly8.mid

-662 Bytes
Binary file not shown.

examples/data/test2_fastarp.mid

-337 Bytes
Binary file not shown.

examples/data/test3_staircase.mid

-181 Bytes
Binary file not shown.

examples/data/test4_layers.mid

-4.58 KB
Binary file not shown.

examples/instruments/flangerInst.ck

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
//-----------------------------------------------------------------------------
2+
// name: flangerInst.ck
3+
// desc: This ezInstrument reads in an audio file and plays it back, repitched
4+
// according to incoming ezNote pitches. It assumes the audio file is a one-shot
5+
// sample with a "root note" pitch. It also applies a flanger effect using comb filtering.
6+
//
7+
// author: Alex Han (https://ccrma.stanford.edu/~alexhan/)
8+
//-----------------------------------------------------------------------------
9+
10+
@import "/Users/alexhan/Desktop/ChucK/smuck/src/smuck.ck"
11+
12+
// This ezInstrument repitches one-shot audio samples and applies a flanger effect using comb filtering
13+
public class flangerInst extends ezInstrument
14+
{
15+
// Signal Chain
16+
// ---------------------------------------
17+
8 => int _n_voices;
18+
setVoices(_n_voices);
19+
SndBuf bufs[_n_voices] => Gain dry => outlet;
20+
SinOsc lfo => blackhole;
21+
22+
bufs => DelayL del => Gain wet => outlet;
23+
1::second => del.max;
24+
25+
// Private variables
26+
// ---------------------------------------
27+
// Audio file to be loaded
28+
string _filename;
29+
// Pitch of the audio sample (assumed to be one-shot)
30+
int _root;
31+
32+
// LFO frequency
33+
1.6 => float _freq;
34+
lfo.freq(_freq);
35+
// LFO mod depth
36+
.5 => float _depth;
37+
// Dry/Wet mix
38+
.9 => float _mix;
39+
40+
// Base delay
41+
6::ms => dur _base;
42+
// Modulation delay
43+
2::ms => dur _mod;
44+
45+
46+
// Constructor
47+
// ---------------------------------------
48+
fun flangerInst(string file)
49+
{
50+
filename(file);
51+
}
52+
53+
// Get/Set functions
54+
// ---------------------------------------
55+
// Set the filename of the audio sample
56+
fun void filename(string filename)
57+
{
58+
filename => _filename;
59+
for(auto buf : bufs)
60+
{
61+
buf.read(_filename);
62+
buf.pos(buf.samples());
63+
}
64+
}
65+
66+
// Get the filename of the audio sample
67+
fun string filename()
68+
{
69+
return _filename;
70+
}
71+
72+
// Set the root note of the audio sample
73+
fun void root(int root)
74+
{
75+
root => _root;
76+
}
77+
78+
// Get the root note of the audio sample
79+
fun int root()
80+
{
81+
return _root;
82+
}
83+
84+
// Set the LFO frequency
85+
fun void freq(float val)
86+
{
87+
val => _freq;
88+
lfo.freq(_freq);
89+
}
90+
91+
// Get the LFO frequency
92+
fun float freq()
93+
{
94+
return _freq;
95+
}
96+
97+
// Set the LFO mod depth
98+
fun void depth(float val)
99+
{
100+
val => _depth;
101+
}
102+
103+
// Get the LFO mod depth
104+
fun float depth()
105+
{
106+
return _depth;
107+
}
108+
109+
// Set the dry/wet mix
110+
fun void mix(float val)
111+
{
112+
val => _mix;
113+
_mix => wet.gain;
114+
1.0 - _mix => dry.gain;
115+
}
116+
117+
// Get the dry/wet mix
118+
fun float mix()
119+
{
120+
return _mix;
121+
}
122+
123+
// Set the base delay
124+
fun void base(dur val)
125+
{
126+
val => _base;
127+
}
128+
129+
// Get the base delay
130+
fun dur base()
131+
{
132+
return _base;
133+
}
134+
135+
// Set the modulation delay
136+
fun void mod(dur val)
137+
{
138+
val => _mod;
139+
}
140+
141+
// Get the modulation delay
142+
fun dur mod()
143+
{
144+
return _mod;
145+
}
146+
147+
// Helper functions
148+
// ---------------------------------------
149+
fun float transpose(int amount)
150+
{
151+
return Math.pow(2, amount / 12.0);
152+
}
153+
154+
// LFO driver
155+
fun void lfoDriver()
156+
{
157+
while(true)
158+
{
159+
(_base + (lfo.last() * _mod)) * _depth => del.delay;
160+
1::ms => now;
161+
}
162+
}
163+
164+
// Automaticall spork the LFO driver
165+
spork~lfoDriver();
166+
167+
168+
// Note functions called by player
169+
// ---------------------------------------
170+
fun void noteOn(ezNote theNote, int which)
171+
{
172+
transpose((theNote.pitch() - _root) $ int) => bufs[which].rate;
173+
theNote.velocity() => bufs[which].gain;
174+
bufs[which].pos(0);
175+
}
176+
177+
fun void noteOff(ezNote theNote,int which)
178+
{
179+
// Unused
180+
}
181+
182+
}
183+

examples/instruments/releaseInst.ck

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//-----------------------------------------------------------------------------
2+
// name: releaseInst.ck
3+
// desc: This ezInstrument demonstrates how to design instruments with long release
4+
// times that may extend beyond the end of a note's duration.
5+
//
6+
// author: Alex Han (https://ccrma.stanford.edu/~alexhan/)
7+
//-----------------------------------------------------------------------------
8+
@import "smuck"
9+
10+
public class releaseInst extends ezInstrument
11+
{
12+
16 => int n_voices;
13+
setVoices(n_voices);
14+
TriOsc oscs[n_voices] => ADSR envs[n_voices] => LPF lpf => outlet;
15+
16+
2200 => lpf.freq;
17+
18+
for(int i; i < n_voices; i++)
19+
{
20+
envs[i].set(50::ms, 450::ms, 0.9, 2500::ms); // Set up an ADSR envelope with a 2.5 second release time
21+
}
22+
23+
fun void noteOn(ezNote note, int voice)
24+
{
25+
Std.mtof(note.pitch()) => oscs[voice].freq;
26+
envs[voice].keyOn();
27+
}
28+
29+
fun void noteOff(ezNote note, int voice)
30+
{
31+
envs[voice].keyOff();
32+
envs[voice].releaseTime() => now; // Allows time to pass after keyOff is called, letting the note release to happen
33+
}
34+
}

examples/instruments/samplerInst.ck

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//-----------------------------------------------------------------------------
2+
// name: samplerInst.ck
3+
// desc: This ezInstrument reads in an audio file and plays it back, repitched
4+
// according to incoming ezNote pitches. It assumes the audio file is a one-shot
5+
// sample with a "root note" pitch.
6+
//
7+
// author: Alex Han (https://ccrma.stanford.edu/~alexhan/)
8+
//-----------------------------------------------------------------------------
9+
10+
@import "smuck"
11+
12+
public class samplerInst extends ezInstrument
13+
{
14+
// Set up signal chain
15+
16 => int _n_voices;
16+
SndBuf bufs[_n_voices] => outlet;
17+
18+
// Private variables
19+
string _filename;
20+
int _root;
21+
22+
// Constructor
23+
fun sampleInst(string file)
24+
{
25+
filename(file);
26+
}
27+
28+
// Set filename
29+
fun void filename(string filename)
30+
{
31+
filename => _filename;
32+
for(auto buf : bufs)
33+
{
34+
buf.read(_filename);
35+
buf.pos(buf.samples());
36+
}
37+
}
38+
39+
// Get filename
40+
fun string filename()
41+
{
42+
return _filename;
43+
}
44+
45+
// Set root note
46+
fun void root(int root)
47+
{
48+
root => _root;
49+
}
50+
51+
// Get root note
52+
fun int root()
53+
{
54+
return _root;
55+
}
56+
57+
// Convert semitone offset to frequency ratio for playback rate
58+
fun float transpose(int amount)
59+
{
60+
return Math.pow(2, amount / 12.0);
61+
}
62+
63+
64+
// Note on function
65+
fun void noteOn(ezNote note, int voice)
66+
{
67+
<<<"noteOn", voice, note.pitch()>>>;
68+
transpose((note.pitch() $ int) - _root) => bufs[voice].rate;
69+
note.velocity() => bufs[voice].gain;
70+
bufs[voice].pos(0);
71+
}
72+
73+
// Note off function
74+
fun void noteOff(ezNote note, int voice)
75+
{
76+
// Unused
77+
}
78+
79+
}

0 commit comments

Comments
 (0)