ref: c0e8f37c8bd2f9e6470979e210b5c2b61b9eedfd
parent: 575d8d6fa450d5a37701afed0cc0a4e32818c6e6
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Mon Nov 26 07:44:45 EST 2018
Cleaning up the API
--- a/dnn/lpcnet.c
+++ b/dnn/lpcnet.c
@@ -32,7 +32,9 @@
#include "lpcnet.h"
#define NB_FEATURES 38
+#define LPC_ORDER 16
+
#define PITCH_GAIN_FEATURE 37
#define PDF_FLOOR 0.002
@@ -40,6 +42,13 @@
#define SAMPLE_INPUT_SIZE (2*EMBED_SIG_OUT_SIZE + EMBED_EXC_OUT_SIZE + FEATURE_DENSE2_OUT_SIZE)
+struct LPCNetState {+ NNetState nnet;
+ int last_exc;
+ short last_sig[LPC_ORDER];
+};
+
+
static int ulaw2lin(int u)
{float s;
@@ -97,12 +106,25 @@
compute_mdense(&dual_fc, pdf, net->gru_b_state);
}
-void generate_samples(LPCNetState *lpcnet, short *output, const float *features, int pitch, int N)
+LPCNetState *lpcnet_create()
{+ LPCNetState *lpcnet;
+ lpcnet = (LPCNetState *)calloc(sizeof(LPCNetState), 1);
+ return lpcnet;
+}
+
+void lpcnet_destroy(LPCNetState *lpcnet)
+{+ free(lpcnet);
+}
+
+void lpcnet_synthesize(LPCNetState *lpcnet, short *output, const float *features, int N)
+{int i;
float condition[FEATURE_DENSE2_OUT_SIZE];
float lpc[LPC_ORDER];
float pdf[DUAL_FC_OUT_SIZE];
+ int pitch = (int)floor(.5 + 50*features[36]+100);
run_frame_network(&lpcnet->nnet, condition, lpc, features, pitch);
for (i=0;i<N;i++)
{--- a/dnn/lpcnet.h
+++ b/dnn/lpcnet.h
@@ -27,18 +27,12 @@
#ifndef _LPCNET_H_
#define _LPCNET_H_
+typedef struct LPCNetState LPCNetState;
-#include "nnet_data.h"
+LPCNetState *lpcnet_create();
-#define LPC_ORDER 16
+void lpcnet_destroy(LPCNetState *lpcnet);
-typedef struct {- NNetState nnet;
- int last_exc;
- short last_sig[LPC_ORDER];
-} LPCNetState;
-
-
-
+void lpcnet_synthesize(LPCNetState *lpcnet, short *output, const float *features, int N);
#endif
--
⑨