Replacing RNN_ macros with existing OPUS_ ones
This commit is contained in:
parent
5af9e9524a
commit
9f4fc8bbfa
12 changed files with 79 additions and 108 deletions
46
dnn/common.h
46
dnn/common.h
|
@ -6,16 +6,12 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include "opus_defines.h"
|
||||||
#define RNN_INLINE inline
|
|
||||||
#ifndef OPUS_INLINE
|
|
||||||
#define OPUS_INLINE inline
|
|
||||||
#endif
|
|
||||||
|
|
||||||
float lpc_from_cepstrum(float *lpc, const float *cepstrum);
|
float lpc_from_cepstrum(float *lpc, const float *cepstrum);
|
||||||
|
|
||||||
#define LOG256 5.5451774445f
|
#define LOG256 5.5451774445f
|
||||||
static RNN_INLINE float log2_approx(float x)
|
static OPUS_INLINE float log2_approx(float x)
|
||||||
{
|
{
|
||||||
int integer;
|
int integer;
|
||||||
float frac;
|
float frac;
|
||||||
|
@ -34,7 +30,7 @@ static RNN_INLINE float log2_approx(float x)
|
||||||
|
|
||||||
#define log_approx(x) (0.69315f*log2_approx(x))
|
#define log_approx(x) (0.69315f*log2_approx(x))
|
||||||
|
|
||||||
static RNN_INLINE float ulaw2lin(float u)
|
static OPUS_INLINE float ulaw2lin(float u)
|
||||||
{
|
{
|
||||||
float s;
|
float s;
|
||||||
float scale_1 = 32768.f/255.f;
|
float scale_1 = 32768.f/255.f;
|
||||||
|
@ -44,7 +40,7 @@ static RNN_INLINE float ulaw2lin(float u)
|
||||||
return s*scale_1*(exp(u/128.*LOG256)-1);
|
return s*scale_1*(exp(u/128.*LOG256)-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RNN_INLINE int lin2ulaw(float x)
|
static OPUS_INLINE int lin2ulaw(float x)
|
||||||
{
|
{
|
||||||
float u;
|
float u;
|
||||||
float scale = 255.f/32768.f;
|
float scale = 255.f/32768.f;
|
||||||
|
@ -58,39 +54,5 @@ static RNN_INLINE int lin2ulaw(float x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** RNNoise wrapper for malloc(). To do your own dynamic allocation, all you need t
|
|
||||||
o do is replace this function and rnnoise_free */
|
|
||||||
#ifndef OVERRIDE_RNNOISE_ALLOC
|
|
||||||
static RNN_INLINE void *rnnoise_alloc (size_t size)
|
|
||||||
{
|
|
||||||
return malloc(size);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** RNNoise wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function and rnnoise_alloc */
|
|
||||||
#ifndef OVERRIDE_RNNOISE_FREE
|
|
||||||
static RNN_INLINE void rnnoise_free (void *ptr)
|
|
||||||
{
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Copy n elements from src to dst. The 0* term provides compile-time type checking */
|
|
||||||
#ifndef OVERRIDE_RNN_COPY
|
|
||||||
#define RNN_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Copy n elements from src to dst, allowing overlapping regions. The 0* term
|
|
||||||
provides compile-time type checking */
|
|
||||||
#ifndef OVERRIDE_RNN_MOVE
|
|
||||||
#define RNN_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Set n elements of dst to zero */
|
|
||||||
#ifndef OVERRIDE_RNN_CLEAR
|
|
||||||
#define RNN_CLEAR(dst, n) (memset((dst), 0, (n)*sizeof(*(dst))))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "dred_rdovae_dec.h"
|
#include "dred_rdovae_dec.h"
|
||||||
#include "dred_rdovae_constants.h"
|
#include "dred_rdovae_constants.h"
|
||||||
|
#include "os_support.h"
|
||||||
|
|
||||||
void dred_rdovae_dec_init_states(
|
void dred_rdovae_dec_init_states(
|
||||||
RDOVAEDecState *h, /* io: state buffer handle */
|
RDOVAEDecState *h, /* io: state buffer handle */
|
||||||
|
@ -65,7 +65,7 @@ void dred_rdovae_decode_qframe(
|
||||||
output_index += DEC_DENSE1_OUT_SIZE;
|
output_index += DEC_DENSE1_OUT_SIZE;
|
||||||
|
|
||||||
compute_gruB(&model->dec_dense2, zero_vector, dec_state->dense2_state, &buffer[input_index]);
|
compute_gruB(&model->dec_dense2, zero_vector, dec_state->dense2_state, &buffer[input_index]);
|
||||||
RNN_COPY(&buffer[output_index], dec_state->dense2_state, DEC_DENSE2_OUT_SIZE);
|
OPUS_COPY(&buffer[output_index], dec_state->dense2_state, DEC_DENSE2_OUT_SIZE);
|
||||||
input_index = output_index;
|
input_index = output_index;
|
||||||
output_index += DEC_DENSE2_OUT_SIZE;
|
output_index += DEC_DENSE2_OUT_SIZE;
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ void dred_rdovae_decode_qframe(
|
||||||
output_index += DEC_DENSE3_OUT_SIZE;
|
output_index += DEC_DENSE3_OUT_SIZE;
|
||||||
|
|
||||||
compute_gruB(&model->dec_dense4, zero_vector, dec_state->dense4_state, &buffer[input_index]);
|
compute_gruB(&model->dec_dense4, zero_vector, dec_state->dense4_state, &buffer[input_index]);
|
||||||
RNN_COPY(&buffer[output_index], dec_state->dense4_state, DEC_DENSE4_OUT_SIZE);
|
OPUS_COPY(&buffer[output_index], dec_state->dense4_state, DEC_DENSE4_OUT_SIZE);
|
||||||
input_index = output_index;
|
input_index = output_index;
|
||||||
output_index += DEC_DENSE4_OUT_SIZE;
|
output_index += DEC_DENSE4_OUT_SIZE;
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ void dred_rdovae_decode_qframe(
|
||||||
output_index += DEC_DENSE5_OUT_SIZE;
|
output_index += DEC_DENSE5_OUT_SIZE;
|
||||||
|
|
||||||
compute_gruB(&model->dec_dense6, zero_vector, dec_state->dense6_state, &buffer[input_index]);
|
compute_gruB(&model->dec_dense6, zero_vector, dec_state->dense6_state, &buffer[input_index]);
|
||||||
RNN_COPY(&buffer[output_index], dec_state->dense6_state, DEC_DENSE6_OUT_SIZE);
|
OPUS_COPY(&buffer[output_index], dec_state->dense6_state, DEC_DENSE6_OUT_SIZE);
|
||||||
input_index = output_index;
|
input_index = output_index;
|
||||||
output_index += DEC_DENSE6_OUT_SIZE;
|
output_index += DEC_DENSE6_OUT_SIZE;
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
#include "dred_rdovae_enc.h"
|
#include "dred_rdovae_enc.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "os_support.h"
|
||||||
|
|
||||||
void dred_rdovae_encode_dframe(
|
void dred_rdovae_encode_dframe(
|
||||||
RDOVAEEncState *enc_state, /* io: encoder state */
|
RDOVAEEncState *enc_state, /* io: encoder state */
|
||||||
|
@ -54,7 +55,7 @@ void dred_rdovae_encode_dframe(
|
||||||
output_index += ENC_DENSE1_OUT_SIZE;
|
output_index += ENC_DENSE1_OUT_SIZE;
|
||||||
|
|
||||||
compute_gruB(&model->enc_dense2, zero_vector, enc_state->dense2_state, &buffer[input_index]);
|
compute_gruB(&model->enc_dense2, zero_vector, enc_state->dense2_state, &buffer[input_index]);
|
||||||
RNN_COPY(&buffer[output_index], enc_state->dense2_state, ENC_DENSE2_OUT_SIZE);
|
OPUS_COPY(&buffer[output_index], enc_state->dense2_state, ENC_DENSE2_OUT_SIZE);
|
||||||
input_index = output_index;
|
input_index = output_index;
|
||||||
output_index += ENC_DENSE2_OUT_SIZE;
|
output_index += ENC_DENSE2_OUT_SIZE;
|
||||||
|
|
||||||
|
@ -63,7 +64,7 @@ void dred_rdovae_encode_dframe(
|
||||||
output_index += ENC_DENSE3_OUT_SIZE;
|
output_index += ENC_DENSE3_OUT_SIZE;
|
||||||
|
|
||||||
compute_gruB(&model->enc_dense4, zero_vector, enc_state->dense4_state, &buffer[input_index]);
|
compute_gruB(&model->enc_dense4, zero_vector, enc_state->dense4_state, &buffer[input_index]);
|
||||||
RNN_COPY(&buffer[output_index], enc_state->dense4_state, ENC_DENSE4_OUT_SIZE);
|
OPUS_COPY(&buffer[output_index], enc_state->dense4_state, ENC_DENSE4_OUT_SIZE);
|
||||||
input_index = output_index;
|
input_index = output_index;
|
||||||
output_index += ENC_DENSE4_OUT_SIZE;
|
output_index += ENC_DENSE4_OUT_SIZE;
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ void dred_rdovae_encode_dframe(
|
||||||
output_index += ENC_DENSE5_OUT_SIZE;
|
output_index += ENC_DENSE5_OUT_SIZE;
|
||||||
|
|
||||||
compute_gruB(&model->enc_dense6, zero_vector, enc_state->dense6_state, &buffer[input_index]);
|
compute_gruB(&model->enc_dense6, zero_vector, enc_state->dense6_state, &buffer[input_index]);
|
||||||
RNN_COPY(&buffer[output_index], enc_state->dense6_state, ENC_DENSE6_OUT_SIZE);
|
OPUS_COPY(&buffer[output_index], enc_state->dense6_state, ENC_DENSE6_OUT_SIZE);
|
||||||
input_index = output_index;
|
input_index = output_index;
|
||||||
output_index += ENC_DENSE6_OUT_SIZE;
|
output_index += ENC_DENSE6_OUT_SIZE;
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "lpcnet.h"
|
#include "lpcnet.h"
|
||||||
#include "lpcnet_private.h"
|
#include "lpcnet_private.h"
|
||||||
|
#include "os_support.h"
|
||||||
|
|
||||||
|
|
||||||
static void biquad(float *y, float mem[2], const float *x, const float *b, const float *a, int N) {
|
static void biquad(float *y, float mem[2], const float *x, const float *b, const float *a, int N) {
|
||||||
|
@ -98,7 +99,7 @@ void write_audio(LPCNetEncState *st, const opus_int16 *pcm, const int *noise, FI
|
||||||
e += noise[i];
|
e += noise[i];
|
||||||
e = IMIN(255, IMAX(0, e));
|
e = IMIN(255, IMAX(0, e));
|
||||||
|
|
||||||
RNN_MOVE(&st->sig_mem[1], &st->sig_mem[0], LPC_ORDER-1);
|
OPUS_MOVE(&st->sig_mem[1], &st->sig_mem[0], LPC_ORDER-1);
|
||||||
st->sig_mem[0] = p + ulaw2lin(e);
|
st->sig_mem[0] = p + ulaw2lin(e);
|
||||||
st->exc_mem = e;
|
st->exc_mem = e;
|
||||||
}
|
}
|
||||||
|
|
11
dnn/freq.c
11
dnn/freq.c
|
@ -39,6 +39,7 @@
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
#include "burg.h"
|
#include "burg.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include "os_support.h"
|
||||||
|
|
||||||
#define SQUARE(x) ((x)*(x))
|
#define SQUARE(x) ((x)*(x))
|
||||||
|
|
||||||
|
@ -94,8 +95,8 @@ int p
|
||||||
opus_val32 r;
|
opus_val32 r;
|
||||||
opus_val32 error = ac[0];
|
opus_val32 error = ac[0];
|
||||||
|
|
||||||
RNN_CLEAR(lpc, p);
|
OPUS_CLEAR(lpc, p);
|
||||||
RNN_CLEAR(rc, p);
|
OPUS_CLEAR(rc, p);
|
||||||
if (ac[0] != 0)
|
if (ac[0] != 0)
|
||||||
{
|
{
|
||||||
for (i = 0; i < p; i++) {
|
for (i = 0; i < p; i++) {
|
||||||
|
@ -169,7 +170,7 @@ static void compute_burg_cepstrum(const float *pcm, float *burg_cepstrum, int le
|
||||||
for (i=0;i<len-1;i++) burg_in[i] = pcm[i+1] - PREEMPHASIS*pcm[i];
|
for (i=0;i<len-1;i++) burg_in[i] = pcm[i+1] - PREEMPHASIS*pcm[i];
|
||||||
g = silk_burg_analysis(burg_lpc, burg_in, 1e-3, len-1, 1, order);
|
g = silk_burg_analysis(burg_lpc, burg_in, 1e-3, len-1, 1, order);
|
||||||
g /= len - 2*(order-1);
|
g /= len - 2*(order-1);
|
||||||
RNN_CLEAR(x, WINDOW_SIZE);
|
OPUS_CLEAR(x, WINDOW_SIZE);
|
||||||
x[0] = 1;
|
x[0] = 1;
|
||||||
for (i=0;i<order;i++) x[i+1] = -burg_lpc[i]*pow(.995, i+1);
|
for (i=0;i<order;i++) x[i+1] = -burg_lpc[i]*pow(.995, i+1);
|
||||||
forward_transform(LPC, x);
|
forward_transform(LPC, x);
|
||||||
|
@ -283,7 +284,7 @@ static float lpc_from_bands(float *lpc, const float *Ex)
|
||||||
float x_auto[WINDOW_SIZE];
|
float x_auto[WINDOW_SIZE];
|
||||||
interp_band_gain(Xr, Ex);
|
interp_band_gain(Xr, Ex);
|
||||||
Xr[FREQ_SIZE-1] = 0;
|
Xr[FREQ_SIZE-1] = 0;
|
||||||
RNN_CLEAR(X_auto, FREQ_SIZE);
|
OPUS_CLEAR(X_auto, FREQ_SIZE);
|
||||||
for (i=0;i<FREQ_SIZE;i++) X_auto[i].r = Xr[i];
|
for (i=0;i<FREQ_SIZE;i++) X_auto[i].r = Xr[i];
|
||||||
inverse_transform(x_auto, X_auto);
|
inverse_transform(x_auto, X_auto);
|
||||||
for (i=0;i<LPC_ORDER+1;i++) ac[i] = x_auto[i];
|
for (i=0;i<LPC_ORDER+1;i++) ac[i] = x_auto[i];
|
||||||
|
@ -312,7 +313,7 @@ float lpc_from_cepstrum(float *lpc, const float *cepstrum)
|
||||||
int i;
|
int i;
|
||||||
float Ex[NB_BANDS];
|
float Ex[NB_BANDS];
|
||||||
float tmp[NB_BANDS];
|
float tmp[NB_BANDS];
|
||||||
RNN_COPY(tmp, cepstrum, NB_BANDS);
|
OPUS_COPY(tmp, cepstrum, NB_BANDS);
|
||||||
tmp[0] += 4;
|
tmp[0] += 4;
|
||||||
idct(Ex, tmp);
|
idct(Ex, tmp);
|
||||||
for (i=0;i<NB_BANDS;i++) Ex[i] = pow(10.f, Ex[i])*compensation[i];
|
for (i=0;i<NB_BANDS;i++) Ex[i] = pow(10.f, Ex[i])*compensation[i];
|
||||||
|
|
33
dnn/lpcnet.c
33
dnn/lpcnet.c
|
@ -36,6 +36,7 @@
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
#include "lpcnet.h"
|
#include "lpcnet.h"
|
||||||
#include "lpcnet_private.h"
|
#include "lpcnet_private.h"
|
||||||
|
#include "os_support.h"
|
||||||
|
|
||||||
#define PREEMPH 0.85f
|
#define PREEMPH 0.85f
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ void rc2lpc(float *lpc, const float *rc)
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
float tmp[LPC_ORDER];
|
float tmp[LPC_ORDER];
|
||||||
float ntmp[LPC_ORDER] = {0.0};
|
float ntmp[LPC_ORDER] = {0.0};
|
||||||
RNN_COPY(tmp, rc, LPC_ORDER);
|
OPUS_COPY(tmp, rc, LPC_ORDER);
|
||||||
for(i = 0; i < LPC_ORDER ; i++)
|
for(i = 0; i < LPC_ORDER ; i++)
|
||||||
{
|
{
|
||||||
for(j = 0; j <= i-1; j++)
|
for(j = 0; j <= i-1; j++)
|
||||||
|
@ -93,15 +94,15 @@ void run_frame_network(LPCNetState *lpcnet, float *gru_a_condition, float *gru_b
|
||||||
pitch = (int)floor(.1 + 50*features[NB_BANDS]+100);
|
pitch = (int)floor(.1 + 50*features[NB_BANDS]+100);
|
||||||
pitch = IMIN(255, IMAX(33, pitch));
|
pitch = IMIN(255, IMAX(33, pitch));
|
||||||
net = &lpcnet->nnet;
|
net = &lpcnet->nnet;
|
||||||
RNN_COPY(in, features, NB_FEATURES);
|
OPUS_COPY(in, features, NB_FEATURES);
|
||||||
compute_embedding(&lpcnet->model.embed_pitch, &in[NB_FEATURES], pitch);
|
compute_embedding(&lpcnet->model.embed_pitch, &in[NB_FEATURES], pitch);
|
||||||
compute_conv1d(&lpcnet->model.feature_conv1, conv1_out, net->feature_conv1_state, in);
|
compute_conv1d(&lpcnet->model.feature_conv1, conv1_out, net->feature_conv1_state, in);
|
||||||
if (lpcnet->frame_count < FEATURE_CONV1_DELAY) RNN_CLEAR(conv1_out, FEATURE_CONV1_OUT_SIZE);
|
if (lpcnet->frame_count < FEATURE_CONV1_DELAY) OPUS_CLEAR(conv1_out, FEATURE_CONV1_OUT_SIZE);
|
||||||
compute_conv1d(&lpcnet->model.feature_conv2, conv2_out, net->feature_conv2_state, conv1_out);
|
compute_conv1d(&lpcnet->model.feature_conv2, conv2_out, net->feature_conv2_state, conv1_out);
|
||||||
if (lpcnet->frame_count < FEATURES_DELAY) RNN_CLEAR(conv2_out, FEATURE_CONV2_OUT_SIZE);
|
if (lpcnet->frame_count < FEATURES_DELAY) OPUS_CLEAR(conv2_out, FEATURE_CONV2_OUT_SIZE);
|
||||||
_lpcnet_compute_dense(&lpcnet->model.feature_dense1, dense1_out, conv2_out);
|
_lpcnet_compute_dense(&lpcnet->model.feature_dense1, dense1_out, conv2_out);
|
||||||
_lpcnet_compute_dense(&lpcnet->model.feature_dense2, condition, dense1_out);
|
_lpcnet_compute_dense(&lpcnet->model.feature_dense2, condition, dense1_out);
|
||||||
RNN_COPY(rc, condition, LPC_ORDER);
|
OPUS_COPY(rc, condition, LPC_ORDER);
|
||||||
_lpcnet_compute_dense(&lpcnet->model.gru_a_dense_feature, gru_a_condition, condition);
|
_lpcnet_compute_dense(&lpcnet->model.gru_a_dense_feature, gru_a_condition, condition);
|
||||||
_lpcnet_compute_dense(&lpcnet->model.gru_b_dense_feature, gru_b_condition, condition);
|
_lpcnet_compute_dense(&lpcnet->model.gru_b_dense_feature, gru_b_condition, condition);
|
||||||
#ifdef END2END
|
#ifdef END2END
|
||||||
|
@ -124,11 +125,11 @@ void run_frame_network_deferred(LPCNetState *lpcnet, const float *features)
|
||||||
int max_buffer_size = lpcnet->model.feature_conv1.kernel_size + lpcnet->model.feature_conv2.kernel_size - 2;
|
int max_buffer_size = lpcnet->model.feature_conv1.kernel_size + lpcnet->model.feature_conv2.kernel_size - 2;
|
||||||
celt_assert(max_buffer_size <= MAX_FEATURE_BUFFER_SIZE);
|
celt_assert(max_buffer_size <= MAX_FEATURE_BUFFER_SIZE);
|
||||||
if (lpcnet->feature_buffer_fill == max_buffer_size) {
|
if (lpcnet->feature_buffer_fill == max_buffer_size) {
|
||||||
RNN_MOVE(lpcnet->feature_buffer, &lpcnet->feature_buffer[NB_FEATURES], (max_buffer_size-1)*NB_FEATURES);
|
OPUS_MOVE(lpcnet->feature_buffer, &lpcnet->feature_buffer[NB_FEATURES], (max_buffer_size-1)*NB_FEATURES);
|
||||||
} else {
|
} else {
|
||||||
lpcnet->feature_buffer_fill++;
|
lpcnet->feature_buffer_fill++;
|
||||||
}
|
}
|
||||||
RNN_COPY(&lpcnet->feature_buffer[(lpcnet->feature_buffer_fill-1)*NB_FEATURES], features, NB_FEATURES);
|
OPUS_COPY(&lpcnet->feature_buffer[(lpcnet->feature_buffer_fill-1)*NB_FEATURES], features, NB_FEATURES);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run_frame_network_flush(LPCNetState *lpcnet)
|
void run_frame_network_flush(LPCNetState *lpcnet)
|
||||||
|
@ -153,15 +154,15 @@ int run_sample_network(LPCNetState *lpcnet, const float *gru_a_condition, const
|
||||||
#if 1
|
#if 1
|
||||||
compute_gru_a_input(gru_a_input, gru_a_condition, GRU_A_STATE_SIZE, &lpcnet->model.gru_a_embed_sig, last_sig, &lpcnet->model.gru_a_embed_pred, pred, &lpcnet->model.gru_a_embed_exc, last_exc);
|
compute_gru_a_input(gru_a_input, gru_a_condition, GRU_A_STATE_SIZE, &lpcnet->model.gru_a_embed_sig, last_sig, &lpcnet->model.gru_a_embed_pred, pred, &lpcnet->model.gru_a_embed_exc, last_exc);
|
||||||
#else
|
#else
|
||||||
RNN_COPY(gru_a_input, gru_a_condition, 3*GRU_A_STATE_SIZE);
|
OPUS_COPY(gru_a_input, gru_a_condition, 3*GRU_A_STATE_SIZE);
|
||||||
accum_embedding(&lpcnet->model.gru_a_embed_sig, gru_a_input, last_sig);
|
accum_embedding(&lpcnet->model.gru_a_embed_sig, gru_a_input, last_sig);
|
||||||
accum_embedding(&lpcnet->model.gru_a_embed_pred, gru_a_input, pred);
|
accum_embedding(&lpcnet->model.gru_a_embed_pred, gru_a_input, pred);
|
||||||
accum_embedding(&lpcnet->model.gru_a_embed_exc, gru_a_input, last_exc);
|
accum_embedding(&lpcnet->model.gru_a_embed_exc, gru_a_input, last_exc);
|
||||||
#endif
|
#endif
|
||||||
/*compute_gru3(&gru_a, net->gru_a_state, gru_a_input);*/
|
/*compute_gru3(&gru_a, net->gru_a_state, gru_a_input);*/
|
||||||
compute_sparse_gru(&lpcnet->model.sparse_gru_a, net->gru_a_state, gru_a_input);
|
compute_sparse_gru(&lpcnet->model.sparse_gru_a, net->gru_a_state, gru_a_input);
|
||||||
RNN_COPY(in_b, net->gru_a_state, GRU_A_STATE_SIZE);
|
OPUS_COPY(in_b, net->gru_a_state, GRU_A_STATE_SIZE);
|
||||||
RNN_COPY(gru_b_input, gru_b_condition, 3*GRU_B_STATE_SIZE);
|
OPUS_COPY(gru_b_input, gru_b_condition, 3*GRU_B_STATE_SIZE);
|
||||||
compute_gruB(&lpcnet->model.gru_b, gru_b_input, net->gru_b_state, in_b);
|
compute_gruB(&lpcnet->model.gru_b, gru_b_input, net->gru_b_state, in_b);
|
||||||
return sample_mdense(&lpcnet->model.dual_fc, net->gru_b_state, sampling_logit_table, rng);
|
return sample_mdense(&lpcnet->model.dual_fc, net->gru_b_state, sampling_logit_table, rng);
|
||||||
}
|
}
|
||||||
|
@ -174,7 +175,7 @@ int lpcnet_get_size()
|
||||||
void lpcnet_reset(LPCNetState *lpcnet)
|
void lpcnet_reset(LPCNetState *lpcnet)
|
||||||
{
|
{
|
||||||
const char* rng_string="LPCNet";
|
const char* rng_string="LPCNet";
|
||||||
RNN_CLEAR((char*)&lpcnet->LPCNET_RESET_START,
|
OPUS_CLEAR((char*)&lpcnet->LPCNET_RESET_START,
|
||||||
sizeof(LPCNetState)-
|
sizeof(LPCNetState)-
|
||||||
((char*)&lpcnet->LPCNET_RESET_START - (char*)lpcnet));
|
((char*)&lpcnet->LPCNET_RESET_START - (char*)lpcnet));
|
||||||
lpcnet->last_exc = lin2ulaw(0.f);
|
lpcnet->last_exc = lin2ulaw(0.f);
|
||||||
|
@ -227,9 +228,9 @@ void lpcnet_reset_signal(LPCNetState *lpcnet)
|
||||||
{
|
{
|
||||||
lpcnet->deemph_mem = 0;
|
lpcnet->deemph_mem = 0;
|
||||||
lpcnet->last_exc = lin2ulaw(0.f);
|
lpcnet->last_exc = lin2ulaw(0.f);
|
||||||
RNN_CLEAR(lpcnet->last_sig, LPC_ORDER);
|
OPUS_CLEAR(lpcnet->last_sig, LPC_ORDER);
|
||||||
RNN_CLEAR(lpcnet->nnet.gru_a_state, GRU_A_STATE_SIZE);
|
OPUS_CLEAR(lpcnet->nnet.gru_a_state, GRU_A_STATE_SIZE);
|
||||||
RNN_CLEAR(lpcnet->nnet.gru_b_state, GRU_B_STATE_SIZE);
|
OPUS_CLEAR(lpcnet->nnet.gru_b_state, GRU_B_STATE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lpcnet_synthesize_tail_impl(LPCNetState *lpcnet, opus_int16 *output, int N, int preload)
|
void lpcnet_synthesize_tail_impl(LPCNetState *lpcnet, opus_int16 *output, int N, int preload)
|
||||||
|
@ -238,7 +239,7 @@ void lpcnet_synthesize_tail_impl(LPCNetState *lpcnet, opus_int16 *output, int N,
|
||||||
|
|
||||||
if (lpcnet->frame_count <= FEATURES_DELAY)
|
if (lpcnet->frame_count <= FEATURES_DELAY)
|
||||||
{
|
{
|
||||||
RNN_CLEAR(output, N);
|
OPUS_CLEAR(output, N);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (i=0;i<N;i++)
|
for (i=0;i<N;i++)
|
||||||
|
@ -259,7 +260,7 @@ void lpcnet_synthesize_tail_impl(LPCNetState *lpcnet, opus_int16 *output, int N,
|
||||||
} else {
|
} else {
|
||||||
pcm = pred + ulaw2lin(exc);
|
pcm = pred + ulaw2lin(exc);
|
||||||
}
|
}
|
||||||
RNN_MOVE(&lpcnet->last_sig[1], &lpcnet->last_sig[0], LPC_ORDER-1);
|
OPUS_MOVE(&lpcnet->last_sig[1], &lpcnet->last_sig[0], LPC_ORDER-1);
|
||||||
lpcnet->last_sig[0] = pcm;
|
lpcnet->last_sig[0] = pcm;
|
||||||
lpcnet->last_exc = exc;
|
lpcnet->last_exc = exc;
|
||||||
pcm += PREEMPH*lpcnet->deemph_mem;
|
pcm += PREEMPH*lpcnet->deemph_mem;
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
#include "lpcnet.h"
|
#include "lpcnet.h"
|
||||||
#include "freq.h"
|
#include "freq.h"
|
||||||
|
#include "os_support.h"
|
||||||
|
|
||||||
#ifdef USE_WEIGHTS_FILE
|
#ifdef USE_WEIGHTS_FILE
|
||||||
# if __unix__
|
# if __unix__
|
||||||
|
@ -179,7 +180,7 @@ int main(int argc, char **argv) {
|
||||||
size_t ret;
|
size_t ret;
|
||||||
ret = fread(in_features, sizeof(features[0]), NB_TOTAL_FEATURES, fin);
|
ret = fread(in_features, sizeof(features[0]), NB_TOTAL_FEATURES, fin);
|
||||||
if (feof(fin) || ret != NB_TOTAL_FEATURES) break;
|
if (feof(fin) || ret != NB_TOTAL_FEATURES) break;
|
||||||
RNN_COPY(features, in_features, NB_FEATURES);
|
OPUS_COPY(features, in_features, NB_FEATURES);
|
||||||
lpcnet_synthesize(net, features, pcm, LPCNET_FRAME_SIZE);
|
lpcnet_synthesize(net, features, pcm, LPCNET_FRAME_SIZE);
|
||||||
fwrite(pcm, sizeof(pcm[0]), LPCNET_FRAME_SIZE, fout);
|
fwrite(pcm, sizeof(pcm[0]), LPCNET_FRAME_SIZE, fout);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "lpcnet_private.h"
|
#include "lpcnet_private.h"
|
||||||
#include "lpcnet.h"
|
#include "lpcnet.h"
|
||||||
|
#include "os_support.h"
|
||||||
|
|
||||||
|
|
||||||
int lpcnet_encoder_get_size() {
|
int lpcnet_encoder_get_size() {
|
||||||
|
@ -65,9 +66,9 @@ void lpcnet_encoder_destroy(LPCNetEncState *st) {
|
||||||
|
|
||||||
static void frame_analysis(LPCNetEncState *st, kiss_fft_cpx *X, float *Ex, const float *in) {
|
static void frame_analysis(LPCNetEncState *st, kiss_fft_cpx *X, float *Ex, const float *in) {
|
||||||
float x[WINDOW_SIZE];
|
float x[WINDOW_SIZE];
|
||||||
RNN_COPY(x, st->analysis_mem, OVERLAP_SIZE);
|
OPUS_COPY(x, st->analysis_mem, OVERLAP_SIZE);
|
||||||
RNN_COPY(&x[OVERLAP_SIZE], in, FRAME_SIZE);
|
OPUS_COPY(&x[OVERLAP_SIZE], in, FRAME_SIZE);
|
||||||
RNN_COPY(st->analysis_mem, &in[FRAME_SIZE-OVERLAP_SIZE], OVERLAP_SIZE);
|
OPUS_COPY(st->analysis_mem, &in[FRAME_SIZE-OVERLAP_SIZE], OVERLAP_SIZE);
|
||||||
apply_window(x);
|
apply_window(x);
|
||||||
forward_transform(X, x);
|
forward_transform(X, x);
|
||||||
lpcn_compute_band_energy(Ex, X);
|
lpcn_compute_band_energy(Ex, X);
|
||||||
|
@ -85,7 +86,7 @@ void compute_frame_features(LPCNetEncState *st, const float *in) {
|
||||||
float ener0;
|
float ener0;
|
||||||
int sub;
|
int sub;
|
||||||
float ener;
|
float ener;
|
||||||
RNN_COPY(aligned_in, &st->analysis_mem[OVERLAP_SIZE-TRAINING_OFFSET], TRAINING_OFFSET);
|
OPUS_COPY(aligned_in, &st->analysis_mem[OVERLAP_SIZE-TRAINING_OFFSET], TRAINING_OFFSET);
|
||||||
frame_analysis(st, X, Ex, in);
|
frame_analysis(st, X, Ex, in);
|
||||||
logMax = -2;
|
logMax = -2;
|
||||||
follow = -2;
|
follow = -2;
|
||||||
|
@ -100,14 +101,14 @@ void compute_frame_features(LPCNetEncState *st, const float *in) {
|
||||||
st->features[0] -= 4;
|
st->features[0] -= 4;
|
||||||
lpc_from_cepstrum(st->lpc, st->features);
|
lpc_from_cepstrum(st->lpc, st->features);
|
||||||
for (i=0;i<LPC_ORDER;i++) st->features[NB_BANDS+2+i] = st->lpc[i];
|
for (i=0;i<LPC_ORDER;i++) st->features[NB_BANDS+2+i] = st->lpc[i];
|
||||||
RNN_MOVE(st->exc_buf, &st->exc_buf[FRAME_SIZE], PITCH_MAX_PERIOD);
|
OPUS_MOVE(st->exc_buf, &st->exc_buf[FRAME_SIZE], PITCH_MAX_PERIOD);
|
||||||
RNN_COPY(&aligned_in[TRAINING_OFFSET], in, FRAME_SIZE-TRAINING_OFFSET);
|
OPUS_COPY(&aligned_in[TRAINING_OFFSET], in, FRAME_SIZE-TRAINING_OFFSET);
|
||||||
for (i=0;i<FRAME_SIZE;i++) {
|
for (i=0;i<FRAME_SIZE;i++) {
|
||||||
int j;
|
int j;
|
||||||
float sum = aligned_in[i];
|
float sum = aligned_in[i];
|
||||||
for (j=0;j<LPC_ORDER;j++)
|
for (j=0;j<LPC_ORDER;j++)
|
||||||
sum += st->lpc[j]*st->pitch_mem[j];
|
sum += st->lpc[j]*st->pitch_mem[j];
|
||||||
RNN_MOVE(st->pitch_mem+1, st->pitch_mem, LPC_ORDER-1);
|
OPUS_MOVE(st->pitch_mem+1, st->pitch_mem, LPC_ORDER-1);
|
||||||
st->pitch_mem[0] = aligned_in[i];
|
st->pitch_mem[0] = aligned_in[i];
|
||||||
st->exc_buf[PITCH_MAX_PERIOD+i] = sum + .7f*st->pitch_filt;
|
st->exc_buf[PITCH_MAX_PERIOD+i] = sum + .7f*st->pitch_filt;
|
||||||
st->pitch_filt = sum;
|
st->pitch_filt = sum;
|
||||||
|
@ -192,7 +193,7 @@ void process_single_frame(LPCNetEncState *st, FILE *ffeat) {
|
||||||
for (i=0;i<PITCH_MAX_PERIOD-PITCH_MIN_PERIOD;i++) st->pitch_max_path[1][i] -= max_path_all;
|
for (i=0;i<PITCH_MAX_PERIOD-PITCH_MIN_PERIOD;i++) st->pitch_max_path[1][i] -= max_path_all;
|
||||||
/*for (i=0;i<PITCH_MAX_PERIOD-PITCH_MIN_PERIOD;i++) printf("%f ", st->pitch_max_path[1][i]);
|
/*for (i=0;i<PITCH_MAX_PERIOD-PITCH_MIN_PERIOD;i++) printf("%f ", st->pitch_max_path[1][i]);
|
||||||
printf("\n");*/
|
printf("\n");*/
|
||||||
RNN_COPY(&st->pitch_max_path[0][0], &st->pitch_max_path[1][0], PITCH_MAX_PERIOD);
|
OPUS_COPY(&st->pitch_max_path[0][0], &st->pitch_max_path[1][0], PITCH_MAX_PERIOD);
|
||||||
st->pitch_max_path_all = max_path_all;
|
st->pitch_max_path_all = max_path_all;
|
||||||
st->best_i = best_i;
|
st->best_i = best_i;
|
||||||
}
|
}
|
||||||
|
@ -226,7 +227,7 @@ static int lpcnet_compute_single_frame_features_impl(LPCNetEncState *st, float *
|
||||||
preemphasis(x, &st->mem_preemph, x, PREEMPHASIS, FRAME_SIZE);
|
preemphasis(x, &st->mem_preemph, x, PREEMPHASIS, FRAME_SIZE);
|
||||||
compute_frame_features(st, x);
|
compute_frame_features(st, x);
|
||||||
process_single_frame(st, NULL);
|
process_single_frame(st, NULL);
|
||||||
RNN_COPY(features, &st->features[0], NB_TOTAL_FEATURES);
|
OPUS_COPY(features, &st->features[0], NB_TOTAL_FEATURES);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "lpcnet_private.h"
|
#include "lpcnet_private.h"
|
||||||
#include "lpcnet.h"
|
#include "lpcnet.h"
|
||||||
#include "plc_data.h"
|
#include "plc_data.h"
|
||||||
|
#include "os_support.h"
|
||||||
|
|
||||||
#ifndef M_PI
|
#ifndef M_PI
|
||||||
#define M_PI 3.141592653
|
#define M_PI 3.141592653
|
||||||
|
@ -44,12 +45,12 @@ int lpcnet_plc_get_size() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void lpcnet_plc_reset(LPCNetPLCState *st) {
|
void lpcnet_plc_reset(LPCNetPLCState *st) {
|
||||||
RNN_CLEAR((char*)&st->LPCNET_PLC_RESET_START,
|
OPUS_CLEAR((char*)&st->LPCNET_PLC_RESET_START,
|
||||||
sizeof(LPCNetPLCState)-
|
sizeof(LPCNetPLCState)-
|
||||||
((char*)&st->LPCNET_PLC_RESET_START - (char*)st));
|
((char*)&st->LPCNET_PLC_RESET_START - (char*)st));
|
||||||
lpcnet_reset(&st->lpcnet);
|
lpcnet_reset(&st->lpcnet);
|
||||||
lpcnet_encoder_init(&st->enc);
|
lpcnet_encoder_init(&st->enc);
|
||||||
RNN_CLEAR(st->pcm, PLC_BUF_SIZE);
|
OPUS_CLEAR(st->pcm, PLC_BUF_SIZE);
|
||||||
st->pcm_fill = PLC_BUF_SIZE;
|
st->pcm_fill = PLC_BUF_SIZE;
|
||||||
st->skip_analysis = 0;
|
st->skip_analysis = 0;
|
||||||
st->blend = 0;
|
st->blend = 0;
|
||||||
|
@ -110,12 +111,12 @@ void lpcnet_plc_fec_add(LPCNetPLCState *st, const float *features) {
|
||||||
fprintf(stderr, "FEC buffer full\n");
|
fprintf(stderr, "FEC buffer full\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RNN_MOVE(&st->fec[0][0], &st->fec[st->fec_keep_pos][0], (st->fec_fill_pos-st->fec_keep_pos)*NB_FEATURES);
|
OPUS_MOVE(&st->fec[0][0], &st->fec[st->fec_keep_pos][0], (st->fec_fill_pos-st->fec_keep_pos)*NB_FEATURES);
|
||||||
st->fec_fill_pos = st->fec_fill_pos-st->fec_keep_pos;
|
st->fec_fill_pos = st->fec_fill_pos-st->fec_keep_pos;
|
||||||
st->fec_read_pos -= st->fec_keep_pos;
|
st->fec_read_pos -= st->fec_keep_pos;
|
||||||
st->fec_keep_pos = 0;
|
st->fec_keep_pos = 0;
|
||||||
}
|
}
|
||||||
RNN_COPY(&st->fec[st->fec_fill_pos][0], features, NB_FEATURES);
|
OPUS_COPY(&st->fec[st->fec_fill_pos][0], features, NB_FEATURES);
|
||||||
st->fec_fill_pos++;
|
st->fec_fill_pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,12 +141,12 @@ static int get_fec_or_pred(LPCNetPLCState *st, float *out) {
|
||||||
if (st->fec_read_pos != st->fec_fill_pos && st->fec_skip==0) {
|
if (st->fec_read_pos != st->fec_fill_pos && st->fec_skip==0) {
|
||||||
float plc_features[2*NB_BANDS+NB_FEATURES+1] = {0};
|
float plc_features[2*NB_BANDS+NB_FEATURES+1] = {0};
|
||||||
float discard[NB_FEATURES];
|
float discard[NB_FEATURES];
|
||||||
RNN_COPY(out, &st->fec[st->fec_read_pos][0], NB_FEATURES);
|
OPUS_COPY(out, &st->fec[st->fec_read_pos][0], NB_FEATURES);
|
||||||
st->fec_read_pos++;
|
st->fec_read_pos++;
|
||||||
/* Make sure we can rewind a few frames back at resync time. */
|
/* Make sure we can rewind a few frames back at resync time. */
|
||||||
st->fec_keep_pos = IMAX(0, IMAX(st->fec_keep_pos, st->fec_read_pos-FEATURES_DELAY-1));
|
st->fec_keep_pos = IMAX(0, IMAX(st->fec_keep_pos, st->fec_read_pos-FEATURES_DELAY-1));
|
||||||
/* Update PLC state using FEC, so without Burg features. */
|
/* Update PLC state using FEC, so without Burg features. */
|
||||||
RNN_COPY(&plc_features[2*NB_BANDS], out, NB_FEATURES);
|
OPUS_COPY(&plc_features[2*NB_BANDS], out, NB_FEATURES);
|
||||||
plc_features[2*NB_BANDS+NB_FEATURES] = -1;
|
plc_features[2*NB_BANDS+NB_FEATURES] = -1;
|
||||||
compute_plc_pred(st, discard, plc_features);
|
compute_plc_pred(st, discard, plc_features);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -165,11 +166,11 @@ static void fec_rewind(LPCNetPLCState *st, int offset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_state(LPCNetPLCState *st) {
|
void clear_state(LPCNetPLCState *st) {
|
||||||
RNN_CLEAR(st->lpcnet.last_sig, LPC_ORDER);
|
OPUS_CLEAR(st->lpcnet.last_sig, LPC_ORDER);
|
||||||
st->lpcnet.last_exc = lin2ulaw(0.f);
|
st->lpcnet.last_exc = lin2ulaw(0.f);
|
||||||
st->lpcnet.deemph_mem = 0;
|
st->lpcnet.deemph_mem = 0;
|
||||||
RNN_CLEAR(st->lpcnet.nnet.gru_a_state, GRU_A_STATE_SIZE);
|
OPUS_CLEAR(st->lpcnet.nnet.gru_a_state, GRU_A_STATE_SIZE);
|
||||||
RNN_CLEAR(st->lpcnet.nnet.gru_b_state, GRU_B_STATE_SIZE);
|
OPUS_CLEAR(st->lpcnet.nnet.gru_b_state, GRU_B_STATE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In this causal version of the code, the DNN model implemented by compute_plc_pred()
|
/* In this causal version of the code, the DNN model implemented by compute_plc_pred()
|
||||||
|
@ -188,7 +189,7 @@ int lpcnet_plc_update(LPCNetPLCState *st, opus_int16 *pcm) {
|
||||||
if (st->blend) {
|
if (st->blend) {
|
||||||
opus_int16 tmp[FRAME_SIZE-TRAINING_OFFSET];
|
opus_int16 tmp[FRAME_SIZE-TRAINING_OFFSET];
|
||||||
float zeros[2*NB_BANDS+NB_FEATURES+1] = {0};
|
float zeros[2*NB_BANDS+NB_FEATURES+1] = {0};
|
||||||
RNN_COPY(zeros, plc_features, 2*NB_BANDS);
|
OPUS_COPY(zeros, plc_features, 2*NB_BANDS);
|
||||||
zeros[2*NB_BANDS+NB_FEATURES] = 1;
|
zeros[2*NB_BANDS+NB_FEATURES] = 1;
|
||||||
if (st->enable_blending) {
|
if (st->enable_blending) {
|
||||||
LPCNetState copy;
|
LPCNetState copy;
|
||||||
|
@ -213,14 +214,14 @@ int lpcnet_plc_update(LPCNetPLCState *st, opus_int16 *pcm) {
|
||||||
#ifdef PLC_SKIP_UPDATES
|
#ifdef PLC_SKIP_UPDATES
|
||||||
lpcnet_reset_signal(&st->lpcnet);
|
lpcnet_reset_signal(&st->lpcnet);
|
||||||
#else
|
#else
|
||||||
RNN_COPY(tmp, pcm, FRAME_SIZE-TRAINING_OFFSET);
|
OPUS_COPY(tmp, pcm, FRAME_SIZE-TRAINING_OFFSET);
|
||||||
lpcnet_synthesize_tail_impl(&st->lpcnet, tmp, FRAME_SIZE-TRAINING_OFFSET, FRAME_SIZE-TRAINING_OFFSET);
|
lpcnet_synthesize_tail_impl(&st->lpcnet, tmp, FRAME_SIZE-TRAINING_OFFSET, FRAME_SIZE-TRAINING_OFFSET);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
RNN_COPY(st->pcm, &pcm[FRAME_SIZE-TRAINING_OFFSET], TRAINING_OFFSET);
|
OPUS_COPY(st->pcm, &pcm[FRAME_SIZE-TRAINING_OFFSET], TRAINING_OFFSET);
|
||||||
st->pcm_fill = TRAINING_OFFSET;
|
st->pcm_fill = TRAINING_OFFSET;
|
||||||
} else {
|
} else {
|
||||||
RNN_COPY(&st->pcm[st->pcm_fill], pcm, FRAME_SIZE);
|
OPUS_COPY(&st->pcm[st->pcm_fill], pcm, FRAME_SIZE);
|
||||||
st->pcm_fill += FRAME_SIZE;
|
st->pcm_fill += FRAME_SIZE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,7 +232,7 @@ int lpcnet_plc_update(LPCNetPLCState *st, opus_int16 *pcm) {
|
||||||
compute_frame_features(&st->enc, x);
|
compute_frame_features(&st->enc, x);
|
||||||
process_single_frame(&st->enc, NULL);
|
process_single_frame(&st->enc, NULL);
|
||||||
if (!st->blend) {
|
if (!st->blend) {
|
||||||
RNN_COPY(&plc_features[2*NB_BANDS], st->enc.features, NB_FEATURES);
|
OPUS_COPY(&plc_features[2*NB_BANDS], st->enc.features, NB_FEATURES);
|
||||||
plc_features[2*NB_BANDS+NB_FEATURES] = 1;
|
plc_features[2*NB_BANDS+NB_FEATURES] = 1;
|
||||||
compute_plc_pred(st, st->features, plc_features);
|
compute_plc_pred(st, st->features, plc_features);
|
||||||
/* Discard an FEC frame that we know we will no longer need. */
|
/* Discard an FEC frame that we know we will no longer need. */
|
||||||
|
@ -247,7 +248,7 @@ int lpcnet_plc_update(LPCNetPLCState *st, opus_int16 *pcm) {
|
||||||
st->skip_analysis--;
|
st->skip_analysis--;
|
||||||
} else {
|
} else {
|
||||||
for (i=0;i<FRAME_SIZE;i++) st->pcm[PLC_BUF_SIZE+i] = pcm[i];
|
for (i=0;i<FRAME_SIZE;i++) st->pcm[PLC_BUF_SIZE+i] = pcm[i];
|
||||||
RNN_COPY(output, &st->pcm[0], FRAME_SIZE);
|
OPUS_COPY(output, &st->pcm[0], FRAME_SIZE);
|
||||||
#ifdef PLC_SKIP_UPDATES
|
#ifdef PLC_SKIP_UPDATES
|
||||||
{
|
{
|
||||||
run_frame_network_deferred(&st->lpcnet, st->enc.features);
|
run_frame_network_deferred(&st->lpcnet, st->enc.features);
|
||||||
|
@ -255,7 +256,7 @@ int lpcnet_plc_update(LPCNetPLCState *st, opus_int16 *pcm) {
|
||||||
#else
|
#else
|
||||||
lpcnet_synthesize_impl(&st->lpcnet, st->enc.features, output, FRAME_SIZE, FRAME_SIZE);
|
lpcnet_synthesize_impl(&st->lpcnet, st->enc.features, output, FRAME_SIZE, FRAME_SIZE);
|
||||||
#endif
|
#endif
|
||||||
RNN_MOVE(st->pcm, &st->pcm[FRAME_SIZE], PLC_BUF_SIZE);
|
OPUS_MOVE(st->pcm, &st->pcm[FRAME_SIZE], PLC_BUF_SIZE);
|
||||||
}
|
}
|
||||||
st->loss_count = 0;
|
st->loss_count = 0;
|
||||||
st->blend = 0;
|
st->blend = 0;
|
||||||
|
@ -273,16 +274,16 @@ int lpcnet_plc_conceal(LPCNetPLCState *st, opus_int16 *pcm) {
|
||||||
/*fprintf(stderr, "update state for PLC %d\n", st->pcm_fill);*/
|
/*fprintf(stderr, "update state for PLC %d\n", st->pcm_fill);*/
|
||||||
int update_count;
|
int update_count;
|
||||||
update_count = IMIN(st->pcm_fill, FRAME_SIZE);
|
update_count = IMIN(st->pcm_fill, FRAME_SIZE);
|
||||||
RNN_COPY(output, &st->pcm[0], update_count);
|
OPUS_COPY(output, &st->pcm[0], update_count);
|
||||||
RNN_MOVE(&st->plc_copy[1], &st->plc_copy[0], FEATURES_DELAY);
|
OPUS_MOVE(&st->plc_copy[1], &st->plc_copy[0], FEATURES_DELAY);
|
||||||
st->plc_copy[0] = st->plc_net;
|
st->plc_copy[0] = st->plc_net;
|
||||||
get_fec_or_pred(st, st->features);
|
get_fec_or_pred(st, st->features);
|
||||||
lpcnet_synthesize_impl(&st->lpcnet, &st->features[0], output, update_count, update_count);
|
lpcnet_synthesize_impl(&st->lpcnet, &st->features[0], output, update_count, update_count);
|
||||||
RNN_MOVE(st->pcm, &st->pcm[FRAME_SIZE], PLC_BUF_SIZE);
|
OPUS_MOVE(st->pcm, &st->pcm[FRAME_SIZE], PLC_BUF_SIZE);
|
||||||
st->pcm_fill -= update_count;
|
st->pcm_fill -= update_count;
|
||||||
st->skip_analysis++;
|
st->skip_analysis++;
|
||||||
}
|
}
|
||||||
RNN_MOVE(&st->plc_copy[1], &st->plc_copy[0], FEATURES_DELAY);
|
OPUS_MOVE(&st->plc_copy[1], &st->plc_copy[0], FEATURES_DELAY);
|
||||||
st->plc_copy[0] = st->plc_net;
|
st->plc_copy[0] = st->plc_net;
|
||||||
lpcnet_synthesize_tail_impl(&st->lpcnet, pcm, FRAME_SIZE-TRAINING_OFFSET, 0);
|
lpcnet_synthesize_tail_impl(&st->lpcnet, pcm, FRAME_SIZE-TRAINING_OFFSET, 0);
|
||||||
if (get_fec_or_pred(st, st->features)) st->loss_count = 0;
|
if (get_fec_or_pred(st, st->features)) st->loss_count = 0;
|
||||||
|
|
11
dnn/nnet.c
11
dnn/nnet.c
|
@ -40,6 +40,7 @@
|
||||||
#include "nnet_data.h"
|
#include "nnet_data.h"
|
||||||
#include "dred_rdovae_constants.h"
|
#include "dred_rdovae_constants.h"
|
||||||
#include "plc_data.h"
|
#include "plc_data.h"
|
||||||
|
#include "os_support.h"
|
||||||
|
|
||||||
#ifdef NO_OPTIMIZATIONS
|
#ifdef NO_OPTIMIZATIONS
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
@ -99,7 +100,7 @@ void compute_activation(float *output, const float *input, int N, int activation
|
||||||
output[i] = relu(input[i]);
|
output[i] = relu(input[i]);
|
||||||
} else if (activation == ACTIVATION_SOFTMAX) {
|
} else if (activation == ACTIVATION_SOFTMAX) {
|
||||||
#ifdef SOFTMAX_HACK
|
#ifdef SOFTMAX_HACK
|
||||||
RNN_COPY(output, input, N);
|
OPUS_COPY(output, input, N);
|
||||||
/*for (i=0;i<N;i++)
|
/*for (i=0;i<N;i++)
|
||||||
output[i] = input[i];*/
|
output[i] = input[i];*/
|
||||||
#else
|
#else
|
||||||
|
@ -390,7 +391,7 @@ void compute_gru3(const GRULayer *gru, float *state, const float *input)
|
||||||
celt_assert(input != state);
|
celt_assert(input != state);
|
||||||
celt_assert(gru->reset_after);
|
celt_assert(gru->reset_after);
|
||||||
stride = 3*N;
|
stride = 3*N;
|
||||||
RNN_COPY(zrh, input, 3*N);
|
OPUS_COPY(zrh, input, 3*N);
|
||||||
for (i=0;i<3*N;i++)
|
for (i=0;i<3*N;i++)
|
||||||
recur[i] = gru->bias[3*N + i];
|
recur[i] = gru->bias[3*N + i];
|
||||||
sgemv_accum8x4(recur, gru->recurrent_weights, 3*N, N, stride, state);
|
sgemv_accum8x4(recur, gru->recurrent_weights, 3*N, N, stride, state);
|
||||||
|
@ -457,8 +458,8 @@ void compute_conv1d(const Conv1DLayer *layer, float *output, float *mem, const f
|
||||||
float tmp[MAX_CONV_INPUTS_ALL];
|
float tmp[MAX_CONV_INPUTS_ALL];
|
||||||
celt_assert(input != output);
|
celt_assert(input != output);
|
||||||
celt_assert(layer->nb_inputs*layer->kernel_size <= MAX_CONV_INPUTS_ALL);
|
celt_assert(layer->nb_inputs*layer->kernel_size <= MAX_CONV_INPUTS_ALL);
|
||||||
RNN_COPY(tmp, mem, layer->nb_inputs*(layer->kernel_size-1));
|
OPUS_COPY(tmp, mem, layer->nb_inputs*(layer->kernel_size-1));
|
||||||
RNN_COPY(&tmp[layer->nb_inputs*(layer->kernel_size-1)], input, layer->nb_inputs);
|
OPUS_COPY(&tmp[layer->nb_inputs*(layer->kernel_size-1)], input, layer->nb_inputs);
|
||||||
M = layer->nb_inputs*layer->kernel_size;
|
M = layer->nb_inputs*layer->kernel_size;
|
||||||
N = layer->nb_neurons;
|
N = layer->nb_neurons;
|
||||||
stride = N;
|
stride = N;
|
||||||
|
@ -466,7 +467,7 @@ void compute_conv1d(const Conv1DLayer *layer, float *output, float *mem, const f
|
||||||
output[i] = layer->bias[i];
|
output[i] = layer->bias[i];
|
||||||
sgemv_accum(output, layer->input_weights, N, M, stride, tmp);
|
sgemv_accum(output, layer->input_weights, N, M, stride, tmp);
|
||||||
compute_activation(output, output, N, layer->activation);
|
compute_activation(output, output, N, layer->activation);
|
||||||
RNN_COPY(mem, &tmp[layer->nb_inputs], layer->nb_inputs*(layer->kernel_size-1));
|
OPUS_COPY(mem, &tmp[layer->nb_inputs], layer->nb_inputs*(layer->kernel_size-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void compute_embedding(const EmbeddingLayer *layer, float *output, int input)
|
void compute_embedding(const EmbeddingLayer *layer, float *output, int input)
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "nnet.h"
|
#include "nnet.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "os_support.h"
|
||||||
|
|
||||||
/* This is a bit of a hack because we need to build nnet_data.c and plc_data.c without USE_WEIGHTS_FILE,
|
/* This is a bit of a hack because we need to build nnet_data.c and plc_data.c without USE_WEIGHTS_FILE,
|
||||||
but USE_WEIGHTS_FILE is defined in config.h. */
|
but USE_WEIGHTS_FILE is defined in config.h. */
|
||||||
|
@ -56,7 +57,7 @@ void write_weights(const WeightArray *list, FILE *fout)
|
||||||
h.type = list[i].type;
|
h.type = list[i].type;
|
||||||
h.size = list[i].size;
|
h.size = list[i].size;
|
||||||
h.block_size = (h.size+WEIGHT_BLOCK_SIZE-1)/WEIGHT_BLOCK_SIZE*WEIGHT_BLOCK_SIZE;
|
h.block_size = (h.size+WEIGHT_BLOCK_SIZE-1)/WEIGHT_BLOCK_SIZE*WEIGHT_BLOCK_SIZE;
|
||||||
RNN_CLEAR(h.name, sizeof(h.name));
|
OPUS_CLEAR(h.name, sizeof(h.name));
|
||||||
strncpy(h.name, list[i].name, sizeof(h.name));
|
strncpy(h.name, list[i].name, sizeof(h.name));
|
||||||
h.name[sizeof(h.name)-1] = 0;
|
h.name[sizeof(h.name)-1] = 0;
|
||||||
celt_assert(sizeof(h) == WEIGHT_BLOCK_SIZE);
|
celt_assert(sizeof(h) == WEIGHT_BLOCK_SIZE);
|
||||||
|
|
|
@ -56,7 +56,7 @@ int dred_encoder_load_model(DREDEnc* enc, const unsigned char *data, int len)
|
||||||
|
|
||||||
void dred_encoder_reset(DREDEnc* enc)
|
void dred_encoder_reset(DREDEnc* enc)
|
||||||
{
|
{
|
||||||
RNN_CLEAR((char*)&enc->DREDENC_RESET_START,
|
OPUS_CLEAR((char*)&enc->DREDENC_RESET_START,
|
||||||
sizeof(DREDEnc)-
|
sizeof(DREDEnc)-
|
||||||
((char*)&enc->DREDENC_RESET_START - (char*)enc));
|
((char*)&enc->DREDENC_RESET_START - (char*)enc));
|
||||||
enc->input_buffer_fill = DRED_SILK_ENCODER_DELAY;
|
enc->input_buffer_fill = DRED_SILK_ENCODER_DELAY;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue