-
1Step 1
Here is the optimised decoding algorithm in JavaScript.
function decode_3R(DEPTH, // Log2(sample number) stream) { // pointer to the array of sample var A=DEPTH-1, // stack pointer C=0, // loop counter R, // checksum register S=1<<DEPTH, // Shift register STACK=[], // no-init stack T=stream[0], // Temp. register flux_index=1, V; // input value R=T; // init function out_value(val) { R -= val; // insert your filter code here } do { while (true) { V = stream[flux_index++]; // read one input value if (S & 2) break; STACK[A--] = T-V; T = V; S = S >> 1; } out_value(V); out_value(T-V); A=1; // new stack pointer /* branch-prediction-friendly version if (C & 2) { A=2; if (C & 4) { A=3; if (C & 8) { A=4; if (C & 16) { A=5; */ while ( C & (1<<A) ) A++; /* } } } } */ T = STACK[A--]; S = C = C+2; } while (C < 1<<DEPTH); return R; // R=0 if the block is valid }
This code is very optimised yet very easy to tinker with and to port to other languages.
Other parts are missing, since they are application-dependent : the bitstream extraction and the filter/predictor must be carefully developed.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.