Last active
April 12, 2019 09:30
-
-
Save beyondlimits/9cff6c92e7e85f7b47fd55544cfd8a2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"/> | |
| <title>Sub-stereo test</title> | |
| </head> | |
| <body style="margin:0"> | |
| <audio id="audio" src="test.ogg" type="audio/ogg" controls="controls" autoplay="autoplay" style="width:100%"></audio> | |
| <table> | |
| <tr> | |
| <td> | |
| <label for="bass">bass</label> | |
| </td> | |
| <td> | |
| <input type="range" id="bass" min="0" max="2" step="any"> | |
| </td> | |
| </tr> | |
| <tr> | |
| <td> | |
| <label for="treble">treble</label> | |
| </td> | |
| <td> | |
| <input type="range" id="treble" min="0" max="2" step="any"> | |
| </td> | |
| </tr> | |
| <tr> | |
| <td> | |
| <label for="filter">bass/treble split</label> | |
| </td> | |
| <td> | |
| <input type="range" id="filter" min="0" max="1" step="any"> | |
| </td> | |
| </tr> | |
| <tr> | |
| <td> | |
| <label for="delay">LR delay in samples</label> | |
| </td> | |
| <td> | |
| <input type="range" id="delay" min="1" max="2000" step="any"> | |
| </td> | |
| </tr> | |
| </table> | |
| <script src="script.js" type="text/javascript"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| var TheWild = { | |
| audio: document.getElementById('audio'), | |
| filter: 0.05, | |
| delay: 200, | |
| bass: 1, | |
| treble: 1, | |
| }; | |
| !function(){ | |
| var context = new AudioContext; | |
| var source = context.createMediaElementSource(TheWild.audio); | |
| var script = context.createScriptProcessor(16384, 1, 2); | |
| var lastLow = 0; | |
| var lastHigh; | |
| var low = new Float32Array(16384); | |
| var high = new Float32Array(16384); | |
| var cursor = 0; | |
| script.addEventListener('audioprocess', function(e){ | |
| var input = e.inputBuffer.getChannelData(0); | |
| var left = e.outputBuffer.getChannelData(0); | |
| var right = e.outputBuffer.getChannelData(1); | |
| for (var i = 0, n = input.length; i < n; i++) { | |
| lastLow += TheWild.filter * (input[i] - lastLow); | |
| lastHigh = input[i] - lastLow; | |
| var delayed = (cursor - TheWild.delay) & 0x3FFF; | |
| left[i] = TheWild.bass * lastLow + TheWild.treble * high[delayed]; | |
| right[i] = TheWild.bass * low[delayed] + TheWild.treble * lastHigh; | |
| low[cursor] = lastLow; | |
| high[cursor] = lastHigh; | |
| cursor++; | |
| cursor &= 0x3FFF; | |
| } | |
| }); | |
| source.connect(script); | |
| script.connect(context.destination); | |
| /* | |
| document.body.style.background = '#000'; | |
| document.body.style.margin = 0; | |
| */ | |
| ['bass', 'treble', 'filter', 'delay'].forEach(function(param){ | |
| var slider = document.getElementById(param); | |
| slider.value = TheWild[param]; | |
| slider.addEventListener('input', function(e){ | |
| TheWild[param] = this.value; | |
| }); | |
| }); | |
| }(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment