From e63292bd563d02e4f1f1c03558d22b0fe35d444f Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Sun, 17 Mar 2019 13:24:58 -0400 Subject: [PATCH] Split off decoder code --- dnn/Makefile | 2 +- dnn/dump_data.c | 118 ++------------------------------- dnn/lpcnet_dec.c | 154 +++++++++++++++++++++++++++++++++++++++++++ dnn/lpcnet_enc.c | 6 +- dnn/lpcnet_private.h | 4 ++ dnn/train_lpcnet.py | 6 +- 6 files changed, 168 insertions(+), 122 deletions(-) create mode 100644 dnn/lpcnet_dec.c diff --git a/dnn/Makefile b/dnn/Makefile index 6d037bec..e29c7e25 100644 --- a/dnn/Makefile +++ b/dnn/Makefile @@ -22,7 +22,7 @@ endif all: dump_data test_lpcnet test_vec -dump_data_objs := src/dump_data.o src/freq.o src/kiss_fft.o src/pitch.o src/celt_lpc.o src/lpcnet_enc.o src/ceps_codebooks.o +dump_data_objs := src/dump_data.o src/freq.o src/kiss_fft.o src/pitch.o src/celt_lpc.o src/lpcnet_dec.o src/lpcnet_enc.o src/ceps_codebooks.o dump_data_deps := $(dump_data_objs:.o=.d) dump_data: $(dump_data_objs) gcc -o $@ $(CFLAGS) $(dump_data_objs) -lm diff --git a/dnn/dump_data.c b/dnn/dump_data.c index a9b24cba..33364c74 100644 --- a/dnn/dump_data.c +++ b/dnn/dump_data.c @@ -42,118 +42,6 @@ #include "lpcnet.h" #include "lpcnet_private.h" -typedef struct { - int byte_pos; - int bit_pos; - int max_bytes; - const unsigned char *chars; -} unpacker; - -void bits_unpacker_init(unpacker *bits, unsigned char *buf, int size) { - bits->byte_pos = 0; - bits->bit_pos = 0; - bits->max_bytes = size; - bits->chars = buf; -} - -unsigned int bits_unpack(unpacker *bits, int nb_bits) { - unsigned int d=0; - while(nb_bits) - { - if (bits->byte_pos == bits->max_bytes) { - fprintf(stderr, "something went horribly wrong\n"); - return 0; - } - d<<=1; - d |= (bits->chars[bits->byte_pos]>>(BITS_PER_CHAR-1 - bits->bit_pos))&1; - bits->bit_pos++; - if (bits->bit_pos==BITS_PER_CHAR) - { - bits->bit_pos=0; - bits->byte_pos++; - } - nb_bits--; - } - return d; -} - -void decode_packet(FILE *ffeat, float *vq_mem, unsigned char buf[8]) -{ - int c0_id; - int main_pitch; - int modulation; - int corr_id; - int vq_end[3]; - int vq_mid; - int interp_id; - - int i; - int sub; - int voiced = 1; - float frame_corr; - float features[4][NB_TOTAL_FEATURES]; - unpacker bits; - - bits_unpacker_init(&bits, buf, 8); - c0_id = bits_unpack(&bits, 7); - main_pitch = bits_unpack(&bits, 6); - modulation = bits_unpack(&bits, 3); - corr_id = bits_unpack(&bits, 2); - vq_end[0] = bits_unpack(&bits, 10); - vq_end[1] = bits_unpack(&bits, 10); - vq_end[2] = bits_unpack(&bits, 10); - vq_mid = bits_unpack(&bits, 13); - interp_id = bits_unpack(&bits, 3); - //fprintf(stdout, "%d %d %d %d %d %d %d %d %d\n", c0_id, main_pitch, modulation, corr_id, vq_end[0], vq_end[1], vq_end[2], vq_mid, interp_id); - - - for (i=0;i<4;i++) RNN_CLEAR(&features[i][0], NB_TOTAL_FEATURES); - - modulation -= 4; - if (modulation==-4) { - voiced = 0; - modulation = 0; - } - if (voiced) { - frame_corr = 0.3875f + .175f*corr_id; - } else { - frame_corr = 0.0375f + .075f*corr_id; - } - for (sub=0;sub<4;sub++) { - float p = pow(2.f, main_pitch/21.)*PITCH_MIN_PERIOD; - p *= 1 + modulation/16./7.*(2*sub-3); - features[sub][2*NB_BANDS] = .02*(p-100); - features[sub][2*NB_BANDS + 1] = frame_corr-.5; - } - - features[3][0] = (c0_id-64)/4.; - for (i=0;i= 4096) { - vq_mid -= 4096; - sign = -1; - } - for (i=0;i +#include +#include +#include "kiss_fft.h" +#include "common.h" +#include +#include "freq.h" +#include "pitch.h" +#include "arch.h" +#include "celt_lpc.h" +#include +#include "lpcnet_private.h" +#include "lpcnet.h" + + +typedef struct { + int byte_pos; + int bit_pos; + int max_bytes; + const unsigned char *chars; +} unpacker; + +void bits_unpacker_init(unpacker *bits, unsigned char *buf, int size) { + bits->byte_pos = 0; + bits->bit_pos = 0; + bits->max_bytes = size; + bits->chars = buf; +} + +unsigned int bits_unpack(unpacker *bits, int nb_bits) { + unsigned int d=0; + while(nb_bits) + { + if (bits->byte_pos == bits->max_bytes) { + fprintf(stderr, "something went horribly wrong\n"); + return 0; + } + d<<=1; + d |= (bits->chars[bits->byte_pos]>>(BITS_PER_CHAR-1 - bits->bit_pos))&1; + bits->bit_pos++; + if (bits->bit_pos==BITS_PER_CHAR) + { + bits->bit_pos=0; + bits->byte_pos++; + } + nb_bits--; + } + return d; +} + +void decode_packet(float features[4][NB_TOTAL_FEATURES], float *vq_mem, unsigned char buf[8]) +{ + int c0_id; + int main_pitch; + int modulation; + int corr_id; + int vq_end[3]; + int vq_mid; + int interp_id; + + int i; + int sub; + int voiced = 1; + float frame_corr; + ; + unpacker bits; + + bits_unpacker_init(&bits, buf, 8); + c0_id = bits_unpack(&bits, 7); + main_pitch = bits_unpack(&bits, 6); + modulation = bits_unpack(&bits, 3); + corr_id = bits_unpack(&bits, 2); + vq_end[0] = bits_unpack(&bits, 10); + vq_end[1] = bits_unpack(&bits, 10); + vq_end[2] = bits_unpack(&bits, 10); + vq_mid = bits_unpack(&bits, 13); + interp_id = bits_unpack(&bits, 3); + //fprintf(stdout, "%d %d %d %d %d %d %d %d %d\n", c0_id, main_pitch, modulation, corr_id, vq_end[0], vq_end[1], vq_end[2], vq_mid, interp_id); + + + for (i=0;i<4;i++) RNN_CLEAR(&features[i][0], NB_TOTAL_FEATURES); + + modulation -= 4; + if (modulation==-4) { + voiced = 0; + modulation = 0; + } + if (voiced) { + frame_corr = 0.3875f + .175f*corr_id; + } else { + frame_corr = 0.0375f + .075f*corr_id; + } + for (sub=0;sub<4;sub++) { + float p = pow(2.f, main_pitch/21.)*PITCH_MIN_PERIOD; + p *= 1 + modulation/16./7.*(2*sub-3); + features[sub][2*NB_BANDS] = .02*(p-100); + features[sub][2*NB_BANDS + 1] = frame_corr-.5; + } + + features[3][0] = (c0_id-64)/4.; + for (i=0;i= 4096) { + vq_mid -= 4096; + sign = -1; + } + for (i=0;i