📄 fea.me
字号:
The steps above show what is required to create a feature file and howto handle the data records. In most cases there will be severalprograms that deal with a particular feature file subtype. In thiscase it is worth the effort to create a library module that contains aset of standard routines for creating records for the subtype,initializing the header of the feature file and for doing record I/O.This module should be named \fIxx\fRsupport.c, where \fIxx\fR is a namefor the subtype. .ppTypical support functions for a new file type include: an initializationroutine that creates the required feature file fields and generic header items for a new outputfile; an allocate record function that allocates the feature file record,allocates the subtype record, and calls \fIget_fea_ptr\fR to assignpointer values of the data fields to the pointers in the subtype recordstructure; and get/put record functions that do the record input/output..ppIn most cases the get/put functions simply read or write a feature filerecord. Since the subtype record consists of pointers to the datarecord memory there is no moving of data required. In some cases,however, it might be desirable to move the data into a different type ofdata structure. For example, you might want to represent the data inthe program as a matrix (this could also be done just by setting up anarray of pointers, but in some cases it might be just as well to movethe data). In such cases, the get/put routines would be where thismovement of the data is done..ppWe will use our example from above where we reimplemented the ANA filetype as a feature file and show the required support modules.So as not to be confused with the existing anasupport routine (named anasupport.c), we will use the name \fIfana\fRfor our new subtype in this example..sh 2 "init_fana_hd".ppThis routine is used to fill in the header of a feature file to make ita file of the correct subtype.The routine creates generic header items as needed and creates the datarecord fields.In general, this routine will take as argumentsthose values that affect the size of the data record. These valuesshould be stored in the file header (as generic header items)..ppThis routine is only used when creating a new \fIfana\fR file foroutput. It is not used when reading an \fIfana\fR file. This functionreturns zero on success and non-zero on failure..ip.nf\fBint\fRinit_fana_hd(hd, maxraw, maxlpc, maxpulses, order_vcd, order_unvcd)\fBstruct\fR header hd;\fBint\fR maxraw, maxlpc, maxpulses, order_vcd, order_unvcd;/* save parameters in the header*/*add_genhd_l("maxraw",\fB\s-1NULL\fR\s+1,1,hd) = maxraw;*add_genhd_l("maxlpc",\fB\s-1NULL\fR\s+1,1,hd) = maxlpc;*add_genhd_l("maxpulses",\fB\s-1NULL\fR\s+1,1,hd) = maxpulses;*add_genhd_l("order_vcd",\fB\s-1NULL\fR\s+1,1,hd) = order_vcd;*add_genhd_l("order_unvcd",\fB\s-1NULL\fR\s+1,1,hd) = order_unvcd;/* create the record fields*/\fBif\fR (add_fea_fld("raw_power",maxraw,1,\fB\s-1NULL,FLOAT,NULL\fR\s+1,hd) == -1 || add_fea_fld("lpc_power",maxlpc,1,\fB\s-1NULL,FLOAT,NULL\fR\s+1,hd) == -1 || add_fea_fld("p_pulse_len",maxpulses,1,\fB\s-1NULL,FLOAT,NULL\fR\s+1,hd) == -1 || add_fea_fld("ref_coeff",max(order_vcd,order_unvcd),1, \fB\s-1NULL,FLOAT,NULL\fR\s+1,hd) == -1 || add_fea_fld("frame_len",1,0,\fB\s-1NULL,SHORT,NULL\fR\s+1,hd) == -1)) \fBreturn\fR (1);hd->hd.fea->fea_type = \fB\s-1VQ_FANA\fR\s+1; /* this type code is assigned when the subtype becomes official */\fBreturn\fR 0;}.fi.sh 2 "allo_fana_rec".ppThis function allocates a record for the FEA file subtype FEA_ANA. Itallocates a structure and assigns the pointer values in it to the valuesreturned by \fIget_fea_ptr\fR, which is the address of the data in thefeature file record. Note that the address of the feature file recorditself is saved in the record. This is so that other subtype specificroutines can simply be passed a pointer to the subtype record and stillhave access to the underlying feature file record.The feature file header must be set up before this function is called..ip.nf\fBstruct\fR fea_ana_data *allo_fana_rec(hd)\fBstruct\fR header hd;{\fBstruct\fR fea_ana_data *fana = (\fBstruct\fR fea_ana_data *)calloc(1,\fBsizeof\fR *ana);\fBstruct\fR fea_data *fea_rec = allo_fea_rec(hd);/* check to be sure this is the right kind of file*/\fBif\fR(hd->common.type != \fB\s-1FT_FEA\fR\s+1) error("Not a feature file");\fBif\fR(hd->hd.fea->fea_type != \fB\s-1FEA_FANA\fR\s+1) error("Not a fana feature file");/* hook the pointers in the ana record up to the data area in the feature file record*/fana->tag = &fea_rec->tag;fana->raw_power = (float *)get_fea_ptr(fea_rec, "raw_power", hd);fana->lpc_power = (float *)get_fea_ptr(fea_rec, "lpc_power", hd);fana->p_pulse_len = (float *)get_fea_ptr(fea_rec, "p_pulse_len", hd);fana->ref_coeff = (float *)get_fea_ptr(fea_rec, "ref_coeff", hd);fana->frame_len = (short *)get_fea_ptr(fea_rec, "frame_len", hd);/* save the pointer to the feature file record in the ana record*/fana->fea_rec = fea_rec;\fBreturn\fR fana;}.fi.sh 2 "put_fana_rec".ppThis routine writes a record of the FEA file subtype FEA_ANA. In thisexample, it does nothing more than write the feature file record. Insome other cases, it might have to do some transformation of the data(for example to support a matrix data structure)..ip.nf\fBvoid\fRput_fana_rec(rec, hd, strm)\fBstruct\fR fea_ana_data *rec;\fBstruct\fR header *hd;\fBFILE\fR *strm;{\fBif\fR (hd->common.type != \fB\s-1FT_FEA\fR\s+1) error("Not a feature file");\fBif\fR (hd->hd.fea->fea_type != \fB\s-1FEA_FANA\fR\s+1) error("Not a fana feature file");put_fea_rec(rec->fea_rec, hd, strm);}.fi.sh 2 "get_fana_rec".ppThis routine reads a record of the FEA file subtype FEA_ANA. Like the putfunction above, it does nothing more than get the feature file record.It returns 1 because all other ESPS \fIget_record\fR functions return EOFon end of file or a positive non-zero integer if the record is readcorrectly..ip.nf\fBint\fRget_fana_rec(rec, hd, strm)\fBstruct\fR fea_ana_data *rec;\fBstruct\fR header *hd;\fBFILE\fR *strm;{\fBif\fR (hd->common.type != \fB\s-1FT_FEA\fR\s+1) error("Not a feature file");\fBif\fR (hd->hd.fea->fea_type != \fB\s-1FEA_FANA\fR\s+1) error("Not a fana feature file");\fBif\fR (get_fea_rec(rec->fea_rec, hd, strm) == \fB\s-1EOF\fR\s+1) return \fB\s-1EOF\fR\s+1;\fBreturn\fR (1);}.fi.sh 2 "Other Parts of the Support Module".ppIn addition to these routines the support module should containdefinitions for any global variables needed by the feature file subtype.The most common example of required global variables are string arraysused to define possible values for coded or enumerated data fields inthe record. See \fIlin_search\fR(3\-ESPS)..ppFor a more complete (and more complex) example of a feature file subtypesupport routine see \fI/usr/esps/general/src/lib/vqsupport.c\fR. The mostsignificant difference between vqsupport.c and the example here that oneof the items in the data structure is a two-dimensional array, so thedata is moved between the feature file record and the vq record. Thiscould have been done by setting up an array of pointers with the correctvalues, but since vq files do not have many records it did not seemnecessary at this time. Of course, it could be changed withoutaffecting existing programs. The other difference between vqsupport.cand this example, is that it is complete and does compile and execute..sh 1 "Documentation for Official Feature File Subtypes".ppThis section describesthe standard documentation format for an official feature file subtype.The feature file header has a field for a type code to allow for thedefinition of new file types implemented with feature files. When thisis done, the new file type must be documented so that other programmerscan properly design programs that must use these files..ppThe format of the documentation for these files is nearly the same asthe existing section 5 manual pages for files types such as ANA. Theinformation that a programmer must have to use a feature fileincludes:.(lfile type code,generic header items and their meaning,listing of the fields in the feature file and their size information,the data structure of the record if one is appropriate, andmanual pages for supporting functions as appropriate..)l.ppIn most cases when a new file type is implemented using feature files,the designer should provide a data structure like our ANA example abovefor other programmers to use. This will go into an include file that will beinstalled into /usr/esps/include/esps. This header file should also includedeclarations for any support functions for the new file type. See\fI<esps/vq.h>\fR for an example of this..ppWhen a feature file subtype is to be made official, the designer willsubmit the following to the ESPS maintainer:.(lsection 5 manual page,section 3 manual pages for support functions,support functions C module as described above, andinclude file with structure declarations..)l.ppThe ESPS maintainer will assign the file type a type code (FEA_\fIxx\fR)and add this to the others in \fI<esps/fea.h>\fR.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -