Browse Source

Add initial 4p presentation

master
Sam Black 11 years ago
parent
commit
249aefbbb2
7 changed files with 89297 additions and 59 deletions
  1. +78
    -59
      ee4p/c/htkwrite.c
  2. +27
    -0
      ee4p/c/setup.py
  3. +1
    -0
      ee4p/docs/Presentations/.~lock.bench_inspect-0812071414.odp#
  4. BIN
      ee4p/docs/Presentations/bench_inspect-0812071414.odp
  5. +89189
    -0
      ee4p/docs/htkbook.pdf
  6. BIN
      ee4p/docs/htkbook.pdf.gz
  7. +2
    -0
      ee4p/python/pca/randnum.py

+ 78
- 59
ee4p/c/htkwrite.c View File

@@ -1,6 +1,10 @@
/* ------< C code to write HTK [1,2].* data >-----
by Guillaume Gravier <ggravier@inf.enst.fr>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Python.h>

/* -------------------------------------------------- */
/* ----- Private type definition for HTKWrite() ----- */
@@ -12,83 +16,98 @@ typedef struct {
short parmKind;
} htk_header_t;

#define H_LPC 1
#define H_LPREFC 2
#define H_LPCEPSTRA 3
#define H_MFCC 6
#define H_FBANK 7
#define TRUE 1
#define FALSE 0
#define H_USER 9

#define HASENERGY 0x0040
#define HASNOE 0x0080
#define HASDELTA 0x0100
#define HASZMEAN 0x0800
#define HASENERGY 0100 /* _E log energy included */
#define HASNULLE 0200 /* _N absolute energy suppressed */
#define HASDELTA 0400 /* _D delta coef appended */
#define HASACCS 01000 /* _A acceleration coefs appended */
#define HASCOMPX 02000 /* _C is compressed */
#define HASZEROM 04000 /* _Z zero meaned */
#define HASCRCC 010000 /* _K has CRC check */
#define HASZEROC 020000 /* _0 0'th Cepstra included */
#define HASVQ 040000 /* _V has VQ index attached */
#define HASTHIRD 0100000 /* _T has Delta-Delta-Delta index attached */

