From 0e397a7241a8dd0021acc0677c80c222c5156440 Mon Sep 17 00:00:00 2001
From: Jean-Marc Valin <jmvalin@amazon.com>
Date: Wed, 18 Oct 2023 00:43:03 -0400
Subject: [PATCH] Making the build possible without the models

No dependency on the data files if no DNN code enabled
---
 Makefile.am         |  8 ++++++++
 celt/celt_decoder.c |  3 +++
 lpcnet_headers.mk   | 20 +++++++++++---------
 lpcnet_sources.mk   |  1 +
 silk/API.h          |  3 +++
 src/opus_decoder.c  |  5 +++++
 6 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 50ff1eb4d..452f6d228 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -97,6 +97,14 @@ include lpcnet_headers.mk
 include silk_headers.mk
 include opus_headers.mk
 
+LPCNET_HEAD =
+if ENABLE_DEEP_PLC
+LPCNET_HEAD += $(DEEP_PLC_HEAD)
+endif
+if ENABLE_DRED
+LPCNET_HEAD += $(DRED_HEAD)
+endif
+
 libopus_la_SOURCES = $(CELT_SOURCES) $(SILK_SOURCES) $(LPCNET_SOURCES) $(OPUS_SOURCES)
 libopus_la_LDFLAGS = -no-undefined -version-info @OPUS_LT_CURRENT@:@OPUS_LT_REVISION@:@OPUS_LT_AGE@
 libopus_la_LIBADD = $(NE10_LIBS) $(LIBM)
diff --git a/celt/celt_decoder.c b/celt/celt_decoder.c
index 7508a245c..dd7279766 100644
--- a/celt/celt_decoder.c
+++ b/celt/celt_decoder.c
@@ -50,8 +50,11 @@
 #include <stdarg.h>
 #include "celt_lpc.h"
 #include "vq.h"
+
+#ifdef ENABLE_DEEP_PLC
 #include "lpcnet.h"
 #include "lpcnet_private.h"
+#endif
 
 /* The maximum pitch lag to allow in the pitch-based PLC. It's possible to save
    CPU time in the PLC pitch search by making this smaller than MAX_PERIOD. The
diff --git a/lpcnet_headers.mk b/lpcnet_headers.mk
index f09adf16f..c4c8f7d45 100644
--- a/lpcnet_headers.mk
+++ b/lpcnet_headers.mk
@@ -1,9 +1,4 @@
-LPCNET_HEAD = \
-silk/dred_coding.h \
-silk/dred_config.h \
-silk/dred_decoder.h \
-silk/dred_encoder.h \
-dnn/dred_rdovae.h \
+DEEP_PLC_HEAD = \
 dnn/lpcnet.h \
 dnn/burg.h \
 dnn/common.h \
@@ -17,11 +12,18 @@ dnn/tansig_table.h \
 dnn/vec.h \
 dnn/vec_avx.h \
 dnn/vec_neon.h \
+dnn/pitchdnn.h \
+dnn/pitchdnn_data.h
+
+DRED_HEAD = \
+silk/dred_coding.h \
+silk/dred_config.h \
+silk/dred_decoder.h \
+silk/dred_encoder.h \
+dnn/dred_rdovae.h \
 dnn/dred_rdovae_constants.h \
 dnn/dred_rdovae_enc.h \
 dnn/dred_rdovae_enc_data.h \
 dnn/dred_rdovae_dec.h \
 dnn/dred_rdovae_dec_data.h \
-dnn/dred_rdovae_stats_data.h \
-dnn/pitchdnn.h \
-dnn/pitchdnn_data.h
+dnn/dred_rdovae_stats_data.h
diff --git a/lpcnet_sources.mk b/lpcnet_sources.mk
index b8313f305..051d3c44e 100644
--- a/lpcnet_sources.mk
+++ b/lpcnet_sources.mk
@@ -11,6 +11,7 @@ dnn/plc_data.c \
 dnn/parse_lpcnet_weights.c \
 dnn/pitchdnn.c \
 dnn/pitchdnn_data.c
+
 DRED_SOURCES = \
 dnn/dred_rdovae.c \
 dnn/dred_rdovae_enc.c \
diff --git a/silk/API.h b/silk/API.h
index 82ae68119..6e623b844 100644
--- a/silk/API.h
+++ b/silk/API.h
@@ -33,7 +33,10 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "errors.h"
 #include "entenc.h"
 #include "entdec.h"
+
+#ifdef ENABLE_DEEP_PLC
 #include "lpcnet_private.h"
+#endif
 
 #ifdef __cplusplus
 extern "C"
diff --git a/src/opus_decoder.c b/src/opus_decoder.c
index 1f098e82c..0a500398c 100644
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -51,7 +51,10 @@
 #include "define.h"
 #include "mathops.h"
 #include "cpu_support.h"
+
+#ifdef ENABLE_DEEP_PLC
 #include "dred_rdovae_dec_data.h"
+#endif
 
 struct OpusDecoder {
    int          celt_dec_offset;
@@ -1125,7 +1128,9 @@ int opus_decoder_get_nb_samples(const OpusDecoder *dec,
 }
 
 struct OpusDREDDecoder {
+#ifdef ENABLE_DRED
    RDOVAEDec model;
+#endif
    int arch;
    opus_uint32 magic;
 };
-- 
GitLab