diff options
Diffstat (limited to 'apps/codecs/libspeex/preprocess.c')
-rw-r--r-- | apps/codecs/libspeex/preprocess.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/apps/codecs/libspeex/preprocess.c b/apps/codecs/libspeex/preprocess.c index d030d3fcb2..7e7f106b55 100644 --- a/apps/codecs/libspeex/preprocess.c +++ b/apps/codecs/libspeex/preprocess.c | |||
@@ -229,6 +229,7 @@ struct SpeexPreprocessState_ { | |||
229 | #ifndef FIXED_POINT | 229 | #ifndef FIXED_POINT |
230 | int agc_enabled; | 230 | int agc_enabled; |
231 | float agc_level; | 231 | float agc_level; |
232 | float loudness_accum; | ||
232 | float *loudness_weight; /**< Perceptual loudness curve */ | 233 | float *loudness_weight; /**< Perceptual loudness curve */ |
233 | float loudness; /**< Loudness estimate */ | 234 | float loudness; /**< Loudness estimate */ |
234 | float agc_gain; /**< Current AGC gain */ | 235 | float agc_gain; /**< Current AGC gain */ |
@@ -509,12 +510,13 @@ SpeexPreprocessState *speex_preprocess_state_init(int frame_size, int sampling_r | |||
509 | st->loudness_weight[i]=.01f; | 510 | st->loudness_weight[i]=.01f; |
510 | st->loudness_weight[i] *= st->loudness_weight[i]; | 511 | st->loudness_weight[i] *= st->loudness_weight[i]; |
511 | } | 512 | } |
512 | st->loudness = pow(AMP_SCALE*st->agc_level,LOUDNESS_EXP); | 513 | /*st->loudness = pow(AMP_SCALE*st->agc_level,LOUDNESS_EXP);*/ |
514 | st->loudness = 1e-15; | ||
513 | st->agc_gain = 1; | 515 | st->agc_gain = 1; |
514 | st->nb_loudness_adapt = 0; | 516 | st->nb_loudness_adapt = 0; |
515 | st->max_gain = 10; | 517 | st->max_gain = 30; |
516 | st->max_increase_step = exp(0.11513f * 6.*st->frame_size / st->sampling_rate); | 518 | st->max_increase_step = exp(0.11513f * 12.*st->frame_size / st->sampling_rate); |
517 | st->max_decrease_step = exp(-0.11513f * 30.*st->frame_size / st->sampling_rate); | 519 | st->max_decrease_step = exp(-0.11513f * 40.*st->frame_size / st->sampling_rate); |
518 | st->prev_loudness = 1; | 520 | st->prev_loudness = 1; |
519 | st->init_max = 1; | 521 | st->init_max = 1; |
520 | #endif | 522 | #endif |
@@ -578,17 +580,19 @@ static void speex_compute_agc(SpeexPreprocessState *st, spx_word16_t Pframe, spx | |||
578 | loudness=sqrt(loudness); | 580 | loudness=sqrt(loudness); |
579 | /*if (loudness < 2*pow(st->loudness, 1.0/LOUDNESS_EXP) && | 581 | /*if (loudness < 2*pow(st->loudness, 1.0/LOUDNESS_EXP) && |
580 | loudness*2 > pow(st->loudness, 1.0/LOUDNESS_EXP))*/ | 582 | loudness*2 > pow(st->loudness, 1.0/LOUDNESS_EXP))*/ |
581 | if (Pframe>.5f) | 583 | if (Pframe>.3f) |
582 | { | 584 | { |
583 | st->nb_loudness_adapt++; | 585 | st->nb_loudness_adapt++; |
584 | rate=2.0f*Pframe*Pframe/(1+st->nb_loudness_adapt); | 586 | /*rate=2.0f*Pframe*Pframe/(1+st->nb_loudness_adapt);*/ |
587 | rate = .03*Pframe*Pframe; | ||
585 | st->loudness = (1-rate)*st->loudness + (rate)*pow(AMP_SCALE*loudness, LOUDNESS_EXP); | 588 | st->loudness = (1-rate)*st->loudness + (rate)*pow(AMP_SCALE*loudness, LOUDNESS_EXP); |
589 | st->loudness_accum = (1-rate)*st->loudness_accum + rate; | ||
586 | if (st->init_max < st->max_gain && st->nb_adapt > 20) | 590 | if (st->init_max < st->max_gain && st->nb_adapt > 20) |
587 | st->init_max *= 1.f + .05f*Pframe*Pframe; | 591 | st->init_max *= 1.f + .1f*Pframe*Pframe; |
588 | } | 592 | } |
589 | /*printf ("%f %f %f %f\n", Pframe, loudness, pow(st->loudness, 1.0f/LOUDNESS_EXP), st->loudness2);*/ | 593 | /*printf ("%f %f %f %f\n", Pframe, loudness, pow(st->loudness, 1.0f/LOUDNESS_EXP), st->loudness2);*/ |
590 | 594 | ||
591 | target_gain = AMP_SCALE*st->agc_level*pow(st->loudness, -1.0f/LOUDNESS_EXP); | 595 | target_gain = AMP_SCALE*st->agc_level*pow(st->loudness/(1e-4+st->loudness_accum), -1.0f/LOUDNESS_EXP); |
592 | 596 | ||
593 | if ((Pframe>.5 && st->nb_adapt > 20) || target_gain < st->agc_gain) | 597 | if ((Pframe>.5 && st->nb_adapt > 20) || target_gain < st->agc_gain) |
594 | { | 598 | { |
@@ -603,7 +607,7 @@ static void speex_compute_agc(SpeexPreprocessState *st, spx_word16_t Pframe, spx | |||
603 | 607 | ||
604 | st->agc_gain = target_gain; | 608 | st->agc_gain = target_gain; |
605 | } | 609 | } |
606 | /*printf ("%f %f %f\n", loudness, (float)AMP_SCALE_1*pow(st->loudness, 1.0f/LOUDNESS_EXP), st->agc_gain);*/ | 610 | /*fprintf (stderr, "%f %f %f\n", loudness, (float)AMP_SCALE_1*pow(st->loudness, 1.0f/LOUDNESS_EXP), st->agc_gain);*/ |
607 | 611 | ||
608 | for (i=0;i<2*N;i++) | 612 | for (i=0;i<2*N;i++) |
609 | ft[i] *= st->agc_gain; | 613 | ft[i] *= st->agc_gain; |