// ========================================================== // ========= / THE CODE COMPILED BY EMCC ENDS HERE ========== // ========================================================== asm$ = { malloc: function(type, size) { real_size=size*type.BYTES_PER_ELEMENT; pointer = Module._malloc(real_size); heap = new Uint8Array(Module.HEAPU8.buffer, pointer, real_size); return { asm$: true, ptr: heap.byteOffset, free: function() { Module._free(this.ptr); }, arr: new type(heap.buffer, heap.byteOffset, size), size: size }; }, cpy: function(dst, dst_offset, src, src_offset, size) { if(typeof dst.asm$!='undefined') dst=dst.arr; if(typeof src.asm$!='undefined') src=src.arr; for(var i=0;i rwithin"); for(var i=0;i this.buffer_size) { return new Float32Array(0); console.log("sdrjs.RationalResamplerFF: critical audio buffering error"); //This should not happen... /* console.log("RationalResamplerFF: splitting..."); //TODO: this branch has not been checked output_buffers=Array(); new_buffer_size=this.buffer_size/2; i=0; //process the input in chunks of new_buffer_size, and add the output product Float32Array-s to output_buffers. while((i++)*new_buffer_size<=input.length) { output_buffers.push(this._process_noheapcheck(input.subarray(i*new_buffer_size,(i+1)*new_buffer_size))); } //add up the sizes of the output_buffer-s. total_output_length=0; output_buffers.forEach(function(a){total_output_length+=a.length;}); //create one big buffer from concatenating the output_buffer-s output=new Float32Array(total_output_length); output_pos=0; output_buffers.forEach(function(a){ asm$.cpy(output,output_pos,a,0,a.length); output_pos+=a.length; }); return output;*/ } else return this._process_noheapcheck(input); }; this._process_noheapcheck=function(input) //if we are sure we have enough space in the buffers { asm$.cpy(this.input_buffer.arr,0,this.input_buffer.arr,this.remain_offset,this.remain); asm$.cpy(this.input_buffer.arr, this.remain, input, 0, input.length); var total_input_size=input.length+this.remain; d=rational_resampler_ff(this.input_buffer.ptr, this.output_buffer.ptr, total_input_size, this.interpolation, this.decimation, this.taps.ptr, this.taps_length, this.last_taps_delay); this.last_taps_delay=d.last_taps_delay; this.remain=total_input_size-d.input_processed; this.remain_offset=d.input_processed; var output_copy_arr=new Float32Array(d.output_size); asm$.cpy(output_copy_arr,0,this.output_buffer.arr,0,d.output_size); return output_copy_arr; }; }; _sdrjs_logb=function(what) { document.body.innerHTML+=what+"
"; } function test_firdes_lowpass_f_original() { //Original method explained over here: //http://kapadia.github.io/emscripten/2013/09/13/emscripten-pointers-and-pointers.html _sdrjs_logb("test_firdes_lowpass_f_original():"); _sdrjs_logb("Now designing FIR filter with firdes_lowpass_f in sdr.js..."); _sdrjs_logb("output should be the same as: csdr firdes_lowpass_f 0.1 101 HAMMING"); var outputSize = 101*4; var outputPtr = Module._malloc(outputSize); var outputHeap = new Uint8Array(Module.HEAPU8.buffer, outputPtr, outputSize); firdes_lowpass_f(outputHeap.byteOffset,101,0.1,2); var output = new Float32Array(outputHeap.buffer, outputHeap.byteOffset, 101); outputStr=String(); for(i=0;icsdr firdes_lowpass_f 0.1 101 HAMMING"); output=asm$.malloc(Float32Array,101); firdes_lowpass_f(output.ptr,101,0.1,2); outputStr=String(); for(i=0;i