Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*!
- *
- * This is the four chord song.
- * ------------------
- *
- *I don't know any music, but I tried to make this play stuff while
- messing around,
- * and I got sine and triangle waves to work.
- * and then I got chords to work
- * and then with looking at an example
- I got it to play chords in sequence
- * and then I looked up the chords of the four chord song
- * and then the notes of those chords
- *
- and then the frequencies of those notes
- * and then I had it play it with triangle and sine chords together.
- * I think it sounds
- (for use on wavepot.com)
- pretty neat.
- * -humbleElitist
- *
- */
- export function dsp(t) {
- return generalWackyMusic(fourChordSong,t,t/10-1,note);
- //return rTriNote(261.6,t);
- //simpleGeneralSong(fourChordSong,t,note);
- //return subNoise(t,10*abs(wackyMusic(fourChordSong,t*.9,3)))-0.5;
- //return
- //simpleSquareSong(fourChordSong,t)*subNoise(t,1.5);
- //return simpleSineSong(fourChordSong,t) + 0.1*simpleSineSong(fourChordSong,t+0.0001*Math.random());
- //return (squareNote(413,t)+triangleNote(413,t)+note(413,t))/3 + 0.09*noise(t);
- //return wackyMusic
- //(fourChordSong,t,5)+0.6*simpleTriangleSong(fourChordSong,t*1);
- //return 0.9*simpleTriangleSong(fourChordSong,t) + 0.9*simpleSineSong(fourChordSong,t);
- }
- function note(f,t) {
- return 0.1 * Math.sin(2 * Math.PI * t * f);
- }
- function chord(notes,t) {
- return notes.map(function(f){return note(f,t);}).reduce(function(a,b){return a+b;});
- }
- function triangleNote(f,t){
- return 0.1 * ((t*f % 2) -1);
- }
- function rTriNote(f,t){
- return f*(t-Math.floor(t*f+0.5)/f)*(Math.pow(-1,Math.floor(t*f+0.5)));
- }
- function triangleChord(notes,t) {
- return notes.map(function(f){return triangleNote(f,t);}).reduce(function(a,b){return a+b;});
- }
- function simpleSineSong(chords,t){
- var p = chords[(t / 2 | 0) % chords.length];
- return chord(p,t);
- }
- function simpleTriangleSong(chords,t){
- var p = chords[(t / 2 | 0) % chords.length];
- return triangleChord(p,t);
- }
- function wackyMusic(chords,t,n){
- if(n<=0){
- return simpleSineSong(chords,t);
- }else{
- return simpleSineSong(chords,t)+0.5*wackyMusic(chords,t*2,n-1);
- }
- }
- function squareNote(f,t){
- if((f*t%2)>=1){
- return 0.1;
- }else{
- return -0.1;
- }
- }
- function squareChord(notes,t) {
- return notes.map(function(f){return squareNote(f,t);}).reduce(function(a,b){return a+b;});
- }
- //function simpleSquareSong(chords,t)
- function generalChord(notes,t,noteType){
- return notes.map(function(f){return noteType(f,t);}).reduce(function(a,b){return a+b;});
- }
- function simpleGeneralSong(chords,t,noteType){
- var p = chords[(t / 2 | 0) % chords.length];
- return generalChord(p,t,noteType);
- }
- function generalWackyMusic(chords,t,n,noteType){
- if(n<=0){
- return simpleGeneralSong(chords,t,noteType);
- }else{
- return simpleGeneralSong(chords,t,noteType)+0.5*generalWackyMusic(chords,t*2,n-1,noteType);
- }
- }
- function noise(t){
- return Math.random();
- }
- function subNoise(t,level){
- return (level+noise(t))/(1+level);
- }
- function abs(value){
- return Math.abs(value);
- }
- function noteShift(f,n){
- return f*Math.pow(1.059463094,n);
- }
- var cNote=261.6;
- var cMajChord=[261.6,329.6,392.0];
- var eMajChord=[329.6,415.3,493.9];// E - G# - B
- var bMajChord=[493.9,311.127,369.994];// B - D# - F#
- var cMinChord=[261.6,311.1,392.0];//C Eb G
- var cSharpMinChord=[277.2,329.6,415.3];// Root Note: C#
- //Minor Third: E Perfect Fifth: G#
- var aMajChord=[220.0,277.2,329.6];//A C# E
- var simpleTune=[bMajChord,cMajChord,bMajChord,cMajChord,eMajChord,cMinChord];
- var fourChordSong=[eMajChord,bMajChord,cSharpMinChord,aMajChord];// E
- //major, B major, C# minor, and A major
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement