mirror of
https://github.com/xiph/opus.git
synced 2025-06-07 16:00:56 +00:00
C code for packet loss simulator
This commit is contained in:
parent
b923fd1e28
commit
bd710e97f3
4 changed files with 101 additions and 1 deletions
69
dnn/lossgen.c
Normal file
69
dnn/lossgen.c
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include "lossgen.h"
|
||||||
|
#include "os_support.h"
|
||||||
|
#include "nnet.h"
|
||||||
|
#include "lpcnet_private.h"
|
||||||
|
|
||||||
|
int sample_loss(
|
||||||
|
LossGenState *st,
|
||||||
|
float percent_loss,
|
||||||
|
int arch
|
||||||
|
)
|
||||||
|
{
|
||||||
|
float input[2];
|
||||||
|
float tmp[LOSSGEN_DENSE_IN_OUT_SIZE];
|
||||||
|
float out;
|
||||||
|
int loss;
|
||||||
|
LossGen *model = &st->model;
|
||||||
|
input[0] = st->last_loss;
|
||||||
|
input[1] = percent_loss;
|
||||||
|
compute_generic_dense(&model->lossgen_dense_in, tmp, input, ACTIVATION_TANH, arch);
|
||||||
|
compute_generic_gru(&model->lossgen_gru1_input, &model->lossgen_gru1_recurrent, st->gru1_state, tmp, arch);
|
||||||
|
compute_generic_gru(&model->lossgen_gru2_input, &model->lossgen_gru2_recurrent, st->gru2_state, st->gru1_state, arch);
|
||||||
|
compute_generic_dense(&model->lossgen_dense_out, &out, st->gru2_state, ACTIVATION_SIGMOID, arch);
|
||||||
|
loss = (float)rand()/RAND_MAX < out;
|
||||||
|
st->last_loss = loss;
|
||||||
|
return loss;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void lossgen_init(LossGenState *st)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
OPUS_CLEAR(st, 1);
|
||||||
|
#ifndef USE_WEIGHTS_FILE
|
||||||
|
ret = init_lossgen(&st->model, lossgen_arrays);
|
||||||
|
#else
|
||||||
|
ret = 0;
|
||||||
|
#endif
|
||||||
|
celt_assert(ret == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lossgen_load_model(LossGenState *st, const unsigned char *data, int len) {
|
||||||
|
WeightArray *list;
|
||||||
|
int ret;
|
||||||
|
parse_weights(&list, data, len);
|
||||||
|
ret = init_lossgen(&st->model, list);
|
||||||
|
opus_free(list);
|
||||||
|
if (ret == 0) return 0;
|
||||||
|
else return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#include <stdio.h>
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int i, N;
|
||||||
|
float p;
|
||||||
|
LossGenState st;
|
||||||
|
lossgen_init(&st);
|
||||||
|
p = atof(argv[1]);
|
||||||
|
N = atoi(argv[2]);
|
||||||
|
for (i=0;i<N;i++) {
|
||||||
|
printf("%d\n", sample_loss(&st, p, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
30
dnn/lossgen.h
Normal file
30
dnn/lossgen.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef LOSSGEN_H
|
||||||
|
#define LOSSGEN_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "lossgen_data.h"
|
||||||
|
|
||||||
|
#define PITCH_MIN_PERIOD 32
|
||||||
|
#define PITCH_MAX_PERIOD 256
|
||||||
|
|
||||||
|
#define NB_XCORR_FEATURES (PITCH_MAX_PERIOD-PITCH_MIN_PERIOD)
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
LossGen model;
|
||||||
|
float gru1_state[LOSSGEN_GRU1_STATE_SIZE];
|
||||||
|
float gru2_state[LOSSGEN_GRU2_STATE_SIZE];
|
||||||
|
int last_loss;
|
||||||
|
} LossGenState;
|
||||||
|
|
||||||
|
|
||||||
|
void lossgen_init(LossGenState *st);
|
||||||
|
int lossgen_load_model(LossGenState *st, const unsigned char *data, int len);
|
||||||
|
|
||||||
|
int sample_loss(
|
||||||
|
LossGenState *st,
|
||||||
|
float percent_loss,
|
||||||
|
int arch
|
||||||
|
);
|
||||||
|
|
||||||
|
#endif
|
|
@ -147,6 +147,7 @@ extern const WeightArray rdovaedec_arrays[];
|
||||||
extern const WeightArray fwgan_arrays[];
|
extern const WeightArray fwgan_arrays[];
|
||||||
extern const WeightArray fargan_arrays[];
|
extern const WeightArray fargan_arrays[];
|
||||||
extern const WeightArray pitchdnn_arrays[];
|
extern const WeightArray pitchdnn_arrays[];
|
||||||
|
extern const WeightArray lossgen_arrays[];
|
||||||
|
|
||||||
int linear_init(LinearLayer *layer, const WeightArray *arrays,
|
int linear_init(LinearLayer *layer, const WeightArray *arrays,
|
||||||
const char *bias,
|
const char *bias,
|
||||||
|
|
|
@ -7,7 +7,7 @@ to build a generative model for packet loss.
|
||||||
|
|
||||||
We use the training data provided for the Audio Deep Packet Loss Concealment Challenge, which is available at:
|
We use the training data provided for the Audio Deep Packet Loss Concealment Challenge, which is available at:
|
||||||
|
|
||||||
http://plcchallenge2022pub.blob.core.windows.net/plcchallengearchive/test\_train.tar.gz
|
http://plcchallenge2022pub.blob.core.windows.net/plcchallengearchive/test_train.tar.gz
|
||||||
|
|
||||||
To create the training data, run:
|
To create the training data, run:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue