Created
February 27, 2016 23:28
-
-
Save Enkerli/ca88b9aea545a3bc9ebb 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: Industriver | |
// 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; // This total count will later be split into beats | |
0 => int barcount; // Each time we reach the first beat, we’ll start a new bar | |
0=> int bar; // Similar to beats, bars will loop | |
// Setting up arrays to receives the different types of samples | |
// Was looking into a way to standardize the variable names and only have one array which can be reused | |
string kicksamps[5]; | |
string hihatsamps[4]; | |
string snaresamps[3]; | |
string fxsamps[5]; | |
// Adding the names of the drumkick samples to their array, so the samples can then be read by referring to an index | |
for(1=>int j;j<=kicksamps.cap();j++){ | |
me.dir()+"audio/kick_0"+j+".wav"=>kicksamps[j-1]; | |
} | |
// Adding the names of the hihat samples to their array, for future reference | |
for(1=>int j;j<=hihatsamps.cap();j++){ | |
me.dir()+"audio/hihat_0"+j+".wav"=>hihatsamps[j-1]; | |
} | |
// Adding the names of the snare samples to their array, for future reference | |
for(1=>int j;j<=snaresamps.cap();j++){ | |
me.dir()+"audio/hihat_0"+j+".wav"=>snaresamps[j-1]; | |
} | |
// Adding the names of the fx samples to their array, for future reference | |
for(1=>int j;j<=fxsamps.cap();j++){ | |
me.dir()+"audio/stereo_fx_0"+j+".wav"=>fxsamps[j-1]; | |
} | |
while(true){ // Main loop | |
while(true) // Bars also loop | |
{ | |
count%8=>int beat; // The bar is a cycle of eight beats | |
if((beat==1)||(beat==5)){ // Play drumkick on beats 1 and 5 (twice as fast as the whole bar) | |
kicksamps[Math.random2(0,kicksamps.cap()-1)]=>kick.read; // Randomly select a drumkick sample, avoiding the array’s limit | |
0=>kick.pos; // Always setting the playhead at the beginning of the sample | |
Math.random2f(-0.2,1)=>kick.rate; // Randomizing the drumkick sample’s playing rate, including reverse samples (which wouldn’t sound since the playhead is at the beginning) | |
Math.random2f(0,0.8)=>kick.gain; // Randomizing the drumkick sample’s gain, including silence | |
} | |
if((beat==2)||(beat==6)){ // Play hihat right after the kick | |
hihatsamps[Math.random2(0,hihatsamps.cap()-1)]=>hihat.read; // Randomly select a hihat sample, avoiding the array’s limit | |
Math.random2(0,hihat.samples()/2)=>hihat.pos; // Randomizing the playhead position but still getting at least half of the full sample | |
Math.random2f(-2,1)=>hihat.rate; // Encouraging the playing of reverse samples | |
Math.random2f(0,0.8)=>hihat.gain; // Randomizing the hihat sample’s gain, including silence | |
} | |
snaresamps[Math.random2(0,snaresamps.cap()-1)]=>snare.read; // The snare should play a random sample every beat | |
Math.random2f(0.1,1)=>snare.rate; // Randomizing the snare sample’s play rate from a tenth of its full rate to full rate | |
Math.random2(0,snare.samples())=>snare.pos; // The snare sample’s playhead can be at any position, including at the very end of the sample | |
Math.random2f(0,0.8)=>snare.gain; // Randomizing the snare sample’s gain, including silence | |
if(beat==0){ // Starting a new bar on beat 0 | |
barcount++; // Incrementing the total bar count | |
barcount%3=>bar; // Cycling every three bars | |
if(bar==1){ // On the second bar (out of three), play a stereo effect | |
fxsamps[Math.random2(0,fxsamps.cap()-1)]=>fx.read; // Randomly select a stereo effect sample | |
Math.random2f(-0.3,0.8)=>fx.gain; // Randomizing the fx sample’s gain so that it will be silent once in a while | |
Math.random2f(-2,2)=>fx.rate; // Allowing for the fx sample to be played up to twice as fast, both in reverse and in normal mode | |
Math.random2(0,fx.samples())=>fx.pos; // The fx sample’s playhead can be at any position, including at the very end of the sample | |
} | |
} | |
Math.random2f(0.17,0.23)::second=>now; // Add slight variation to the beat duration | |
count++; // Incrementing the total number of beats | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment