tsphere.c
来自「speech signal process tools」· C语言 代码 · 共 1,240 行 · 第 1/3 页
C
1,240 行
sp_print_return_status(stdout); } printf("------ Verifying 3 header fields\n"); if ((sp->write_spifr->header->fc != 3) || (sp->write_spifr->status->file_header->fc != 3)){ printf("***************************************************\n"); printf("* The following header should have three fields *\n"); printf("***************************************************\n"); sp_file_dump(sp,stdout); exit(-1); } printf("------ Illegal Field Deletion:\n"); if ((rtn=sp_h_delete_field(SPNULL,"field1")) < 100){ printf(" sp_h_delete_field: Invalid Deletion, SPNULL, failed\n"); sp_print_return_status(stdout); } if ((rtn=sp_h_delete_field(sp,CNULL)) < 100){ printf(" sp_h_delete_field: Invalid Deletion, Field name NULL, failed\n"); sp_print_return_status(stdout); } if (((rtn=sp_h_delete_field(sp,"field84")) == 0) && (rtn >= 100)){ printf(" sp_h_delete_field: Invalid Deletion, field already deleted, failed\n"); sp_print_return_status(stdout); } printf("------ Legal Field Deletion:\n"); if ((rtn=sp_h_delete_field(sp,"field1")) != 0){ printf(" sp_h_delete_field: Valid STRING Deletion failed\n"); sp_print_return_status(stdout); } if ((rtn=sp_h_delete_field(sp,"field2")) != 0){ printf(" sp_h_delete_field: Valid INTEGER Deletion failed\n"); sp_print_return_status(stdout); } if ((rtn=sp_h_delete_field(sp,"field3")) != 0){ printf(" sp_h_delete_field: Valid REAL Deletion failed\n"); sp_print_return_status(stdout); } printf("------ Verifying an empty header\n"); if ((sp->write_spifr->header->fc != 0) || (sp->write_spifr->status->file_header->fc != 0)){ printf("***************************************************\n"); printf("* The following header should be empty *\n"); printf("***************************************************\n"); sp_file_dump(sp,stdout); exit(-1); } sp_close(sp); system("rm -f testing.wav"); printf("\n"); printf("-- Read Mode header operations:\n"); if ((sp=sp_open(EXAMPLE1_10,"r")) == SPNULL) { printf(" sp_open: Valid spopen for read of file '%s' failed\n",EXAMPLE1_10); sp_print_return_status(stdout); exit(-1); } printf("---- Testing the file header io:\n"); printf("------ Field creation:\n"); if (sp_h_set_field(SPNULL,"field1",T_STRING,"char string 1") == 0) printf(" sp_h_set_field: Null SPFILE pointer failed\n"); if (sp_h_set_field(sp,CNULL,T_STRING,"char string 1") == 0) printf(" sp_h_set_field: Null field name failed\n"); if (sp_h_set_field(sp,"field1",4930,"char string 1") == 0) printf(" sp_h_set_field: Invalid field type failed\n"); if (sp_h_set_field(sp,"field1",T_STRING,CNULL) == 0) printf(" sp_h_set_field: Null value failed\n"); if (sp_h_set_field(sp,"field1",T_STRING,"string value1") != 0){ printf(" sp_h_set_field: valid STRING command failed\n"); sp_print_return_status(stdout); } lint=1; if (sp_h_set_field(sp,"field2",T_INTEGER,&lint) != 0){ printf(" sp_h_set_field: valid INTEGER command failed\n"); sp_print_return_status(stdout); exit(-1); } real=2.0; if (sp_h_set_field(sp,"field3",T_REAL,&real) != 0){ printf(" sp_h_set_field: valid REAL command failed\n"); sp_print_return_status(stdout); } printf("------ Field access:\n"); if (sp_h_get_field(sp,"field1",T_STRING,&str) != 0){ printf(" sp_h_get_field: valid STRING command failed\n"); sp_print_return_status(stdout); } mtrf_free(str); lint=1; if (sp_h_get_field(sp,"field2",T_INTEGER,&lint) != 0){ printf(" sp_h_get_field: valid INTEGER command failed\n"); sp_print_return_status(stdout); exit(-1); } real=2.0; if ((rtn=sp_h_get_field(sp,"field3",T_REAL,&real)) != 0){ printf(" sp_h_get_field: valid REAL command returned %d and failed\n",rtn); sp_print_return_status(stdout); } printf("------ Illegal Field access:\n"); if ((rtn=sp_h_get_field(SPNULL,"field3",T_REAL,&real)) < 100){ printf(" sp_h_get_field: Invalid REAL command, SPNULL, returned %d and failed\n",rtn); sp_print_return_status(stdout); } if ((rtn=sp_h_get_field(sp,CNULL,T_REAL,&real)) < 100){ printf(" sp_h_get_field: Invalid REAL command, Field NULL, returned %d and failed\n",rtn); sp_print_return_status(stdout); } if ((rtn=sp_h_get_field(sp,"field3",6,&real)) < 100){ printf(" sp_h_get_field: Invalid REAL command, Bad Type, returned %d and failed\n",rtn); sp_print_return_status(stdout); } if ((rtn=sp_h_get_field(sp,"field3",T_REAL,CNULL)) < 100){ printf(" sp_h_get_field: Invalid REAL command, Null value pointer, returned %d and failed\n",rtn); sp_print_return_status(stdout); } if ((rtn=sp_h_get_field(sp,"field3",T_INTEGER,&real)) < 100){ printf(" sp_h_get_field: Invalid REAL command Accessed as an INTEGER returned %d and failed\n",rtn); sp_print_return_status(stdout); } if ((rtn=sp_h_get_field(sp,"field3",T_STRING,&real)) < 100){ printf(" sp_h_get_field: Invalid REAL command Accessed as an STRING returned %d and failed\n",rtn); sp_print_return_status(stdout); } if ((rtn=sp_h_get_field(sp,"field2",T_STRING,&lint)) < 100){ printf(" sp_h_get_field: Invalid INTEGER command accessed as a STRING failed\n"); sp_print_return_status(stdout); } if ((rtn=sp_h_get_field(sp,"field2",T_REAL,&lint)) < 100){ printf(" sp_h_get_field: Invalid INTEGER command accessed as a REAL failed\n"); sp_print_return_status(stdout); } if (sp_h_get_field(sp,"field1",T_REAL,&str) < 100){ printf(" sp_h_get_field: Invalid STRING command accessed as a REAL failed\n"); sp_print_return_status(stdout); } if (sp_h_get_field(sp,"field1",T_INTEGER,&str) < 100){ printf(" sp_h_get_field: Invalid STRING command accessed as a INTEGER failed\n"); sp_print_return_status(stdout); } printf("------ Illegal Field Deletion:\n"); if ((rtn=sp_h_delete_field(SPNULL,"field1")) < 100){ printf(" sp_h_delete_field: Invalid Deletion, SPNULL, failed\n"); sp_print_return_status(stdout); } if ((rtn=sp_h_delete_field(sp,CNULL)) < 100){ printf(" sp_h_delete_field: Invalid Deletion, Field name NULL, failed\n"); sp_print_return_status(stdout); } if (((rtn=sp_h_delete_field(sp,"field84")) == 0) && (rtn >= 100)){ printf(" sp_h_delete_field: Invalid Deletion, field already deleted, failed\n"); sp_print_return_status(stdout); } printf("------ Legal Field Deletion:\n"); if ((rtn=sp_h_delete_field(sp,"field1")) != 0){ printf(" sp_h_delete_field: Valid STRING Deletion failed\n"); sp_print_return_status(stdout); } if ((rtn=sp_h_delete_field(sp,"field2")) != 0){ printf(" sp_h_delete_field: Valid INTEGER Deletion failed\n"); sp_print_return_status(stdout); } if ((rtn=sp_h_delete_field(sp,"field3")) != 0){ printf(" sp_h_delete_field: Valid REAL Deletion failed\n"); sp_print_return_status(stdout); } printf("\n"); sp_close(sp);}diff_files(file1,file2)char *file1, *file2;{ FILE *fp1, *fp2; char c1, c2; fp1 = fopen(file1, "r"); fp2 = fopen(file2, "r"); do { c1 = fgetc(fp1); c2 = fgetc(fp2); if (c1 != c2){ fclose(fp1); fclose(fp2); return(100); } } while (!feof(fp1)); if (!feof(fp2)){ fclose(fp1); fclose(fp2); return(100); } fclose(fp1); fclose(fp2); return(0);}diff_data(file1,file2)char *file1, *file2;{ FILE *fp1, *fp2; struct header_t *h1, *h2; char c1, c2, *errmsg; fp1 = fopen(file1, "r"); fp2 = fopen(file2, "r"); if ((h1 = sp_open_header(fp1,TRUE,&errmsg)) == HDRNULL){ printf("diff_data: Unable to open SPHERE header for file %s\n",file2); exit(-1); } if ((h2 = sp_open_header(fp2,TRUE,&errmsg)) == HDRNULL){ printf("diff_data: Unable to open SPHERE header for file %s\n",file2); exit(-1); } do { c1 = fgetc(fp1); c2 = fgetc(fp2); if (c1 != c2){ fclose(fp1); fclose(fp2); return(100); } } while (!feof(fp1)); if (!feof(fp2)){ sp_close_header(h1); sp_close_header(h2); fclose(fp1); fclose(fp2); return(100); } sp_close_header(h1); sp_close_header(h2); fclose(fp1); fclose(fp2); return(0);}diff_header(file1,file2,chg,ins,del,verbose)char *file1, *file2;int *chg, *ins, *del;int verbose;{ FILE *fp1, *fp2; struct header_t *h1, *h2; char c1, c2, *errmsg; int i1, i2, found; *chg = *ins = *del = 0; fp1 = fopen(file1, "r"); fp2 = fopen(file2, "r"); if ((h1 = sp_open_header(fp1,TRUE,&errmsg)) == HDRNULL){ printf("diff_data: Unable to open SPHERE header for file %s\n",file2); exit(-1); } if ((h2 = sp_open_header(fp2,TRUE,&errmsg)) == HDRNULL){ printf("diff_data: Unable to open SPHERE header for file %s\n",file2); exit(-1); } for (i1=0 ;i1 < h1->fc; i1++) { found=0; for (i2=0 ;i2 < h2->fc; i2++) { if (strsame(h1->fv[i1]->name,h2->fv[i2]->name)) { found=1; if (h1->fv[i1]->type != h2->fv[i2]->type){ if (verbose) printf(" Changed field '%s' type %d -> %d\n", h1->fv[i1]->name,h1->fv[i1]->type,h2->fv[i2]->type); *chg += 1; continue; } else { if (! strsame(h1->fv[i1]->data,h2->fv[i2]->data)){ if (strsame(h1->fv[i1]->name,SAMPLE_CODING_FIELD) && (strncmp(h1->fv[i1]->data,h2->fv[i2]->data,20) == 0)) ; else { if (verbose) printf(" Changed field '%s' value %s -> %s\n", h1->fv[i1]->name,h1->fv[i1]->data,h2->fv[i2]->data); *chg += 1; } } continue; } } } if (found == 0){ if (verbose) printf(" Deleted field %s\n",h1->fv[i1]->name); *del += 1; } } for (i2=0 ;i2 < h2->fc; i2++) { found=0; for (i1=0 ;found==0 && i1 < h1->fc; i1++) { if (strsame(h1->fv[i1]->name,h2->fv[i2]->name)) found=1; } if (found == 0){ if (verbose) printf(" Inserted field %s\n",h2->fv[i2]->name); *ins += 1; } } sp_close_header(h1); sp_close_header(h2); fclose(fp1); fclose(fp2); return(0);}diff_waveforms(file1,file2)char *file1, *file2;{ SP_FILE *sp1, *sp2; short buff1[512], buff2[512]; int n1, n2, i, samp=0, fail=0; if ((sp1 = sp_open(file1, "r")) == SPNULL){ fail=1; fprintf(stdout,"DIFFERENT WAVEFORM: files %s and %s\n",file1,file2); fprintf(stdout,"sp_open failed on file %s\n",file1); sp_print_return_status(stdout); } if ((sp2 = sp_open(file2, "r")) == SPNULL){ if (fail == 0) fprintf(stdout,"DIFFERENT WAVEFORM: files %s and %s\n",file1,file2); fail=1; fprintf(stdout,"sp_open failed on file %s\n",file2); sp_print_return_status(stdout); } if (fail == 1){ if (sp1 != SPNULL) sp_close(sp1); if (sp2 != SPNULL) sp_close(sp2); exit(-1); } do { n1 = sp_read_data((char *)buff1,2,512,sp1); n2 = sp_read_data((char *)buff2,2,512,sp2); if (n1 != n2){ fprintf(stdout,"DIFFERENT WAVEFORM: files %s and %s\n",file1,file2); fprintf(stdout," Beginning sample: %d\n",samp); fprintf(stdout," %d samples read from %s\n",n1,file1); fprintf(stdout," %d samples read from %s\n",n2,file2); sp_close(sp1); sp_close(sp2); return(100); } for (i=0; i<n1; i++, samp++) if (buff1[i] != buff2[i]){ fprintf(stdout,"DIFFERENT WAVEFORM: files %s and %s\n",file1,file2); fprintf(stdout," Sample discrepancy: %d\n",samp); sp_close(sp1); sp_close(sp2); return(100); } } while (!sp_eof(sp1)); if (!sp_eof(sp2)){ fprintf(stdout,"DIFFERENT WAVEFORM: files %s and %s\n",file1,file2); fprintf(stdout," file %s not at eof\n",file2); sp_close(sp1); sp_close(sp2); return(100); } sp_close(sp1); sp_close(sp2); return(0);}update_sphere_file(filein, format_conversion)char *filein, *format_conversion;{ SP_FILE *sp; if ((sp=sp_open(filein,"u")) == SPNULL){ sp_print_return_status(stdout); fprintf(stdout,"Unable to open file '%s' to update\n",filein); return(100); } if (sp_set_data_mode(sp,format_conversion) != 0){ sp_print_return_status(stdout); fprintf(stdout,"Unable to set data mode to '%s'\n",format_conversion); sp_close(sp); return(100); } if (sp_close(sp) != 0){ sp_print_return_status(stdout); fprintf(stdout,"File Close failed\n"); return(100); } return(0);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?