Advertisement
Guest User

Simple Spectrum javascript WebGL

a guest
Mar 8th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <script type='text/javascript'>
  2. /*
  3. WebGLInject - Part of Simple Spectrum V2.1 by Sam Boyer.
  4. */
  5.  
  6. window.SimpleSpectrum = {};
  7.  
  8. window.AudioContext = (function(){
  9. var ACConsructor = window.AudioContext || window.webkitAudioContext; //keep a reference to the original function
  10.  
  11. //console.log('AudioContext Constructor overriden');
  12.  
  13. return function(){
  14. var ac = new ACConsructor();
  15.  
  16. //console.log('AudioContext constructed');
  17.  
  18. window.SimpleSpectrum.ac = ac;
  19.  
  20. window.SimpleSpectrum.a = ac.createAnalyser();
  21. window.SimpleSpectrum.a.smoothingTimeConstant = 0;
  22.  
  23. window.SimpleSpectrum.fa = new Uint8Array(window.SimpleSpectrum.a.frequencyBinCount); //frequency array, size of frequencyBinCount
  24.  
  25. window.SimpleSpectrum.la = new Uint8Array(window.SimpleSpectrum.a.fftSize); //loudness array, size of fftSize
  26.  
  27. window.SimpleSpectrum.a.connect(ac.destination); //connect the AnalyserNode to the AudioContext's destination.
  28.  
  29. ac.actualDestination = ac.destination; //keep a reference to the destination.
  30.  
  31. Object.defineProperty(ac, 'destination', { //replace ac.destination with our AnalyserNode.
  32. value: window.SimpleSpectrum.a,
  33. writable: false
  34. });
  35.  
  36. return ac; //send our modified AudioContext back to Unity.
  37. }
  38. })();
  39. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement