<commit_before>ready(function() {
  var waveStep = 0;

  function step(t) {
    var waveforms = document.getElementById('waveforms').getContext('2d');

    waveforms.clearRect(0, 0, 1200, 800);

    waveforms.fillStyle = '#333';
    waveforms.font = '32px Share Tech Mono';
    waveforms.textBaseline = 'top';

    waveforms.lineWidth = 6;
    waveforms.strokeStyle = '#333';

    waveforms.fillText('Sine', 8, 8);

    waveforms.beginPath();
    for (var i = 0, x = 0 - waveStep; i < 14; i++) {
      waveforms.moveTo(x, 100);
      waveforms.quadraticCurveTo(x + 50, i % 2 == 0 ? 50 : 150, x + 100, 100);
      x += 100;
    }
    waveforms.stroke();
    waveforms.closePath();

    waveforms.fillText('Triangle', 8, 208);

    waveforms.beginPath();
    waveforms.moveTo(-50 - waveStep, 250);
    waveforms.lineTo(50 - waveStep, 350);
    for (var i = 0, x = 150 - waveStep; i < 14; i++) {
      waveforms.lineTo(x, i % 2 == 0 ? 250 : 350);
      x += 100;
    }
    waveforms.stroke();
    waveforms.closePath();

    waveforms.fillText('Sawtooth', 8, 408);

    waveforms.beginPath();
    waveforms.moveTo(-50 - waveStep, 550);
    for (var i = 0, x = 150 - waveStep; i < 8; i++) {
      waveforms.lineTo(x, 450);
      waveforms.lineTo(x, 550);
      x += 200;
    }
    waveforms.stroke();
    waveforms.closePath();

    waveforms.fillText('Square', 8, 608);

    waveforms.beginPath();
    waveforms.moveTo(-50 - waveStep, 650);
    for (var i = 0, x = 50 - waveStep; i < 15; i++) {
      waveforms.lineTo(x, i % 2 == 0 ? 650 : 750);
      waveforms.lineTo(x, i % 2 == 0 ? 750 : 650);
      x += 100;
    }
    waveforms.stroke();
    waveforms.closePath();

    waveStep += 4;
    if (waveStep > 200) {
      waveStep = 0;
    }

    if(!s){var s=t}if(t-s<2000)window.requestAnimationFrame(step);
  }
  window.requestAnimationFrame(step);
});<commit_msg>Play tones when clicking buttons in webaudio basics blog<commit_after>ready(function() {
  var audio;
  if (AudioContext) {
    audio = new AudioContext;
  }
  else if (webkitAudioContext) {
    audio = new webkitAudioContext;
  }

  function playRawOsc(e) {
    e.preventDefault();

    if (audio) {
      var osc = audio.createOscillator();
      osc.connect(audio.destination);
      osc.start(audio.currentTime);
      osc.stop(audio.currentTime + 0.1);
    }
  }
  function playSawtooth(e) {
    e.preventDefault();

    if (audio) {
      var osc = audio.createOscillator();
      osc.type = 'sawtooth';
      osc.frequency.setValueAtTime(220, audio.currentTime);
      osc.connect(audio.destination);
      osc.start(audio.currentTime);
      osc.stop(audio.currentTime + 0.1);
    }
  }
  function playSofter(e) {
    e.preventDefault();

    if (audio) {
      var osc = audio.createOscillator();
      var gain = audio.createGain();
      gain.gain.setValueAtTime(0.1, audio.currentTime);

      osc.connect(gain);
      gain.connect(audio.destination);

      osc.start(audio.currentTime);
      osc.stop(audio.currentTime + 0.1);
    }
  }
  function playRamp(e) {
    e.preventDefault();

    if (audio) {
      var osc = audio.createOscillator();
      var gain = audio.createGain();

      gain.gain.setValueAtTime(0, audio.currentTime);
      gain.gain.linearRampToValueAtTime(0.1, audio.currentTime + 0.01);

      gain.gain.setValueAtTime(0.1, audio.currentTime + 0.99);
      gain.gain.linearRampToValueAtTime(0, audio.currentTime + 1);

      osc.connect(gain);
      gain.connect(audio.destination);

      osc.start(audio.currentTime);
      osc.stop(audio.currentTime + 0.1);
    }
  }

  document.getElementById('raw-osc').addEventListener('click', playRawOsc);
  document.getElementById('sawtooth').addEventListener('click', playSawtooth);
  document.getElementById('softer').addEventListener('click', playSofter);
  document.getElementById('ramp').addEventListener('click', playRamp);

  var waveStep = 0;

  function step(t) {
    var waveforms = document.getElementById('waveforms').getContext('2d');

    waveforms.clearRect(0, 0, 1200, 800);

    waveforms.lineWidth = 6;
    waveforms.strokeStyle = '#333';

    waveforms.beginPath();
    for (var i = 0, x = 0 - waveStep; i < 11; i++) {
      waveforms.moveTo(x, 100);
      waveforms.quadraticCurveTo(x + 50, i % 2 == 0 ? 50 : 150, x + 100, 100);
      x += 100;
    }
    waveforms.stroke();
    waveforms.closePath();

    waveforms.beginPath();
    waveforms.moveTo(-50 - waveStep, 250);
    waveforms.lineTo(50 - waveStep, 350);
    for (var i = 0, x = 150 - waveStep; i < 11; i++) {
      waveforms.lineTo(x, i % 2 == 0 ? 250 : 350);
      x += 100;
    }
    waveforms.stroke();
    waveforms.closePath();

    waveforms.beginPath();
    waveforms.moveTo(-50 - waveStep, 550);
    for (var i = 0, x = 150 - waveStep; i < 6; i++) {
      waveforms.lineTo(x, 450);
      waveforms.lineTo(x, 550);
      x += 200;
    }
    waveforms.stroke();
    waveforms.closePath();

    waveforms.beginPath();
    waveforms.moveTo(-50 - waveStep, 650);
    for (var i = 0, x = 50 - waveStep; i < 12; i++) {
      waveforms.lineTo(x, i % 2 == 0 ? 650 : 750);
      waveforms.lineTo(x, i % 2 == 0 ? 750 : 650);
      x += 100;
    }
    waveforms.stroke();
    waveforms.closePath();

    waveforms.fillStyle = '#333';
    waveforms.font = '64px Share Tech Mono';
    waveforms.textBaseline = 'middle';

    waveforms.clearRect(900, 0, 300, 800);
    waveforms.fillText('Sine', 915, 100);
    waveforms.fillText('Triangle', 915, 300);
    waveforms.fillText('Sawtooth', 915, 500);
    waveforms.fillText('Square', 915, 700);

    waveStep += 4;
    if (waveStep > 200) {
      waveStep = 0;
    }

    if(!s){var s=t}if(t-s<2000)window.requestAnimationFrame(step);
  }
  window.requestAnimationFrame(step);
});
{'fraction_non_alphanumeric': 0.15903949886897512, 'fraction_numerical': 0.05776927092396033, 'mean_word_length': 2.784068466096116, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '743716', 'n_tokens_mistral': 2294, 'n_tokens_neox': 1967, 'n_words': 414}