git @ Cat's Eye Technologies Dipple / master javascript / moz-audio.html
master

Tree @master (Download .tar.gz)

moz-audio.html @masterraw · history · blame

<!DOCTYPE html>
<!--
SPDX-FileCopyrightText: Chris Pressey, the original author of this work, has dedicated it to the public domain.
For more information, please refer to <https://unlicense.org/>
SPDX-License-Identifier: Unlicense
-->
<head>
  <meta charset="utf-8">
  <title>Mozilla Audio Demo</title>
</head>
<body>

<h1>Mozilla Audio Demo</h1>

</body>
<script>
  var audio = new Audio();
  audio.mozSetup(1, 44100);
  var samples = 20000;
  var data = new Float32Array(samples);
  for (var i = 0; i < samples; i++) {
      var amplitude = 1.0 - (i / samples);
      //data[i] = (Math.random() * 2.0 * amplitude) - 1.0;
      data[i] = (Math.sin(i / 50) * 2.0 * amplitude) - 1.0;
  }
  var w = audio.mozWriteAudio(data);
  // if samples === 80000, this goes "35900 samples not written" for me
  if (w < samples) { alert((samples - w) + " samples not written"); }
</script>