JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://dks-portal.de/rc.min.js"></script>
Listen to the difference: <button id="o">Orginal</button><button id="m">Merged</button><br><br>
JavaScript
//Generate a continus sinus in 2 arrays
var buffer1 = [];
var buffer2 = [];
for(var i=0;i<16384;i++){
if(i < 8192)
buffer1.push(Math.sin(i/10));
else
buffer2.push(Math.sin(i/10));
}
//Encode and decode both arrays seperatly
var en = Codec.encode(buffer1);
var dec1 = Codec.decode(en);
var en = Codec.encode(buffer2);
var dec2 = Codec.decode(en);
//Merge the arrays to 1 output array
var merge = [];
for(var i in dec1)
merge.push(dec1[i]);
for(var i in dec2)
merge.push(dec2[i]);
//Generate one big array with the same data as in the two arrays above
var verg = [];
for(var i=0;i<16384;i++)
verg.push(Math.sin(i/10));
//encode and decode the array hole in one
var enV = Codec.encode(verg);
var decV = Codec.decode(enV);
//-----------------
//Down under is only for playing the 2 different arrays
//-------------------
var audioCtx = new window.AudioContext || new window.webkitAudioContext;
var audioBuffer = audioCtx.createBuffer(1, verg.length, 44100);
$("#o").click(function() {
var bufferData = audioBuffer.getChannelData(0);
bufferData.set(verg);
var source = audioCtx.createBufferSource();
source.buffer = audioBuffer;
source.connect(audioCtx.destination);
source.start();
});
$("#m").click(function() {
var audioBuffer = audioCtx.createBuffer(1, merge.length, 44100);
var bufferData = audioBuffer.getChannelData(0);
bufferData.set(merge);
var source = audioCtx.createBufferSource();
source.buffer = audioBuffer;
source.connect(audioCtx.destination);
source.start();
});