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

📄 fea.me

📁 speech signal process tools
💻 ME
📖 第 1 页 / 共 2 页
字号:
.lo.SJ "Guidelines for Implementing ESPS Feature File Subtypes".AU "Alan Parker".RB "John Shore".TM ETM-S-86-25:rap 1.2 6/5/87.*RESPS User's Manual.*RETM-S-86-14, Entropic Signal Processing System Programming Guidelines.sh 1 Introduction.ppThis document describes how to use the ESPS Feature file type(\fIfea\fR(5\-ESPS)). .(f\(co Copyright 1987 Entropic Speech, Inc.; All rights reserved.  .)fESPS feature files allow the user to create a ESPS data file with namedfields of different data types and sizes.   They can be used to define anew public ESPS file type (known as a feature file subtype), or to implement a private data file forthe user's own work.    When used in conjunction with the generic headerfeature (\fIadd_genhd\fR(3\-ESPS)), FEA files provide a very general way forthe user to create ESPS data files.The general model for using feature files depends on whether the file isbeing used for input or output.   .ppThis document uses as an example a feature file subtype FEA_ANA that was created to replace an old ESPS file type called ANA..sh 2 "Output Files".ppTo create an output feature file\fInew_header\fR is called to create a new feature file header.   Thefields in the file must be created by calling \fIadd_fea_fld\fR andproviding the required type and size information.    Genericheader items are created using \fIadd_genhd_x\fR(3\-ESPS).After all the header information is fixed inplace the header is written out, as with any other kind of ESPS file.The common part of the header contains the same fields as other ESPSfiles.  After the header has been written to the file, the program canstart writing the data out.   Methods for dealing with the data arediscussed below..sh 2 "Input Files".ppFor input feature files, life is simpler since the fields have alreadybeen defined (when the file was created).    In most cases the programmerwill know what the fields are and their types.   The sizes of the fields might be known by definition, or through someheader item.   But in all cases this informationis available in the FEA header and through access functions (see\fIget_fea_siz\fR(3\-ESPS).    If the feature file is a predefined public subtype (public in the sensethat a file type like ANA was public) then documentation of that filetype will show the data structure to use (and usually provide it througha header file), and will list all the fields and give their type and sizeinformation.   The method of dealing with the data records is much thesame as in the output case and is discussed below..sh 1 "Dealing with the Data Records".ppThe simple way to use feature files is to create the fields, getpointers to the data using \fIget_fea_ptr\fR and then move data fromvariables in your program to the feature file record.   But withpointers you can use the memory allocated in the feature file record.    This is much better than moving all the data around and it's onereason C has pointers.For example, consider the data structure that was used to define records in ANA files:.ip.nf\fBstruct\fR ana_data {	\fBlong\fR tag;	\fBfloat\fR *raw_power;	\fBfloat\fR *lpc_power;	\fBfloat\fR *p_pulse_len;	\fBfloat\fR *ref_coeff;	\fBshort\fR frame_len;}.fi.ppOnly tag and frame_len here are not pointers, because they are fixedsize (happens to be 1, but could be any fixed size).   The others arepointers because the amount of memory allocated depends on some valuesin the file header.  You can think of these as unallocated arrays ofsome size.   The \fIallo_ana_rec\fR function allocates the right amountof memory for each of these depending on some values in the header andassigns the pointers (such as raw_power) the \fIaddress\fR of theallocated memory.   You can write raw_power[i] if you wish and thecompiler will do some pointer arithmetic for you..ppHere's how we replaced the ANA file type with the FEA file subtypeFEA_ANA.  First, field frame_len and tag were changed topointers, since the feature file routines have to allocatememory for it.  So here is our new ANA data structure for featurefiles:.ip.nf\fBstruct\fR fea_ana_data {	\fBlong\fR *tag;	\fBfloat\fR *raw_power;	\fBfloat\fR *lpc_power;	\fBfloat\fR *p_pulse_len;	\fBfloat\fR *ref_coeff;	\fBshort\fR *frame_len;	\fBstruct\fR fea_data *fea_rec;}.fi.ppBesides changing two items to pointers, we added a pointer to thefeature file record (*fea_rec).   This will be explained later..ppNow to use this we have to create the fields if this is a new file..ip.nfhd = new_header(\fB\s-1FT_FEA\fR\s+1);add_fea_fld("raw_power",maxraw,1,\fB\s-1NULL,FLOAT,NULL\fR\s+1,hd);add_fea_fld("lpc_power",maxlpc,1,\fB\s-1NULL,FLOAT,NULL\fR\s+1,hd);add_fea_fld("p_pulse_len",maxpulses,1,\fB\s-1NULL,FLOAT,NULL\fR\s+1,hd);add_fea_fld("ref_coeff",max(order_vcd,order_unvcd),1,\fB\s-1NULL,FLOAT,NULL\fR\s+1,hd);add_fea_fld("frame_len",1,0,\fB\s-1NULL,SHORT,NULL\fR\s+1,hd);.fi.ppNote that these functions really return an error code, but I'm ignoringthat here..ppNow assuming that all other header items have been fixed we will writethe header.  This is just like any other ESPS file..ipwrite_header(hd,file);.ppNext a \fIfea_ana_data\fR structure must be allocated.    Of course,depending on the needs in the program, this could have been declared atcompile-time..ip\fBstruct\fR fea_ana_data *ana = (\fBstruct\fR fea_ana_data *)calloc(1,\fBsizeof\fR *ana);.ppBefore we can get pointers to the data area we must allocate the datarecord memory.   That is done with \fIallo_fea_rec\fR.  It usesinformation in the file header to allocate the correct amount of memoryof each data type.   After the feature record is allocated,\fIget_fea_ptr\fR is called to return a pointer to the memory associatedwith a particular named field.   Note that the return data type of thisfunction is (char *), so it must be cast to the correct data type.(This is like \fImalloc\fR(3)).  If you fail to use the correct cast,you will get a compile time error complaining about illegal pointercombinations..ppNote the way the tag field is handled here.  If you do not want to botheraccessing it through a pointer, you can just use it directly from thefeature file record.  It's the one field that is directly built-in andpreallocated in feature file records..ip.nfrec = allo_fea_rec(hd);ana->tag = &rec->tag;ana->raw_power = (\fBfloat *\fR)get_fea_ptr(rec,"raw_power",hd);ana->lpc_power = (\fBfloat *\fR)get_fea_ptr(rec,"lpc_power",hd);ana->p_pulse_len =(\fBfloat *\fR) get_fea_ptr(rec,"p_pulse_len",hd);ana->ref_coeff = (\fBfloat *\fR)get_fea_ptr(rec,"ref_coeff",hd);ana->frame_len = (\fBshort *\fR)get_fea_ptr(rec,"frame_len",hd);.fi.ppNow, let use the data.   Just use the arrays exactly like you wouldwith the real ANA data structure.   It works the same and you can easilyhang yourself in all the same ways.   Note that in this case you havetwo ways for knowing the size of the arrays, such as lpc_power.    Oneway is to know that it is maxlpc from the header (assumingthat you stored it in the header).  If you did not knowthat, or the rules were changed, you can get the size of a feature filefield with \fIget_fea_siz\fR. But before you can use the data (for an input file) it must be readfrom the file.   This is done with \fIget_fea_rec\fR.   This just readsin the next record into the pool of memory set up by the\fIallo_fea_rec\fR call.   .ip.nf\fBif\fR (get_fea_rec(rec,hd) == EOF) \fIend of file ...\fR\fBfor\fR (i=0; i<maxlpc; i+) {  something = ana->lpc_power[i] + something_else;}.fi.ppOf course, you could be real C programmer and avoid the use of arraysubscripts entirely and just increment the pointer value.   Thats OK,and you could do that also with the real ANA file.  It's no different..ppAs for the scalers (tag and frame_len) in thiscase you must remember that they are now pointers.  So to get theframe_len value do:.ip.nfxx = *ana->frame_len;.fi.ppOf course you can use *ana->frame_len in any expression as often as youplease.    No need to assign it to another variable.   You can accessthe tag by *ana->tag.   You can also access the tag by rec->tag; byjustgetting the tag value directly from the record.  Note that ana->tag is a pointer containing the addressof rec->tag, so to say *ana->tag is to refer to the same memory asrec->tag..ppIf you forget that frame_len is a pointer and say ana->frame_len in anexpression, you will get a funny number which is the address of thedata.  In some such cases you will get a message about illegalcombination of pointer and integer or some such, but don't count on it..ppSince \fIget_fea_ptr\fR returns a pointer, you can use its return valuedirectly to access the data.   This probably is not the best way touse the function in general.  In particular, you probably don't want toput the function call in a processing loop that gets executed 10,000times.  But this does work: (if \fIzeta\fR is a feature file field oftype \fB\s-1FLOAT\fR\s+1).ip.nfsomething = *(\fBfloat\fR *)get_fea_ptr(rec,"zeta",hd) + something_else;.fi.lpSo does this:.ip*(\fBfloat\fR *)get_fea_ptr(rec,"zeta",hd) = 77.9;.sh 1 "Feature File Subtype Support Module".pp

⌨️ 快捷键说明

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