Skip to content

Commit

Permalink
Remove support for LPCNet quantization
Browse files Browse the repository at this point in the history
  • Loading branch information
jmvalin committed Jun 22, 2023
1 parent bfa01f1 commit 247e6a5
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 972 deletions.
8 changes: 8 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ noinst_PROGRAMS = celt/tests/test_unit_cwrs32 \
celt/tests/test_unit_types \
opus_compare \
opus_demo \
lpcnet_demo \
dump_data \
repacketizer_demo \
silk/tests/test_unit_LPC_inv_pred_gain \
tests/test_opus_api \
Expand Down Expand Up @@ -239,6 +241,12 @@ opus_custom_demo_LDADD = libopus.la $(LIBM)
endif
endif

lpcnet_demo_SOURCES = dnn/lpcnet_demo.c
lpcnet_demo_LDADD = $(LPCNET_OBJ) $(CELT_OBJ) $(LIBM)

dump_data_SOURCES = dnn/dump_data.c
dump_data_LDADD = $(LPCNET_OBJ) $(CELT_OBJ) $(LIBM)

EXTRA_DIST = opus.pc.in \
opus-uninstalled.pc.in \
opus.m4 \
Expand Down
50 changes: 3 additions & 47 deletions dnn/dump_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void biquad(float *y, float mem[2], const float *x, const float *b, const
}
}

