insertion of bit errors from command line rather than compile time #define

pull/42/head
drowe67 2022-01-01 09:32:23 +10:30 committed by David Rowe
parent a05993e4aa
commit d72e424045
4 changed files with 26 additions and 15 deletions

View File

@ -136,7 +136,8 @@ void quant_pred_mbest(float vec_out[],
int num_stages,
float vq[],
int m[], int k,
int mbest_survivors)
int mbest_survivors,
float ber)
{
float err[k], w[k], se1;
int i,j,s,s1,ind;
@ -205,15 +206,16 @@ void quant_pred_mbest(float vec_out[],
if (lpcnet_fsv != NULL) fprintf(lpcnet_fsv, "%f\t%f\t", vec_in[0],sqrt(se1));
if (lpcnet_verbose) fprintf(stderr, " se1: %f\n", se1);
//#define INSERT_ERROR
#ifdef INSERT_ERROR
/* insert random errors in bits of first stage to test index optimisation */
for (s=0; s<num_stages; s++) {
for(int b=0; b<12; b++)
if ((float)rand()/RAND_MAX < 0.01)
indexes[s] ^= 1<<b;
if (ber > 0.0) {
/* optionally insert random errors in indexes to test index optimisation */
for (s=0; s<num_stages; s++) {
int log2m = roundf(log2(m[s]));
for(int b=0; b<log2m; b++)
if ((float)rand()/RAND_MAX < ber)
indexes[s] ^= 1<<b;
}
}
#endif
quant_pred_output(vec_out, indexes, err, pred, num_stages, vq, k);
for(i=0; i<num_stages; i++)
@ -385,7 +387,7 @@ int lpcnet_features_to_frame(LPCNET_QUANT *q, float features[], char frame[]) {
/* non-interpolated frame ----------------------------------------*/
quant_pred_mbest(q->features_quant, indexes, features, q->pred, q->num_stages, q->vq, q->m, k, q->mbest);
quant_pred_mbest(q->features_quant, indexes, features, q->pred, q->num_stages, q->vq, q->m, k, q->mbest, 0.0);
pitch_ind = pitch_encode(features[2*NB_BANDS], q->pitch_bits);
pitch_gain_ind = pitch_gain_encode(features[2*NB_BANDS+1]);
pack_frame(q->num_stages, q->m, indexes, q->pitch_bits, pitch_ind, pitch_gain_ind, frame);

View File

@ -67,7 +67,8 @@ void quant_pred_mbest(float vec_out[], /* prev quant vector, and output, need t
int num_stages,
float vq[],
int m[], int k,
int mbest_survivors);
int mbest_survivors,
float ber);
void quant_pred_output(float vec_out[],
int indexes[],

View File

@ -64,11 +64,13 @@ int main(int argc, char *argv[]) {
int pitch_bits = 0;
int small_vec = 0;
int logmag = 0;
float ber = 0.0;
for(i=0; i<MAX_STAGES*NB_BANDS*MAX_ENTRIES; i++) vq[i] = 0.0;
static struct option long_options[] = {
{"small", required_argument, 0, 'a'},
{"ber", required_argument, 0, 'b'},
{"decimate", required_argument, 0, 'd'},
{"extpitch", required_argument, 0, 'e'},
{"first", required_argument, 0, 'f'},
@ -90,13 +92,17 @@ int main(int argc, char *argv[]) {
int opt_index = 0;
while ((c = getopt_long (argc, argv, "ad:q:vs:f:p:e:u:l:m:h:wg:o:ix:", long_options, &opt_index)) != -1) {
while ((c = getopt_long (argc, argv, "ab:d:q:vs:f:p:e:u:l:m:h:wg:o:ix:", long_options, &opt_index)) != -1) {
switch (c) {
case 'a':
/* small vec - zero out higher order bands */
small_vec = 1;
break;
case 'f':
case 'b':
ber = atof(optarg);
fprintf(stderr, "BER = %f\n", ber);
break;
case 'f':
/* start VQ at band first+1 */
first = atoi(optarg);
k = NB_BANDS-first;
@ -195,6 +201,7 @@ int main(int argc, char *argv[]) {
break;
default:
fprintf(stderr,"usage: %s [Options]:\n [-d --decimation 1/2/3...]\n [-q --quant quantfile1,quantfile2,....]\n", argv[0]);
fprintf(stderr," [-b --ber BER Insert random bit errors in mag VQ indexes (default 0.0)]\n");
fprintf(stderr," [-g --gain pitch gain bias]\n");
fprintf(stderr," [-h --hard lowerLimitdB\n");
fprintf(stderr," [-i --mag\n");
@ -329,7 +336,8 @@ int main(int argc, char *argv[]) {
if (num_stages) {
if (mbest_survivors) {
/* mbest predictive VQ */
quant_pred_mbest(&features_quant[first], indexes, &features[first], pred, num_stages, vq, m, k, mbest_survivors);
quant_pred_mbest(&features_quant[first], indexes, &features[first], pred, num_stages,
vq, m, k, mbest_survivors, ber);
}
else {
/* standard predictive VQ */

View File

@ -202,7 +202,7 @@ int main(int argc, char *argv[]) {
if ((f % dec) == 0) {
/* non-interpolated frame ----------------------------------------*/
quant_pred_mbest(features_quant_, indexes, features, pred, num_stages, vq, m, k, mbest_survivors);
quant_pred_mbest(features_quant_, indexes, features, pred, num_stages, vq, m, k, mbest_survivors, 0.0);
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);