summaryrefslogtreecommitdiff
path: root/htk_io
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2016-02-24 17:00:40 +0800
committerDeterminant <[email protected]>2016-02-24 17:00:40 +0800
commit39b1967870e6fabe6764360bccefad8a2a9db24d (patch)
tree0a60f3e6d5137b6b32f82e496b9701e13e52f9d4 /htk_io
parent3f742c01540b8bad940d66331d562082a63d975b (diff)
adjust the code according to the changes made in nerv/wrapped-handleswrapped-handles
Diffstat (limited to 'htk_io')
-rw-r--r--htk_io/Makefile3
-rw-r--r--htk_io/src/cwrapper.cpp15
-rw-r--r--htk_io/src/cwrapper.h9
-rw-r--r--htk_io/src/init.c12
-rw-r--r--htk_io/src/test.c7
5 files changed, 30 insertions, 16 deletions
diff --git a/htk_io/Makefile b/htk_io/Makefile
index d32d17a..fe9593d 100644
--- a/htk_io/Makefile
+++ b/htk_io/Makefile
@@ -17,6 +17,7 @@ OBJ_SUBDIR := $(addprefix $(OBJ_DIR)/,$(SUBDIR))
LUA_SUBDIR := $(addprefix $(LUA_DIR)/,$(SUBDIR))
LUA_LIBS := $(addprefix $(LUA_DIR)/,$(LUA_LIBS))
LIB_PATH := $(LUA_BINDIR)/../lib
+LUALIB_PATH := $(LUA_BINDIR)/../lib/lua/5.1/
build: $(OBJ_DIR) $(OBJ_SUBDIR) $(OBJS) tnet $(OBJ_DIR)/src/test
install: $(LUA_DIR) $(LUA_SUBDIR) $(LUA_LIBS) $(LIBS)
@@ -26,7 +27,7 @@ $(OBJ_DIR) $(LUA_DIR) $(OBJ_SUBDIR) $(LUA_SUBDIR):
$(LUA_DIR)/%.lua: %.lua
cp $< $@
$(LIBS): $(OBJ_DIR)/src/cwrapper.o $(OBJ_DIR)/init.o $(OBJ_DIR)/src/init.o $(OBJ_DIR)/src/libKaldiLib.a
- gcc -shared -o $@ $(OBJ_DIR)/src/cwrapper.o $(OBJ_DIR)/init.o $(OBJ_DIR)/src/libKaldiLib.a $(OBJ_DIR)/src/init.o -lstdc++ -Wl,-rpath=$(LIB_PATH) -L$(LIB_PATH) -lnervcore -lluaT
+ gcc -shared -o $@ $(OBJ_DIR)/src/cwrapper.o $(OBJ_DIR)/init.o $(OBJ_DIR)/src/libKaldiLib.a $(OBJ_DIR)/src/init.o -lstdc++ -Wl,-rpath=$(LIB_PATH) -L$(LIB_PATH) -lnervcore -Wl,-rpath=$(LUALIB_PATH) -L$(LUALIB_PATH) -lnerv -lluaT
$(OBJ_DIR)/src/test: $(OBJ_DIR)/src/cwrapper.o $(OBJ_DIR)/src/test.o $(OBJ_DIR)/src/libKaldiLib.a
gcc -o $@ $^ -Wl,-rpath=$(LIB_PATH) -L$(LIB_PATH) -lnervcore -Wl,-rpath=$(LUA_LIBDIR) -L$(LUA_LIBDIR) -lluajit-5.1 -lstdc++ -lm
$(OBJ_DIR)/src/cwrapper.o: src/cwrapper.cpp
diff --git a/htk_io/src/cwrapper.cpp b/htk_io/src/cwrapper.cpp
index b7ce2d5..efb5628 100644
--- a/htk_io/src/cwrapper.cpp
+++ b/htk_io/src/cwrapper.cpp
@@ -8,9 +8,10 @@
extern "C" {
#include "cwrapper.h"
#include "string.h"
-#include "nerv/common.h"
+#include "nerv/lib/common.h"
+#include "nerv/lib/matrix/mmatrix.h"
- extern Matrix *nerv_matrix_host_float_create(long nrow, long ncol, Status *status);
+ extern Matrix *nerv_matrix_host_float_create(long nrow, long ncol, MContext *context, Status *status);
struct TNetFeatureRepo {
TNet::FeatureRepository feature_repo;
@@ -53,7 +54,8 @@ extern "C" {
return repo;
}
- Matrix *tnet_feature_repo_read_utterance(TNetFeatureRepo *repo, lua_State *L, int debug) {
+ Matrix *tnet_feature_repo_read_utterance(TNetFeatureRepo *repo, lua_State *L,
+ int debug, MContext *context) {
Matrix *mat; /* nerv implementation */
repo->feature_repo.ReadFullMatrix(repo->feats_host);
std::string utter_str = repo->feature_repo.Current().Logical();
@@ -61,7 +63,7 @@ extern "C" {
int n = repo->feats_host.Rows();
int m = repo->feats_host.Cols();
Status status;
- mat = nerv_matrix_host_float_create(n, m, &status);
+ mat = nerv_matrix_host_float_create(n, m, context, &status);
NERV_LUA_CHECK_STATUS(L, status);
size_t stride = mat->stride;
if (debug)
@@ -119,7 +121,8 @@ extern "C" {
size_t sample_rate,
const char *tag,
lua_State *L,
- int debug) {
+ int debug,
+ MContext *context) {
std::vector<TNet::Matrix<float> > labs_hosts; /* KaldiLib implementation */
Matrix *mat;
repo->label_repo.GenDesiredMatrixExt(labs_hosts, frames,
@@ -127,7 +130,7 @@ extern "C" {
int n = labs_hosts[0].Rows();
int m = labs_hosts[0].Cols();
Status status;
- mat = nerv_matrix_host_float_create(n, m, &status);
+ mat = nerv_matrix_host_float_create(n, m, context, &status);
NERV_LUA_CHECK_STATUS(L, status);
size_t stride = mat->stride;
if (debug)
diff --git a/htk_io/src/cwrapper.h b/htk_io/src/cwrapper.h
index e1bce6e..0469773 100644
--- a/htk_io/src/cwrapper.h
+++ b/htk_io/src/cwrapper.h
@@ -1,7 +1,7 @@
#ifndef NERV_TNET_IO_CWRAPPER
#define NERV_TNET_IO_CWRAPPER
-#include "nerv/matrix/matrix.h"
-#include "nerv/common.h"
+#include "nerv/lib/matrix/mmatrix.h"
+#include "nerv/lib/common.h"
#ifdef __cplusplus
extern "C" {
#endif
@@ -10,7 +10,7 @@ extern "C" {
TNetFeatureRepo *tnet_feature_repo_new(const char *scp,
const char *config, int context);
- Matrix *tnet_feature_repo_read_utterance(TNetFeatureRepo *repo, lua_State *L, int debug);
+ Matrix *tnet_feature_repo_read_utterance(TNetFeatureRepo *repo, lua_State *L, int debug, MContext *context);
size_t tnet_feature_repo_current_samplerate(TNetFeatureRepo *repo);
const char *tnet_feature_repo_current_tag(TNetFeatureRepo *repo);
void tnet_feature_repo_next(TNetFeatureRepo *repo);
@@ -28,7 +28,8 @@ extern "C" {
size_t sample_rate,
const char *tag,
lua_State *L,
- int debug);
+ int debug,
+ MContext *context);
void tnet_label_repo_destroy(TNetLabelRepo *repo);
#ifdef __cplusplus
diff --git a/htk_io/src/init.c b/htk_io/src/init.c
index 8a1ec3b..a5132ba 100644
--- a/htk_io/src/init.c
+++ b/htk_io/src/init.c
@@ -1,4 +1,5 @@
-#include "nerv/common.h"
+#include "nerv/lib/common.h"
+#include "nerv/matrix/matrix.h"
#include "cwrapper.h"
#include <stdio.h>
@@ -28,12 +29,14 @@ static int feat_repo_current_tag(lua_State *L) {
}
static int feat_repo_current_utterance(lua_State *L) {
+ MContext *context;
+ MMATRIX_GET_CONTEXT(L, 3);
TNetFeatureRepo *repo = luaT_checkudata(L, 1, nerv_tnet_feat_repo_tname);
int debug;
if (!lua_isboolean(L, 2))
nerv_error(L, "debug flag should be a boolean");
debug = lua_toboolean(L, 2);
- Matrix *utter = tnet_feature_repo_read_utterance(repo, L, debug);
+ Matrix *utter = tnet_feature_repo_read_utterance(repo, L, debug, context);
luaT_pushudata(L, utter, nerv_matrix_host_float_tname);
return 1;
}
@@ -72,6 +75,8 @@ static int label_repo_new(lua_State *L) {
}
static int label_repo_read_utterance(lua_State *L) {
+ MContext *context;
+ MMATRIX_GET_CONTEXT(L, 5);
TNetLabelRepo *repo = luaT_checkudata(L, 1, nerv_tnet_label_repo_tname);
TNetFeatureRepo *feat_repo = luaT_checkudata(L, 2, nerv_tnet_feat_repo_tname);
size_t frames = luaL_checkinteger(L, 3);
@@ -82,7 +87,8 @@ static int label_repo_read_utterance(lua_State *L) {
Matrix *utter = tnet_label_repo_read_utterance(repo,
frames,
tnet_feature_repo_current_samplerate(feat_repo),
- tnet_feature_repo_current_tag(feat_repo), L, debug);
+ tnet_feature_repo_current_tag(feat_repo),
+ L, debug, context);
luaT_pushudata(L, utter, nerv_matrix_host_float_tname);
return 1;
}
diff --git a/htk_io/src/test.c b/htk_io/src/test.c
index 6812ef1..1ced108 100644
--- a/htk_io/src/test.c
+++ b/htk_io/src/test.c
@@ -1,6 +1,9 @@
#include "cwrapper.h"
+#include "nerv/lib/matrix/mmatrix.h"
#include <stdio.h>
+MContext context;
+
void print_nerv_matrix(Matrix *mat) {
int n = mat->nrow;
int m = mat->ncol;
@@ -22,7 +25,7 @@ int main() {
"/slfs1/users/mfy43/swb_ivec/train_bp.scp",
"/slfs1/users/mfy43/swb_ivec/plp_0_d_a.conf", 5);
Matrix *feat_utter;
- feat_utter = tnet_feature_repo_read_utterance(feat_repo, NULL, 1);
+ feat_utter = tnet_feature_repo_read_utterance(feat_repo, NULL, 1, &context);
TNetLabelRepo *lab_repo = tnet_label_repo_new(
"/slfs1/users/mfy43/swb_ivec/ref.mlf",
@@ -34,7 +37,7 @@ int main() {
feat_utter->nrow - 5 * 2,
tnet_feature_repo_current_samplerate(feat_repo),
tnet_feature_repo_current_tag(feat_repo), NULL,
- 1);
+ 1, &context);
print_nerv_matrix(lab_utter);
return 0;
}