Danger

Danger nearby,

Log in to post a comment.

// Play a note by midi number or predefined variables or use hz_to_midi( freq ) to convert frequency to note number.
//
// See: https://sonic-pi.mehackit.org/exercises/en/01-introduction/02-play-a-melody.html
//
const noise  = synth.def( (phase, env, tick, options) => (Math.random() * 2 - 1) * env.value, { env: adsr2 });
const kick   = synth.def( (phase, env, tick, options) => Math.sin(phase * 2 * Math.PI * (1.5 - tick * 4)) * env.value, { attack: 0.025, release: 0.15, amp: 4, env: adsr2 });


loop( () => {
    
    sine.play(c3, { attack: 0.01, release: 0.25, amp: 0.75 });
    sleep( 0.25 );
    
    for (let i=0; i<3; i++) {
        sine.play(f3, { attack: 0.01, release: 0.25, amp: 0.75 });
        sleep( 0.25 );
    }
   
    sleep( 0.5 );
    sine.play(g3, { attack: 0.01, release: 0.15, amp: 0.75 });
    
    sleep( 0.25 );
    
    sine.play(g3, { attack: 0.01, release: 0.1, amp: 0.75 });
    sleep( 0.25 );
});


loop( () => {
    
    kick.play(c3, { amp: 0.5,  release: 0.1});
    sleep(0.25);
    kick.play(d3, { amp: 1, release: 0.1 });
    sleep(0.25);
    kick.play(f3, { amp: 1.25, release: 0.1});
    sleep(0.25);
    kick.play(d3, { amp: 1, release: 0.1 });
    sleep(0.25);
    kick.play(c3, { amp: 0.5, release: 0.1 });

    sleep(1);
});



loop( () => {
  for (let i=0; i<5; i++) {
        noise.play(c3, { attack: 0.025, release: 0.15, amp: .02 + Math.random() * 0.05 });
        sleep( 0.25 );
    }
         //noise.play(c, { attack: 0.025, release: 0.15, amp: .05 + Math.random() * 0.05 });
     //sleep(0.25 + Math.random() * 0.25);
});

loop( (phase) => {
  var w = Math.sin(phase / 10);
  
  var amplitude = 0.15 + w * (0.35 - 0.15);
    
    //Math.sin(phase * 2 * Math.PI * (1.5 - tick * 4)
    sine.play(g4, { attack: 0.01, pan: Math.random() * 2 - 1, release: 0.25, amp: amplitude });
    sleep( 0.25 );
});