diff options
author | Jean-Marc Valin <jmvalin@amazon.com> | 2023-08-01 07:15:55 +0300 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@amazon.com> | 2023-08-01 07:15:55 +0300 |
commit | 8fe8e0194e1ea4335de4ef72a31ffc40249435ca (patch) | |
tree | dc994ba744801d9bbfb4c083eaee618a985a46fa | |
parent | f2e996c99fcadf805d200260327a894f24c43ca7 (diff) |
Add pre-emphasis filter before LPC filterexp-fwgan2
-rw-r--r-- | dnn/fwgan.c | 19 | ||||
-rw-r--r-- | dnn/fwgan.h | 2 |
2 files changed, 17 insertions, 4 deletions
diff --git a/dnn/fwgan.c b/dnn/fwgan.c index c97ce6b8..7b2e3bdd 100644 --- a/dnn/fwgan.c +++ b/dnn/fwgan.c @@ -120,14 +120,24 @@ static void apply_gain(float *pcm, float c0, float *last_gain) { *last_gain = gain; } -static void fwgan_lpc_syn(float *pcm, float *mem, const float *lpc) { +static void fwgan_lpc_syn(float *pcm, float *mem, const float *lpc, float last_lpc[LPC_ORDER]) { int i; - for (i=0;i<FWGAN_FRAME_SIZE;i++) { + for (i=0;i<SUBFRAME_SIZE;i++) { int j; - for (j=0;j<LPC_ORDER;j++) pcm[i] -= mem[j]*lpc[j]; + for (j=0;j<LPC_ORDER;j++) pcm[i] -= mem[j]*last_lpc[j]; OPUS_MOVE(&mem[1], &mem[0], LPC_ORDER-1); mem[0] = pcm[i]; } + OPUS_COPY(last_lpc, lpc, LPC_ORDER); +} + +static void fwgan_preemphasis(float *pcm, float *preemph_mem) { + int i; + for (i=0;i<SUBFRAME_SIZE;i++) { + float tmp = pcm[i]; + pcm[i] -= FWGAN_DEEMPHASIS * *preemph_mem; + *preemph_mem = tmp; + } } static void fwgan_deemphasis(float *pcm, float *deemph_mem) { @@ -223,7 +233,8 @@ void fwgan_synthesize(FWGANState *st, float *pcm, const float *features) sub_cond = &cond[subframe*BFCC_WITH_CORR_UPSAMPLER_FC_OUT_SIZE/4]; run_fwgan_subframe(st, &pcm[subframe*SUBFRAME_SIZE], sub_cond, w0); apply_gain(&pcm[subframe*SUBFRAME_SIZE], features[0], &st->last_gain); + fwgan_preemphasis(&pcm[subframe*SUBFRAME_SIZE], &st->preemph_mem); + fwgan_lpc_syn(&pcm[subframe*SUBFRAME_SIZE], st->syn_mem, lpc, st->last_lpc); } - fwgan_lpc_syn(pcm, st->syn_mem, lpc); fwgan_deemphasis(pcm, &st->deemph_mem); } diff --git a/dnn/fwgan.h b/dnn/fwgan.h index 9ed4943a..3af76cda 100644 --- a/dnn/fwgan.h +++ b/dnn/fwgan.h @@ -47,7 +47,9 @@ typedef struct { int cont_initialized; double embed_phase; float last_gain; + float last_lpc[LPC_ORDER]; float syn_mem[LPC_ORDER]; + float preemph_mem; float deemph_mem; float cont_conv1_mem[FEAT_IN_CONV1_CONV_STATE_SIZE]; float cont[FEAT_IN_NL1_GATE_OUT_SIZE]; |