/* ----------------------------------------------------- */
/* ----- err_t HTKWrite(data_t *,float,int,FILE *) ----- */
/* ----------------------------------------------------- */
/*
* Write data (structure containing feature vectors) to output
* stream in HTK 1.* or 2.* format (HTK 3.0 format is the same
* as the HTK 2.* format).
*/
err_t HTKWrite(data_t *data,float period,int hversion,FILE *f)
static PyObject * HTKWriteBin(PyObject *self, PyObject *args)
{
htk_header_t header;
short htk_kind;
int nelem;
float *ptr;
int i;
int nelem, i, samps, len, *s;
float *ptr, period;
char *filename, *flags, buf[255];
PyListObject *in_data;
int hasV=FALSE,hasE=FALSE,hasD=FALSE,hasN=FALSE,hasA=FALSE,hasT=FALSE,hasF=FALSE,hasC=FALSE,hasK=FALSE,hasZ=FALSE,has0=FALSE;

if(sizeof(param_t) != sizeof(float)) {
/*
if param_t is double, should copy to a vector of float
since HTK needs float, not double
*/
gerror(HCOMPAT_ERR,"HTKWrite(): sizeof(param_t) != sizeof(float)");
return(HCOMPAT_ERR);
}
if (!PyArg_ParseTuple(args, "iifsOs", &nelem, &samps, &period, &flags, &in_data, &filename))
return Py_BuildValue("i",7);

nelem=DataVecSize(data); /* set feature vector dimension */
header.nSamples=(long)(data->n); /* set number of samples */
header.nSamples=(long)samps; /* set number of samples */
header.sampSize=(short)(nelem*sizeof(float)); /* set sample size */
header.sampPeriod=(long)(period*10000.0); /* set sample period */

if(hversion == 1) /* HTK 1.* format --> try to find a sample kind equivalence */
switch(data->kind) {
case FBANK: htk_kind=(short)H_FBANK; break;
case FBCEPSTRA: htk_kind=(short)H_MFCC; break;
case LPCEPSTRA: htk_kind=(short)H_LPCEPSTRA; break;
case LPCOEFF: htk_kind=(short)H_LPC; break;
case PARCOR: htk_kind=(short)H_LPREFC; break;
default:
gerror(NO_HFORMAT_ERR,"HTKWrite(): No equivalent format in HTK 1.4 for %s",
kind2str(data->kind));
return(NO_HFORMAT_ERR);
htk_kind=(short)H_USER;

strcpy(buf,flags);
len=strlen(buf);
s=&buf[len-2];
while (len>2 && s=='_') {
switch(*(s+1)){
case 'E': hasE = TRUE; break;
case 'D': hasD = TRUE; break;
case 'N': hasN = TRUE; break;
case 'A': hasA = TRUE; break;
case 'C': hasC = TRUE; break;
case 'T': hasT = TRUE; break;
case 'F': hasF = TRUE; break;
case 'K': hasK = TRUE; break;
case 'Z': hasZ = TRUE; break;
case '0': has0 = TRUE; break;
case 'V': hasV = TRUE; break;
default: ;;
}
else /* HTK 2.* --> write USER defined data */
htk_kind=(short)H_USER;
*s = '\0';
len -= 2;
s -= 2;
}

if(data->flag & WITHE) htk_kind |= HASENERGY; /* set header flags */
if(data->flag & WITHD) htk_kind |= HASDELTA;
if(data->flag & WITHN) htk_kind |= HASNOE;
if(hversion == 2 && (data->flag & WITHZ)) htk_kind |= HASZMEAN;
if (hasE) htk_kind |= HASENERGY;
if (hasD) htk_kind |= HASDELTA;
if (hasN) htk_kind |= HASNULLE;
if (hasA) htk_kind |= HASACCS;
if (hasT) htk_kind |= HASTHIRD;
if (hasK) htk_kind |= HASCRCC;
if (hasC) htk_kind |= HASCOMPX;
if (hasZ) htk_kind |= HASZEROM;
if (has0) htk_kind |= HASZEROC;
if (hasV) htk_kind |= HASVQ;
header.parmKind=htk_kind;

if(fwrite(&header,sizeof(htk_header_t),1,f) != 1) {
gerror(DUMP_ERR,"HTKWrite(): cannot write HTK header (%d bytes)",
sizeof(htk_header_t));
return(DUMP_ERR);
if(fwrite(&header,sizeof(htk_header_t),1,filename) != 1) {
printf("HTKWriteFS(): cannot write HTK header (%d bytes)", sizeof(htk_header_t));
return Py_BuildValue("i",5);
}
for(i=0;i<data->n;i++) {
ptr=(float *)DataGetVec(data,i,nelem);
for(i=0;i<(int)PyList_Size(in_data);i++) {
ptr=(float *)PyList_GetItem(in_data,i);
printf("%f\n", ptr);
/* now, ptr points to the i'th feature vector! Write it! */
if(fwrite(ptr,sizeof(float),nelem,f) != nelem) {
gerror(DUMP_ERR,"HTKWrite(): cannot write %d'th vector (%d bytes)",
i+1,nelem*sizeof(float));
return(DUMP_ERR);
if(fwrite(ptr,sizeof(float),nelem,filename) != nelem) {
printf("HTKWriteFS(): cannot write %d'th vector (%d bytes)", i+1,nelem*sizeof(float));
return Py_BuildValue("i",5);
}
}

DONE;
return Py_BuildValue("i",0);
}

static PyMethodDef HTKWriteMethods[] = {
{"writebinfile", HTKWriteBin, METH_VARARGS, "Write HTK data out to a binary file"},
{NULL, NULL, 0, NULL} /* Sentinel */
};

PyMODINIT_FUNC inithtkwritefile(void) {
(void) Py_InitModule("htkwritefile", HTKWriteMethods);
}


+ 27
- 0
ee4p/c/setup.py View File

@@ -0,0 +1,27 @@
#!/usr/bin/python
# setup.py
#
# Copyright 2008 Sam Black <samwwwblack@lapwing.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
from distutils.core import setup, Extension

module1 = Extension('htkwritefile', sources = ['htkwrite.c'])

setup (name = 'HTKWriteFile',
version = '0.1',
description = 'Write HTK compatible binary files',
ext_modules = [module1])

+ 1
- 0
ee4p/docs/Presentations/.~lock.bench_inspect-0812071414.odp# View File

@@ -0,0 +1 @@
Sam Black,sam,victor.lapwing.linux,07.12.2008 14:14,file:///home/sam/.openoffice.org/3;

BIN
ee4p/docs/Presentations/bench_inspect-0812071414.odp View File


+ 89189
- 0
ee4p/docs/htkbook.pdf
File diff suppressed because it is too large
View File


BIN
ee4p/docs/htkbook.pdf.gz View File


+ 2
- 0
ee4p/python/pca/randnum.py View File

@@ -86,3 +86,5 @@ dataarrays = []
for arr in tmpdataarrays:
dataarrays.append([arr, arr.view((numpy.float32,3)).mean(), arr.view((numpy.float32,3)).std(), arr.view((numpy.float32,3)).var()])
print "Created data arrays"

# Import MDP, mdp.pca(data)

Loading…
Cancel
Save