Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <p><small>Made by the <a href="https://addpipe.com">Pipe Recording Platform</a></small></p>
<div class="visualizer-container">
  <div id="visualizer"></div>
</div>
<button id="startButton">Start Analyzer</button>
              
            
!

CSS

              
                body {
  font-family: Arial, sans-serif;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
  background-color: #1a1a1a;
  color: #fff;
}

.visualizer-container {
  width: 90%;
  height: 300px;
  border: 1px solid #444;
  background-color: #000;
  overflow: hidden;
}

#visualizer {
  display: flex;
  align-items: end;
  height: 100%;
  width: 100%;
}

#visualizer div {
  width: 4px;
  background: linear-gradient(180deg, #ffeb3b, #4caf50);
  margin: 0 1px;
  transition: height 0.1s ease-in-out;
}

button {
  margin-top: 20px;
  padding: 10px 20px;
  background-color: #4caf50;
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  font-size: 16px;
}

button:hover {
  background-color: #45a049;
}

              
            
!

JS

              
                const fftSize = 512; // Determines the number of waves (frequency bins)
const visualizer = document.getElementById("visualizer");
const startButton = document.getElementById("startButton");

let audioContext, analyser, dataArray;

// Initialize the microphone input and analyzer
async function initAudioAnalyzer() {
  audioContext = new (window.AudioContext || window.webkitAudioContext)();
  analyser = audioContext.createAnalyser();
  analyser.fftSize = fftSize;

  const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
  const source = audioContext.createMediaStreamSource(stream);
  source.connect(analyser);

  dataArray = new Uint8Array(analyser.frequencyBinCount);
  createWaves();
  animate();
}

// Create visualizer bars based on the frequencyBinCount
function createWaves() {
  const numWaves = analyser.frequencyBinCount;
  for (let i = 0; i < numWaves; i++) {
    const bar = document.createElement("div");
    visualizer.appendChild(bar);
  }
}

// Animate the waves based on frequency data
function animate() {
  analyser.getByteFrequencyData(dataArray);

  const bars = visualizer.children;
  for (let i = 0; i < bars.length; i++) {
    const value = dataArray[i];
    bars[i].style.height = `${(value / 255) * 100}%`; // Scale height based on frequency data
  }

  requestAnimationFrame(animate);
}

startButton.addEventListener("click", async () => {
  if (!audioContext) {
    await initAudioAnalyzer();
  }
  audioContext.resume();
});

              
            
!
999px

Console