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

📄 tsphere.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 5 页
字号:
	59262, 60690, 62135, 63597, 65076, 1036, 2549, 4079, 5626,	7190, 8771, 10369, 11984, 13616, 15265, 16931, 18614};    static SP_CHECKSUM sum_arr[100] = { 17, 68, 153, 272, 425, 612, 833,	1088, 1377, 1700, 2057, 2448, 2873, 3332, 3825, 4352, 4913,	5508, 6137, 6800, 7497, 8228, 8993, 9792, 10625, 11492, 12393,	13328, 14297, 15300, 16337, 17408, 18513, 19652, 20825, 22032,	23273, 24548, 25857, 27200, 28577, 29988, 31433, 32912, 34425,	35972, 37553, 39168, 40817, 42500, 44217, 45968, 47753, 49572,	51425, 53312, 55233, 57188, 59177, 61200, 63257, 65348, 1937,	4096, 6289, 8516, 10777, 13072, 15401, 17764, 20161, 22592,	25057, 27556, 30089, 32656, 35257, 37892, 40561, 43264, 46001,	48772, 51577, 54416, 57289, 60196, 63137, 576, 3585, 6628,	9705, 12816, 15961, 19140, 22353, 25600, 28881, 32196, 35545};    short sh_arr[100];    int i, failure=FALSE;    fprintf(spfp,"Test %2d: Waveform checksum calculation tests:\n",test);    if (sizeof(long) <= 2)	fprintf(spfp,"Proc %s: Long int is only %ld bytes, >2 needed\n",		proc,sizeof(long));    if (sizeof(short) != 2)	fprintf(spfp,"Proc %s: short int is only %ld bytes, != 2\n",		proc,sizeof(short));    for (i=0; i<100; i++)	sh_arr[i] = i*17;           for (i=0; i<100; i++){	comp_chksm = sp_compute_short_checksum(sh_arr, i+1, FALSE);	if (comp_chksm != ex_arr[i]){	    fprintf(spfp,"Error: Computed checksum %d != Expected[%d] %d\n",		    comp_chksm,i,ex_arr[i]);	    failure=TRUE;	}    }    for (i=0; i<99; i++){	comp_chksm = sp_compute_short_checksum(sh_arr, i+1, FALSE);	comp_chksm1 = sp_compute_short_checksum(sh_arr, i+2, FALSE);	sum_chksm = sp_add_checksum(comp_chksm,comp_chksm1);	if (sum_chksm != sum_arr[i]){	    fprintf(spfp,"Error: Summed checksum %d -> %d+%d=%d != %d\n",		    i,comp_chksm,comp_chksm1,sum_chksm,sum_arr[i]);	    failure=TRUE;	}    }    fprintf(spfp,"\n");    return(0);}void array_access_tests(int test){    SP_FILE *sp_inter=SPNULL, *sp_array=SPNULL;    SP_INTEGER nchan, snb;    void *inter_buf=(void *)0, **array_buf=(void **)0;    char conversion[100], array_conversion[100];    int frame_size=3000, ret, ret2, return_value;    int s,c,fmt;    fprintf(spfp,"Test %2d: Array access to waveform tests:\n",test);    /* change the input data formats */    /*     read in a 4-channel mux-ed file as interleaved data */    /*     read in a 4-channel mux-ed file as an array         */    /*     if that passes, */    /*         change the data formats */    /*            re-read the file as an array, writing it as an array */    /*            do a data diff on the original and the new           */    for (fmt=0; fmt < 6; fmt++){		switch (fmt){	  case 0: 	    fprintf(spfp,"---- %d: No format changes\n",fmt+1);	    strcpy(conversion,"");	    sprintf(array_conversion,"DF-ARRAY");	    break;	  case 1:	    fprintf(spfp,"---- %d: Changing to ULAW\n",fmt+1);	    sprintf(conversion,"SE-ULAW:SBF-1");	    sprintf(array_conversion,"SE-ULAW:SBF-1:DF-ARRAY");	    break;	  case 2:	    fprintf(spfp,"---- %d: Changing to Channels 1,2\n",fmt+1);	    sprintf(conversion,"CH-1,2");	    sprintf(array_conversion,"CH-1,2:DF-ARRAY");	    break;	  case 3:	    fprintf(spfp,"---- %d: Changing to Channels 2,1\n",fmt+1);	    sprintf(conversion,"CH-2,1");	    sprintf(array_conversion,"CH-2,1:DF-ARRAY");	    break;	  case 4:	    fprintf(spfp,"---- %d: Changing to ULAW, Channels 1,2\n",fmt+1);	    sprintf(conversion,"CH-1,2:SE-ULAW:SBF-1");	    sprintf(array_conversion,"CH-1,2:SE-ULAW:SBF-1:DF-ARRAY");	    break;	  case 5:	    fprintf(spfp,"---- %d: Changing to ULAW, Channels 2,1\n",fmt+1);	    sprintf(conversion,"CH-2,1:SE-ULAW:SBF-1");	    sprintf(array_conversion,"CH-2,1:SE-ULAW:SBF-1:DF-ARRAY");	    break;	}	/* open both files */	if ((sp_inter=sp_open(EX6,"r")) == SPNULL) {	    fprintf(spfp,"   sp_open: spopen for interleaved read of ");	    fprintf(spfp,"file '%s' failed\n",EX6);	    sp_print_return_status(spfp);	    goto FATAL_QUIT;	}	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);

⌨️ 快捷键说明

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