⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdatamod.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
	  case SP_wc_shortpack:	  case SP_wc_wavpack:	  case SP_wc_shorten:	    if (new_compress != SP_wc_none)		return_err(proc,124,124,			   rsprintf("Illegal write transformation to %s",				    "compress a compressed file"));	    break;	  case SP_wc_none:	    break;	  default:	    return_err(proc,125,125,		       "Internal function error: old compression not set");	}	switch (old_sbf){	  case SP_sbf_10:	  case SP_sbf_01:	  case SP_sbf_N:	    if (new_sbf == SP_sbf_1)		if ((new_encoding == SP_se_pcm1) ||		    (new_encoding == SP_se_ulaw))		    ;		else		    return_err(proc,126,126,			  "Unable to convert to a one-byte per sample format");	    break;	  case SP_sbf_1:	    if (new_sbf != SP_sbf_1)		if (new_encoding == SP_se_pcm2)		    ;		else		    return_err(proc,127,127,			   "Unable to convert to a 2-byte per sample format");	    break;	  default:	    if (new_sbf != old_sbf)		return_err(proc,128,128,			   "Internal function error for file opened for write");	}	break;      default:	return_err(proc,129,129,		   "Unknown file open mode in SPFILE structure");    }    /* now update the hidden header: file_header for write, user_header for */    /* read and update the status structure variables                       */    {   struct header_t *hdr_to_modify;	SP_INTEGER lint;	char new_sample_coding[100];	int channels_changed = FALSE;       	if (sp->open_mode == SP_mode_read){	    if (sp_verbose > 15)		fprintf(spfp,"Proc %s: modifying the user's header \n",			proc);	    hdr_to_modify = sp->read_spifr->header;	}	else {	    if (sp_verbose > 15)		fprintf(spfp,"Proc %s: modifying the file's header \n",			proc);	    hdr_to_modify = sp->write_spifr->status->file_header;	}	/* set the sample_n_bytes field */	if (new_encoding == SP_se_pcm2){	    lint = 2;	    if (sp_verbose > 15) 		fprintf(spfp,"Proc %s: new %s value %d\n",			proc,SAMPLE_N_BYTES_FIELD,lint);	    if (h_set_field(hdr_to_modify, SAMPLE_N_BYTES_FIELD, 			    T_INTEGER, &lint))		return_err(proc,150,150,			   "Unable to update sample_n_bytes field\n");	} else if ((new_encoding == SP_se_ulaw) ||		   (new_encoding == SP_se_pcm1)) {	    lint = 1;	    if (sp_verbose > 15)		fprintf(spfp,"Proc %s: new %s value %d\n",			proc,SAMPLE_N_BYTES_FIELD,lint);	    if (h_set_field(hdr_to_modify, SAMPLE_N_BYTES_FIELD,			    T_INTEGER, &lint))		return_err(proc,151,151,			   "Unable to update sample_n_bytes field\n"); 	    	} else { /* nothing has changed, used the file_sample_n_bytes */	    if (sp->open_mode == SP_mode_read)		lint = sp->read_spifr->status->file_sample_n_bytes;	    else		lint = sp->write_spifr->status->file_sample_n_bytes;	}		/* setup the new sample_n_bytes values */	if (sp->open_mode == SP_mode_read)	    sp->read_spifr->status->user_sample_n_bytes = lint ;	else	    sp->write_spifr->status->file_sample_n_bytes = lint ;	/* set the sample byte format */ 	{   char *str = header_str_SP_sample_byte_fmt(new_sbf);	    if (new_sbf == SP_sbf_null)		return_err(proc,157,157,"Internal function error");	    if (sp_verbose > 15) 		fprintf(spfp,"Proc %s: new sample_byte_format %s\n",			proc,str);	    if (h_set_field(hdr_to_modify, SAMPLE_BF_FIELD, T_STRING, str))	      return_err(proc,153,153,		rsprintf("Unable to update sample_byte_format field to '%s'\n",			 str));	}	/* set the new channel count */ 	lint = -1;	if (sp->open_mode == SP_mode_read) {	    if (sp->read_spifr->status->channels != CHANNELSNULL)		lint = sp->read_spifr->status->user_channel_count = 		    sp->read_spifr->status->channels->num_chan;	} else {	    if (sp->write_spifr->status->channels != CHANNELSNULL)		lint = sp->write_spifr->status->file_channel_count = 		    sp->write_spifr->status->channels->num_chan;	} 	if (lint != (-1)){	    if (sp_verbose > 15) 		fprintf(spfp,"Proc %s: new channel count %d\n",			proc,lint);	    if (h_set_field(hdr_to_modify, CHANNEL_COUNT_FIELD, T_INTEGER, 			    (void *)&lint))		return_err(proc,154,154,			   rsprintf("%schannel count field to %d\n",				    "Unable to update ",lint));	    channels_changed = TRUE;	}		    	/* set the sample encoding field */	*new_sample_coding = '\0';	switch (new_encoding){	  case SP_se_pcm1:	  case SP_se_pcm2: strcat(new_sample_coding,"pcm"); break;	  case SP_se_ulaw: strcat(new_sample_coding,"ulaw"); break;	  case SP_se_raw: strcat(new_sample_coding,"raw"); break;	  default: return_err(proc,158,158,"Internal Function Error");	}	switch (new_compress){	  case SP_wc_shorten:	    strcat(new_sample_coding,		   rsprintf(",embedded-shorten-v%1d.%s",FORMAT_VERSION,			    BUGFIX_RELEASE));	    break;	  case SP_wc_wavpack:	    strcat(new_sample_coding,rsprintf(",embedded-%s", WAVPACK_MAGIC));	    break;	  case SP_wc_shortpack:	    strcat(new_sample_coding,",embedded-shortpack-vIDONTKNOW");	    break;	  default: ;	}	if (h_set_field(hdr_to_modify, SAMPLE_CODING_FIELD,			T_STRING, new_sample_coding))	    return_err(proc,160,160,		   rsprintf("Unable to update sample_coding field to '%s'\n",			    new_sample_coding));	if (sp_verbose > 15)	    fprintf(spfp,"Proc %s: new sample coding %s\n",		    proc,new_sample_coding);	/* if the mode is write and theses conditions have been met, delete */	/* the channel count */	if (sp->open_mode == SP_mode_write)     	    if ((old_encoding !=  new_encoding) || channels_changed){		if (h_delete_field(hdr_to_modify, SAMPLE_CHECKSUM_FIELD) > 100)		    return_err(proc,170,170,			       "Unable to delete sample checksum field");		if (sp_verbose > 15)		    fprintf(spfp,"Proc %s: deleting sample checksum\n",proc);	    }	/* encoding has changed, re-set the sample_sig_bits */	if (old_encoding !=  new_encoding){	    if (new_encoding == SP_se_pcm2)		lint = 16;	    else if ((new_encoding == SP_se_ulaw) || 		     (new_encoding == SP_se_pcm1))		lint = 8;	    	    if (h_set_field(hdr_to_modify, SAMPLE_SIG_BITS_FIELD,			    T_INTEGER, (void *)&lint)){				if (sp_verbose > 15)		    fprintf(spfp,"Proc %s: new sample_sig_bits to %d\n",			    proc,lint);		return_err(proc,180,180,			   rsprintf("Unable to update sample_sig_bits %s %d\n",				    "field to ",lint));	    }	}	/* setup the new values */	if (sp->open_mode == SP_mode_read){	    sp->read_spifr->status->user_encoding = new_encoding ;	    sp->read_spifr->status->user_compress = new_compress ;	    sp->read_spifr->status->user_sbf      = new_sbf      ;	    sp->read_spifr->status->user_data_fmt = new_data_fmt ;	} else {	    sp->write_spifr->status->file_encoding = new_encoding ;	    sp->write_spifr->status->file_compress = new_compress ;	    sp->write_spifr->status->file_sbf      = new_sbf      ;	    sp->write_spifr->status->user_data_fmt = new_data_fmt ;	}    }    if (sp_verbose > 16) sp_file_dump(sp,spfp);    if (sp_verbose > 11) fprintf(spfp,"Proc %s: Exit\n",proc);/* make a warning if the default mode is used */        if (sp->open_mode == SP_mode_read)	sp->read_spifr->status->set_data_mode_occured_flag = TRUE;    else	sp->write_spifr->status->set_data_mode_occured_flag = TRUE;    return_success(proc,0,0,"ok");}int parse_channel_selection(char *desc, SP_FILE *sp){    char *tstr, *tstr2, tmp[10], *temp_description, *next_str;    int out_channels = 0, c;    int first, last, len, pass, max_chan_add=1, chan_add;    CHANNELS *Channels;    int sp_nchan;    char *proc="parse_channel_selection " SPHERE_VERSION_STR;    SPIFR *spifr;    if (sp_verbose > 10) fprintf(spfp,"Proc %s:\n",proc);    if (sp_verbose > 15)	fprintf(spfp,"Proc %s: channel description string '%s'\n",proc,desc);    if (sp == SPNULL) return_err(proc,100,100,"Null SPFILE");    if (desc == CNULL)	return_err(proc,101,101,"NULL channel descriptor passed");    if (sp->open_mode == SP_mode_read)	spifr = sp->read_spifr;    else	spifr = sp->write_spifr;    sp_nchan = spifr->status->user_channel_count;    if (strspn(desc,"0123456789,.+") != strlen(desc))	return_err(proc,102,102,		   rsprintf("Error: Illegal format for descriptor '%s'\n",			    desc));    /* make sure .'s occure in pairs */    tstr = desc;    while ((tstr2 = (char *)strchr(tstr,'.')) != CNULL){	if (*(tstr2+1) != '.')	    return_err(proc,103,103,		 rsprintf("Illegal channel range format for descriptor '%s'\n",			  desc));	tstr = tstr2+2;    }    for (pass=0; pass < 2; pass++){	temp_description = (char *)mtrf_strdup(desc);		if (pass == 1) {	    if (spifr->status->channels != CHANNELSNULL)		free_CHANNELS(spifr->status->channels);	    if ((Channels = alloc_CHANNELS(out_channels,max_chan_add)) ==		CHANNELSNULL)		return_err(proc,102,102,"Unable to alloc Channel structure");	    spifr->status->channels = Channels;	}	/* count the channels in the tokens */        /* instead of using strtok, use strchr() and do it by hand */        tstr = temp_description;        if ((tstr2 = (char *)strchr(tstr,',')) != CNULL){            next_str = tstr2+1;            *tstr2 = '\0';        } else            next_str = CNULL;	while (tstr != CNULL){	    if (pass == 0 && sp_verbose > 15)		fprintf(spfp,"Proc %s: token '%s'\n",proc,tstr);	    if (strspn(tstr,"0123456789") == strlen(tstr)){		first = atoi(tstr);		if ((first > sp_nchan) || (first <= 0))		    return_err(proc,1000,1000,			   rsprintf("Error: channel %s out of range\n",tstr));		if (pass == 0)		    out_channels ++;		else {		    Channels->ochan[Channels->num_chan].num_origin=1;		    Channels->ochan[Channels->num_chan].orig_channel[0]=first;		    Channels->num_chan++;		}	    } else if ((char *)strchr(tstr,'+') != CNULL){		chan_add=0;		if ((spifr->status->user_encoding != SP_se_pcm2) &&		    (spifr->status->user_encoding != SP_se_ulaw))		    return_err(proc,2000,2000,	         "Error: Can't add channels for types other that pcm or ulaw");		while ((len = strspn(tstr,"0123456789")) > 0) {		    strncpy(tmp,tstr,len);		    *(tmp+len) = '\0';		    first = atoi(tmp);		    if ((first > sp_nchan) || (first <= 0))			return_err(proc,1000,1000,			    rsprintf("Error: channel %s out of range\n",tmp));		    if (*(tstr+=len) != '\0')			tstr++;		    chan_add++;		    if (pass == 1){			c=Channels->ochan[Channels->num_chan].num_origin;			Channels->ochan[Channels->num_chan].orig_channel[c]=			     first;			Channels->ochan[Channels->num_chan].num_origin++;		    }		}		if (pass == 0){		    if (chan_add > max_chan_add)			max_chan_add = chan_add;		    out_channels ++;		} else {		    Channels->num_chan++;		}	    } else if ((tstr2 = (char *)strchr(tstr,'.')) != CNULL) {		/* get off the first number */		strncpy(tmp,tstr,tstr2-tstr) ;		*(tmp + (tstr2-tstr)) = '\0';		first = atoi(tmp);		if ((first > sp_nchan) || (first <= 0))		    return_err(proc,1000,1000,			   rsprintf("Error: channel %s out of range\n",tmp));		tstr2+=2;		if ((char *)strchr(tstr2,'.') != CNULL)		    return_err(proc,1001,1001,			 rsprintf("Illegal format of channel desc %s\n",tstr));		strcpy(tmp,tstr2);		last=atoi(tmp);		if ((last > sp_nchan) || (last <= 0))		    return_err(proc,1000,1000,			     rsprintf("Error: channel %s out of range\n",tmp));		if (pass == 0)		    out_channels += last-first + 1;		else {		    for (c=first; c<=last; c++){			Channels->ochan[Channels->num_chan].num_origin=1;			Channels->ochan[Channels->num_chan].orig_channel[0]=c;			Channels->num_chan++;		    }		}	    }            if (next_str == CNULL)                tstr = next_str;            else {                tstr = next_str;                if ((tstr2 = (char *)strchr(next_str,',')) != CNULL){                    next_str = tstr2+1;                    *tstr2 = '\0';                } else                    next_str = CNULL;            }	}	mtrf_free(temp_description);    }    return_success(proc,0,0,"ok");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -