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.

            
              <!-- 
  MADE FROM THE WONDERFUL CODE OF Chris Wilson
  https://webaudiodemos.appspot.com/volume-meter/
-->
<svg viewBox="0 0 101 33" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="1.5">
  <path id="path" d="M.5 14.761 c1.244 0 1.236 3.9 1.996 3.9.761 0 1.205-6.017 1.967-6.017.763 0 1.153 8.252 2.272 8.294 1.12.042 1.298-10.767 2.382-10.767 1.083 0 1.062 14.022 2.224 14.022 1.163 0 1.424-17.596 2.367-17.596.944 0 1.132 21.22 2.256 21.22 1.124 0 1.176-24.517 2.259-24.517 1.084 0 1.186 27.425 2.25 27.425 1.063 0 1.433-29.361 2.477-29.361 1.043 0 1.317 30.886 2.28 30.886.963 0 1.239-31.75 2.403-31.75s.996 30.953 2.159 30.953c1.162 0 1.077-29.34 2.401-29.34 1.324 0 .88 27.364 2.044 27.364 1.163 0 1.3-24.585 2.299-24.585.998 0 1.453 21.328 2.376 21.328.923 0 1.559-17.764 2.33-17.752.879.013.831 13.885 2.356 13.885s1.719-10.559 2.842-10.559c1.124 0 1.985 10.441 2.865 10.441.881 0 .579-10.471 1.903-10.471s.657 5.961 1.941 5.961 1.053-5.902 2.012-5.903c.98-.002.458 10.434 1.622 10.434 1.163 0 1.625-13.753 2.782-13.728 1.14.023 1.06 17.714 2.344 17.714 1.284 0 1.088-21.383 2.292-21.383 1.204 0 1.263 24.575 2.266 24.575 1.004 0 1.124-27.442 2.124-27.442.999 0 1.425 29.572 2.504 29.572 1.08 0 1.033-30.967 2.157-30.967 1.123 0 1.082 31.608 2.375 31.608 1.292 0 1.23-30.783 2.22-30.783.991 0 1.214 29.195 2.516 29.195 1.303 0 1.137-27.284 2.233-27.295 1.094-.012 1.045 24.406 2.289 24.406 1.244 0 1.146-21.129 2.229-21.129 1.084 0 .945 17.469 2.361 17.719 1.415.251 1.085-14.159 2.183-14.159 1.098 0 1.369 10.961 2.453 10.961 1.083 0 1.18-8.521 2.146-8.498.963.022 1.302 6.084 2.195 6.084.892 0 .228-4.225 2.048-4.225" fill="none" stroke="#fefefe" stroke-width="1px"/>
</svg>


            
          
!
            
              * {
  margin: 0;
  transition: all -1s;
}
svg {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translateY(-50%);
}
body {
  background: #0B0F10;
}

#id {
  height: 100px;
  background: blue;
}
            
          
!
            
              var audioContext = null;
var meter = null;
var rafID = null;

window.onload = function() {
    // monkeypatch Web Audio
    window.AudioContext = window.AudioContext || window.webkitAudioContext;
	
    // grab an audio context
    audioContext = new AudioContext();

    // Attempt to get audio input
    try {
        // monkeypatch getUserMedia
        navigator.getUserMedia = 
        	navigator.getUserMedia ||
        	navigator.webkitGetUserMedia ||
        	navigator.mozGetUserMedia;

        // ask for an audio input
        navigator.getUserMedia(
        {
            "audio": {
                "mandatory": {
                    "googEchoCancellation": "false",
                    "googAutoGainControl": "false",
                    "googNoiseSuppression": "false",
                    "googHighpassFilter": "false"
                },
                "optional": []
            },
        }, gotStream, didntGetStream);
    } catch (e) {
        alert('getUserMedia threw exception :' + e);
    }

}

function didntGetStream() {
    alert('Stream generation failed.');
}

var mediaStreamSource = null;

function gotStream(stream) {
  audioContext.resume();
    // Create an AudioNode from the stream.
    mediaStreamSource = audioContext.createMediaStreamSource(stream);

    // Create a new volume meter and connect it.
    meter = createAudioMeter(audioContext, .7);
    mediaStreamSource.connect(meter);

    // kick off the visual updating
    drawSVG();
}

function drawSVG( time ) {
  var body = document.getElementsByTagName("body")[0];
  var path = document.getElementById("path");
  
  // set the stroke-width of the SVG in relation to the volume
  path.setAttribute("stroke-width", meter.volume*10 + "px"); 
  
  // if the audio is clipping change the background color
  if (meter.checkClipping()) {
    //use milliseconds to get a modulator
    var modulator = (360/999)*((new Date()).getMilliseconds());
    body.style.background = "hsl("+modulator+", 100%, 50%)";
  } else {
    body.style.background = "#0B0F10";
  }
  window.requestAnimationFrame( drawSVG );
}

// FIX FOR CHROME
// https://github.com/processing/p5.js-sound/issues/249#issuecomment-386657799
var restart = function () {
  if (audioContext.state !== 'running') {
    audioContext.resume();
  }
}
            
          
!
999px
🕑 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.

Console