summaryrefslogtreecommitdiff
path: root/htk_io/src
diff options
context:
space:
mode:
Diffstat (limited to 'htk_io/src')
-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
4 files changed, 28 insertions, 15 deletions
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;
}