You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should rename RadwareSigcompress to RadwareSigcompress16 (or similar) and implement the 32-bit version, to compress presummed waveforms.
Here's the 32-bit version of the original C code from @radforddc (with more comments, to be added to our data format specs docs):
intcompress_signal_32(int*sig_in, unsigned int*sig_out, intsig_len_in) {
/* 32-bit version of compress_signal() for waveforms that are int32 values Assume ADC is actually a maximum of 20 bits, i.e. signed values between 0x7FFFF = 524287 and 0xfff8000 = -524288 returned value = iso = number of ints stored in output stream *sig_out *sig_in = input waveform (uncompressed) of length sig_len_in samples *sig_out = output waveform (compressed) of length iso */inti, j, max1, max2, min1, min2, ds, nb1, nb2;
intiso, nw, bp, dd1, dd2;
unsigned intdb[2];
unsigned long*dd= (unsigned long*) db;
staticunsigned shortmask[21] = {0, 1,3,7,15, 31,63,127,255,
511,1023,2047,4095, 8191,16383,32767,65535,
0x1ffff, 0x3ffff, 0x7ffff, 0xfffff};
//static int len[17] = {4096, 2048,512,256,128, 128,128,128,128,// 128,128,128,128, 48,48,48,48};/* ------------ do compression of signal ------------ */j=iso=bp=0;
sig_out[iso++] =sig_len_in; // signal lengthwhile (j<sig_len_in) { // j = starting index of section of signal to be compressed// find optimal method and length for compression of next section of signal max1=min1=sig_in[j];
max2=-0x100000;
min2=0xfffff; // initialize to min and max expected valuesnb1=nb2=2; // number of bits needed for encoding each samplenw=1; // number of samples to encode in this segmentfor (i=j+1; i<sig_len_in&&i<j+48; i++) { // FIXME; # 48 could be tuned better?if (max1<sig_in[i]) max1=sig_in[i]; // max and min of first 48 absolute valuesif (min1>sig_in[i]) min1=sig_in[i];
ds=sig_in[i] -sig_in[i-1];
if (max2<ds) max2=ds; // max and min of first 48 difference valuesif (min2>ds) min2=ds;
nw++;
}
if (max1-min1 <= max2-min2) { // use absolute ADC valuesnb2=99;
while (max1-min1>mask[nb1]) nb1++; // updated number of bits needed for encoding each sample//for (; i < sig_len_in && i < j+len[nb1]; i++) {for (; i<sig_len_in&&i<j+128; i++) { // FIXME; # 128 could be tuned better?if (max1<sig_in[i]) max1=sig_in[i];
dd1=max1-min1;
if (min1>sig_in[i]) dd1=max1-sig_in[i]; // updated range of values to encodeif (dd1>mask[nb1]) break; // uh-oh, would need to add another bit for encodingif (min1>sig_in[i]) min1=sig_in[i];
nw++; // updated number of samples to encode in this segment
}
} else { // use differences/derivative of ADC valuesnb1=99;
while (max2-min2>mask[nb2]) nb2++; // updated number of bits needed for encoding each sample//for (; i < sig_len_in && i < j+len[nb1]; i++) {for (; i<sig_len_in&&i<j+128; i++) { // FIXME; # 128 could be tuned better?ds=sig_in[i] -sig_in[i-1];
if (max2<ds) max2=ds;
dd2=max2-min2;
if (min2>ds) dd2=max2-ds; // updated range of values to encodeif (dd2>mask[nb2]) break; // uh-oh, would need to add another bit for encodingif (min2>ds) min2=ds;
nw++; // updated number of samples to encode in this segment
}
}
if (bp>0) iso++; // increment iso if we have a partial short already used in the oputput stream/* ----- do actual compression ----- */sig_out[iso++] =nw; // compressed signal data, first byte = # samplesbp=0; // bit pointer into output streamif (nb1 <= nb2) {
/* ----- encode absolute values ----- */sig_out[iso++] =nb1; // # bits used for encodingsig_out[iso++] = (unsigned short) min1; // min value used for encodingfor (i=iso; i <= iso+nw*nb1/16; i++) sig_out[i] =0; // initialze output stream to 0for (i=j; i<j+nw; i++) {
dd[0] =sig_in[i] -min1; // value to encodedd[0] =dd[0] << (32-bp-nb1); // pack nb1 bitssig_out[iso] |= db[1];
bp+=nb1;
while (bp>31) {
sig_out[++iso] =db[0];
bp-=32;
}
}
} else {
/* ----- encode derivative / difference values ----- */sig_out[iso++] =nb2+32; // # bits used for encoding, plus flag indicating derivativessig_out[iso++] = (unsigned short) sig_in[j]; // starting signal valuesig_out[iso++] = (unsigned short) min2; // min value used for encodingfor (i=iso; i <= iso+nw*nb2/16; i++) sig_out[i] =0; // initialze output stream to 0for (i=j+1; i<j+nw; i++) {
dd[0] =sig_in[i] -sig_in[i-1] -min2; // value to encodedd[0]=dd[0] << (32-bp-nb2); // pack nb2 bitssig_out[iso] |= db[1];
bp+=nb2;
while (bp>31) {
sig_out[++iso] =db[0];
bp-=32;
}
}
}
j+=nw;
}
if (bp>0) iso++; // increment iso if we have a partial short left over in the oputput streamif (iso%2) iso++; // make sure iso is even for 4-byte paddingreturniso; // return number of shorts in compressed signal data
}
The text was updated successfully, but these errors were encountered:
We should rename
RadwareSigcompress
toRadwareSigcompress16
(or similar) and implement the 32-bit version, to compress presummed waveforms.Here's the 32-bit version of the original C code from @radforddc (with more comments, to be added to our data format specs docs):
The text was updated successfully, but these errors were encountered: