From 77d02dbd2f6e93cedd83e0ebab15fb2b5fedeab1 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Wed, 27 Mar 2019 14:12:52 -0400 Subject: [PATCH] Using macros for sizes in the demo --- dnn/include/lpcnet.h | 2 ++ dnn/lpcnet_demo.c | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/dnn/include/lpcnet.h b/dnn/include/lpcnet.h index 44dfb593..627598aa 100644 --- a/dnn/include/lpcnet.h +++ b/dnn/include/lpcnet.h @@ -49,6 +49,8 @@ #define LPCNET_COMPRESSED_SIZE 8 /** Number of audio samples in a packet. */ #define LPCNET_PACKET_SAMPLES (4*160) +/** Number of audio samples in a feature frame (not for encoding/decoding). */ +#define LPCNET_FRAME_SIZE (160) typedef struct LPCNetState LPCNetState; diff --git a/dnn/lpcnet_demo.c b/dnn/lpcnet_demo.c index afa6cf9f..5dbdbc31 100644 --- a/dnn/lpcnet_demo.c +++ b/dnn/lpcnet_demo.c @@ -73,24 +73,24 @@ int main(int argc, char **argv) { LPCNetEncState *net; net = lpcnet_encoder_create(); while (1) { - unsigned char buf[8]; - short pcm[4*FRAME_SIZE]; - fread(pcm, sizeof(pcm[0]), 4*FRAME_SIZE, fin); + unsigned char buf[LPCNET_COMPRESSED_SIZE]; + short pcm[LPCNET_PACKET_SAMPLES]; + fread(pcm, sizeof(pcm[0]), LPCNET_PACKET_SAMPLES, fin); if (feof(fin)) break; lpcnet_encode(net, pcm, buf); - fwrite(buf, 1, 8, fout); + fwrite(buf, 1, LPCNET_COMPRESSED_SIZE, fout); } lpcnet_encoder_destroy(net); } else if (mode == MODE_DECODE) { LPCNetDecState *net; net = lpcnet_decoder_create(); while (1) { - unsigned char buf[8]; - short pcm[4*FRAME_SIZE]; - fread(buf, sizeof(buf[0]), 8, fin); + unsigned char buf[LPCNET_COMPRESSED_SIZE]; + short pcm[LPCNET_PACKET_SAMPLES]; + fread(buf, sizeof(buf[0]), LPCNET_COMPRESSED_SIZE, fin); if (feof(fin)) break; lpcnet_decode(net, buf, pcm); - fwrite(pcm, sizeof(pcm[0]), 4*FRAME_SIZE, fout); + fwrite(pcm, sizeof(pcm[0]), LPCNET_PACKET_SAMPLES, fout); } lpcnet_decoder_destroy(net); } else if (mode == MODE_FEATURES) { @@ -101,13 +101,13 @@ int main(int argc, char **argv) { while (1) { float in_features[NB_TOTAL_FEATURES]; float features[NB_FEATURES]; - short pcm[FRAME_SIZE]; + short pcm[LPCNET_FRAME_SIZE]; fread(in_features, sizeof(features[0]), NB_TOTAL_FEATURES, fin); if (feof(fin)) break; RNN_COPY(features, in_features, NB_FEATURES); RNN_CLEAR(&features[18], 18); - lpcnet_synthesize(net, features, pcm, FRAME_SIZE); - fwrite(pcm, sizeof(pcm[0]), FRAME_SIZE, fout); + lpcnet_synthesize(net, features, pcm, LPCNET_FRAME_SIZE); + fwrite(pcm, sizeof(pcm[0]), LPCNET_FRAME_SIZE, fout); } lpcnet_destroy(net); } else {