Created
February 28, 2016 04:34
-
-
Save Enkerli/05c6d9d4c6f1e93a27b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Title: FunctDustRiver | |
// Learning Author: Alex Enkerli | |
// Date: 27 February 2016 | |
// Course: Introduction to Programming for Musicians and Digital Artists | |
// Assignment for Session 3 – Sound File Manipulation | |
// Requires the audio samples from this link to be in the same directory: http://lar.me/30y | |
Gain master=>NRev r=>dac; // Adding reverb to master gain | |
.1=>r.mix; // Mixing the reverb with the master | |
SndBuf2 fx => master; // Sending stereo fx samples to master | |
SndBuf kick => master; // Sending drumkick samples to master | |
SndBuf hihat => master; // Sending hihat samples to master | |
SndBuf snare => master; // Sending snare samples to master | |
0 => int count; // Total count of beats | |
// Setting up arrays to receive the filenames for the different types of samples | |
string kicksamps[5]; // There are five drumkick samples: kick_01.wav .. kick_05.wav | |
string hihatsamps[4]; // There are four hihat samples: hihat_01.wav .. hihat_04.wav | |
string snaresamps[3]; // There are three snare samples: snare_01.wav .. snare_05.wav | |
string fxsamps[5]; // There are five stereo fx samples: stereo_fx_01.wav .. stereo_fx_05.wav | |
fun void loadarray(string name, string array[]) // Load an array with filenames from samples | |
{ | |
for(1=>int k;k<=array.cap();k++){ // Increment the array index up to capacity | |
me.dir()+"audio/"+name+"_0"+k+".wav"=>array[k-1]; // Construct the full file name and chuck that into the array | |
} | |
} | |
fun void playarray(string array[],float tim) // Sequentially play each sample loaded into an array, with a set time between samples | |
{ | |
SndBuf sound=>dac; // Local sound buffer | |
for(1=>int k;k<=array.cap();k++){ // Increment the array index up to capacity | |
array[k-1]=>sound.read; // Chuck the filename into the local sound buffer | |
tim::second=>now; // Wait a set amount of time | |
} | |
} | |
fun void playinst(SndBuf inst, string array[], int posmin, int posmax, float ratemin, float ratemax, float gainmin, float gainmax) // Give all the necessary parameters to play a ransomized sample | |
{ | |
array[Math.random2(0,array.cap()-1)]=>inst.read; // Randomly select a sample from the array provided, avoiding the array’s limit | |
Math.random2(posmin, posmax)=>inst.pos; // Always setting the playhead at the beginning of the sample | |
Math.random2f(ratemin,ratemax)=>inst.rate; // Randomizing the sample’s playing rate | |
Math.random2f(gainmin,gainmax)=>inst.gain; // Randomizing the sample’s gain | |
} | |
fun void playbar(int numbeat, float timlow, float timhi) // Structure of a single bar | |
{ | |
for(1=>int beat; beat<=numbeat; beat++) // Go through the bar | |
{ | |
if((beat==1)||(beat==5)) playinst(kick, kicksamps, 0, 0, -0.2, 1, 0, 0.8);// Play drumkick on beats 1 and 5 (twice as fast as the whole bar) | |
if((beat==2)||(beat==6)) playinst(hihat, hihatsamps, 0, hihat.samples()/2, -2, 1, 0, 0.8); // Play hihat right after the kick | |
if(count%24==1) playinst(fx,fxsamps,0,fx.samples(),-2,2,-0.3,0.8); // Play fx samples every 24 beats | |
playinst(snare, snaresamps, 0, snare.samples(), -0.1, 1, 0, 0.8); // Play snare every beat | |
Math.random2f(timlow,timhi)::second=>now; // Add slight variation to the beat duration | |
<<<count>>>; | |
count++; | |
} | |
} | |
// Load the arrays | |
loadarray("kick",kicksamps); // Load an array of drumkick samples | |
loadarray("hihat",hihatsamps); // Load an array of hihat samples | |
loadarray("snare",snaresamps); // Load an array of snare samples | |
loadarray("stereo_fx",fxsamps); // Load an array of stereo effects samples | |
// Introduce the stereo effects sample | |
//playarray(fxsamps,0.4); // Play the stereo effects samples loaded in the array | |
// Main loop | |
while(count<1000) { // Play bars for 1000 beats | |
playbar(8,0.2,0.2); | |
playbar(7,0.14,0.213); | |
playbar(9,0.11,0.22); | |
} | |
// End | |
5::second=>now; // Let sounds decay a bit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment