📄 steim.c
字号:
FILE *fp;int *p_seed_data_records;DATA_HEADER * p_fsdh ;LONG wk ;LONG ck ;DATA_STATE * ds ;{ ds->w0 |= ck << ( 2 * ( 15 - ds->seed_index ) ) ; p_seed_data_records[ds->record_offset+(ds->seed_frame*16)+ds->seed_index] = wk ; ds->seed_index++; if (ds->seed_index > 15) { /*-----------------------------------------------------------*\ Finish a frame ... \*-----------------------------------------------------------*/ p_seed_data_records[ds->record_offset + (ds->seed_frame*16)] = ds->w0 ; /*-----------------------------------------------------------*\ Start next frame ... \*-----------------------------------------------------------*/ ds->seed_index = 1; ds->seed_frame ++; ds->w0 = 0; if (ds->seed_frame >= ds->frames_per_record) { if (-1 == finish_record(fp, p_seed_data_records, p_fsdh, ds )) return(-1); } } return(0);}/*--------------------------------------------------------------------------*\ STEIM COMPRESSION -\*--------------------------------------------------------------------------*/long Steim_comp(fp, p_dbuf, p_fsdh, Number_of_samples, data_rec_length, p_seed_data_records, num_cont_blk, num_cont_blk_bytes, cont_blk, num_once_blk, num_once_blk_bytes, once_blk)FILE *fp;float * p_dbuf;DATA_HEADER * p_fsdh;int Number_of_samples ;int data_rec_length;int *p_seed_data_records;int num_cont_blk; /* number of continuous blockettes */int num_cont_blk_bytes; /* number of bytes in continuous blockette */char *cont_blk; /* pointer to blockettes in every data record */int num_once_blk; /* number of one shot blockettes */int num_once_blk_bytes; /* number of bytes in one shot blockette */char *once_blk; /* pointer to blockettes in first data record */ { LONG d[4] ; ULONG tossed = 0 ; ULONG stat[4]; LONG ck ; LONG wk ; int token, i ; DATA_HEADER new_fsdh ; /* buffer for new fixed section data headers */ DATA_STATE ds ; /*-----------------------------------------------------------*\ Build the seed data record initial state \*-----------------------------------------------------------*/ ds.sample_rate = eval_rate(p_fsdh->Sample_rate_factor,p_fsdh->Sample_rate_multiplier); if (num_cont_blk_bytes != 0) if (((struct data_blk_100 *)cont_blk)->hdr.type == 100) ds.sample_rate = ((struct data_blk_100 *)cont_blk)->sample_rate; ds.frames_per_record = (data_rec_length - p_fsdh->Beginning_of_data)/64; ds.record_offset = p_fsdh->Beginning_of_data / sizeof(int); ds.seed_frame = 0; ds.seed_index = 3; /* points past initial w0, x0, xN */ ds.w0 = 0 ; ds.num_data_rec = 0; ds.data_rec_length = data_rec_length ; ds.left_over = 0.0; /*-----------------------------------------------------------*\ Initialize x sub -1 for use in computing the forward and reverse integration constants x sub 0 and x sub N. \*-----------------------------------------------------------*/ ds.get_new_x0 = TRUE ; ds.xN = 0 ; ds.num_cont_blk = num_cont_blk; /* # continuous blockettes */ ds.num_cont_blk_bytes = num_cont_blk_bytes; /* # bytes in continuous blocks */ ds.cont_blk = cont_blk; /* pointer to blockettes in every data record */ ds.num_once_blk = num_once_blk; /* # of one shot blockettes */ ds.num_once_blk_bytes = num_once_blk_bytes; /* number of bytes in one shot blockette */ ds.once_blk = once_blk; /* pointer to blockettes in first data record */ /*-----------------------------------------------------------*\ Build the blockette next_blk_byte fields \*-----------------------------------------------------------*/ /* for (i=0; i<num_cont_blk; i++) { if (((struct data_blk_100 *)cont_blk)->hdr.next_blk_byte == 0) break; else ((struct data_blk_100 *)cont_blk)->hdr.next_blk_byte += 48; } */ for (i=0; i<num_once_blk; i++) { if (((struct data_blk_100 *)once_blk)->hdr.next_blk_byte == 0) break; else ((struct data_blk_100 *)once_blk)->hdr.next_blk_byte += 48 + num_cont_blk_bytes; } /*-----------------------------------------------------------*\ Copy all the values from the passed fsdh, then set values affected by the steim compression. \*-----------------------------------------------------------*/ memcpy((char *)&new_fsdh, (char *)p_fsdh, 48 ) ; /* Now set static values in the new fsdh */ /* new_fsdh.Data_header_indicator = input.type; */ new_fsdh.Reserved_bytes_A = ' ' ;/* * commented out so it does not overwrite the * network code * memcpy(new_fsdh.Reserved_bytes_B, " ", 2); */ new_fsdh.Number_of_samples = 0 ; /* Gets updated later */ new_fsdh.Number_of_blockettes_follow = num_cont_blk + num_once_blk; if (num_cont_blk || num_once_blk) new_fsdh.First_blockette = p_fsdh->First_blockette; else new_fsdh.First_blockette = 0 ; new_fsdh.Beginning_of_data = p_fsdh->Beginning_of_data /* *ds.seed_frame */; for (i=0; i<4; stat[i++]=0); if (verbose) { printf("starting up the compressor ..\n"); display_header(p_fsdh); } { ULONG dbuf_index ; ULONG range = Number_of_samples ; LONG dif ; int state = _START_STATE ; for (dbuf_index=0; dbuf_index<range; dbuf_index++ ) { dif = ((int)p_dbuf[dbuf_index]) - ds.xN ; ds.xN = (int)p_dbuf[dbuf_index] ; if (ds.get_new_x0) { ds.x0 = (int)p_dbuf[dbuf_index] ; ds.get_new_x0 = FALSE ; } /*-----------------------------------------------------------*\ Check for a one-byte dif - _D1_ \*-----------------------------------------------------------*/ if ((dif <= 127) && (dif >= -128)) { char cx = (char)dif; token = 0 ; } /*-----------------------------------------------------------*\ Check for a two-byte dif - _D2_ \*-----------------------------------------------------------*/ else if ((dif <= 32767) && (dif > -32768)) { short sx = (short)dif; token = 1 ; } /*-----------------------------------------------------------*\ Must be a four-byte dif - _D4_ \*-----------------------------------------------------------*/ else { token = 2 ; } /*-----------------------------------------------------------*\ Make the transition ... \*-----------------------------------------------------------*/ { /* (begin scope local variable tran_index) */ int tran_index = state * 3 + token ; if (transition[tran_index].unget) { dbuf_index -= transition[tran_index].unget ; ds.xN = (int)p_dbuf[dbuf_index] ; } if (-1 < transition[tran_index].dif_index) { d[transition[tran_index].dif_index] = dif ; } /* The state assignment must be done last. */ state = transition[tran_index].new_state ; } /* (end scope local variables) */ /*-----------------------------------------------------------*\ Got to a final state, put values into data section ... \*-----------------------------------------------------------*/ if (final[state]) { switch (state) { case _D4_f: /* one 4-byte difference (one 32 bit sample) */ wk = d[0]; ck = 3 ; new_fsdh.Number_of_samples += 1 ; break; case _D2_D2_f: /* two 2-byte differences (two 16 bit samples) */ wk = ((d[0]&0xFFFFL) << 16) | (d[1] & 0xFFFFL) ; ck = 2 ; new_fsdh.Number_of_samples += 2 ; break; case _D1_D1_D1_D1_f: /* four 1-byte differences (four 8 bit samples) */ wk = ((d[0]&0xFFL) << 24) | ((d[1]&0xFFL) << 16) | ((d[2]&0xFFL) << 8) | (d[3]&0xFFL) ; ck = 1 ; new_fsdh.Number_of_samples += 4 ; break; } stat[ck]++; state = _START_STATE ; if (-1 == Add_word(fp, p_seed_data_records, &new_fsdh, wk, ck, &ds )) return(-1); } } /*-----------------------------------------------------------*\ Ran out of input, decide what to do with the data already in the buffer ... \*-----------------------------------------------------------*/ if (!final[state]) { switch (state) { case _START_STATE: /* nothing !*/ break; case _D1: ck = 3; stat[ck]++; wk = d[0]; new_fsdh.Number_of_samples += 1 ; break; case _D2: ck = 3; stat[ck]++; wk = d[0]; new_fsdh.Number_of_samples += 1 ; break; case _D1_D1: ck = 2; stat[ck]++; wk = ((d[0]&0xFFFFL) << 16) | (d[1] & 0xFFFFL) ; new_fsdh.Number_of_samples += 2 ; break; case _D1_D1_D1: ck = 2; stat[ck]++; wk = ((d[0]&0xFFFFL) << 16) | (d[1] & 0xFFFFL) ; new_fsdh.Number_of_samples += 2 ; /*:: call to Add_word may finish a record. */ ds.xN = p_dbuf[range-2] ; if (-1 == Add_word(fp, p_seed_data_records, &new_fsdh, wk, ck, &ds )) return(-1); ck = 3; stat[ck]++; wk = d[2]; new_fsdh.Number_of_samples += 1 ; /*:: Get new X0 value if necessary. */ /*:: Explicitly set xN to last value. */ /*:: We may be starting a new record. */ if (ds.get_new_x0) { ds.x0 = p_dbuf[range-1] ; ds.get_new_x0 = FALSE ; } ds.xN = p_dbuf[range-1]; break; } /* switch */ if (-1 == Add_word(fp, p_seed_data_records, &new_fsdh, wk, ck, &ds )) return(-1); } /* if */ } if (new_fsdh.Number_of_samples) { /*-----------------------------------------------------------*\ Finish the frame ... \*-----------------------------------------------------------*/ p_seed_data_records[ds.record_offset+(ds.seed_frame*16)] = ds.w0 ; /*-----------------------------------------------------------*\ Finish the record ... \*-----------------------------------------------------------*/ finish_record(fp, p_seed_data_records, &new_fsdh, &ds ) ; } /* display_results */ if (verbose) { statistics( stat, tossed, Number_of_samples ); } /* dump array */#if 0 { int ix; FILE *fptr; fptr = fopen("seed.dump.asc", "w+"); for (ix = 0; ix < Number_of_samples; ix++) { fprintf(fptr, "%ld ", *(p_seed_data_records + 1)); } fclose(fptr); }#endif return ds.num_data_rec ; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -