Skip to content

Commit 393d463

Browse files
committed
Add lossgen_demo
Also skip the first loss values being generated since they're biased towards "not lost" due to the initialization.
1 parent a97151d commit 393d463

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

Makefile.am

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,16 @@ endif
308308
if ENABLE_DRED
309309
TESTS += tests/test_opus_dred
310310
endif
311+
312+
if ENABLE_LOSSGEN
313+
noinst_PROGRAMS += lossgen_demo
314+
lossgen_demo_SOURCES = dnn/lossgen_demo.c $(LOSSGEN_SOURCES)
315+
lossgen_demo_LDADD = $(LIBM)
311316
endif
312317

318+
endif
319+
320+
313321
EXTRA_DIST = opus.pc.in \
314322
opus-uninstalled.pc.in \
315323
opus.m4 \

dnn/lossgen.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void compute_generic_dense_lossgen(const LinearLayer *layer, float *output, cons
7070
}
7171

7272

73-
int sample_loss(
73+
static int sample_loss_impl(
7474
LossGenState *st,
7575
float percent_loss)
7676
{
@@ -90,6 +90,19 @@ int sample_loss(
9090
return loss;
9191
}
9292

93+
int sample_loss(
94+
LossGenState *st,
95+
float percent_loss)
96+
{
97+
/* Due to GRU being initialized with zeros, the first packets aren't quite random,
98+
so we skip them. */
99+
if (!st->used) {
100+
int i;
101+
for (i=0;i<100;i++) sample_loss_impl(st, percent_loss);
102+
st->used = 1;
103+
}
104+
return sample_loss_impl(st, percent_loss);
105+
}
93106

94107
void lossgen_init(LossGenState *st)
95108
{

dnn/lossgen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ typedef struct {
1515
float gru1_state[LOSSGEN_GRU1_STATE_SIZE];
1616
float gru2_state[LOSSGEN_GRU2_STATE_SIZE];
1717
int last_loss;
18+
int used;
1819
} LossGenState;
1920

2021

dnn/lossgen_demo.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "lossgen.h"
4+
int main(int argc, char **argv)
5+
{
6+
LossGenState st;
7+
long num_packets;
8+
long i;
9+
float percent;
10+
if (argc != 3) {
11+
fprintf(stderr, "usage: %s <percent_loss> <nb packets>\n", argv[0]);
12+
return 1;
13+
}
14+
lossgen_init(&st);
15+
percent = atof(argv[1]);
16+
num_packets = atol(argv[2]);
17+
/*printf("loss: %f %d\n", percent, num_packets);*/
18+
for (i=0;i<num_packets;i++) {
19+
printf("%d\n", sample_loss(&st, percent*0.01f));
20+
}
21+
return 0;
22+
}

0 commit comments

Comments
 (0)