static float uni_rand() {
static float uni_rand(void) {
return rand()/(double)RAND_MAX-.5;
}

Expand Down Expand Up @@ -135,9 +135,6 @@ int main(int argc, char **argv) {
LPCNetEncState *st;
float noise_std=0;
int training = -1;
int encode = 0;
int decode = 0;
int quantize = 0;
int burg = 0;
srand(getpid());
st = lpcnet_encoder_create();
Expand All @@ -151,24 +148,7 @@ int main(int argc, char **argv) {
training = 0;
}
if (argc == 5 && strcmp(argv[1], "-train")==0) training = 1;
if (argc == 5 && strcmp(argv[1], "-qtrain")==0) {
training = 1;
quantize = 1;
}
if (argc == 4 && strcmp(argv[1], "-test")==0) training = 0;
if (argc == 4 && strcmp(argv[1], "-qtest")==0) {
training = 0;
quantize = 1;
}
if (argc == 4 && strcmp(argv[1], "-encode")==0) {
training = 0;
quantize = 1;
encode = 1;
}
if (argc == 4 && strcmp(argv[1], "-decode")==0) {
training = 0;
decode = 1;
}
if (training == -1) {
fprintf(stderr, "usage: %s -train <speech> <features out> <pcm out>\n", argv0);
fprintf(stderr, " or %s -test <speech> <features out>\n", argv0);
Expand All @@ -184,23 +164,6 @@ int main(int argc, char **argv) {
fprintf(stderr,"Error opening output feature file: %s\n", argv[3]);
exit(1);
}
if (decode) {
float vq_mem[NB_BANDS] = {0};
while (1) {
int ret;
unsigned char buf[8];
float features[4][NB_TOTAL_FEATURES];
/*int c0_id, main_pitch, modulation, corr_id, vq_end[3], vq_mid, interp_id;*/
/*ret = fscanf(f1, "%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);*/
ret = fread(buf, 1, 8, f1);
if (ret != 8) break;
decode_packet(features, vq_mem, buf);
for (i=0;i<4;i++) {
fwrite(features[i], sizeof(float), NB_TOTAL_FEATURES, ffeat);
}
}
return 0;
}
if (training) {
fpcm = fopen(argv[4], "wb");
if (fpcm == NULL) {
Expand Down Expand Up @@ -279,18 +242,11 @@ int main(int argc, char **argv) {
compute_noise(&noisebuf[st->pcount*FRAME_SIZE], noise_std);
}

if (!quantize) {
process_single_frame(st, ffeat);
if (fpcm) write_audio(st, pcm, &noisebuf[st->pcount*FRAME_SIZE], fpcm, 1);
}
process_single_frame(st, ffeat);
if (fpcm) write_audio(st, pcm, &noisebuf[st->pcount*FRAME_SIZE], fpcm, 1);
st->pcount++;
/* Running on groups of 4 frames. */
if (st->pcount == 4) {
if (quantize) {
unsigned char buf[8];
process_superframe(st, buf, ffeat, encode, quantize);
if (fpcm) write_audio(st, pcmbuf, noisebuf, fpcm, 4);
}
st->pcount = 0;
}
/*if (fpcm) fwrite(pcm, sizeof(short), FRAME_SIZE, fpcm);*/
Expand Down
40 changes: 0 additions & 40 deletions dnn/lpcnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,43 +279,3 @@ void lpcnet_synthesize_impl(LPCNetState *lpcnet, const float *features, short *o
LPCNET_EXPORT void lpcnet_synthesize(LPCNetState *lpcnet, const float *features, short *output, int N) {
lpcnet_synthesize_impl(lpcnet, features, output, N, 0);
}

#ifndef OPUS_BUILD

LPCNET_EXPORT int lpcnet_decoder_get_size()
{
return sizeof(LPCNetDecState);
}

LPCNET_EXPORT int lpcnet_decoder_init(LPCNetDecState *st)
{
memset(st, 0, lpcnet_decoder_get_size());
lpcnet_init(&st->lpcnet_state);
return 0;
}

LPCNET_EXPORT LPCNetDecState *lpcnet_decoder_create()
{
LPCNetDecState *st;
st = malloc(lpcnet_decoder_get_size());
lpcnet_decoder_init(st);
return st;
}

LPCNET_EXPORT void lpcnet_decoder_destroy(LPCNetDecState *st)
{
free(st);
}

LPCNET_EXPORT int lpcnet_decode(LPCNetDecState *st, const unsigned char *buf, short *pcm)
{
int k;
float features[4][NB_TOTAL_FEATURES];
decode_packet(features, st->vq_mem, buf);
for (k=0;k<4;k++) {
lpcnet_synthesize(&st->lpcnet_state, features[k], &pcm[k*FRAME_SIZE], FRAME_SIZE);
}
return 0;
}

#endif
156 changes: 0 additions & 156 deletions dnn/lpcnet_dec.c

This file was deleted.

38 changes: 3 additions & 35 deletions dnn/lpcnet_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,13 @@ void free_blob(unsigned char *blob, int len) {
# endif
#endif

#define MODE_ENCODE 0
#define MODE_DECODE 1
#define MODE_FEATURES 2
#define MODE_SYNTHESIS 3
#define MODE_PLC 4
#define MODE_ADDLPC 5

void usage(void) {
fprintf(stderr, "usage: lpcnet_demo -encode <input.pcm> <compressed.lpcnet>\n");
fprintf(stderr, " lpcnet_demo -decode <compressed.lpcnet> <output.pcm>\n");
fprintf(stderr, " lpcnet_demo -features <input.pcm> <features.f32>\n");
fprintf(stderr, "usage: lpcnet_demo -features <input.pcm> <features.f32>\n");
fprintf(stderr, " lpcnet_demo -synthesis <features.f32> <output.pcm>\n");
fprintf(stderr, " lpcnet_demo -plc <plc_options> <percent> <input.pcm> <output.pcm>\n");
fprintf(stderr, " lpcnet_demo -plc_file <plc_options> <percent> <input.pcm> <output.pcm>\n");
Expand All @@ -113,9 +109,7 @@ int main(int argc, char **argv) {
const char *filename = "weights_blob.bin";
#endif
if (argc < 4) usage();
if (strcmp(argv[1], "-encode") == 0) mode=MODE_ENCODE;
else if (strcmp(argv[1], "-decode") == 0) mode=MODE_DECODE;
else if (strcmp(argv[1], "-features") == 0) mode=MODE_FEATURES;
if (strcmp(argv[1], "-features") == 0) mode=MODE_FEATURES;
else if (strcmp(argv[1], "-synthesis") == 0) mode=MODE_SYNTHESIS;
else if (strcmp(argv[1], "-plc") == 0) {
mode=MODE_PLC;
Expand Down Expand Up @@ -160,33 +154,7 @@ int main(int argc, char **argv) {
#ifdef USE_WEIGHTS_FILE
data = load_blob(filename, &len);
#endif
if (mode == MODE_ENCODE) {
LPCNetEncState *net;
net = lpcnet_encoder_create();
while (1) {
unsigned char buf[LPCNET_COMPRESSED_SIZE];
short pcm[LPCNET_PACKET_SAMPLES];
size_t ret;
ret = fread(pcm, sizeof(pcm[0]), LPCNET_PACKET_SAMPLES, fin);
if (feof(fin) || ret != LPCNET_PACKET_SAMPLES) break;
lpcnet_encode(net, pcm, buf);
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[LPCNET_COMPRESSED_SIZE];
short pcm[LPCNET_PACKET_SAMPLES];
size_t ret;
ret = fread(buf, sizeof(buf[0]), LPCNET_COMPRESSED_SIZE, fin);
if (feof(fin) || ret != LPCNET_COMPRESSED_SIZE) break;
lpcnet_decode(net, buf, pcm);
fwrite(pcm, sizeof(pcm[0]), LPCNET_PACKET_SAMPLES, fout);
}
lpcnet_decoder_destroy(net);
} else if (mode == MODE_FEATURES) {
if (mode == MODE_FEATURES) {
LPCNetEncState *net;
net = lpcnet_encoder_create();
while (1) {
Expand Down
Loading

0 comments on commit 247e6a5

Please sign in to comment.