コード例 #1
0
ファイル: rle.c プロジェクト: gwowen/seismicunix
void codeSilence (void *inb, void *outb)
/***********************************************************************
Silence encoding, takes care of "silence" pieces 
************************************************************************
inb	input buffer
outb	output buffer
***********************************************************************/
{
	memBUFF *inbuff = (memBUFF *) inb;
	memBUFF *outbuff = (memBUFF *) outb;
	int look_ahead[LOOKAHSZ];
	int index, i, run_length, flag;

	/* preload the look ahead buffer */
	for(i=0; i<LOOKAHSZ; i++)
	    if(buffGetc(inbuff, look_ahead[i]) == MEM_EOB)
		break;

	/* if not enough samples, no RLE */
	if(i < LOOKAHSZ){
	    buffMerge(outbuff, inbuff);
	    return;
	}

	index = 0;
	for(;;){

	    if(look_ahead[index] == MEM_EOB) break;

	    if(silence_run(look_ahead, index)){
		run_length = 0;

		do{
		    flag = buffGetc(inbuff, look_ahead[index]);
		    if(flag == MEM_EOB) look_ahead[index] = MEM_EOB;
		    index ++;
		    index &= LOOKAHMASK;
		    if(++run_length == MAXLENGTH){
			buffPutc(outbuff, SILENCECODE);
			buffPutc(outbuff, MAXLENGTH);
			run_length = 0;
		    }
		} while(!end_of_silence(look_ahead, index));

		if(run_length > 0){
		    buffPutc(outbuff, SILENCECODE);
		    buffPutc(outbuff, run_length);
		}
	    }

	    if(look_ahead[index] == MEM_EOB) break;

	    /* the silence code in the input get changed */
	    if(look_ahead[index] == SILENCECODE) look_ahead[index]++;
	    buffPutc(outbuff, look_ahead[index]);

	    /* get a new code */
	    flag = buffGetc(inbuff, look_ahead[index]);
	    if(flag == MEM_EOB) look_ahead[index] = MEM_EOB;
	    index ++;
	    index &= LOOKAHMASK;
	}
}
コード例 #2
0
ファイル: wpcsilence.c プロジェクト: JOravetz/SeisUnix
void codeSilence (void *inb, void *outb)
/***********************************************************************
Silence encoding, takes care of "silence" pieces 
************************************************************************
inb	input buffer
outb	output buffer
************************************************************************
Note:	To avoid the inefficiency in encoding isolated 0's, I start a run
	only when there are CODESTARTTHRSHOLD consective 0's. Therefore, 
	a look ahead buffer is needed. The run is stopped as soon as there
	is a non-0 symbol.  
***********************************************************************/
{
	wpcBUFF *inbuff = (wpcBUFF *) inb;
	wpcBUFF *outbuff = (wpcBUFF *) outb;
	int look_ahead[CODELOOKAHSZ];
	int index, i, run_length, flag;

	/* preload the look ahead buffer */
	for(i=0; i<CODELOOKAHSZ; i++)
	    if(buffGetc(inbuff, look_ahead[i]) == WPC_EOB)
		break;

	/* if not enough samples, no RLE */
	if(i < CODELOOKAHSZ){
	    buffMerge(outbuff, inbuff);
	    return;
	}

	index = 0;
	for(;;){

	    if(look_ahead[index] == WPC_EOB) break;

	    if(silence_run(look_ahead, index)){
		run_length = 0;

		do{
		    flag = buffGetc(inbuff, look_ahead[index]);
		    if(flag == WPC_EOB) look_ahead[index] = WPC_EOB;
		    index ++;
		    index &= CODELOOKAHMASK;
		    if(++run_length == CODEMAXLENGTH){
			buffPutc(outbuff, CODESILENCECODE);
			buffPutc(outbuff, CODEMAXLENGTH);
			run_length = 0;
		    }
		} while(!end_of_silence(look_ahead, index));

		if(run_length > 0){
		    buffPutc(outbuff, CODESILENCECODE);
		    buffPutc(outbuff, run_length);
		}
	    }

	    if(look_ahead[index] == WPC_EOB) break;

	    /* the silence code in the input get changed */
	    if(look_ahead[index] == CODESILENCECODE) look_ahead[index]++;
	    buffPutc(outbuff, look_ahead[index]);

	    /* get a new code */
	    flag = buffGetc(inbuff, look_ahead[index]);
	    if(flag == WPC_EOB) look_ahead[index] = WPC_EOB;
	    index ++;
	    index &= CODELOOKAHMASK;
	}
}