Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <p>This is a web audio test and a proof of concept of a binaural beats generator.  Needs to be listen to through headphones.</p>

  Carrier Frequency: <span id="carrierLabel">250</span><br>
  <input class="slider" id="carrier" type="range" value="250" min="100" max="1000" step="1" oninput="handleCarrierChange(value)" />
  Binaural Beat Frequency: <span id="beatLabel">10</span><br>
  <input class="slider" id="beat" type="range" value="10" min="0" max="40" step="1" oninput="handleBeatChange(value)" />
  Volume: <span id="volumeLabel">50</span><br>
  <input class="slider" id="beat" type="range" value="50" min="0" max="100" step="1" oninput="handleVolumeChange(value)" />

  <button name="toggleButton" onclick="toggleSound()">Start / Stop</button>

<p>If you don't know what a binaural beat is <a href="">check out my article</a> or this <a href="">wiki article</a>.</p>
              input.slider {
  width: 300px;

label {
	font-size: 13px;
	width: 110px;
              var carrier_freq = 250;
var beat_freq = 10;
var isPlaying = false;
var left_osc, right_osc;
var volume = .5;
var AudioContext = window.AudioContext || window.webkitAudioContext;

var cntx = new AudioContext();

var merger = cntx.createChannelMerger(2);

var volumeNode = cntx.createGain();
volumeNode.gain.value = volume;


function toggleSound() {
  if (isPlaying) {
    isPlaying = false;
  } else {
    //the oscillators are created here because once they are stopped they can not 
    //be started again.
    left_osc = cntx.createOscillator();
    right_osc = cntx.createOscillator();
    right_osc.connect(merger, 0, 0);
    left_osc.connect(merger, 0, 1);
    isPlaying = true;

function setFreqs() {
   if (typeof right_osc != "undefined") {
     right_osc.frequency.value = carrier_freq;
     left_osc.frequency.value = carrier_freq + beat_freq;

function handleVolumeChange(val) {
  var element = document.getElementById("volumeLabel");
  element.innerHTML = val;
  volume = Number(val)/100;
  volumeNode.gain.value = volume;

function handleCarrierChange(val) {
  var element = document.getElementById("carrierLabel");
  element.innerHTML = val;
  carrier_freq = Number(val);

function handleBeatChange(val) {
  var element = document.getElementById("beatLabel");
  element.innerHTML = val;
  beat_freq = Number(val);
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.