cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <div class="element">
  <canvas id="equalizer" width="400" height="400"></canvas>
</div>

<p class="view-collection"><span class="hint">&lt;hint&gt Must run over <a href="https://codepen.io/fleeting/pen/QGGMPb/" target="_blank">https</a>.</span><br />&bull; #codevember &bull; <a href="https://codepen.io/collection/nxZbMW/" target="_blank">View Collection</a> &bull;<br />
  <span>Handcrafted with <span class="love">♥</span> from Austin, TX by <a href="https://twitter.com/fleetingftw">James Fleeting</a></span></p>
            
          
!
            
              @use postcss-simple-vars;
@use postcss-media-minmax;
@use postcss-nested;

.element {
  margin: 0 auto;
  width: 500px;
  text-align: center;
}

body {
  background: radial-gradient(ellipse at center, #343436 0%,#1d1f20 100%);
  background: #000;
}

.view-collection {
  margin: 10px 0 35px;
  color: #fff;
  text-align: center;
  font-size: 15px;
  font-family: 'Montserrat', sans-serif;
  line-height: 1.6;
  
  span {
    font-size: 13px;
  }
  
  .hint {
    font-size: 11px;
    color: #d2d2d2;
  }
  
  .love {
    color: #cc0000;
  }
  
  a {
    color: #c90087;
    text-decoration: none;
    transition: all 0.7s;
    
    &:hover, &:focus {
      color: #fff;
    }
  }
}

            
          
!
            
              var canvas = document.getElementById('equalizer');

var chart_labels = [];
for (var i = 0; i < 64; i++) {
  chart_labels.push("");
}

/* Canvas Gradient */
var ctx = canvas.getContext('2d'),
gradient;
//gradient = ctx.createLinearGradient(0.000, 150.000, 300.000, 150.000); // horizontal
gradient = ctx.createLinearGradient(150.000, 300.000, 150.000, 0.000); //vertical

gradient.addColorStop(0.000, 'rgba(201, 8, 95, 1.000)');
gradient.addColorStop(0.100, 'rgba(153, 14, 133, 1.000)');
gradient.addColorStop(0.250, 'rgba(62, 39, 151, 1.000)');
gradient.addColorStop(0.375, 'rgba(62, 40, 138, 1.000)');
gradient.addColorStop(0.500, 'rgba(51, 166, 0, 1.000)');
gradient.addColorStop(0.625, 'rgba(220, 201, 4, 1.000)');
gradient.addColorStop(0.750, 'rgba(254, 143, 1, 1.000)');
gradient.addColorStop(0.875, 'rgba(254, 22, 2, 1.000)');
/* /Canvas Gradient */

var data = {
    labels: chart_labels,
    datasets: [
        {
            label: "Audio",
            backgroundColor: gradient,
            borderColor: '',
            borderWidth: 1,
            data: [],
        }
    ]
};

var equalizerChart = new Chart(canvas, {
    type: 'bar',
    data: data
});

// var data = {
//     datasets: [
//       {
//         data: [''],
//         backgroundColor: gradient,
//         label: '' // for legend
//       }
//     ],
//     labels: []
// };

// var equalizerChart = new Chart(canvas, {
//     type: 'polarArea',
//     data: data
// });

// set up audio context
var audioContext = (window.AudioContext || window.webkitAudioContext);
// create audio class
if (audioContext) {
  // Web Audio API is available.
  var audioAPI = new audioContext();
} else {
  // Web Audio API is not available. Ask the user to use a supported browser.
  alert("It appears your browser does not support the Web Audio API, please upgrade or use a different browser");
}

var analyserNode,
    frequencyData = new Uint8Array(64);    

// create an audio API analyser node and connect to source
function createAnalyserNode(audioSource) {
  analyserNode = audioAPI.createAnalyser();
  analyserNode.fftSize = 128;
  audioSource.connect(analyserNode);
}

// constantly picking up mic data
function animate() {
  requestAnimationFrame(animate);
  analyserNode.getByteFrequencyData(frequencyData);
  analyse();
}

// getUserMedia success callback -> pipe audio stream into audio API
var gotStream = function(stream) {
  // Create an audio input from the stream.
  var audioSource = audioAPI.createMediaStreamSource(stream);
  createAnalyserNode(audioSource);
  animate();
}

// pipe in analysing to getUserMedia
navigator.mediaDevices.getUserMedia({ audio: true, video: false })
  .then(gotStream);

function analyse() {
  //console.log('frequencyData', frequencyData);
  
  for (var i = 0; i < 64; i++) {
    equalizerChart.data.datasets[0].data[i] = frequencyData[i];
    equalizerChart.update();
  }
}
            
          
!
999px
Loading ..................

Console