Mercurial > libavcodec.hg
comparison qcelpdec.c @ 10493:5f2ced30548b libavcodec
Implement ff_scale_vector_to_given_sum_of_squares()
to aid generic gain control routines. Changes
for qcelp are included. Patch Collin McQuillan.
author | reynaldo |
---|---|
date | Wed, 04 Nov 2009 19:29:29 +0000 |
parents | c1cfa4679371 |
children | f132cde57bbe |
comparison
equal
deleted
inserted
replaced
10492:63910f7ba293 | 10493:5f2ced30548b |
---|---|
404 break; | 404 break; |
405 } | 405 } |
406 } | 406 } |
407 | 407 |
408 /** | 408 /** |
409 * Compute the gain control | |
410 * | |
411 * @param v_in gain-controlled vector | |
412 * @param v_ref vector to control gain of | |
413 * | |
414 * @return gain control | |
415 * | |
416 * FIXME: If v_ref is a zero vector, it energy is zero | |
417 * and the behavior of the gain control is | |
418 * undefined in the specs. | |
419 * | |
420 * TIA/EIA/IS-733 2.4.8.3-2/3/4/5, 2.4.8.6 | |
421 */ | |
422 static float compute_gain_ctrl(const float *v_ref, const float *v_in, const int len) | |
423 { | |
424 float scalefactor = ff_dot_productf(v_in, v_in, len); | |
425 | |
426 if(scalefactor) | |
427 scalefactor = sqrt(ff_dot_productf(v_ref, v_ref, len) / scalefactor); | |
428 else | |
429 av_log_missing_feature(NULL, "Zero energy for gain control", 1); | |
430 return scalefactor; | |
431 } | |
432 | |
433 /** | |
434 * Apply generic gain control. | 409 * Apply generic gain control. |
435 * | 410 * |
436 * @param v_out output vector | 411 * @param v_out output vector |
437 * @param v_in gain-controlled vector | 412 * @param v_in gain-controlled vector |
438 * @param v_ref vector to control gain of | 413 * @param v_ref vector to control gain of |
440 * TIA/EIA/IS-733 2.4.8.3, 2.4.8.6 | 415 * TIA/EIA/IS-733 2.4.8.3, 2.4.8.6 |
441 */ | 416 */ |
442 static void apply_gain_ctrl(float *v_out, const float *v_ref, | 417 static void apply_gain_ctrl(float *v_out, const float *v_ref, |
443 const float *v_in) | 418 const float *v_in) |
444 { | 419 { |
445 int i, j, len; | 420 int i; |
446 float scalefactor; | 421 |
447 | 422 for (i = 0; i < 160; i += 40) |
448 for(i=0, j=0; i<4; i++) | 423 ff_scale_vector_to_given_sum_of_squares(v_out + i, v_in + i, |
449 { | 424 ff_dot_productf(v_ref + i, |
450 scalefactor = compute_gain_ctrl(v_ref + j, v_in + j, 40); | 425 v_ref + i, 40), |
451 for(len=j+40; j<len; j++) | 426 40); |
452 v_out[j] = scalefactor * v_in[j]; | |
453 } | |
454 } | 427 } |
455 | 428 |
456 /** | 429 /** |
457 * Apply filter in pitch-subframe steps. | 430 * Apply filter in pitch-subframe steps. |
458 * | 431 * |