mirror of https://github.com/drowe67/LPCNet.git
frame packing and unpacking
parent
54d6b1b69c
commit
ed0403ba0c
|
@ -265,3 +265,33 @@ int pitch_gain_encode(float pitch_gain_feature) {
|
|||
float pitch_gain_decode(int ind) {
|
||||
return pitch_gain_cb[ind];
|
||||
}
|
||||
|
||||
void pack_frame(int num_stages, int m[], int indexes[], int pitch_bits, int pitch_ind, int pitch_gain_ind, char frame[]) {
|
||||
int s,b,k=0,nbits;
|
||||
|
||||
for(s=0; s<num_stages; s++) {
|
||||
nbits = log2(m[s]);
|
||||
for (b=0; b<nbits; b++)
|
||||
frame[k++] = (indexes[s] >> (nbits-1-b)) & 0x1;
|
||||
}
|
||||
for (b=0; b<pitch_bits; b++)
|
||||
frame[k++] = (pitch_ind >> (pitch_bits-1-b)) & 0x1;
|
||||
frame[k++] = (pitch_gain_ind >> 1) & 0x1;
|
||||
frame[k++] = pitch_gain_ind & 0x1;
|
||||
}
|
||||
|
||||
void unpack_frame(int num_stages, int m[], int indexes[], int pitch_bits, int *pitch_ind, int *pitch_gain_ind, char frame[]) {
|
||||
int s,b,k=0,nbits;
|
||||
|
||||
for(s=0; s<num_stages; s++) {
|
||||
nbits = log2(m[s]);
|
||||
indexes[s] = 0;
|
||||
for (b=0; b<nbits; b++)
|
||||
indexes[s] |= (int)frame[k++] << (nbits-1-b);
|
||||
}
|
||||
*pitch_ind = 0;
|
||||
for (b=0; b<pitch_bits; b++)
|
||||
*pitch_ind |= (int)frame[k++] << (pitch_bits-1-b);
|
||||
*pitch_gain_ind = ((int)frame[k]<<1) + frame[k+1];
|
||||
}
|
||||
|
||||
|
|
|
@ -48,5 +48,7 @@ int pitch_encode(float pitch_feature, int pitch_bits);
|
|||
float pitch_decode(int pitch_bits, int q);
|
||||
int pitch_gain_encode(float pitch_gain_feature);
|
||||
float pitch_gain_decode(int pitch_bits);
|
||||
void pack_frame(int num_stages, int m[], int indexes[], int pitch_bits, int pitch_ind, int pitch_gain_ind, char frame[]);
|
||||
void unpack_frame(int num_stages, int m[], int indexes[], int pitch_bits, int *pitch_ind, int *pitch_gain_ind, char frame[]);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -94,7 +94,12 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "dec: %d pred: %3.2f num_stages: %d mbest: %d", dec, pred, num_stages, mbest_survivors);
|
||||
int bits_per_frame = pitch_bits + 2;
|
||||
for(i=0; i<num_stages; i++)
|
||||
bits_per_frame += log2(m[i]);
|
||||
char frame[bits_per_frame];
|
||||
fprintf(stderr, "dec: %d pred: %3.2f num_stages: %d mbest: %d bits_per_frame: %d bit_rate: %5.2f",
|
||||
dec, pred, num_stages, mbest_survivors, bits_per_frame, (float)bits_per_frame/(dec*0.01));
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
/* delay line so we can pass some features (like pitch and voicing) through unmodified */
|
||||
|
@ -195,12 +200,16 @@ int main(int argc, char *argv[]) {
|
|||
quant_pred_mbest(features_quant_, indexes, features, pred, num_stages, vq, m, k, mbest_survivors);
|
||||
pitch_ind = pitch_encode(features[2*NB_BANDS], pitch_bits);
|
||||
pitch_gain_ind = pitch_gain_encode(features[2*NB_BANDS+1]);
|
||||
pack_frame(num_stages, m, indexes, pitch_bits, pitch_ind, pitch_gain_ind, frame);
|
||||
|
||||
}
|
||||
|
||||
/* decoder */
|
||||
|
||||
if ((f % dec) == 0) {
|
||||
/* non-interpolated frame ----------------------------------------*/
|
||||
|
||||
unpack_frame(num_stages, m, indexes, pitch_bits, &pitch_ind, &pitch_gain_ind, frame);
|
||||
quant_pred_output(features_quant, indexes, err, pred, num_stages, vq, k);
|
||||
|
||||
features_quant[2*NB_BANDS] = pitch_decode(pitch_bits, pitch_ind);
|
||||
|
|
Loading…
Reference in New Issue