spopen.c
来自「speech signal process tools」· C语言 代码 · 共 888 行 · 第 1/3 页
C
888 行
" however the header value is", spifr->status->file_sample_n_bytes)); if (spifr->status->file_encoding == SP_se_alaw && spifr->status->file_sample_n_bytes != 1) return_err(proc,1201,1201, rsprintf("Alaw encoding requires a 1 byte sample,%s %d", " however the header value is", spifr->status->file_sample_n_bytes)); if (spifr->status->file_encoding == SP_se_pcm1 && spifr->status->file_sample_n_bytes != 1) return_err(proc,120,120, rsprintf("PCM1 encoding requires a 1 byte sample, %s %d", "however the header value is", spifr->status->file_sample_n_bytes)); if (spifr->status->file_encoding == SP_se_pcm1 && spifr->status->file_sample_n_bytes != 2) return_err(proc,120,120, rsprintf("PCM2 encoding requires a 2 byte sample, %s %d", "however the header value is", spifr->status->file_sample_n_bytes)); /********************************/ /* set up the default decodings */ if (sp->open_mode == SP_mode_read) if (sp_set_data_mode(sp,"") != 0){ print_return_status(spfp); return_err(proc,110,110, rsprintf("Unable to set up default encodings %s", "on file opened for read")); } else if (sp->open_mode == SP_mode_update) if (sp_set_data_mode(sp,"SE_ORIG:SBF_ORIG") != 0){ print_return_status(spfp); return_err(proc,111,111, "Unable to set up default encodings on file opened for update"); } if (sp_verbose > 11) fprintf(spfp,"Proc %s: Returning 0\n",proc); return_success(proc,0,0,"ok");}int parse_sample_byte_format(char *str, enum SP_sample_byte_fmt *sbf){ char *proc="parse_sample_byte_format " SPHERE_VERSION_STR; if (sp_verbose > 10) fprintf(spfp,"Proc %s:\n",proc); if (str == CNULL) return_err(proc,100,100,"Null sample_byte_format_string"); if (sbf == (enum SP_sample_byte_fmt *)0) return_err(proc,101,101,"Null sbf pointer"); if (strsame(str,"01")) *sbf = SP_sbf_01; else if (strsame(str,"10")) *sbf = SP_sbf_10; else if (strsame(str,"1")) *sbf = SP_sbf_1; else if (strsame(str,"0123")) *sbf = SP_sbf_0123; else if (strsame(str,"1032")) *sbf = SP_sbf_1032; else if (strsame(str,"2301")) *sbf = SP_sbf_2301; else if (strsame(str,"3210")) *sbf = SP_sbf_3210; else if (strsame(str,"N")) *sbf = SP_sbf_N; if (strstr(str,"shortpack") != CNULL) { /* this return value must remain 1000, other functions depend on it*/ return_err(proc,1000,1000, rsprintf("Unknown sample_byte_format value '%s' in header",str)); } if (sp_verbose > 11) fprintf(spfp,"Proc %s: Returning 0\n",proc); return_success(proc,0,0,"ok");} int parse_sample_coding(char *str, int sample_n_bytes, enum SP_sample_encoding *sample_encoding, enum SP_waveform_comp *wav_compress){ int enc_set=FALSE, comp_set=FALSE; char *pstr, *str_mem; char *proc="parse_sample_coding " SPHERE_VERSION_STR; if (sp_verbose > 10) fprintf(spfp,"Proc %s:\n",proc); if (str == CNULL) return_err(proc,101,101,"Null coding string"); if (sample_n_bytes < 1 || sample_n_bytes > 2) { /*then we are assuming the field wasn't set yet, so use the default*/ sample_n_bytes = 0; } if (sample_encoding == (enum SP_sample_encoding *)0) return_err(proc,103,103,"Null sample encoding pointer"); if (wav_compress == (enum SP_waveform_comp *)0) return_err(proc,104,104,"Null waveform compress pointer"); *wav_compress = SP_wc_null; *sample_encoding = SP_se_null; if (sp_verbose > 16) fprintf(spfp,"%s: string IS %s\n",proc,str); /* the algorithm to parse the sample encoding field is : */ /* 1: get a token before a ',' or NULL */ /* 2: set a flag to what it matches */ /* 3: move past the token */ /* 4: loop to (1) */ /* make a duplicate copy because strtok is destructive */ str_mem = mtrf_strdup(str); pstr = strtok(str_mem,","); while (pstr != CNULL){ if (sp_verbose > 16) fprintf(spfp,"%s: token found = %s\n",proc,pstr); if (strsame(pstr,"pcm")){ if (enc_set){ mtrf_free(str_mem); return_err(proc,105,105, "Multiple sample encodings in header field"); } if (sample_n_bytes == 1) *sample_encoding = SP_se_pcm1; else *sample_encoding = SP_se_pcm2; enc_set = TRUE; } else if (strsame(pstr,"ulaw") || strsame(pstr,"mu-law")) { if (enc_set){ mtrf_free(str_mem); return_err(proc,105,105, "Multiple sample encodings in header field"); } *sample_encoding = SP_se_ulaw; enc_set = TRUE; } else if (strsame(pstr,"pculaw")) { if (enc_set){ mtrf_free(str_mem); return_err(proc,105,105, "Multiple sample encodings in header field"); } *sample_encoding = SP_se_pculaw; enc_set = TRUE; } else if (strsame(pstr,"alaw")){ if (enc_set){ mtrf_free(str_mem); return_err(proc,1051,1051, "Multiple sample encodings in header field"); } *sample_encoding = SP_se_alaw; enc_set = TRUE; } else if (strsame(pstr,"raw")){ if (enc_set){ mtrf_free(str_mem); return_err(proc,105,105, "Multiple sample encodings in header field"); } *sample_encoding = SP_se_raw; enc_set = TRUE; } else if (strstr(pstr,"embedded-shorten-v") != CNULL) { if (comp_set) { mtrf_free(str_mem); return_err(proc,106,106, "Multiple waveform compressions in header field"); } *wav_compress = SP_wc_shorten; comp_set = TRUE; } else if (strstr(pstr,"embedded-wavpack") != CNULL) { if (comp_set){ mtrf_free(str_mem); return_err(proc,106,106, "Multiple waveform compressions in header field"); } *wav_compress = SP_wc_wavpack; comp_set = TRUE; } else if (strstr(pstr,"embedded-shortpack-v") != CNULL) { if (comp_set){ mtrf_free(str_mem); return_err(proc,106,106, "Multiple waveform compressions in header field"); } *wav_compress = SP_wc_shortpack; comp_set = TRUE; } else { mtrf_free(str_mem); return_err(proc,107,107,"Unknown token in sample coding field"); } pstr = strtok(CNULL,","); } if (*wav_compress == SP_wc_null) *wav_compress = SP_wc_none; if (*sample_encoding == SP_se_null) *sample_encoding = SP_se_pcm2; mtrf_free(str_mem); if (sp_verbose > 11) fprintf(spfp,"Proc %s: Returning 0\n",proc); return_success(proc,0,0,"ok");}/* * sp_fd_open * Version of sp_open added by A. Parker at ERL. This version takes an * already open file descriptor, instead of a file name. * */SP_FILE *sp_fp_open(FILE *fp){ SP_FILE *tsp; char *errmsg, *proc="sp_fd_open " SPHERE_VERSION_STR, *fopen_mode; enum SP_file_open_mode current_mode; if (sp_verbose > 10) fprintf(spfp,"Proc %s:\n",proc); if (fp == NULL) return_err(proc,101,SPNULL,"Null file stream pointer"); if ((tsp=sp_alloc_and_init_sphere_t()) == SPNULL) return_err(proc,102,SPNULL,"Unable to malloc SPFILE memory"); /* set the file open mode in the status structure */ current_mode = tsp->open_mode = SP_mode_read; tsp->read_spifr->status->extra_checksum_verify = FALSE; fopen_mode = READMODE; tsp->read_spifr->waveform->sp_fp = fp; tsp->read_spifr->status->is_disk_file = TRUE; tsp->read_spifr->status->external_filename = mtrf_strdup("ESPS"); /* now that the file is opened, load the header if it exist, */ /* otherwise alloc an empty header for the user */ /* read the header */ tsp->read_spifr->header = sp_open_header(tsp->read_spifr->waveform->sp_fp,TRUE,&errmsg); if ( tsp->read_spifr->header == HDRNULL ) { free_sphere_t(tsp); return_err(proc,104,SPNULL, rsprintf("Unable to open SPHERE header of file, %s", errmsg)); } /* get the size of the header */ if ((tsp->read_spifr->waveform->header_data_size = sp_header_size(tsp->read_spifr->header)) < 0){ free_sphere_t(tsp); return_err(proc,111,SPNULL, rsprintf("Unable to get SPHERE header size of file")); } /****** Remove the sample_count field if it's ******/ /****** value is 999999999 and the file is a stream ******/ /****** Added by JGF June 22, 1994 ******/ if (! tsp->read_spifr->status->is_disk_file){ int type, size; SP_INTEGER l_int; if (sp_get_field(tsp->read_spifr->header, SAMPLE_COUNT_FIELD,&type,&size) == 0){ if (sp_get_data(tsp->read_spifr->header,SAMPLE_COUNT_FIELD, (char *)&l_int,&size) == 0){ if (l_int == 999999999){ if (sp_delete_field(tsp->read_spifr->header, SAMPLE_COUNT_FIELD) < 0) return_err(proc,112,SPNULL, rsprintf("Unable to delete fake '%s' field", SAMPLE_COUNT_FIELD)); } } } } /****** Correct any out-of-date headers right NOW ******/ if (correct_out_of_date_headers(tsp) != 0){ fprintf(spfp,"Warning: correction of "); fprintf(spfp,"out-of-date headers failed\n"); sp_print_return_status(spfp); } /* duplicate the header for the file interface */ if ((tsp->read_spifr->status->file_header = sp_dup_header(tsp->read_spifr->header)) == HDRNULL){ fprintf(spfp,"Error: sp_open_header unable "); fprintf(spfp,"to dup header for file\n"); free_sphere_t(tsp); return_err(proc,106,SPNULL, rsprintf("Unable to duplicate the SPHERE header of file")); } /* set the default operation settings */ if (sp_set_default_operations(tsp) != 0){ print_return_status(spfp); return_err(proc,107,SPNULL, rsprintf("Unable to interpret the SPHERE header of file")); }/* sp_file_dump(tsp,spfp);*/ if (sp_verbose > 17) sp_file_dump(tsp,spfp); if (sp_verbose > 11) fprintf(spfp,"Proc %s: Returning Sphere-file pointer\n",proc); return_success(proc,0,tsp,"ok");}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?