Skip to content

Commit 792c5ec

Browse files
committed
Moving GRU_A's condition computation to the frame rate network
Completes optimizations from Section 3.6 of the LPCNet paper.
1 parent a674854 commit 792c5ec

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/lpcnet.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static void print_vector(float *x, int N)
8989
}
9090
#endif
9191

92-
void run_frame_network(LPCNetState *lpcnet, float *condition, const float *features, int pitch)
92+
void run_frame_network(LPCNetState *lpcnet, float *condition, float *gru_a_condition, const float *features, int pitch)
9393
{
9494
int i;
9595
NNetState *net;
@@ -110,19 +110,15 @@ void run_frame_network(LPCNetState *lpcnet, float *condition, const float *featu
110110
memcpy(lpcnet->old_input[0], in, FRAME_INPUT_SIZE*sizeof(in[0]));
111111
compute_dense(&feature_dense1, dense1_out, conv2_out);
112112
compute_dense(&feature_dense2, condition, dense1_out);
113+
compute_dense(&gru_a_dense_feature, gru_a_condition, condition);
113114
if (lpcnet->frame_count < 1000) lpcnet->frame_count++;
114115
}
115116

116-
void run_sample_network(NNetState *net, float *pdf, const float *condition, int last_exc, int last_sig, int pred)
117+
void run_sample_network(NNetState *net, float *pdf, const float *condition, const float *gru_a_condition, int last_exc, int last_sig, int pred)
117118
{
118-
float in_a[SAMPLE_INPUT_SIZE];
119119
float gru_a_input[3*GRU_A_STATE_SIZE];
120120
float in_b[GRU_A_STATE_SIZE+FEATURE_DENSE2_OUT_SIZE];
121-
compute_embedding(&embed_sig, &in_a[0], last_sig);
122-
compute_embedding(&embed_sig, &in_a[EMBED_SIG_OUT_SIZE], pred);
123-
compute_embedding(&embed_exc, &in_a[2*EMBED_SIG_OUT_SIZE], last_exc);
124-
RNN_COPY(&in_a[2*EMBED_SIG_OUT_SIZE + EMBED_EXC_OUT_SIZE], condition, FEATURE_DENSE2_OUT_SIZE);
125-
compute_dense(&gru_a_dense_feature, gru_a_input, condition);
121+
RNN_COPY(gru_a_input, gru_a_condition, 3*GRU_A_STATE_SIZE);
126122
accum_embedding(&gru_a_embed_sig, gru_a_input, last_sig);
127123
accum_embedding(&gru_a_embed_pred, gru_a_input, pred);
128124
accum_embedding(&gru_a_embed_exc, gru_a_input, last_exc);
@@ -151,6 +147,7 @@ void lpcnet_synthesize(LPCNetState *lpcnet, short *output, const float *features
151147
float condition[FEATURE_DENSE2_OUT_SIZE];
152148
float lpc[LPC_ORDER];
153149
float pdf[DUAL_FC_OUT_SIZE];
150+
float gru_a_condition[3*GRU_A_STATE_SIZE];
154151
int pitch;
155152
float pitch_gain;
156153
/* FIXME: Remove this -- it's just a temporary hack to match the Python code. */
@@ -159,7 +156,7 @@ void lpcnet_synthesize(LPCNetState *lpcnet, short *output, const float *features
159156
pitch = (int)floor(50*features[36]+100);
160157
/* FIXME: get the pitch gain from 2 frames in the past. */
161158
pitch_gain = features[PITCH_GAIN_FEATURE];
162-
run_frame_network(lpcnet, condition, features, pitch);
159+
run_frame_network(lpcnet, condition, gru_a_condition, features, pitch);
163160
memcpy(lpc, lpcnet->old_lpc[FEATURES_DELAY-1], LPC_ORDER*sizeof(lpc[0]));
164161
memmove(lpcnet->old_lpc[1], lpcnet->old_lpc[0], (FEATURES_DELAY-1)*LPC_ORDER*sizeof(lpc[0]));
165162
memcpy(lpcnet->old_lpc[0], new_lpc, LPC_ORDER*sizeof(lpc[0]));
@@ -179,7 +176,7 @@ void lpcnet_synthesize(LPCNetState *lpcnet, short *output, const float *features
179176
for (j=0;j<LPC_ORDER;j++) pred -= lpcnet->last_sig[j]*lpc[j];
180177
last_sig_ulaw = lin2ulaw(lpcnet->last_sig[0]);
181178
pred_ulaw = lin2ulaw(pred);
182-
run_sample_network(&lpcnet->nnet, pdf, condition, lpcnet->last_exc, last_sig_ulaw, pred_ulaw);
179+
run_sample_network(&lpcnet->nnet, pdf, condition, gru_a_condition, lpcnet->last_exc, last_sig_ulaw, pred_ulaw);
183180
exc = sample_from_pdf(pdf, DUAL_FC_OUT_SIZE, MAX16(0, 1.5f*pitch_gain - .5f), PDF_FLOOR);
184181
pcm = pred + ulaw2lin(exc);
185182
RNN_MOVE(&lpcnet->last_sig[1], &lpcnet->last_sig[0], LPC_ORDER-1);

0 commit comments

Comments
 (0)