📄 tsphere.c
字号:
#include <stdio.h>#include <math.h>#include <string.h>#define SPHERE_PRE_2_2 #include <sp/sphere.h>#include <util/hsgetopt.h>#include <util/memory.h>#if defined(NARCH_SUN) || defined(NARCH_HP) /* cth */#include <sys/types.h>#include <netinet/in.h>#endif#define EX1_10_BASE "ex1_10.wav"#define EX1_01_BASE "ex1_01.wav"#define EX1_10_WAVPACK_BASE "ex1_10wp.wav"#define EX1_10_SHORTEN_BASE "ex1_10st.wav"#define EX1_10_SHORTPACK_BASE "ex1_10sh.wav"#define EX1_01_WAVPACK_BASE "ex1_01wp.wav"#define EX1_01_SHORTEN_BASE "ex1_01st.wav"#define EX1_01_SHORTPACK_BASE "ex1_01sh.wav"#define EX2_10_BASE "ex2_10.wav"#define EX2_10_BASE "ex2_10.wav"#define EX2_01_BASE "ex2_01.wav"#define EX2_10_WAVPACK_BASE "ex2_10wp.wav"#define EX2_10_SHORTEN_BASE "ex2_10st.wav"#define EX2_01_WAVPACK_BASE "ex2_01wp.wav"#define EX2_01_SHORTEN_BASE "ex2_01st.wav"#define EX4_ULAW_BASE "ex4.wav"#define EX4_ULAW_WAVPACK_BASE "ex4_wp.wav"#define EX4_ULAW_SHORTEN_BASE "ex4_sh.wav"#define EX4_ULAW_10_BASE "ex4_10.wav"#define EX4_ULAW_01_BASE "ex4_01.wav"#define EX5_ULAW_2CHAN_BASE "ex5.wav"#define EX5_ULAW_2CHAN_PCM_BASE "ex5_p.wav"#define EX5_ULAW_2CHAN_PCM_01_BASE "ex5_p01.wav"#define EX5_ULAW_2CHAN_PCM_SHORTEN_BASE "ex5_p_sh.wav"#define EX5_ULAW_2CHAN_PCM_WAVPACK_BASE "ex5_p_wp.wav"#define EX5_ULAW_2CHAN_WAVPACK_BASE "ex5_wp.wav"#define EX5_ULAW_2CHAN_SHORTEN_BASE "ex5_sh.wav"#define EX5_ULAW_CHAN1_BASE "ex5_c1.wav"#define EX5_ULAW_CHAN1_PCM_BASE "ex5_c1_p.wav"#define EX5_ULAW_CHAN2_BASE "ex5_c2.wav"#define EX5_ULAW_CHAN2_PCM_BASE "ex5_c2_p.wav"#define EX5_ULAW_CHAN12_BASE "ex5_12.wav"#define EX5_ULAW_CHAN12_PCM_BASE "ex5_12_p.wav"#define EX6_BASE "ex6.wav"char EX1_10[256], EX1_01[256], EX1_10_WAVPACK[256];char EX1_10_SHORTEN[256], EX1_01_WAVPACK[256], EX1_01_SHORTEN[256];char EX1_10_SHORTPACK[256], EX1_01_SHORTPACK[256];char EX2_10[256], EX2_01[256], EX2_10_WAVPACK[256];char EX2_10_SHORTEN[256], EX2_01_WAVPACK[256], EX2_01_SHORTEN[256];char EX4_ULAW[256], EX4_ULAW_10[256], EX4_ULAW_01[256];char EX4_ULAW_SHORTEN[256], EX4_ULAW_WAVPACK[256];char EX5_2CHAN[256], EX5_2CHAN_SHORTEN[256], EX5_2CHAN_WAVPACK[256];char EX5_CHAN1[256], EX5_CHAN2[256];char EX5_2CHAN_PCM[256], EX5_CHAN1_PCM[256], EX5_CHAN2_PCM[256];char EX5_2CHAN_PCM_SHORTEN[256], EX5_2CHAN_PCM_WAVPACK[256];char EX5_CHAN12[256], EX5_CHAN12_PCM[256], EX5_2CHAN_PCM_01[256];char EX6[256];/* function prototypes */void header_test(void);void doc_example_2_test(void);void doc_example_4_test(void);void ulaw_test(void);void converted_read_check(char *, char *, char *);void two_channel_test(void);int perform_2_channel_write_test(char *, char *, char *, char *);int perform_2_channel_read_test(char *, char *, char *, char *);void large_file_test(void);void do_large_file_conversion(char *, char *, char *);void make_test_file(char *, int, char *);void write_required_field_test(void);void write_check_adding_fields(char *, char *);void write_check_adding_fields_test(void);void update_test(void);void header_update(char *, int);void waveform_update(char *, char *, char *);void checksum_pre_post_verification(void);void pre_read_check(char *);void post_write_check(char *);void print_usage(void);void build_example_file_names(char *);void mult_channel_raw_data_test(void);void selective_channel_test(void);int do_selective_read_test(char *, char *, char *, char *, int);void array_access_tests(void);int write_with_array_access(char *, char *, char *, int);int verify_checksum_computations(void);#ifndef M_PI#define M_PI 3.14159265358979323846#endif#define COPY "cp"void print_usage(void) { fprintf(spfp, "Usage: tsphere -[vmMeh] [-l iterations] [ -[bf] n ] -d sphere_lib_dir\n");}int warning = 0;int main(int argc, char **argv){ char *sphere_lib_dir="."; int c,l,loop=1,start_test=0,final_test=100; char *prog; prog = strrchr(argv[0],'/'); prog = (prog == CNULL) ? argv[0] : (prog + 1); while (( c=hs_getopt( argc, argv, "d:l:b:f:hvmMe" )) != -1 ) switch ( c ) { case 'd': sphere_lib_dir = hs_optarg; break; case 'v': sp_verbose ++; break; case 'l': loop = atoi(hs_optarg); break; case 'b': start_test = atoi(hs_optarg); break; case 'f': final_test = atoi(hs_optarg); break; case 'm': mtrf_set_dealloc(0); mtrf_set_verbose(1); break; case 'M': mtrf_set_dealloc(1); mtrf_set_verbose(1); break; case 'e': set_error_util_debug(1); break; case 'h': print_usage(); exit(0); default: print_usage(); fprintf(spfp,"Illegal argument: %c\n",c); exit(100); } fprintf(spfp,"%s: %s\n\n",prog,sp_get_version()); if (hs_optind != argc){ print_usage(); exit(100); } hs_resetopt(); build_example_file_names(sphere_lib_dir); for (l=0; l!=loop; l++){ if (loop != 1) fprintf(spfp, "************* Beginning Iteration %d ************\n\n", l+1); if (start_test <= 0 && final_test >= 0) header_test(); if (start_test <= 1 && final_test >= 1) checksum_pre_post_verification(); if (start_test <= 2 && final_test >= 2) write_required_field_test(); if (start_test <= 3 && final_test >= 3) write_check_adding_fields_test(); if (start_test <= 4 && final_test >= 4) verify_checksum_computations(); if (start_test <= 5 && final_test >= 5) update_test(); if (start_test <= 6 && final_test >= 6) large_file_test(); if (start_test <= 7 && final_test >= 7) ulaw_test(); if (start_test <= 8 && final_test >= 8) two_channel_test(); if (start_test <= 9 && final_test >= 9) mult_channel_raw_data_test(); if (start_test <= 10 && final_test >= 10) doc_example_2_test(); if (start_test <= 11 && final_test >= 11) doc_example_4_test(); if (start_test <= 12 && final_test >= 12) selective_channel_test(); if (start_test <= 13 && final_test >= 13) array_access_tests(); #ifdef SUN if (malloc_verify() == 0){ fprintf(spfp,"****** all tests completed BUT THE MEMORY HEAP"); fprintf(spfp,"IS TRASHED ******\n"); }#endif } if (warning > 0) fprintf(spfp, "******* There were %d non-fatal warnings *******\n",warning); fprintf(spfp,"******* ALL TESTS SUCCESSFULLY COMPLETED *******\n"); exit(0);}void build_example_file_names(char *sphere_lib_dir){ sprintf(EX1_10, "%s/%s", sphere_lib_dir,EX1_10_BASE); sprintf(EX1_01, "%s/%s", sphere_lib_dir,EX1_01_BASE); sprintf(EX1_10_WAVPACK, "%s/%s", sphere_lib_dir, EX1_10_WAVPACK_BASE); sprintf(EX1_10_SHORTEN, "%s/%s", sphere_lib_dir, EX1_10_SHORTEN_BASE); sprintf(EX1_10_SHORTPACK, "%s/%s", sphere_lib_dir, EX1_10_SHORTPACK_BASE); sprintf(EX1_01_WAVPACK, "%s/%s", sphere_lib_dir, EX1_01_WAVPACK_BASE); sprintf(EX1_01_SHORTEN, "%s/%s", sphere_lib_dir, EX1_01_SHORTEN_BASE); sprintf(EX1_01_SHORTPACK, "%s/%s", sphere_lib_dir, EX1_01_SHORTPACK_BASE); sprintf(EX2_10, "%s/%s", sphere_lib_dir,EX2_10_BASE); sprintf(EX2_10_WAVPACK, "%s/%s", sphere_lib_dir, EX2_10_WAVPACK_BASE); sprintf(EX2_10_SHORTEN, "%s/%s", sphere_lib_dir, EX2_10_SHORTEN_BASE); sprintf(EX2_01, "%s/%s", sphere_lib_dir,EX2_01_BASE); sprintf(EX2_01_WAVPACK, "%s/%s", sphere_lib_dir, EX2_01_WAVPACK_BASE); sprintf(EX2_01_SHORTEN, "%s/%s", sphere_lib_dir, EX2_01_SHORTEN_BASE); sprintf(EX4_ULAW, "%s/%s", sphere_lib_dir,EX4_ULAW_BASE); sprintf(EX4_ULAW_WAVPACK, "%s/%s", sphere_lib_dir, EX4_ULAW_WAVPACK_BASE); sprintf(EX4_ULAW_SHORTEN, "%s/%s", sphere_lib_dir, EX4_ULAW_SHORTEN_BASE); sprintf(EX4_ULAW_10, "%s/%s", sphere_lib_dir,EX4_ULAW_10_BASE); sprintf(EX4_ULAW_01, "%s/%s", sphere_lib_dir,EX4_ULAW_01_BASE); sprintf(EX5_2CHAN, "%s/%s", sphere_lib_dir,EX5_ULAW_2CHAN_BASE); sprintf(EX5_2CHAN_PCM, "%s/%s", sphere_lib_dir, EX5_ULAW_2CHAN_PCM_BASE); sprintf(EX5_2CHAN_PCM_01, "%s/%s", sphere_lib_dir, EX5_ULAW_2CHAN_PCM_01_BASE); sprintf(EX5_2CHAN_PCM_SHORTEN, "%s/%s", sphere_lib_dir, EX5_ULAW_2CHAN_PCM_SHORTEN_BASE); sprintf(EX5_2CHAN_PCM_WAVPACK, "%s/%s", sphere_lib_dir, EX5_ULAW_2CHAN_PCM_WAVPACK_BASE); sprintf(EX5_2CHAN_WAVPACK, "%s/%s", sphere_lib_dir, EX5_ULAW_2CHAN_WAVPACK_BASE); sprintf(EX5_2CHAN_SHORTEN, "%s/%s", sphere_lib_dir, EX5_ULAW_2CHAN_SHORTEN_BASE); sprintf(EX5_CHAN1, "%s/%s", sphere_lib_dir,EX5_ULAW_CHAN1_BASE); sprintf(EX5_CHAN1_PCM, "%s/%s", sphere_lib_dir, EX5_ULAW_CHAN1_PCM_BASE); sprintf(EX5_CHAN2, "%s/%s", sphere_lib_dir,EX5_ULAW_CHAN2_BASE); sprintf(EX5_CHAN2_PCM, "%s/%s", sphere_lib_dir, EX5_ULAW_CHAN2_PCM_BASE); sprintf(EX5_CHAN12, "%s/%s", sphere_lib_dir,EX5_ULAW_CHAN12_BASE); sprintf(EX5_CHAN12_PCM, "%s/%s", sphere_lib_dir, EX5_ULAW_CHAN12_PCM_BASE); sprintf(EX6, "%s/%s", sphere_lib_dir,EX6_BASE);}int verify_checksum_computations(void){ char *proc="check_checksum " SPHERE_VERSION_STR; SP_CHECKSUM comp_chksm, comp_chksm1, sum_chksm; static SP_CHECKSUM ex_arr[100] = { 0, 17, 51, 102, 170, 255, 357, 476, 612, 765, 935, 1122, 1326, 1547, 1785, 2040, 2312, 2601, 2907, 3230, 3570, 3927, 4301, 4692, 5100, 5525, 5967, 6426, 6902, 7395, 7905, 8432, 8976, 9537, 10115, 10710, 11322, 11951, 12597, 13260, 13940, 14637, 15351, 16082, 16830, 17595, 18377, 19176, 19992, 20825, 21675, 22542, 23426, 24327, 25245, 26180, 27132, 28101, 29087, 30090, 31110, 32147, 33201, 34272, 35360, 36465, 37587, 38726, 39882, 41055, 42245, 43452, 44676, 45917, 47175, 48450, 49742, 51051, 52377, 53720, 55080, 56457, 57851, 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,"-- Waveform checksum calculation tests:\n"); if (sizeof(long) <= 2) fprintf(spfp,"Proc %s: Long int is only %d bytes, >2 needed\n", proc,sizeof(long)); if (sizeof(short) != 2) fprintf(spfp,"Proc %s: short int is only %d 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(void){ 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,"-- Array access to waveform tests:\n"); /* 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -