ref: 393d463fdd6d17f3fef126a019102694ad89e2f7
parent: a97151d390978d93b4311ef8794bd3af23703355
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Sat Feb 17 09:20:44 EST 2024
Add lossgen_demo Also skip the first loss values being generated since they're biased towards "not lost" due to the initialization.
--- a/Makefile.am
+++ b/Makefile.am
@@ -308,7 +308,15 @@
if ENABLE_DRED
TESTS += tests/test_opus_dred
endif
+
+if ENABLE_LOSSGEN
+noinst_PROGRAMS += lossgen_demo
+lossgen_demo_SOURCES = dnn/lossgen_demo.c $(LOSSGEN_SOURCES)
+lossgen_demo_LDADD = $(LIBM)
endif
+
+endif
+
EXTRA_DIST = opus.pc.in \
opus-uninstalled.pc.in \
--- a/dnn/lossgen.c
+++ b/dnn/lossgen.c
@@ -70,7 +70,7 @@
}
-int sample_loss(
+static int sample_loss_impl(
LossGenState *st,
float percent_loss)
{@@ -90,6 +90,19 @@
return loss;
}
+int sample_loss(
+ LossGenState *st,
+ float percent_loss)
+{+ /* Due to GRU being initialized with zeros, the first packets aren't quite random,
+ so we skip them. */
+ if (!st->used) {+ int i;
+ for (i=0;i<100;i++) sample_loss_impl(st, percent_loss);
+ st->used = 1;
+ }
+ return sample_loss_impl(st, percent_loss);
+}
void lossgen_init(LossGenState *st)
{--- a/dnn/lossgen.h
+++ b/dnn/lossgen.h
@@ -15,6 +15,7 @@
float gru1_state[LOSSGEN_GRU1_STATE_SIZE];
float gru2_state[LOSSGEN_GRU2_STATE_SIZE];
int last_loss;
+ int used;
} LossGenState;
--- /dev/null
+++ b/dnn/lossgen_demo.c
@@ -1,0 +1,22 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "lossgen.h"
+int main(int argc, char **argv)
+{+ LossGenState st;
+ long num_packets;
+ long i;
+ float percent;
+ if (argc != 3) {+ fprintf(stderr, "usage: %s <percent_loss> <nb packets>\n", argv[0]);
+ return 1;
+ }
+ lossgen_init(&st);
+ percent = atof(argv[1]);
+ num_packets = atol(argv[2]);
+ /*printf("loss: %f %d\n", percent, num_packets);*/+ for (i=0;i<num_packets;i++) {+ printf("%d\n", sample_loss(&st, percent*0.01f));+ }
+ return 0;
+}
--
⑨