Skip to content

Commit 84fe83b

Browse files
committed
Adding one extra frame of delay
1 parent 37cf35f commit 84fe83b

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

model_version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f56003f
1+
37cf35f

src/denoise.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ struct DenoiseState {
8282
float mem_hp_x[2];
8383
float lastg[NB_BANDS];
8484
RNNState rnn;
85+
kiss_fft_cpx delayed_X[FREQ_SIZE];
86+
kiss_fft_cpx delayed_P[FREQ_SIZE];
87+
float delayed_Ex[NB_BANDS], delayed_Ep[NB_BANDS];
88+
float delayed_Exp[NB_BANDS];
89+
8590
};
8691

8792
static void compute_band_energy(float *bandE, const kiss_fft_cpx *X) {
@@ -384,7 +389,7 @@ void rnn_pitch_filter(kiss_fft_cpx *X, const kiss_fft_cpx *P, const float *Ex, c
384389
float rnnoise_process_frame(DenoiseState *st, float *out, const float *in) {
385390
int i;
386391
kiss_fft_cpx X[FREQ_SIZE];
387-
kiss_fft_cpx P[WINDOW_SIZE];
392+
kiss_fft_cpx P[FREQ_SIZE];
388393
float x[FRAME_SIZE];
389394
float Ex[NB_BANDS], Ep[NB_BANDS];
390395
float Exp[NB_BANDS];
@@ -402,7 +407,7 @@ float rnnoise_process_frame(DenoiseState *st, float *out, const float *in) {
402407
#if !TRAINING
403408
compute_rnn(&st->model, &st->rnn, g, &vad_prob, features, st->arch);
404409
#endif
405-
rnn_pitch_filter(X, P, Ex, Ep, Exp, g);
410+
rnn_pitch_filter(st->delayed_X, st->delayed_P, st->delayed_Ex, st->delayed_Ep, st->delayed_Exp, g);
406411
for (i=0;i<NB_BANDS;i++) {
407412
float alpha = .6f;
408413
g[i] = MAX16(g[i], alpha*st->lastg[i]);
@@ -411,13 +416,18 @@ float rnnoise_process_frame(DenoiseState *st, float *out, const float *in) {
411416
interp_band_gain(gf, g);
412417
#if 1
413418
for (i=0;i<FREQ_SIZE;i++) {
414-
X[i].r *= gf[i];
415-
X[i].i *= gf[i];
419+
st->delayed_X[i].r *= gf[i];
420+
st->delayed_X[i].i *= gf[i];
416421
}
417422
#endif
418423
}
424+
frame_synthesis(st, out, st->delayed_X);
419425

420-
frame_synthesis(st, out, X);
426+
RNN_COPY(st->delayed_X, X, FREQ_SIZE);
427+
RNN_COPY(st->delayed_P, P, FREQ_SIZE);
428+
RNN_COPY(st->delayed_Ex, Ex, NB_BANDS);
429+
RNN_COPY(st->delayed_Ep, Ep, NB_BANDS);
430+
RNN_COPY(st->delayed_Exp, Exp, NB_BANDS);
421431
return vad_prob;
422432
}
423433

torch/rnnoise/train_rnnoise.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ def mask(g):
115115

116116
pred_gain, pred_vad, states = model(features, states=states)
117117
states = [state.detach() for state in states]
118-
gain = gain[:,4:,:]
119-
vad = vad[:,4:,:]
118+
gain = gain[:,3:-1,:]
119+
vad = vad[:,3:-1,:]
120120
target_gain = torch.clamp(gain, min=0)
121121
target_gain = target_gain*(torch.tanh(5*target_gain)**2)
122122

0 commit comments

Comments
 (0)