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

📄 tsphere.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 5 页
字号:
	}	if ((sp_array=sp_open(EX6,"r")) == SPNULL) {	    fprintf(spfp,"   sp_open: spopen for array read of ");	    fprintf(spfp,"file '%s' failed\n",EX6);	    sp_print_return_status(spfp);	    goto FATAL_QUIT;	    	}	if (sp_set_data_mode(sp_inter,conversion) != 0){	    fprintf(spfp,"Error: sp_set_data_mode to ");	    fprintf(spfp,"'%s' failed interleaved file '%s'\n",conversion,EX6);	    sp_print_return_status(spfp);	    goto FATAL_QUIT;	}	if (sp_h_get_field(sp_inter,CHANNEL_COUNT_FIELD,			   T_INTEGER,(void *)&nchan)!=0){	    fprintf(spfp,"   Can't get the channel count from file '%s'\n",		    EX6);	    sp_print_return_status(spfp);	    goto FATAL_QUIT;	}    	if (sp_h_get_field(sp_inter,CHANNEL_COUNT_FIELD,			   T_INTEGER,(void *)&snb)!=0){	    fprintf(spfp,"   Can't get the sample_n_bytes from file '%s'\n",		    EX6);	    sp_print_return_status(spfp);	    goto FATAL_QUIT;	}    	/* convert the spfile to be read as an array */	if (sp_set_data_mode(sp_array,array_conversion) != 0){	    fprintf(spfp,"Error: sp_set_data_mode to ");	    fprintf(spfp,"'%s' failed on file '%s'\n",array_conversion,EX6);	    sp_print_return_status(spfp);	    goto FATAL_QUIT;	}	/* alloc buffers for each file */	if ((inter_buf = (void *)sp_data_alloc(sp_inter,frame_size))==	    (void *)0){	    fprintf(spfp,"Unable to allocate interleaved memory for ");	    fprintf(spfp,"file '%s'\n",EX6);	    sp_print_return_status(spfp);	    goto FATAL_QUIT;	}	if ((array_buf = (void **)sp_data_alloc(sp_array,frame_size))==	    (void **)0){	    fprintf(spfp,"Unable to allocate array memory for ");	    fprintf(spfp,"file '%s'\n",EX6);	    sp_print_return_status(spfp);	    goto FATAL_QUIT;	}	do {	    ret=sp_read_data(inter_buf,2,frame_size,sp_inter);	    if ((ret == 0) && (sp_error(sp_inter) > 0)){		fprintf(spfp,"   Read failed on interleaved input file\n");		sp_print_return_status(spfp);		goto FATAL_QUIT;	    }	    if (ret > 0){		ret2=sp_read_data(array_buf,2,ret,sp_array);		if ((ret2 == 0) && (sp_error(sp_array) > 0)){		    fprintf(spfp,"   Read failed on array input file\n");		    sp_print_return_status(spfp);		    goto FATAL_QUIT;		}		if (ret != ret2){		    fprintf(spfp,"   Read %d samples from inteleaved file",			    ret);		    fprintf(spfp,", but only %d from array file",ret);		    goto FATAL_QUIT;		}		{   unsigned char **carr=(unsigned char **)array_buf,			          *cintr=(unsigned char *)inter_buf;		    short **sarr = (short **)array_buf,		          *sintr = (short *)inter_buf;		    int val;		    for (s=0; s<ret; s++){			for (c=0; c<nchan; c++){			    if (fmt == 0 || fmt == 2 || fmt == 3)				val = (*(sintr + s*nchan +c) != sarr[c][s]);			    else				val = (*(cintr + s*nchan +c) != carr[c][s]);			    if (val){				fprintf(spfp, 				    "Sample Values != at samp %d, chan %d\n",					s,c);				goto FATAL_QUIT;			    }			}		    }		}	    }	} while (ret > 0);	if (sp_error(sp_inter) > 0 ){	    fprintf(spfp,"Read failure on interleaved file %s\n",EX6);	    sp_print_return_status(spfp);	    goto FATAL_QUIT;	}	if (sp_error(sp_array) > 0 ){	    fprintf(spfp,"Read failure on array file %s\n",EX6);	    sp_print_return_status(spfp);	    goto FATAL_QUIT;	}	if (sp_inter != SPNULL) {	    if (inter_buf != (void *)0) sp_data_free(sp_inter,inter_buf);	    if (sp_close(sp_inter) != 0){		fprintf(spfp,"Error: Unable to close stereo file '%s'\n",EX6);		sp_print_return_status(spfp);		return_value = 200;	    }	    sp_inter = SPNULL; inter_buf = (void *)0;	}	if (sp_array != SPNULL) {	    if (array_buf != (void **)0) sp_data_free(sp_array,array_buf);	    if (sp_close(sp_array) != 0){		fprintf(spfp,"Error: Unable to close stereo file '%s'\n",EX6);		sp_print_return_status(spfp);		return_value = 200;	    }	    sp_array = SPNULL; array_buf = (void **)0;	}	write_with_array_access(EX6, conversion, array_conversion, fmt);	/* everything is ok */	return_value = 0;	goto CLEAN_UP;      FATAL_QUIT:  /* Failed routine */	return_value = 100;	      CLEAN_UP:	if (sp_inter != SPNULL) {	    if (inter_buf != (void *)0) sp_data_free(sp_inter,inter_buf);	    if (sp_close(sp_inter) != 0){		fprintf(spfp,"Error: Unable to close stereo file '%s'\n",EX6);		sp_print_return_status(spfp);		return_value = 200;	    }	    sp_inter = SPNULL; inter_buf = (void *)0;	}	if (sp_array != SPNULL) {	    if (array_buf != (void **)0) sp_data_free(sp_array,array_buf);	    if (sp_close(sp_array) != 0){		fprintf(spfp,"Error: Unable to close stereo file '%s'\n",EX6);		sp_print_return_status(spfp);		return_value = 200;	    }	    sp_array = SPNULL; array_buf = (void **)0;	}	if (return_value != 0)	    exit(-1);    }    fprintf(spfp,"\n");}int write_with_array_access(char *filein, char *conversion,			    char *array_conversion, int fmt){    SP_FILE *sp_inter=SPNULL, *sp_new=SPNULL;    SP_INTEGER nchan;    char *fileout="output.wav";    int frame_size=3000, ret, ret2, c, s, return_value;    void *inter_buf=(void *)0, **new_array_buf=(void **)0;    fprintf(spfp,"------ Writing test into format '%s'\n",	    array_conversion);        /**** re open the input file, un-altered, writting it to the ****/    /**** new file  ****/    if ((sp_inter=sp_open(filein,"r")) == SPNULL) {	fprintf(spfp,"   sp_open: spopen for interleaved read of ");	fprintf(spfp,"file '%s' failed\n",filein);	sp_print_return_status(spfp);	goto FATAL_QUIT;    }    if ((sp_new=sp_open(fileout,"w")) == SPNULL) {	fprintf(spfp,"   sp_open: spopen for array write of ");	fprintf(spfp,"file '%s' failed\n",fileout);	sp_print_return_status(spfp);	goto FATAL_QUIT;    }    if (sp_copy_header(sp_inter, sp_new) > 0){	fprintf(spfp,"Couldn't duplicate the header in file ");	fprintf(spfp,"'%s' for file '%s'\n",filein,fileout);	sp_print_return_status(spfp);	goto FATAL_QUIT;    }    if (sp_set_data_mode(sp_new,array_conversion) != 0){	fprintf(spfp,"Error: sp_set_data_mode to ");	fprintf(spfp,"'%s' failed on file '%s'\n",array_conversion,		fileout);	sp_print_return_status(spfp);	goto FATAL_QUIT;    }    if (sp_h_get_field(sp_inter,CHANNEL_COUNT_FIELD,		       T_INTEGER,(void *)&nchan)!=0){	fprintf(spfp,"   Can't get the channel count from file '%s'\n",		filein);	sp_print_return_status(spfp);	goto FATAL_QUIT;    }        /* alloc buffers for each file */    if ((inter_buf = (void *)sp_data_alloc(sp_inter,frame_size))==	(void *)0){	fprintf(spfp,"Unable to allocate interleaved memory for ");	fprintf(spfp,"file '%s'\n",filein);	sp_print_return_status(spfp);	goto FATAL_QUIT;    }    if ((new_array_buf = (void **)sp_data_alloc(sp_new,frame_size))==	(void **)0){	fprintf(spfp,"Unable to allocate array memory for new ");	fprintf(spfp,"file '%s'\n",fileout);	sp_print_return_status(spfp);	goto FATAL_QUIT;    }    do {	short *sintr = (short *)inter_buf;	short **nsarr = (short **)new_array_buf;		ret=sp_read_data(inter_buf,2,frame_size,sp_inter);	if ((ret == 0) && (sp_error(sp_inter) > 0)){	    fprintf(spfp,"   Read failed on interleaved input file\n");	    sp_print_return_status(spfp);	    goto FATAL_QUIT;	}	if (ret > 0) {	    /* copy the data into the output array data */	    for (s=0; s<ret; s++)		for (c=0; c<nchan; c++)		    nsarr[c][s] = (*(sintr + s*nchan +c));	    	    if ((ret2=sp_write_data(new_array_buf,2,ret,sp_new)) != ret){		fprintf(spfp,"Unable to write %d array samples to file\n",			ret);		sp_print_return_status(spfp);		goto FATAL_QUIT;	    }	}    } while (!sp_eof(sp_inter));    if (sp_new != SPNULL) {	if (new_array_buf != (void **)0) sp_data_free(sp_new,						      new_array_buf);	new_array_buf = (void **)0;	if (sp_close(sp_new) != 0){	    fprintf(spfp,"Error: Unable to close stereo file '%s'\n",		    fileout);	    sp_print_return_status(spfp);	    goto FATAL_QUIT;	}	sp_new = SPNULL;    }            if (diff_waveforms(filein,fileout,conversion,"", 0, spfp) != 0){	fprintf(spfp,"Write of Array Accessed passed, but diff failed\n");	diff_waveforms(filein,fileout,conversion,"", 1, spfp);	goto FATAL_QUIT;    }        /* everything is ok */    return_value = 0;    unlink(fileout);    goto CLEAN_UP;      FATAL_QUIT:  /* Failed routine */    return_value = 100;      CLEAN_UP:    if (sp_inter != SPNULL) {	if (inter_buf != (void *)0) sp_data_free(sp_inter,inter_buf);	if (sp_close(sp_inter) != 0){	    fprintf(spfp,"Error: Unable to close stereo file '%s'\n",filein);	    sp_print_return_status(spfp);	    return_value = 200;	}	sp_inter = SPNULL; inter_buf = (void *)0;    }    if (sp_new != SPNULL) {	if (new_array_buf != (void **)0) sp_data_free(sp_new,						      new_array_buf);	new_array_buf = (void **)0;	if (sp_close(sp_new) != 0){	    fprintf(spfp,"Error: Unable to close stereo file '%s'\n",		    fileout);	    sp_print_return_status(spfp);	    goto FATAL_QUIT;	}	sp_new = SPNULL;    }    if (return_value != 0)	exit(-1);    return(1);    }void selective_channel_test(void){    fprintf(spfp,"-- Selective Channel testing\n");    fprintf(spfp,"---- Invalid read test\n");    if (!do_selective_read_test(EX5_2CHAN,EX5_CHAN1,"CH-2","",0)){	do_selective_read_test(EX5_2CHAN,EX5_CHAN1,"CH-2","",1);	fprintf(spfp,"Error: Expecting an error, but none was detected\n");	exit(-1);    }    fprintf(spfp,"---- Read selective channels\n");    if (do_selective_read_test(EX5_2CHAN,EX5_CHAN1, "CH-1", "",1))	exit(-1);    if (do_selective_read_test(EX5_2CHAN,EX5_CHAN2, "CH-2", "",1))	exit(-1);    if (do_selective_read_test(EX5_2CHAN_PCM,EX5_CHAN1_PCM, "CH-1", "",1))	exit(-1);    if (do_selective_read_test(EX5_2CHAN_PCM,EX5_CHAN2_PCM,"CH-2", "",1))	exit(-1);    fprintf(spfp,"---- Read selective channels converting sample encodings\n");    if (do_selective_read_test(EX5_2CHAN,EX5_CHAN1_PCM,			       "SE-PCM:SBF-N:CH-1", "",1))	exit(-1);    if (do_selective_read_test(EX5_2CHAN,EX5_CHAN2_PCM,			       "SE-PCM:SBF-N:CH-2", "",1))	exit(-1);    fprintf(spfp,"---- Read channels added together\n");    if (do_selective_read_test(EX5_2CHAN_PCM,EX5_CHAN12_PCM,"CH-1+2", "",1))	exit(-1);    if (do_selective_read_test(EX5_2CHAN,EX5_CHAN12, "CH-1+2","",1))	exit(-1);    if (do_selective_read_test(EX5_2CHAN_PCM_01,EX5_CHAN12_PCM, 			       "SBF-01:CH-1+2", "SBF-01",1))	exit(-1);    fprintf(spfp,	    "---- Read channels added together converting sample types\n");    if (do_selective_read_test(EX5_2CHAN,EX5_CHAN12_PCM, 			       "SE-PCM:SBF-01:CH-1+2", "SBF-01",1))	exit(-1);    fprintf(spfp,"\n");    fprintf(spfp,	    "---- Write channels added together changing sample encodings\n");    waveform_update(EX5_2CHAN,"SE-PCM:SBF-10:CH-1+2",EX5_CHAN12_PCM);    fprintf(spfp,"---- Write channels added together\n");    waveform_update(EX5_2CHAN,"CH-1+2", EX5_CHAN12);    waveform_update(EX5_2CHAN_PCM,"SE-PCM:SBF-10:CH-1+2", EX5_CHAN12_PCM);    fprintf(spfp,"---- Write selective channels changing sample encodings\n");    waveform_update(EX5_2CHAN,"SE-PCM:SBF-10:CH-1", EX5_CHAN1_PCM);    waveform_update(EX5_2CHAN,"SE-PCM:SBF-10:CH-2", EX5_CHAN2_PCM);    fprintf(spfp,"---- Write selective channels\n");    waveform_update(EX5_2CHAN_PCM,"SE-PCM:SBF-10:CH-1", EX5_CHAN1_PCM);    waveform_update(EX5_2CHAN_PCM,"SE-PCM:SBF-10:CH-2", EX5_CHAN2_PCM);    waveform_update(EX5_2CHAN,"SE-ULAW:SBF-1:CH-1",EX5_CHAN1);    waveform_update(EX5_2CHAN,"SE-ULAW:SBF-1:CH-2",EX5_CHAN2);    fprintf(spfp,"\n");}int do_selective_read_test(char *f1, char *f2, char *conv1, char *conv2,int v){    if (v) fprintf(spfp,"------ File: %s conv '%s' Compared to %s conv '%s'\n",		  f1,conv1,f2,conv2);    if (diff_waveforms(f1,f2,conv1,conv2, 0, spfp) != 0){	if (v) diff_waveforms(f1,f2,conv1,conv2, 1, spfp);	return(1);    }    return(0);}#define MC_CHAN 4#define MC_BUFS 500void mult_channel_raw_data_test(void){

⌨️ 快捷键说明

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