ref: 8dcccc89348f1f7916338a4b2c36574fc1e90b27
parent: 7086dd73dc7075a1d230f8882f810b3eae592c9f
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Fri Mar 15 09:52:24 EDT 2019
library encoder...
--- a/dnn/dump_data.c
+++ b/dnn/dump_data.c
@@ -369,7 +369,8 @@
st->pcount++;
/* Running on groups of 4 frames. */
if (st->pcount == 4) {
- process_superframe(st, ffeat, encode, quantize);
+ unsigned char buf[8];
+ process_superframe(st, buf, ffeat, encode, quantize);
if (fpcm) write_audio(st, pcmbuf, noisebuf, fpcm);
st->pcount = 0;
}
--- a/dnn/lpcnet.h
+++ b/dnn/lpcnet.h
@@ -42,6 +42,9 @@
void lpcnet_encoder_destroy(LPCNetEncState *st);
+int lpcnet_encode(LPCNetEncState *st, const short *pcm, unsigned char *buf);
+
+
LPCNetState *lpcnet_create();
--- a/dnn/lpcnet_enc.c
+++ b/dnn/lpcnet_enc.c
@@ -586,7 +586,7 @@
}
}
-void process_superframe(LPCNetEncState *st, FILE *ffeat, int encode, int quantize) {
+void process_superframe(LPCNetEncState *st, unsigned char *buf, FILE *ffeat, int encode, int quantize) {
int i;
int sub;
int best_i;
@@ -724,7 +724,6 @@
//printf("\n");
RNN_COPY(st->vq_mem, &st->features[3][0], NB_BANDS);
if (encode) {
- unsigned char buf[8];
packer bits;
//fprintf(stdout, "%d %d %d %d %d %d %d %d %d\n", c0_id+64, main_pitch, voiced ? modulation+4 : 0, corr_id, vq_end[0], vq_end[1], vq_end[2], vq_mid, interp_id);
bits_packer_init(&bits, buf, 8);
@@ -737,8 +736,8 @@
bits_pack(&bits, vq_end[2], 10);
bits_pack(&bits, vq_mid, 13);
bits_pack(&bits, interp_id, 3);
- fwrite(buf, 1, 8, ffeat);
- } else {
+ if (ffeat) fwrite(buf, 1, 8, ffeat);
+ } else if (ffeat) {
for (i=0;i<4;i++) {
fwrite(st->features[i], sizeof(float), NB_TOTAL_FEATURES, ffeat);
}
@@ -753,4 +752,17 @@
*mem = -coef*x[i];
y[i] = yi;
}
+}
+
+int lpcnet_encode(LPCNetEncState *st, const short *pcm, unsigned char *buf) {
+ int i, k;
+ for (k=0;k<4;k++) {
+ float x[FRAME_SIZE];
+ for (i=0;i<FRAME_SIZE;i++) x[i] = pcm[k*FRAME_SIZE + i];
+ preemphasis(x, &st->mem_preemph, x, PREEMPHASIS, FRAME_SIZE);
+ st->pcount = k;
+ compute_frame_features(st, x);
+ }
+ process_superframe(st, buf, NULL, 1, 1);
+ return 0;
}
--- a/dnn/lpcnet_private.h
+++ b/dnn/lpcnet_private.h
@@ -18,6 +18,7 @@
struct LPCNetEncState{
float analysis_mem[OVERLAP_SIZE];
+ float mem_preemph;
int pcount;
float pitch_mem[LPC_ORDER];
float pitch_filt;
@@ -46,7 +47,7 @@
void perform_double_interp(float features[4][NB_TOTAL_FEATURES], const float *mem, int best_id);
-void process_superframe(LPCNetEncState *st, FILE *ffeat, int encode, int quantize);
+void process_superframe(LPCNetEncState *st, unsigned char *buf, FILE *ffeat, int encode, int quantize);
void compute_frame_features(LPCNetEncState *st, const float *in);
--
⑨