| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html> |
| <!-- |
| Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| <head> |
| <title>Sine Wave Synthesizer</title> |
| <script type="text/javascript"> |
| sineSynth = null; // Global application object. |
| |
| // Indicate success when the NaCl module has loaded. |
| function moduleDidLoad() { |
| sineSynth = document.getElementById('sineSynth'); |
| document.getElementById('frequency_field').value = 440; |
| } |
| |
| // Handle a message coming from the NaCl module. The message payload |
| // contains the frequency value. Update the frequency field with this |
| // value. |
| function handleMessage(message_event) { |
| document.getElementById('frequency_field').value = message_event.data; |
| } |
| |
| function toggleSound(flag) { |
| sineSynth.postMessage('setFrequency:' + |
| document.getElementById('frequency_field').value); |
| if (flag) { |
| sineSynth.postMessage('playSound'); |
| } else { |
| sineSynth.postMessage('stopSound'); |
| } |
| } |
| |
| function changeFrequency(freq) { |
| sineSynth.postMessage('setFrequency:' + freq); |
| } |
| </script> |
| </head> |
| |
| <body id="bodyId"> |
| <h1>Sine Wave Synthesizer</h1> |
| <p>Click the button to start and stop the sine wave playing.</p> |
| <button onclick="toggleSound(true)">Play</button> |
| <button onclick="toggleSound(false)">Stop</button> |
| <p>Enter the frequency of the sine wave:</p> |
| <input type="text" size="15" id="frequency_field" |
| value="#undef" onchange="changeFrequency(this.value)" /> |
| <!-- Load the published .nexe. This includes the 'src' attribute which |
| shows how to load multi-architecture modules. Each entry in the "nexes" |
| object in the .nmf manifest file is a key-value pair: the key is the runtime |
| ('x86-32', 'x86-64', etc.); the value is a URL for the desired NaCl module. |
| To load the debug versions of your .nexes, set the 'src' attribute to the |
| _dbg.nmf version of the manifest file. |
| |
| Note: The <EMBED> element is wrapped inside a <DIV>, which has both a 'load' |
| and a 'message' event listener attached. This wrapping method is used |
| instead of attaching the event listeners directly to the <EMBED> element to |
| ensure that the listeners are active before the NaCl module 'load' event |
| fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or |
| pp::Instance.PostMessage() (in C++) from within the initialization code in |
| your NaCl module. |
| --> |
| <div id="listener"> |
| <script type="text/javascript"> |
| var listener = document.getElementById('listener') |
| listener.addEventListener('load', moduleDidLoad, true); |
| listener.addEventListener('message', handleMessage, true); |
| </script> |
| |
| <embed name="nacl_module" |
| id="sineSynth" |
| width=0 height=0 |
| src="sine_synth.nmf" |
| type="application/x-nacl" /> |
| </div> |
| </body> |
| </html> |