ref: 56d9f13efd012fabf9eb725131cf8b2b1ae69b88
parent: f0df3e82ec6d98848578ab9a9ab28852c7c2973a
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Sat Jan 9 22:15:30 EST 2021
Fix quantization bug where pitch can get too low Would cause unused pitch embedding vectors to be used
--- a/dnn/lpcnet.c
+++ b/dnn/lpcnet.c
@@ -130,6 +130,7 @@
float pitch_gain;
/* Matches the Python code -- the 0.1 avoids rounding issues. */
pitch = (int)floor(.1 + 50*features[36]+100);
+ pitch = IMIN(255, IMAX(33, pitch));
pitch_gain = lpcnet->old_gain[FEATURES_DELAY-1];
memmove(&lpcnet->old_gain[1], &lpcnet->old_gain[0], (FEATURES_DELAY-1)*sizeof(lpcnet->old_gain[0]));
lpcnet->old_gain[0] = features[PITCH_GAIN_FEATURE];
--- a/dnn/lpcnet_dec.c
+++ b/dnn/lpcnet_dec.c
@@ -123,6 +123,7 @@
for (sub=0;sub<4;sub++) {
float p = pow(2.f, main_pitch/21.)*PITCH_MIN_PERIOD;
p *= 1 + modulation/16./7.*(2*sub-3);
+ p = MIN16(255, MAX16(33, p));
features[sub][2*NB_BANDS] = .02*(p-100);
features[sub][2*NB_BANDS + 1] = frame_corr-.5;
}
--- a/dnn/lpcnet_enc.c
+++ b/dnn/lpcnet_enc.c
@@ -662,11 +662,11 @@
if (quantize) {
float p = pow(2.f, main_pitch/21.)*PITCH_MIN_PERIOD;
p *= 1 + modulation/16./7.*(2*sub-3);
- p = MIN16(255, MAX16(32, p));
+ p = MIN16(255, MAX16(33, p));
st->features[sub][2*NB_BANDS] = .02*(p-100);
st->features[sub][2*NB_BANDS + 1] = frame_corr-.5;
} else {
- st->features[sub][2*NB_BANDS] = .01*(IMAX(64, IMIN(510, best[2+2*sub]+best[2+2*sub+1]))-200);
+ st->features[sub][2*NB_BANDS] = .01*(IMAX(66, IMIN(510, best[2+2*sub]+best[2+2*sub+1]))-200);
st->features[sub][2*NB_BANDS + 1] = frame_corr-.5;
}
//printf("%f %d %f\n", st->features[sub][2*NB_BANDS], best[2+2*sub], frame_corr);
--
⑨