Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

Behavior

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

Template

Make Template?

Templates are Pens that can be used to start other Pens. You can view all of your templates, or learn more in the documentation.

Screenshot

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

Uploading

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

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.

HTML

            
              <svg>
  <polyline id="scope" points="0,0,1024,1"/>
</svg>

<div class="sliders">
  <input type="range" id="folding" min="0" max="8" step="0.0001" value="0">
</div>
            
          
!

CSS

            
              body{
    margin:0;
    background-color:black;
}
html,body,svg{
    width:100%;
    height:100%;
}
polyline{
    stroke-width:1px;
    stroke:lime;
    fill:none;
}
.sliders{
  position:absolute;
  top:50%;
  background-color:rgba(124,142,112,0.25);
  width:100%;
}
input[type="range"]{
  width:100%;
}
            
          
!

JS

            
              // polyfill
// window.AudioContext = window.AudioContext || window.webkitAudioContext;

//// create a sound studio
var studio = new AudioContext();
var speakers = studio.destination;

//// pick sound modules

///Volume
var volume = studio.createGain();

/// oscillator
var waveA = studio.createOscillator();
waveA.type = 'sine';
waveA.frequency.value = 55;
waveA.start(0);

// variable wave shape
var resolution = 100;
var real = new Float32Array(resolution);
var imag = new Float32Array(resolution);

var shapes = [
  {
    name:"sine",
    imag:Array.apply(0,Array(resolution)).map(function(callback,n){ return (n === 1) ? 1 : 0; })
  },
  {
    name:"triangle",
    imag:Array.apply(0,Array(resolution)).map(function(callback,n){ return ((n % 4 === 1) ? 1 : -0.5) / (n * n); })
  },
  {
    name:"ramp",
    imag:Array.apply(0,Array(resolution)).map(function(callback,n){ return 1/n; })
  },
  {
    name:"square",
    imag:Array.apply(0,Array(resolution)).map(function(callback,n){ return (((n + 1) % 2) ? 0 : 1) / n; })
  },
  {
    name:"pulse",
    imag:Array.apply(0,Array(resolution)).map(function(){ return 0.01; })
  }
];

/// wave folding filter
var folding = 0;
var waveFolder = studio.createScriptProcessor(4096,1,1);
waveFolder.onaudioprocess = function(event) {
  
  for (var channel = 0; channel < event.outputBuffer.numberOfChannels; channel++) {
    var inputData = event.inputBuffer.getChannelData(channel);
    var outputData = event.outputBuffer.getChannelData(channel);

    for(var sample = 0; sample < event.inputBuffer.length; sample++){
      var foldedOut = (1 + folding) * inputData[sample];
      while(foldedOut < -1 || foldedOut > 1){
          if(foldedOut > 1){
            foldedOut = 1 - foldedOut + 1;
          }
          if(foldedOut < -1){
            foldedOut = -1 - foldedOut - 1;
          }
       }

      outputData[sample] = foldedOut;
    }
  }
}

/// oscilloscope
var analyser = studio.createAnalyser();
analyser.fftSize = 2048;
var bufferLength = analyser.fftSize;
var dataArray = new Uint8Array(bufferLength);
analyser.getByteTimeDomainData(dataArray);
var i;
var scope = document.getElementById('scope');
var sliceWidth = window.innerWidth / bufferLength * 2.0;

function draw() {
  analyser.getByteTimeDomainData(dataArray);
  var points = [];
  var x = 0;
  var firstZero;
  for (i = 1; i < bufferLength; i++) {
    var y = dataArray[i] / 128 * window.innerHeight / 2;
    if (firstZero !== undefined) {
      points.push(x, y);
      x += sliceWidth;
    }
    if ((dataArray[i] >= 128 && dataArray[i - 1] < 128) ||
      (dataArray[i] <= 128 && dataArray[i - 1] > 128)) {
      if (firstZero === undefined && (dataArray[i] >= 128 && dataArray[i - 1] < 128))
        firstZero = i;
    }
  }
  mousey = false;
  scope.setAttributeNS(null, 'points', points.join(','));

  requestAnimationFrame(draw); //loop
}
draw(); //start loop

// wires
waveA.connect(waveFolder);
waveFolder.connect(volume);
volume.connect(speakers);
waveFolder.connect(analyser);

// controllers
var controllerX = 0.5;
var controllerY = 0.5;
document.addEventListener('mousemove', function(event) {
  
  // normalize X and multiply by count - 1
  controllerX = event.clientX/window.innerWidth * (shapes.length - 1);

  var from = Math.floor(controllerX);
  var to = Math.ceil(controllerX);

  // use each whole number in controllerX as a section
  lerp = controllerX % 1;
 
  imag = imag.map(function(callback,n){ return (1-lerp) * shapes[from].imag[n] + lerp * shapes[to].imag[n]; });
  waveform = studio.createPeriodicWave(real, imag);
  waveA.setPeriodicWave(waveform);

  //set pitch
  controllerY = 1 - event.clientY / window.innerHeight;
  var pitch = 40 * controllerY + 35;
  waveA.frequency.setTargetAtTime(pitch, studio.currentTime + 0.07, 0.1);

});

document.getElementById('folding').addEventListener('input', function(event){
  // set folding
  folding = parseFloat(this.value);
  console.log('folding',folding);
});

            
          
!
999px

Console