-
Notifications
You must be signed in to change notification settings - Fork 11
/
audiobuffer-to-wav.js
8 lines (8 loc) · 1.46 KB
/
audiobuffer-to-wav.js
1
2
3
4
5
6
7
8
/**
* Minified by jsDelivr using UglifyJS v3.0.24.
* Original file: /npm/[email protected]/index.js
*
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
*/
function audioBufferToWav(t,e){e=e||{};var n,a=t.numberOfChannels,r=t.sampleRate,i=e.float32?3:1,o=3===i?32:16;return n=2===a?interleave(t.getChannelData(0),t.getChannelData(1)):t.getChannelData(0),encodeWAV(n,i,r,a,o)}function encodeWAV(t,e,n,a,r){var i=r/8,o=a*i,l=new ArrayBuffer(44+t.length*i),f=new DataView(l);return writeString(f,0,"RIFF"),f.setUint32(4,36+t.length*i,!0),writeString(f,8,"WAVE"),writeString(f,12,"fmt "),f.setUint32(16,16,!0),f.setUint16(20,e,!0),f.setUint16(22,a,!0),f.setUint32(24,n,!0),f.setUint32(28,n*o,!0),f.setUint16(32,o,!0),f.setUint16(34,r,!0),writeString(f,36,"data"),f.setUint32(40,t.length*i,!0),1===e?floatTo16BitPCM(f,44,t):writeFloat32(f,44,t),l}function interleave(t,e){for(var n=t.length+e.length,a=new Float32Array(n),r=0,i=0;r<n;)a[r++]=t[i],a[r++]=e[i],i++;return a}function writeFloat32(t,e,n){for(var a=0;a<n.length;a++,e+=4)t.setFloat32(e,n[a],!0)}function floatTo16BitPCM(t,e,n){for(var a=0;a<n.length;a++,e+=2){var r=Math.max(-1,Math.min(1,n[a]));t.setInt16(e,r<0?32768*r:32767*r,!0)}}function writeString(t,e,n){for(var a=0;a<n.length;a++)t.setUint8(e+a,n.charCodeAt(a))}window.audioBufferToWav=audioBufferToWav;
//# sourceMappingURL=/sm/93e42302c54e8ebce3612c47b9a1a0e1209826c23d37e027b86352cf51b1446f.map