📄 tsphere.c
字号:
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(int test){ fprintf(spfp,"Test %2d: Selective Channel testing\n",test); 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(int test){ SP_FILE *sp; SP_INTEGER bps, nc=MC_CHAN, sc=MC_BUFS, sr=8000, r_nc, r_bps, r_sc; int c,s,cc,failure,rtn; char *out_file="testing.wav"; double factor; int ntypes=5, cur_type; union{ short **b_short; int **b_int; long **b_long; float **b_float; double **b_double; } buf; union{ short *b_short; int *b_int; long *b_long; float *b_float; double *b_double; } time_samp; char *types[5]; types[0] = "short"; types[1] = "int"; types[2] = "long"; types[3] = "float"; types[4] = "double"; fprintf(spfp,"Test %2d: Write of a multichannel data with varying types\n",test); for (cur_type=0; cur_type<ntypes; cur_type++){ switch (cur_type){ case 0: bps=sizeof(short); break; case 1: bps=sizeof(int); break; case 2: bps=sizeof(long); break; case 3: bps=sizeof(float); break; case 4: bps=sizeof(double); break; } fprintf(spfp,"---- using type '%s', %ld bytes ",types[cur_type],bps); fprintf(spfp,"per sample, %ld channels, %ld samples\n",nc,sc); /* set the byte size and allocate memory for the buffers */ switch (cur_type){ case 0: alloc_2dimarr(buf.b_short,nc,sc,short); alloc_singarr(time_samp.b_short,nc,short); break; case 1: alloc_2dimarr(buf.b_int,nc,sc,int); alloc_singarr(time_samp.b_int,nc,int); break; case 2: alloc_2dimarr(buf.b_long,nc,sc,long); alloc_singarr(time_samp.b_long,nc,long); break; case 3: alloc_2dimarr(buf.b_float,nc,sc,float); alloc_singarr(time_samp.b_float,nc,float); break; case 4: alloc_2dimarr(buf.b_double,nc,sc,double); alloc_singarr(time_samp.b_double,nc,double); break; } /* load the values in the buffer */ for (c=0; c<MC_CHAN; c++){ factor = 1.0 / ((c+1) * 10.0 ); switch (cur_type){ case 0: for (s=0; s<MC_BUFS; s++) buf.b_short[c][s] = (short)((c+1) * 10 * cos( M_PI * 2.0 * s * factor)); break; case 1: for (s=0; s<MC_BUFS; s++) buf.b_int[c][s] = (int)((c+1) * 10 * cos( M_PI * 2.0 * s * factor)); break; case 2: for (s=0; s<MC_BUFS; s++) buf.b_long[c][s] = (long)((c+1) * 10 * cos( M_PI * 2.0 * s * factor)); break; case 3: for (s=0; s<MC_BUFS; s++) buf.b_float[c][s] = (float)((c+1) * 10 * cos( M_PI * 2.0 * s * factor)); break; case 4: for (s=0; s<MC_BUFS; s++) buf.b_double[c][s] = (double)((c+1) * 10 * cos( M_PI * 2.0 * s * factor)); break; } } /* open a sphere file to write out to */ if ((sp=sp_open(out_file,"w")) == SPNULL) { fprintf(spfp," sp_open failed for file '%s' opened for write\n", out_file); sp_print_return_status(spfp); exit(-1); } /* set up the header */ /* set the channel count */ if (sp_h_set_field(sp,CHANNEL_COUNT_FIELD,T_INTEGER,(void *)&nc) != 0){ fprintf(spfp," sp_h_set_fielcase d: failed on field '%s'\n", CHANNEL_COUNT_FIELD); sp_print_return_status(spfp); exit(-1); } /* set the sample_n_bytes */ if (sp_h_set_field(sp,SAMPLE_N_BYTES_FIELD,T_INTEGER,(void *)&bps)!=0){ fprintf(spfp," sp_h_set_field: failed on field '%s'\n", SAMPLE_N_BYTES_FIELD); sp_print_return_status(spfp); exit(-1); } /* set the sample_count */ if (sp_h_set_field(sp,SAMPLE_COUNT_FIELD,T_INTEGER,(void *)&sc) != 0){ fprintf(spfp," sp_h_set_field: failed on field '%s'\n", SAMPLE_COUNT_FIELD); sp_print_return_status(spfp); exit(-1); } /* set the sample_rate */ if (sp_h_set_field(sp,SAMPLE_RATE_FIELD,T_INTEGER,(void *)&sr) != 0){ fprintf(spfp," sp_h_set_field: failed on field '%s'\n", SAMPLE_RATE_FIELD); sp_print_return_status(spfp); exit(-1); } /* set the sample_coding */ if (sp_h_set_field(sp,SAMPLE_CODING_FIELD,T_STRING,(void *)"raw") !=0){ fprintf(spfp," sp_h_set_field: failed on field '%s'\n", SAMPLE_CODING_FIELD); sp_print_return_status(spfp); exit(-1); } /* write the data to the file, INTERLEAVED!!!!! */ for (s=0; s<MC_BUFS; s++){ switch (cur_type){ case 0: for (c=0; c<MC_CHAN; c++) time_samp.b_short[c] = buf.b_short[c][s]; rtn = sp_write_data((void *)time_samp.b_short,bps,1,sp); break; case 1: for (c=0; c<MC_CHAN; c++) time_samp.b_int[c] = buf.b_int[c][s]; rtn = sp_write_data((void *)time_samp.b_int,bps,1,sp); break; case 2: for (c=0; c<MC_CHAN; c++) time_samp.b_long[c] = buf.b_long[c][s]; rtn = sp_write_data((void *)time_samp.b_long,bps,1,sp); break; case 3: for (c=0; c<MC_CHAN; c++) time_samp.b_float[c] = buf.b_float[c][s]; rtn = sp_write_data((void *)time_samp.b_float,bps,1,sp); break; case 4: for (c=0; c<MC_CHAN; c++) time_samp.b_double[c] = buf.b_double[c][s]; rtn = sp_write_data((void *)time_samp.b_double,bps,1,sp); break; default: rtn = 0; } if (rtn != 1){ fprintf(spfp, "Error: Multichannel write failed on time sample %d\n", s); sp_print_return_status(spfp); exit(-1); } } /* Close the output file */ if (sp_close(sp) != 0){ fprintf(spfp,"Erro: Close of multichannel file failed\n"); sp_print_return_status(spfp); exit(-1); } /*** NOW Read the file back in, comparing it to the form in memory ***/ if ((sp=sp_open(out_file,"rv")) == SPNULL) { fprintf(spfp," sp_open failed for file '%s' opened for read\n", out_file); sp_print_return_status(spfp); exit(-1); } /* get the channel count */ if (sp_h_get_field(sp,CHANNEL_COUNT_FIELD,T_INTEGER,(void *)&r_nc)!=0){ fprintf(spfp," sp_h_get_field: failed on field '%s'\n", CHANNEL_COUNT_FIELD); sp_print_return_status(spfp); exit(-1); } /* get the sample_n_bytes */ if (sp_h_get_field(sp,SAMPLE_N_BYTES_FIELD,T_INTEGER,(void *)&r_bps) != 0){ fprintf(spfp," sp_h_get_field: failed on field '%s'\n", SAMPLE_N_BYTES_FIELD); sp_print_return_status(spfp); exit(-1); } /* get the sample_count */ if (sp_h_get_field(sp,SAMPLE_COUNT_FIELD,T_INTEGER,(void *)&r_sc)!= 0){ fprintf(spfp," sp_h_get_field: failed on field '%s'\n", SAMPLE_COUNT_FIELD); sp_print_return_status(spfp); exit(-1); } /* verify the header fields */ if (nc != r_nc){ fprintf(spfp,"Error: read channel_count (%ld) != expected (%ld)\n", r_nc,nc); exit(-1); } if (bps != r_bps){ fprintf(spfp,"Error: read sample_n_bytes (%ld) != expected (%ld)\n" ,r_nc,nc); exit(-1); } if (sc != r_sc){ fprintf(spfp,"Error: read sample_count (%ld) != expected (%ld)\n", r_nc,nc); exit(-1); } if (0) switch (cur_type){ case 0: buf.b_short[1][2] = 32; break; case 1: buf.b_int[1][2] = 32; break; case 2: buf.b_long[1][2] = 32; break; case 3: buf.b_float[1][2] = 32; break; case 4: buf.b_double[1][2] = 32; break; default: fprintf(spfp, "type %d not defined\n",cur_type); exit(-1); } /* loop through reading the data, verifying it against the memory */ /* version */ for (s=0; s<MC_BUFS; s++){ char *mem, *file; switch (cur_type){ case 0: file=(char *)(time_samp.b_short); break; case 1: file=(char *)(time_samp.b_int); break; case 2: file=(char *)(time_samp.b_long); break; case 3: file=(char *)(time_samp.b_float); break; case 4: file=(char *)(time_samp.b_double); break; default: fprintf(spfp, "type %d not defined\n",cur_type); exit(-1); } if (sp_read_data((void *)file,r_bps,1,sp) != 1){ fprintf(spfp, "Error: Multichannel read failed on time sample %d\n", s); sp_print_return_status(spfp); exit(-1); } for (c=0, failure=0; c<MC_CHAN; c++){ switch (cur_type){ case 0: mem = (char *)&(buf.b_short[c][s]); file=(char *)&(time_samp.b_short[c]); break; case 1: mem = (char *)&(buf.b_int[c][s]); file=(char *)&(time_samp.b_int[c]); break; case 2: mem = (char *)&(buf.b_long[c][s]); file=(char *)&(time_samp.b_long[c]); break; case 3: mem = (char *)&(buf.b_float[c][s]); file=(char *)&(time_samp.b_float[c]); break; case 4: mem = (char *)&(buf.b_double[c][s]); file=(char *)&(time_samp.b_double[c]); break; default: fprintf(spfp, "type %d not defined\n",cur_type); exit(-1); } if (memcmp(mem,file,bps)) failure = 1; } if (failure){ fprintf(spfp,"Error Multichannel failed to match"); fprintf(spfp,"memory version on sample %d\n",s); fprintf(spfp,"Memory: "); switch (cur_type){ case 0: file=(char *)(time_samp.b_short); break; case 1: file=(char *)(time_samp.b_int); break; case 2: file=(char *)(time_samp.b_long); break; case 3: file=(char *)(time_samp.b_float); break; case 4: file=(char *)(time_samp.b_double); break; default: fprintf(spfp, "type %d not defined\n",cur_type); exit(-1); } for (c=0; c<MC_CHAN; c++){ switch (cur_type){ case 0: mem = (char *)&(buf.b_short[c][s]); break; case 1: mem = (char *)&(buf.b_int[c][s]); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -