function worker_function() {
    // all code here
    onmessage = function(e) {
        //console.log(e.data);
        var sourceBuffer = e.data.sourceBuffer;
        var sampling = e.data.sampling;
        var sampleRate = e.data.sampleRate / sampling;

        //console.log("received sourceBuffer with bytes: " + sourceBuffer.byteLength);
        //console.log("received sampling : " + sampling);
        //console.log("received sampleRate : " + e.data.sampleRate);

        var sourceChannelLength = Math.floor(sourceBuffer.byteLength / Float32Array.BYTES_PER_ELEMENT);
        //var sourceChannel = new Float32Array(sourceBuffer, 0, sourceChannelLength);
        var sourceChannel = new Float32Array(sourceBuffer);
        //var myArrayBuffer = self.audioCtx.createBuffer(numCh, bufferLength, sampleRate);
        var targetChannelLength = Math.floor(sourceChannelLength / sampling) + 1;
        var targetBuffer = new ArrayBuffer(targetChannelLength * Float32Array.BYTES_PER_ELEMENT);
        //var targetChannel = new Float32Array(targetBuffer, 0, targetChannelLength);
        var targetChannel = new Float32Array(targetBuffer);
        var j = 0;
        for (var i = 0; i < sourceChannel.length; i += sampling) {
            targetChannel[j] = sourceChannel[i];
            j++;
        }
        postMessage(targetBuffer);
        console.log('Posting message back to main script');
    }
}
// This is in case of normal worker start
// "window" is not defined in web worker
// so if you load this file directly using `new Worker`
// the worker code will still execute properly
if(window!=self)
  worker_function();



