Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A pitch sequencer which samples a single cello note, and plays a sequence of root -> m3 -> m6 -> P8.
- // The sample is A3, but the root of the sequence can be changed by multiplying the sample's frequency.
- SndBuf celloA3 => ADSR env => NRev reverb => dac;
- // Load the cello note sample.
- me.dir() => string path;
- "/audio/A3.wav" => string filename;
- path+filename => filename;
- filename => celloA3.read;
- // Duration of keyOn / keyOff.
- // Set keyOn very low (~25) for Pacman sounds!
- 130::ms => dur keyOnDur;
- 10::ms => dur keyOffDur;
- // Configure ASDR
- env.set(10::ms, 8::ms, 0.7, keyOffDur);
- // Configure reverb
- 0.12 => reverb.mix;
- // Define the root notes we want to use, in order: A3, D3, F3, G3, A3.
- [
- celloA3.freq(),
- celloA3.freq() * Math.pow(2.0, (-7.0/12.0)),
- celloA3.freq() * Math.pow(2.0, (-4.0/12.0)),
- celloA3.freq() * Math.pow(2.0, (-2.0/12.0)),
- celloA3.freq()
- ] @=> float roots[];
- // Play the sequence four times for each of the roots.
- for (0 => int i; i < roots.cap(); i++) {
- pitchSequence(roots[i], false);
- pitchSequence(roots[i], false);
- pitchSequence(roots[i], false);
- if (i == 4)
- {
- pitchSequence(roots[i], true);
- }
- else
- {
- pitchSequence(roots[i], false);
- }
- }
- fun void pitchSequence(float rootFreq, int isFinalSequence) {
- // Root
- 2.5 => celloA3.gain;
- 0 => celloA3.pos;
- rootFreq => celloA3.freq;
- env.keyOn();
- keyOnDur => now;
- env.keyOff();
- keyOffDur => now;
- // Minor 3rd
- 1.5 => celloA3.gain;
- 0 => celloA3.pos;
- rootFreq * Math.pow(2.0, (3.0/12.0)) => celloA3.freq;
- env.keyOn();
- keyOnDur => now;
- env.keyOff();
- keyOffDur => now;
- // Minor 6th
- 1.5 => celloA3.gain;
- 0 => celloA3.pos;
- rootFreq * Math.pow(2.0, (8.0/12.0)) => celloA3.freq;
- env.keyOn();
- keyOnDur => now;
- env.keyOff();
- keyOffDur => now;
- // +1 Octave
- 1 => celloA3.gain;
- 0 => celloA3.pos;
- rootFreq * 2 => celloA3.freq;
- env.keyOn();
- keyOnDur => now;
- env.keyOff();
- if (isFinalSequence)
- {
- 2::second => now;
- }
- else
- {
- keyOffDur => now;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement