Guest User

Untitled

a guest
Apr 8th, 2014
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.AudioContext = window.AudioContext||window.webkitAudioContext;
  2. audioContext = new window.AudioContext();
  3.  
  4. var compressor = audioContext.createDynamicsCompressor();
  5. compressor.connect( audioContext.destination );
  6.  
  7. for( var i=0; i<30; i++ )
  8. {
  9.     var osc = audioContext.createOscillator();
  10.     osc.frequency.setValueAtTime( 200 + Math.random()*200, 0 );
  11.     osc.detune.setValueAtTime( Math.random()*20-10, 0 );
  12.     osc.type = "sawtooth";
  13.  
  14.     for( var t=0; t<5; t++ )
  15.     {
  16.         if( Math.random() < 0.1 )
  17.         {
  18.             osc.frequency.exponentialRampToValueAtTime( 200 + Math.random()*200, t*2+Math.random() );
  19.         }
  20.     }
  21.  
  22.     osc.frequency.exponentialRampToValueAtTime( 75 * Math.floor( Math.random()*Math.random()*3 + 1 ), 18 );
  23.  
  24.     for( var t=0; t<15; t++ )
  25.     {
  26.         osc.detune.setValueAtTime( Math.random()*30-15, t*2+Math.random() );
  27.     }
  28.  
  29.     var filter = audioContext.createBiquadFilter();
  30.     filter.type = "lowpass";
  31.     filter.frequency.value = 3000 + Math.random()*2000;
  32.     filter.Q.value = Math.random()*2;
  33.  
  34.     var amp = audioContext.createGain();
  35.     amp.gain.setValueAtTime( 0, 0 );
  36.     amp.gain.linearRampToValueAtTime( 1, 5 + Math.random()*5 );
  37.     amp.gain.setValueAtTime( 1, 22 );
  38.     amp.gain.linearRampToValueAtTime( 0, 30 );
  39.  
  40.     var panner = audioContext.createPanner();
  41.     panner.setPosition( Math.random()*2-1, Math.random()*2-1, Math.random()*2-1 );
  42.  
  43.     osc.connect( filter );
  44.     filter.connect( amp );
  45.     amp.connect( panner );
  46.     panner.connect( compressor );
  47.  
  48.     osc.start(0);
  49.     osc.stop(30);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment