<commit_before><!doctype html>
<!--
Copyright 2018 The Immersive Web Community Group

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<html>
  <head>
    <meta charset='utf-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1, user-scalable=no'>
    <meta name='mobile-web-app-capable' content='yes'>
    <meta name='apple-mobile-web-app-capable' content='yes'>

    <!-- Origin Trial Token, feature = WebXR Device API, origin = https://immersive-web.github.io, expires = 2018-07-25 -->
<meta http-equiv="origin-trial" data-feature="WebXR Device API" data-expires="2018-07-25" content="<KEY>>

    <title>Positional Audio</title>

    <link href='css/common.css' rel='stylesheet'></link>

    <!--The polyfill is not needed for browser that have native API support,
        but is linked by these samples for wider compatibility.-->
    <!--script src='https://cdn.jsdelivr.net/npm/webxr-polyfill@latest/build/webxr-polyfill.js'></script-->
    <script src='js/webxr-polyfill.js'></script>

    <!--This script patches up around implementation differences in past browser versions
        so that the samples can always be written against the most recent spec changes.
        It won't be necessary after the API has been officially shipped for a bit.-->
    <script src='js/webxr-version-shim.js'></script>

    <script src="https://cdn.jsdelivr.net/npm/resonance-audio/build/resonance-audio.min.js"></script>

    <script src='js/cottontail/build/cottontail.debug.js'></script>

    <script src='js/third-party/wglu-url.js'></script>
    <script src='js/webxr-button.js'></script>
  </head>
  <body>
    <header>
      <details open>
        <summary>Positional Audio</summary>
        <p>
          This sample demonstrates playing audio that sounds as if it originates
          at a specific point in the space. Audio will begin playing when you
          enter XR.
          <a class="back" href="./">Back</a>
        </p>
      </details>
    </header>
    <script>
      (function () {
      'use strict';

      // If requested, initialize the WebXR polyfill
      if (QueryArgs.getBool('allowPolyfill', false)) {
        var polyfill = new WebXRPolyfill();
      }
      // Apply the version shim after the polyfill is instantiated, to ensure
      // that the polyfill also gets patched if necessary.
      var versionShim = new WebXRVersionShim();

      // Temporary
      let hideStats = QueryArgs.getBool('hideStats', false);

      const DEFAULT_HEIGHT = 1.5;
      const ANALYSER_FFT_SIZE = 1024;

      // XR globals.
      let xrButton = null;
      let xrImmersiveFrameOfRef = null;
      let xrNonImmersiveFrameOfRef = null;

      // WebGL scene globals.
      let gl = null;
      let renderer = null;
      let scene = new Scene();
      if (hideStats) {
        scene.enableStats(false);
      }
      scene.addNode(new Gltf2Node({url: 'media/gltf/garage/garage.gltf'}));
      scene.standingStats(true);

      let playButton = null;
      let playTexture = new UrlTexture('media/textures/play-button.png');
      let pauseTexture = new UrlTexture('media/textures/pause-button.png');
      let stereo = new Gltf2Node({url: 'media/gltf/stereo/stereo.gltf'});
      // FIXME: Temporary fix to initialize for cloning.
      stereo.visible = false;
      scene.addNode(stereo);

      // Audio scene globals
      let audioContext = new AudioContext();
      let resonance = new ResonanceAudio(audioContext);
      resonance.output.connect(audioContext.destination);

      audioContext.suspend();

      // Rough room dimensions in meters (estimated from model in Blender.)
      let roomDimensions = {
        width : 6,
        height : 3,
        depth : 6
      };

      // Simplified view of the materials that make up the scene.
      let roomMaterials = {
        left : 'plywood-panel', // Garage walls
        right : 'plywood-panel',
        front : 'plywood-panel',
        back : 'metal', // To account for the garage door
        down : 'polished-concrete-or-tile', // garage floor
        up : 'wood-ceiling'
      };
      resonance.setRoomProperties(roomDimensions, roomMaterials);

      function createAudioSource(options) {
        // Create a Resonance source and set its position in space.
        let source = resonance.createSource();
        let pos = options.position;
        source.setPosition(pos[0], pos[1], pos[2]);

        // Connect an analyser. This is only for visualization of the audio, and
        // in most cases you won't want it.
        let analyser = audioContext.createAnalyser();
        analyser.fftSize = ANALYSER_FFT_SIZE;
        analyser.lastRMSdB = 0;

        return fetch(options.url)
          .then((response) => response.arrayBuffer())
          .then((buffer) => audioContext.decodeAudioData(buffer))
          .then((decodedBuffer) => {
            let bufferSource = createBufferSource(<commit_msg>Fixed audio sample not starting up properly.<commit_after><!doctype html>
<!--
Copyright 2018 The Immersive Web Community Group

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<html>
  <head>
    <meta charset='utf-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1, user-scalable=no'>
    <meta name='mobile-web-app-capable' content='yes'>
    <meta name='apple-mobile-web-app-capable' content='yes'>

    <!-- Origin Trial Token, feature = WebXR Device API, origin = https://immersive-web.github.io, expires = 2018-07-25 -->
<meta http-equiv="origin-trial" data-feature="WebXR Device API" data-expires="2018-07-25" content="AiOtRLgiXauzJY1CytLC<KEY>>

    <title>Positional Audio</title>

    <link href='css/common.css' rel='stylesheet'></link>

    <!--The polyfill is not needed for browser that have native API support,
        but is linked by these samples for wider compatibility.-->
    <!--script src='https://cdn.jsdelivr.net/npm/webxr-polyfill@latest/build/webxr-polyfill.js'></script-->
    <script src='js/webxr-polyfill.js'></script>

    <!--This script patches up around implementation differences in past browser versions
        so that the samples can always be written against the most recent spec changes.
        It won't be necessary after the API has been officially shipped for a bit.-->
    <script src='js/webxr-version-shim.js'></script>

    <script src="https://cdn.jsdelivr.net/npm/resonance-audio/build/resonance-audio.min.js"></script>

    <script src='js/cottontail/build/cottontail.debug.js'></script>

    <script src='js/webxr-button.js'></script>
  </head>
  <body>
    <header>
      <details open>
        <summary>Positional Audio</summary>
        <p>
          This sample demonstrates playing audio that sounds as if it originates
          at a specific point in the space. Audio will begin playing when you
          enter XR.
          <a class="back" href="./">Back</a>
        </p>
      </details>
    </header>
    <script>
      (function () {
      'use strict';

      // If requested, initialize the WebXR polyfill
      if (QueryArgs.getBool('allowPolyfill', false)) {
        var polyfill = new WebXRPolyfill();
      }
      // Apply the version shim after the polyfill is instantiated, to ensure
      // that the polyfill also gets patched if necessary.
      var versionShim = new WebXRVersionShim();

      // Temporary
      let hideStats = QueryArgs.getBool('hideStats', false);

      const DEFAULT_HEIGHT = 1.5;
      const ANALYSER_FFT_SIZE = 1024;

      // XR globals.
      let xrButton = null;
      let xrImmersiveFrameOfRef = null;
      let xrNonImmersiveFrameOfRef = null;

      // WebGL scene globals.
      let gl = null;
      let renderer = null;
      let scene = new Scene();
      if (hideStats) {
        scene.enableStats(false);
      }
      scene.addNode(new Gltf2Node({url: 'media/gltf/garage/garage.gltf'}));
      scene.standingStats(true);

      let playButton = null;
      let playTexture = new UrlTexture('media/textures/play-button.png');
      let pauseTexture = new UrlTexture('media/textures/pause-button.png');
      let stereo = new Gltf2Node({url: 'media/gltf/stereo/stereo.gltf'});
      // FIXME: Temporary fix to initialize for cloning.
      stereo.visible = false;
      scene.addNode(stereo);

      // Audio scene globals
      let audioContext = new AudioContext();
      let resonance = new ResonanceAudio(audioContext);
      resonance.output.connect(audioContext.destination);

      audioContext.suspend();

      // TODO: This is crashing in recent versions of Resonance for me, and I'm
      // not sure why. It does run succesfully without it, though.
      // Rough room dimensions in meters (estimated from model in Blender.)
      /*let roomDimensions = {
        width : 6,
        height : 3,
        depth : 6
      };

      // Simplified view of the materials that make up the scene.
      let roomMaterials = {
        left : 'plywood-panel', // Garage walls
        right : 'plywood-panel',
        front : 'plywood-panel',
        back : 'metal', // To account for the garage door
        down : 'polished-concrete-or-tile', // garage floor
        up : 'wood-ceiling'
      };
      resonance.setRoomProperties(roomDimensions, roomMaterials);*/

      function createAudioSource(options) {
        // Create a Resonance source and set its position in space.
        let source = resonance.createSource();
        let pos = options.position;
        source.setPosition(pos[0], pos[1], pos[2]);

        // Connect an analyser. This is only for visualization of the audio, and
        // in most cases you won't want it.
        let analyser = audioContext.createAnalyser();
        analyser.fftSize = ANALYSER_FFT_SIZE;
        analyser.lastRMSdB = 0;

        return fetch(options.url)
          .then((response) => response.arrayBuffer())
          .then((buffer) => audioContext.decodeAudioData(buffer))
          .then((decodedBuffer) => {
            let bufferSource = createBufferSource(
{'fraction_non_alphanumeric': 0.1049273902459498, 'fraction_numerical': 0.006295643414756988, 'mean_word_length': 2.889650669278485, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 95, 'https://': 6, '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': '7620707', 'n_tokens_mistral': 3486, 'n_tokens_neox': 3304, 'n_words': 1136}