tsphere.c
来自「speech signal process tools」· C语言 代码 · 共 1,240 行 · 第 1/3 页
C
1,240 行
waveform_update(EXAMPLE1_10_WAVPACK,"SE-PCM:SBF-10",EXAMPLE1_10); waveform_update(EXAMPLE1_10_WAVPACK,"SE-PCM:SBF-01",EXAMPLE1_01); waveform_update(EXAMPLE1_10_SHORTPACK,"SE-SHORTEN:SBF-10",EXAMPLE1_10_SHORTEN); waveform_update(EXAMPLE1_10_SHORTPACK,"SE-SHORTEN:SBF-01",EXAMPLE1_01_SHORTEN); waveform_update(EXAMPLE1_10_SHORTPACK,"SE-WAVPACK:SBF-10",EXAMPLE1_10_WAVPACK); waveform_update(EXAMPLE1_10_SHORTPACK,"SE-WAVPACK:SBF-01",EXAMPLE1_01_WAVPACK); waveform_update(EXAMPLE1_10_SHORTPACK,"SE-PCM:SBF-10",EXAMPLE1_10); waveform_update(EXAMPLE1_10_SHORTPACK,"SE-PCM:SBF-01",EXAMPLE1_01); waveform_update(EXAMPLE1_01_SHORTEN,"SE-SHORTEN:SBF-01",EXAMPLE1_01_SHORTEN); waveform_update(EXAMPLE1_01_SHORTEN,"SE-SHORTEN:SBF-10",EXAMPLE1_10_SHORTEN); waveform_update(EXAMPLE1_01_SHORTEN,"SE-WAVPACK:SBF-10",EXAMPLE1_10_WAVPACK); waveform_update(EXAMPLE1_01_SHORTEN,"SE-WAVPACK:SBF-01",EXAMPLE1_01_WAVPACK); waveform_update(EXAMPLE1_01_SHORTEN,"SE-PCM:SBF-10",EXAMPLE1_10); waveform_update(EXAMPLE1_01_SHORTEN,"SE-PCM:SBF-01",EXAMPLE1_01); waveform_update(EXAMPLE1_01_WAVPACK,"SE-WAVPACK:SBF-01",EXAMPLE1_01_WAVPACK); waveform_update(EXAMPLE1_01_WAVPACK,"SE-WAVPACK:SBF-10",EXAMPLE1_10_WAVPACK); waveform_update(EXAMPLE1_01_WAVPACK,"SE-SHORTEN:SBF-10",EXAMPLE1_10_SHORTEN); waveform_update(EXAMPLE1_01_WAVPACK,"SE-SHORTEN:SBF-01",EXAMPLE1_01_SHORTEN); waveform_update(EXAMPLE1_01_WAVPACK,"SE-PCM:SBF-10",EXAMPLE1_10); waveform_update(EXAMPLE1_01_WAVPACK,"SE-PCM:SBF-01",EXAMPLE1_01); waveform_update(EXAMPLE1_01_SHORTPACK,"SE-SHORTEN:SBF-01",EXAMPLE1_01_SHORTEN); waveform_update(EXAMPLE1_01_SHORTPACK,"SE-SHORTEN:SBF-10",EXAMPLE1_10_SHORTEN); waveform_update(EXAMPLE1_01_SHORTPACK,"SE-WAVPACK:SBF-10",EXAMPLE1_10_WAVPACK); waveform_update(EXAMPLE1_01_SHORTPACK,"SE-WAVPACK:SBF-01",EXAMPLE1_01_WAVPACK); waveform_update(EXAMPLE1_01_SHORTPACK,"SE-PCM:SBF-10",EXAMPLE1_10); waveform_update(EXAMPLE1_01_SHORTPACK,"SE-PCM:SBF-01",EXAMPLE1_01); printf("\n");}header_update(file, expand)char *file;int expand;{ char *target="speaking_mode"; char *change_target="database_id"; char *insert_target="insert_field"; SP_FILE *sp; int chg, ins, del; int added_field=0, num_to_add=30, i; printf("------ File %s\n",file); system(rsprintf("%s %s output.wav",COPY,file)); if ((sp=sp_open("output.wav","u")) == 0){ printf("Unable to open copy base file '%s' called '%s'\n",file,"output.wav"); sp_print_return_status(stdout); exit(-1); } if (sp_h_delete_field(sp,target) != 0){ printf("Can't delete field '%s' in file %s\n",target,"output.wav"); sp_print_return_status(stdout); } if (sp_h_set_field(sp,change_target,T_STRING,"foobar") != 0){ printf("Can't change field '%s' in file %s\n",change_target,"output.wav"); sp_print_return_status(stdout); } if (sp_h_set_field(sp,insert_target,T_STRING,"foobar") != 0){ printf("Can't insert field '%s' in file %s\n",insert_target,"output.wav"); sp_print_return_status(stdout); } if (expand){ for (i=0; i<num_to_add; i++) { if (sp_h_set_field(sp,rsprintf("dummy_field_%d",i),T_STRING,"Dummy field string value") != 0){ printf("Can't insert field '%s' in file %s\n",rsprintf("dummy_field_%d",i),"output.wav"); sp_print_return_status(stdout); } added_field ++; } } if (sp_close(sp) != 0) { printf(" Failed to close\n"); sp_print_return_status(stdout); exit(-1); } if (diff_waveforms("output.wav",file) != 0){ printf("Update passed, but waveforms of files '%s' and '%s' differ\n","output.wav",file); exit(-1); } if (diff_data("output.wav",file) != 0){ printf("WARNING: files '%s' and '%s' decompress to the same form,\n","output.wav",file); printf(" but are not identical on disk\n"); exit(-1); } if (diff_header(file,"output.wav",&chg,&ins,&del,0) != 0){ printf("Unable to compare headers of file '%s' and '%s'\n","output.wav",file); printf(" but are not identical on disk\n"); exit(-1); } if (! expand){ if ((del != 1) || (chg != 1) || (ins != 1)){ printf(" There should have been one field deleted, inserted and changed, but the actual status is\n"); printf(" Del: %d Ins: %d Chg: %d\n",del,ins,chg); diff_header(file,"output.wav",&chg,&ins,&del,1); exit(-1); } } else { if ((del != 1) || (chg != 1) || (ins != 1 + added_field)){ printf(" There should have been one field deleted and changed, and %d fields inserted\n",1+added_field); printf(" but the actual status is\n"); printf(" Del: %d Ins: %d Chg: %d\n",del,ins,chg); diff_header(file,"output.wav",&chg,&ins,&del,1); exit(-1); } } }waveform_update(base_file,sdm_mode,compare_file)char *base_file, *sdm_mode, *compare_file;{ SP_FILE *sp; printf("------ File: %-13s converted by: %-18s compared to file: %s\n", base_file,sdm_mode,compare_file); system(rsprintf("%s %s output.wav",COPY,base_file)); if ((sp=sp_open("output.wav","u")) == 0){ printf("Unable to open copy base file '%s' called '%s'\n",base_file,"output.wav"); sp_print_return_status(stdout); exit(-1); } if (sp_set_data_mode(sp,sdm_mode) != 0){ printf("Set data mode failed\n"); sp_print_return_status(stdout); exit(-1); } if (sp_close(sp) != 0) { printf(" Failed to close\n"); sp_print_return_status(stdout); exit(-1); } if (diff_waveforms("output.wav",compare_file) != 0){ printf("Update passed, but waveforms of files '%s' and '%s' differ\n","output.wav",compare_file); exit(-1); } if (diff_data("output.wav",compare_file) != 0){ printf("WARNING: files '%s' and '%s' decompress to the same form,\n","output.wav",compare_file); printf(" but are not identical on disk\n"); exit(-1); } unlink("output.wav");}checksum_pre_post_verification(){ printf("-- Checksum verification tests\n"); printf("---- Pre-Read Check\n"); pre_read_check(EXAMPLE1_10); pre_read_check(EXAMPLE1_01); pre_read_check(EXAMPLE1_10_WAVPACK); pre_read_check(EXAMPLE1_10_SHORTEN); pre_read_check(EXAMPLE1_01_WAVPACK); pre_read_check(EXAMPLE1_01_SHORTEN); printf("---- Post-Write Check\n"); post_write_check(EXAMPLE1_10); post_write_check(EXAMPLE1_01); post_write_check(EXAMPLE1_10_WAVPACK); post_write_check(EXAMPLE1_01_WAVPACK); post_write_check(EXAMPLE1_01_SHORTEN); post_write_check(EXAMPLE1_01_SHORTEN); printf("\n");}pre_read_check(file)char *file;{ SP_FILE *sp, *out_sp; short buff[20]; printf("------ File: %s\n",file); if ((sp = sp_open(file,"rv")) == SPNULL) { sp_print_return_status(stdout); fprintf(stdout,"Error: Unable to open file %s to reading\n",file); exit(-1); } if (sp_read_data(buff,2,10,sp) != 10){ sp_print_return_status(stdout); fprintf(stdout,"Error: Unable to pre-verify checksum in file %s\n",file); exit(-1); } sp_close(sp);}post_write_check(file)char *file;{ SP_FILE *sp, *out_sp; printf("------ File: %s\n",file); if ((sp = sp_open(file,"r")) == SPNULL) { sp_print_return_status(stdout); fprintf(stdout,"Error: Unable open input file %s\n",file); exit(-1); } sp_set_data_mode(sp,"SE-ORIG:SBF-ORIG"); if ((out_sp = sp_open("output.wav","w")) == SPNULL) { sp_print_return_status(stdout); fprintf(stdout,"Error: Unable to open SPHERE file %s\n","output.wav"); exit(-1); } if (copy_sp_header(sp,out_sp) != 0){ sp_print_return_status(stdout); exit(-1); } if (sp->read_spifr->status->file_compress != sp->read_spifr->status->user_compress){ switch (sp->read_spifr->status->file_compress){ case SP_wc_shortpack: sp_set_data_mode(out_sp,"SE-SHORTPACK:SBF-ORIG"); break; case SP_wc_wavpack: sp_set_data_mode(out_sp,"SE-WAVPACK:SBF-ORIG"); break; case SP_wc_shorten: sp_set_data_mode(out_sp,"SE-SHORTEN:SBF-ORIG"); break; } } { short buff[2048]; int ret; do { ret=sp_read_data(buff,2,1024,sp); sp_write_data(buff,2,ret,out_sp); } while (ret > 0); }/* sp_file_dump(sp,stdout); sp_file_dump(out_sp,stdout);*/ if (sp_close(sp) != 0) { fprintf(stdout," Closing of file '%s' opened for read failed\n",file); sp_print_return_status(stdout); exit(-1); } if (sp_close(out_sp) != 0) { fprintf(stdout," Closing of file '%s' opened for write failed\n",file); sp_print_return_status(stdout); if (sp_error(out_sp) == 100) fprintf(stdout," POST-WRITE CHECKSUM VERIFICATION FAILED\n"); sp_print_return_status(stdout); exit(-1); } if (diff_waveforms(file,"output.wav") != 0){ fprintf(stdout," Vefication passed, but files were not reproduced identically\n"); exit(-1); } unlink("output.wav");}int copy_sp_header(spin, spout)SP_FILE *spin, *spout;{ char *proc_name="sp_dup"; struct header_t *h; int i, n; long lint; double real; if (spin->open_mode == SP_mode_read) h = spin->read_spifr->header; else if (spin->open_mode == SP_mode_write) h = spin->write_spifr->header; else return_err(proc_name,100,100,"Unable to dup header opened for update"); /* just loop through all the names, adding each field */ for (i=0; i < h->fc ; i++){ switch (h->fv[i]->type){ case T_STRING: if (sp_h_set_field(spout,h->fv[i]->name,h->fv[i]->type,h->fv[i]->data) != 0) return_err(proc_name,200,200,rsprintf("Unable to copy STRING field '%s'",h->fv[i]->name)); break; case T_INTEGER: lint=atol(h->fv[i]->data); if (sp_h_set_field(spout,h->fv[i]->name,h->fv[i]->type,&lint) != 0) return_err(proc_name,200,200,rsprintf("Unable to copy INTEGER field '%s'",h->fv[i]->name)); break; case T_REAL: real=atof(h->fv[i]->data); if (sp_h_set_field(spout,h->fv[i]->name,h->fv[i]->type,&real) != 0) return_err(proc_name,200,200,rsprintf("Unable to copy REAL field '%s'",h->fv[i]->name)); break; } } if (sp_set_default_operations(spout) != 0) return_err(proc_name,300,300,"Unable to set default operations duplicated file"); return_success(proc_name,0,0,"ok");}header_test(){ SP_FILE *sp; char filename[100]; short *waveform; int wave_byte_size, total_samples, rtn; char *str; long i, lint; double real, f; printf("-- Write Mode header operations:\n"); system("rm -f testing.wav"); if ((sp=sp_open("testing.wav","w")) == SPNULL) { printf(" sp_open: Valid write open failed\n"); 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); } lint=1; free(str); 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");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?