⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spread.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
		return_err(proc,109,0,"Internal Error");	    	    current_data_location = out_conversion_block;	}	/* Do the channel conversions */	if (spifr->status->channels != CHANNELSNULL){	    int in_recsize, out_recsize, in_chancnt, out_chancnt;	    	    if (sp_verbose > 15)		fprintf(spfp,"Proc %s: Converting channels\n",proc);	    if (spifr->status->user_data_fmt == SP_df_array)		out_block = spifr->waveform->interleave_buffer;	    else		if (out_block == (void *)0)		    out_block = (void *)buffer;	    current_data_location = out_block;			    if (spifr->status->file_encoding !=	spifr->status->user_encoding)		in_conversion_block = 		    (void *)spifr->waveform->converted_buffer;	    else 		if (in_conversion_block == (void *)0) 		    in_conversion_block =			(void *)spifr->waveform->file_data_buffer;	    	    in_chancnt = spifr->status->file_channel_count;	    in_recsize = spifr->status->user_sample_n_bytes *  in_chancnt;	    out_chancnt = spifr->status->user_channel_count;	    out_recsize = spifr->status->user_sample_n_bytes * out_chancnt;	    	    for (oc=0; oc<spifr->status->channels->num_chan; oc++)		if (spifr->status->channels->ochan[oc].num_origin == 1){		    char *in_ptr, *out_ptr;		    in_ptr = in_conversion_block +                         ((spifr->status->channels->ochan[oc].orig_channel[0]-1)			 * spifr->status->user_sample_n_bytes);		    out_ptr = out_block + 			(oc * spifr->status->user_sample_n_bytes);		    		    for (s=0; s<in_samples; s++){			memcpy(out_ptr,in_ptr,			      spifr->status->user_sample_n_bytes);			in_ptr += in_recsize;			out_ptr += out_recsize;		    }		} else {		    if (spifr->status->user_encoding == SP_se_pcm2) {			/* do a straight add */			ORIGINATION_CHAN *ochn;			short *in_ptr, *out_ptr;			int sum, ch;			if (sp_verbose > 15)			    fprintf(spfp,				    "Proc %s: Adding PCM data %s %d\n",				    proc, "channel",oc);			in_ptr = (short *)in_conversion_block;			out_ptr = (short *)out_block;			ochn = &(spifr->status->channels->ochan[oc]);						if (spifr->status->user_sbf== get_natural_sbf(2)){			    for (s=0; s<in_samples; s++){				for (ch=0, sum=0; ch < ochn->num_origin; 				     ch++){				    sum +=*(in_ptr+ochn->orig_channel[ch]-1);				}				if (sum > 32767) sum = 32767;				else if (sum < -32768) sum = -32768;				*(out_ptr + oc) = (short)sum;				in_ptr += in_chancnt;				out_ptr += out_chancnt;			    }			} else {			    short x;			    if (sp_verbose > 15)				fprintf(spfp,"Proc %s: %s %d\n", proc,					"Adding Swapped PCM data channel",oc);			    for (s=0; s<in_samples; s++){				/*    fprintf(spfp,"sample %d\n",s);  */				for (ch=0, sum=0; ch < ochn->num_origin; 				     ch++){				    x = *(in_ptr+ochn->orig_channel[ch]-1);				    swap_bytes(x);				    sum += x;				    /* fprintf(spfp,"   %d  =  %d\n",x,sum); */				}				if (sum > 32767) x = 32767;				else if (sum < -32768) x = -32768;				else x = sum;				swap_bytes(x);				*(out_ptr + oc) = (short)x;				in_ptr += in_chancnt;				out_ptr += out_chancnt;			    }			    			}			   		    } else if (spifr->status->user_encoding == SP_se_ulaw){			/* do an add on ulaw data */			ORIGINATION_CHAN *ochn;			unsigned char *in_ptr, *out_ptr;			int sum, ch;			if (sp_verbose > 15)			    fprintf(spfp,				    "Proc %s: Adding ULAW data %s %d\n",				    proc, "channel",oc);			in_ptr = (unsigned char *)in_conversion_block;			out_ptr = (unsigned char *)out_block;			ochn = &(spifr->status->channels->ochan[oc]);						for (s=0; s<in_samples; s++){			    for (ch=0, sum=0; ch < ochn->num_origin;				 ch++){				sum +=				    ulaw2linear_10_sbf_lut[					*(in_ptr+ochn->orig_channel[ch]-1)];			    }			    if (sum > 32767) sum = 32767;			    else if (sum < -32768) sum = -32768;			    *(out_ptr + oc) =  linear2ulaw(sum);			    in_ptr += in_chancnt;			    out_ptr += out_chancnt;			}		    }		}	    out_block += out_recsize * in_samples;	}		if (spifr->status->user_data_fmt == SP_df_array){	    /* convert the data from it's interleaved form */	    /* to an array format                          */	    int snb = spifr->status->user_sample_n_bytes;	    int chcnt = spifr->status->user_channel_count;	    int recsize = snb * chcnt;	    char *in_dat;	    	    if (sp_verbose > 15)		fprintf(spfp,"Proc %s: Converting data to an array\n",			proc);	    	    if (arr_buff == (char  **)0)		arr_buff = (char **)buffer;	    for (c=0; c<chcnt; c++){		in_dat =  current_data_location + (snb * c) ;		arr = arr_buff[c] + ((samples_read-in_samples) * snb);				for (s=0; s<in_samples; s++,arr+=snb,in_dat+=recsize)		    memcpy(arr,in_dat,snb);	    }	}	if (sp_verbose > 11){	    fprintf(spfp,"Proc %s: Block %d: Requested %d samples",		    proc,block++,num_sample);	    fprintf(spfp," read %d total %d, Checksum %d (BC %d)\n",		    ret,spifr->waveform->samples_read,		    block_checksum,		    spifr->waveform->checksum);	}    }    return_success(proc,0,samples_read,"ok");}int called_by_waves = 0;static int decompress_waveform(SP_FILE *sp){    int decomp_into_memory=TRUE;    int wav_bytes=0;    SPIFR *spifr = sp->read_spifr;    FOB *fob_in, *fob_out;    char *buff;    int blen;    char *proc="decompress_waveform " SPHERE_VERSION_STR;        wav_bytes = spifr->status->user_sample_count * 	spifr->status->user_channel_count * 	    spifr->status->user_sample_n_bytes;        /* the file must be decompressed, Question: Should it be done in memory? */    if ((wav_bytes > MAX_INTERNAL_WAVFORM) || called_by_waves)	decomp_into_memory = FALSE;        /* The file needs to be de_compressed into memory !!!! */    /* 1. make an FOB struct for the uncompressed waveform to be read into d */    /*    and the original file */    /* 2. allocate memory for the entire waveform */    /* 3. decompress the file */    /* 4. Clean up the FOB struct for the file, moving the fp from the FOB */    /* 5. reset the uncompressed FOB struct to the beginning of the memory */		    if (decomp_into_memory) {	if (sp_verbose > 15)	    fprintf(spfp,"Proc %s: Pre-buffering compressed data into memory\n",		   proc);	if (fob_create2(spifr->waveform->sp_fp, FPNULL, &fob_in, &fob_out) < 0)	    return_err(proc,200,0,"Unable to setup for decompression");	blen = spifr->status->file_channel_count * 	    spifr->status->file_sample_count * 		spifr->status->file_sample_n_bytes;	if ((buff=mtrf_malloc(blen)) == CNULL){	    fob_destroy(fob_in);	    fob_destroy(fob_out);	    return_err(proc,201,0,"Unable to malloc memory to decompress into");	}	fob_bufinit(fob_out, buff, blen);    } else { /* decompress into a disk file */	FILE *temp_fp;	if (sp_verbose > 15)	    fprintf(spfp,"Proc %s: Pre-buffering compressed data %s\n",		   proc,"into a temporary file");	spifr->status->temp_filename = sptemp_dirfile();	if (spifr->status->temp_filename == CNULL)	    return_err(proc,400,0,"Unable to create usable temporary file");	if (sp_verbose > 15)	    fprintf(spfp,"Proc %s: %s%d bytes long, using temp file %s\n",		   proc, "Attempting to read a big file ",wav_bytes,		   spifr->status->temp_filename);	if ((temp_fp=fopen(spifr->status->temp_filename,TRUNCATE_UPDATEMODE)) 	    == FPNULL) 	    return_err(proc,401,0,		       rsprintf("Unable to open temporary file %s",				spifr->status->temp_filename));	if (fob_create2(spifr->waveform->sp_fp, temp_fp, &fob_in, &fob_out) <0)	    return_err(proc,402,0,"Unable to setup for decompression");		/* the FILE pointer will be closed after completion of the           */	/* decompression directly from the fob_in FOB pointer.  this is the  */	/* bug which Francis caught.                                         */		/* Note:  Do NOT set the waveform file to FPNULL here (see bugfix    */	/* below.)  ***PSI***  24-Sep-1993                                   */	/* spifr->waveform->sp_fp = FPNULL; */	spifr->status->is_temp_file = TRUE;    }    if (sp_verbose > 15)	fprintf(spfp,		"Proc %s: before decompression, input file at position %d\n",	       proc,fob_ftell(fob_in));    switch (spifr->status->file_compress){	char message[80];      case SP_wc_shorten:	if (sp_verbose > 15)	    fprintf(spfp,"Proc %s: Executing Shorten Decompression\n",proc);	if (setjmp(exitenv) == 0){	    if (shorten_uncompress(fob_in, fob_out, message) < 0){		fob_destroy(fob_in);		fob_destroy(fob_out);		return_err(proc,202,0,			   rsprintf("Shorten Decompression Failed",message));	    }	} else {	    fob_destroy(fob_in);	    fob_destroy(fob_out);	    return_err(proc,207,0,"Shorten Decompression aborted");	}	break;      case SP_wc_wavpack:	if(setjmp(exitenv) == 0){	    if (sp_verbose > 15) fprintf(spfp,"before set progname\n");	    wavpack_set_progname( "wavpack" );	    if (sp_verbose > 15)		fprintf(spfp,			"Proc %s: Executing Wavpack Decompression\n",proc);	    if (sp_verbose > 15)		wavpack_dump_interface(spfp);	    if (wavpack_unpack(fob_in, fob_out) < 0){		fob_destroy(fob_in);		fob_destroy(fob_out);		return_err(proc,203,0,"Wavpack Decompression Failed");	    }	    wavpack_free_progname();	} else {	    fob_destroy(fob_in);	    fob_destroy(fob_out);	    return_err(proc,206,0,"Wavpack Decompression aborted");	}	break;      case SP_wc_shortpack:	if(setjmp(exitenv) == 0){	    if (sp_verbose > 15)		fprintf(spfp,			"Proc %s: Executing Shortpack Decompression\n",proc);	    if (shortpack_uncompress(fob_in, fob_out,				     spifr->status->file_header) < 0){		fob_destroy(fob_in);		fob_destroy(fob_out);		return_err(proc,203,0,"Shortpack Decompression Failed");	    }	} else {	    fob_destroy(fob_in);	    fob_destroy(fob_out);	    return_err(proc,208,0,"Shortpack Decompression aborted");	}		    	break;      default:	return_err(proc,209,0,"Unable to decompress the requested format\n");    }    fob_rewind(fob_out);            /**** Begin SRI bugfix. ****/        /* If a temporary file is being used, close the waveform file BEFORE    */    /* setting it to FPNULL.  ***PSI***  24-Sep-1993                        */        if (spifr->status->is_temp_file) {	if (sp_verbose > 15)	    fprintf(spfp,"Proc %s: Closing waveform file \"%s\" (%d)\n",		   proc, spifr->status->external_filename,		   fileno(spifr->waveform->sp_fp));		if (fclose(spifr->waveform->sp_fp))	    return_err(proc, 403, 0,		       rsprintf("Unable to close waveform file \"%s\" (%d)",				spifr->status->external_filename,				fileno(spifr->waveform->sp_fp)));	spifr->waveform->sp_fp = FPNULL;/* added by Parker, Entropic */        unlink(spifr->status->temp_filename);    }        /**** End SRI bugfix. ****/        if (! decomp_into_memory) { 	/* Close the original file pointer to the SPHERE file */	fclose(fob_in->fp);    }    fob_destroy(fob_in);	            spifr->waveform->sp_fob = fob_out;    return_success(proc,0,0,"ok");}/* *  This function just computes the checksum of the file pointed to by  *  an FOB structure. */static int fob_short_checksum(FOB *f, SP_CHECKSUM *checksum, int do_byte_swap, 	       SP_CHECKSUM (*add_checksum) (SP_CHECKSUM , SP_CHECKSUM )){    long cur_fp_pos;    short buff[1024];    int len, ss;    SP_CHECKSUM chks;    chks = *checksum = 0;    ss = sizeof(short);    if (fob_is_fp(f)){	cur_fp_pos = ftell(f->fp);	while ((len=fread(buff,ss,1024,f->fp)) > 0){	    chks = sp_compute_short_checksum((short *)buff, len, do_byte_swap);	    *checksum = (*add_checksum)(*checksum,chks);	}	if (ferror(f->fp)){	    fseek(f->fp,cur_fp_pos,SEEK_SET);	    return(-1);	}	fseek(f->fp,cur_fp_pos,SEEK_SET);	clearerr(f->fp);	return(0);    } else {        *checksum = sp_compute_short_checksum((short *)(f->buf),					      f->length/2, do_byte_swap);	return(0);    }}/* *  This function just computes the checksum of the file pointed to by  *  an FOB structure. */static int fob_char_checksum(FOB *f, SP_CHECKSUM *checksum,  	       SP_CHECKSUM (*add_checksum) (SP_CHECKSUM , SP_CHECKSUM )){    long cur_fp_pos;    char buff[1024];    int len, sc;    SP_CHECKSUM chks;    chks = *checksum = 0;    sc = sizeof(char);    if (fob_is_fp(f)){	cur_fp_pos = ftell(f->fp);	while ((len=fread(buff,sc,1024,f->fp)) > 0){	    chks = sp_compute_char_checksum((char *)buff, len);	    *checksum = (*add_checksum)(*checksum,chks);	}	if (ferror(f->fp)){	    fseek(f->fp,cur_fp_pos,SEEK_SET);	    return(-1);	}	fseek(f->fp,cur_fp_pos,SEEK_SET);	clearerr(f->fp);	return(0);    } else {        *checksum = sp_compute_char_checksum((char *)(f->buf),f->length);	return(0);    }}static int pre_verify_checksum(SP_FILE *sp){    char *proc="pre_verify_checksum " SPHERE_VERSION_STR;    SPIFR *spifr=sp->read_spifr;    SP_CHECKSUM checksum;        /* if the samples are in memory, compute the checksum from there. */    /* if not, read in the file, a block at a time and compute the    */    /* checksum.                                                      */    switch (spifr->status->file_encoding){      case SP_se_pcm2:	if (fob_short_checksum(spifr->waveform->sp_fob, &checksum,			       spifr->status->file_sbf != 			       spifr->status->natural_sbf,			       sp_add_checksum) < 0)	    return_err(proc,501,0,"Unable to Pre-Verify Checksum");	if (checksum != spifr->status->file_checksum){	    spifr->waveform->failed_checksum = TRUE;	    return_err(proc,1001,0,		       "Pre-Read Short Checksum Test Failed");	}	break;      default:	if (fob_char_checksum(spifr->waveform->sp_fob,			      &checksum,sp_add_checksum) < 0)	    return_err(proc,502,0,"Unable to Pre-Verify Checksum");	if (checksum != spifr->status->file_checksum){	    spifr->waveform->failed_checksum = TRUE;	    return_err(proc,1001,0,		       "Pre-Read Char Checksum Test Failed");	}	break;    }    return_success(proc,0,0,"ok");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -