Fix flooring of the pitch period

Without the 0.1 bias, the rounding error could cause an offset of -1
This commit is contained in:
Jean-Marc Valin 2018-12-10 11:23:31 -05:00
parent d533e4024d
commit b9e0ea23e0
3 changed files with 4 additions and 4 deletions

View file

@ -154,7 +154,7 @@ void lpcnet_synthesize(LPCNetState *lpcnet, short *output, const float *features
/* FIXME: Remove this -- it's just a temporary hack to match the Python code. */
static int start = LPC_ORDER+1;
/* FIXME: Do proper rounding once the Python code rounds properly. */
pitch = (int)floor(50*features[36]+100);
pitch = (int)floor(.1 + 50*features[36]+100);
/* FIXME: get the pitch gain from 2 frames in the past. */
pitch_gain = features[PITCH_GAIN_FEATURE];
run_frame_network(lpcnet, condition, gru_a_condition, features, pitch);

View file

@ -59,7 +59,7 @@ pcm_chunk_size = frame_size*feature_chunk_size
features = np.reshape(features, (nb_frames, feature_chunk_size, nb_features))
features[:,:,18:36] = 0
periods = (50*features[:,:,36:37]+100).astype('int16')
periods = (.1 + 50*features[:,:,36:37]+100).astype('int16')

View file

@ -136,14 +136,14 @@ features[:,:,18:36] = 0
pred = np.reshape(pred, (nb_frames, pcm_chunk_size, 1))
pred = pred.astype('uint8')
periods = (50*features[:,:,36:37]+100).astype('int16')
periods = (.1 + 50*features[:,:,36:37]+100).astype('int16')
in_data = np.concatenate([in_data, pred], axis=-1)
del pred
# dump models to disk as we go
checkpoint = ModelCheckpoint('lpcnet14_384_10_G16_{epoch:02d}.h5')
checkpoint = ModelCheckpoint('lpcnet15_384_10_G16_{epoch:02d}.h5')
#model.load_weights('lpcnet9b_384_10_G16_01.h5')
model.compile(optimizer=Adam(0.001, amsgrad=True, decay=5e-5), loss='sparse_categorical_crossentropy', metrics=['sparse_categorical_accuracy'])