Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@amazon.com>2023-12-22 07:36:16 +0300
committerJean-Marc Valin <jmvalin@amazon.com>2023-12-22 11:10:31 +0300
commit83766d191c73cb760c22ebc8fa07ce7d0e7c5d97 (patch)
tree1146be86ab0d76f9255dcd8d02e4833261a7a12b
parentcaca188b5a0275b1c04baf8fcc9798b900692a2c (diff)
Add simulated loss to opus_demoexp_sim_loss2
-rw-r--r--Makefile.am6
-rwxr-xr-xautogen.sh2
-rw-r--r--configure.ac9
-rw-r--r--dnn/lossgen.c14
-rw-r--r--dnn/lossgen.h4
-rw-r--r--lpcnet_headers.mk4
-rw-r--r--lpcnet_sources.mk4
-rw-r--r--src/opus_demo.c20
8 files changed, 51 insertions, 12 deletions
diff --git a/Makefile.am b/Makefile.am
index 4fd821a5..f2631f72 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -138,6 +138,9 @@ endif
if ENABLE_OSCE
LPCNET_HEAD += $(OSCE_HEAD)
endif
+if ENABLE_LOSSGEN
+LPCNET_HEAD += $(LOSSGEN_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@
@@ -189,6 +192,9 @@ TESTS = celt/tests/test_unit_cwrs32 \
tests/test_opus_projection
opus_demo_SOURCES = src/opus_demo.c
+if ENABLE_LOSSGEN
+opus_demo_SOURCES += $(LOSSGEN_SOURCES)
+endif
opus_demo_LDADD = libopus.la $(NE10_LIBS) $(LIBM)
diff --git a/autogen.sh b/autogen.sh
index 1987e38b..2cac2083 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -9,7 +9,7 @@ set -e
srcdir=`dirname $0`
test -n "$srcdir" && cd "$srcdir"
-dnn/download_model.sh 591c8ba
+dnn/download_model.sh caca188
echo "Updating build configuration files, please wait...."
diff --git a/configure.ac b/configure.ac
index 84ce651d..63ae9329 100644
--- a/configure.ac
+++ b/configure.ac
@@ -180,6 +180,15 @@ AS_IF([test "$enable_deep_plc" = "yes" || test "$enable_dred" = "yes" || test "$
])
AM_CONDITIONAL([ENABLE_DEEP_PLC], [test "$enable_deep_plc" = "yes" || test "$enable_dred" = "yes" || test "$enable_osce" = "yes" || test "$enable_osce_training_data" = "yes"])
+AC_ARG_ENABLE([lossgen],
+ [AS_HELP_STRING([--enable-lossgen], [Build opus_demo with packet loss simulator])],,
+ [enable_lossgen=no])
+
+AS_IF([test "$enable_lossgen" = "yes"],[
+ AC_DEFINE([ENABLE_LOSSGEN], [1], [LOSSGEN])
+])
+AM_CONDITIONAL([ENABLE_LOSSGEN], [test "$enable_lossgen" = "yes"])
+
has_float_approx=no
case "$host_cpu" in
i[[3456]]86 | x86_64 | arm* | aarch64* | powerpc64 | powerpc32 | ia64)
diff --git a/dnn/lossgen.c b/dnn/lossgen.c
index fa1ee71d..a0da5a4e 100644
--- a/dnn/lossgen.c
+++ b/dnn/lossgen.c
@@ -56,9 +56,7 @@ void compute_generic_dense_lossgen(const LinearLayer *layer, float *output, cons
int sample_loss(
LossGenState *st,
- float percent_loss,
- int arch
- )
+ float percent_loss)
{
float input[2];
float tmp[LOSSGEN_DENSE_IN_OUT_SIZE];
@@ -67,10 +65,10 @@ int sample_loss(
LossGen *model = &st->model;
input[0] = st->last_loss;
input[1] = percent_loss;
- compute_generic_dense_lossgen(&model->lossgen_dense_in, tmp, input, ACTIVATION_TANH, arch);
- compute_generic_gru_lossgen(&model->lossgen_gru1_input, &model->lossgen_gru1_recurrent, st->gru1_state, tmp, arch);
- compute_generic_gru_lossgen(&model->lossgen_gru2_input, &model->lossgen_gru2_recurrent, st->gru2_state, st->gru1_state, arch);
- compute_generic_dense_lossgen(&model->lossgen_dense_out, &out, st->gru2_state, ACTIVATION_SIGMOID, arch);
+ compute_generic_dense_lossgen(&model->lossgen_dense_in, tmp, input, ACTIVATION_TANH, 0);
+ compute_generic_gru_lossgen(&model->lossgen_gru1_input, &model->lossgen_gru1_recurrent, st->gru1_state, tmp, 0);
+ compute_generic_gru_lossgen(&model->lossgen_gru2_input, &model->lossgen_gru2_recurrent, st->gru2_state, st->gru1_state, 0);
+ compute_generic_dense_lossgen(&model->lossgen_dense_out, &out, st->gru2_state, ACTIVATION_SIGMOID, 0);
loss = (float)rand()/RAND_MAX < out;
st->last_loss = loss;
return loss;
@@ -114,7 +112,7 @@ int main(int argc, char **argv) {
p = atof(argv[1]);
N = atoi(argv[2]);
for (i=0;i<N;i++) {
- printf("%d\n", sample_loss(&st, p, 0));
+ printf("%d\n", sample_loss(&st, p));
}
}
#endif
diff --git a/dnn/lossgen.h b/dnn/lossgen.h
index cb0460ae..0ac0860f 100644
--- a/dnn/lossgen.h
+++ b/dnn/lossgen.h
@@ -23,8 +23,6 @@ int lossgen_load_model(LossGenState *st, const unsigned char *data, int len);
int sample_loss(
LossGenState *st,
- float percent_loss,
- int arch
- );
+ float percent_loss);
#endif
diff --git a/lpcnet_headers.mk b/lpcnet_headers.mk
index ce74d954..db750d29 100644
--- a/lpcnet_headers.mk
+++ b/lpcnet_headers.mk
@@ -38,3 +38,7 @@ dnn/osce_features.h \
dnn/nndsp.h \
dnn/lace_data.h \
dnn/nolace_data.h
+
+LOSSGEN_HEAD = \
+dnn/lossgen.h \
+dnn/lossgen_data.h
diff --git a/lpcnet_sources.mk b/lpcnet_sources.mk
index 17f04756..b108d8d4 100644
--- a/lpcnet_sources.mk
+++ b/lpcnet_sources.mk
@@ -30,6 +30,10 @@ dnn/nndsp.c \
dnn/lace_data.c \
dnn/nolace_data.c
+LOSSGEN_SOURCES = \
+dnn/lossgen.c \
+dnn/lossgen_data.c
+
DNN_SOURCES_X86_RTCD = dnn/x86/x86_dnn_map.c
DNN_SOURCES_AVX2 = dnn/x86/nnet_avx2.c
DNN_SOURCES_SSE4_1 = dnn/x86/nnet_sse4_1.c
diff --git a/src/opus_demo.c b/src/opus_demo.c
index bccdf976..6bc06769 100644
--- a/src/opus_demo.c
+++ b/src/opus_demo.c
@@ -39,6 +39,9 @@
#include "opus_types.h"
#include "opus_private.h"
#include "opus_multistream.h"
+#ifdef ENABLE_LOSSGEN
+#include "lossgen.h"
+#endif
#define MAX_PACKET 1500
@@ -111,6 +114,9 @@ void print_usage( char* argv[] )
fprintf(stderr, "-forcemono : force mono encoding, even for stereo input\n" );
fprintf(stderr, "-dtx : enable SILK DTX\n" );
fprintf(stderr, "-loss <perc> : optimize for loss percentage and simulate packet loss, in percent (0-100); default: 0\n" );
+#ifdef ENABLE_LOSSGEN
+ fprintf(stderr, "-sim_loss <perc> : simulate realistic (bursty) packet loss from percentage, using generative model\n" );
+#endif
fprintf(stderr, "-lossfile <file> : simulate packet loss, reading loss from file\n" );
fprintf(stderr, "-dred <frames> : add Deep REDundancy (in units of 10-ms frames)\n" );
}
@@ -346,6 +352,10 @@ int main(int argc, char *argv[])
int forcechannels;
int cvbr = 0;
int packet_loss_perc;
+#ifdef ENABLE_LOSSGEN
+ float lossgen_perc = -1.f;
+ LossGenState lossgen;
+#endif
opus_int32 count=0, count_act=0;
int k;
opus_int32 skip=0;
@@ -555,6 +565,12 @@ int main(int argc, char *argv[])
} else if( strcmp( argv[ args ], "-loss" ) == 0 ) {
packet_loss_perc = atoi( argv[ args + 1 ] );
args += 2;
+#ifdef ENABLE_LOSSGEN
+ } else if( strcmp( argv[ args ], "-sim_loss" ) == 0 ) {
+ lossgen_perc = atof( argv[ args + 1 ] );
+ lossgen_init(&lossgen);
+ args += 2;
+#endif
} else if( strcmp( argv[ args ], "-lossfile" ) == 0 ) {
packet_loss_file = fopen( argv[ args + 1 ], "r" );
if (packet_loss_file == NULL) {
@@ -933,6 +949,10 @@ int main(int argc, char *argv[])
if ( fscanf(packet_loss_file, "%d", &lost) != 1) {
lost = 0;
}
+#ifdef ENABLE_LOSSGEN
+ } else if (lossgen_perc >= 0) {
+ lost = sample_loss(&lossgen, lossgen_perc*.01f);
+#endif
} else {
lost = (packet_loss_perc>0) && (rand()%100 < packet_loss_perc);
}