comparison qcelpdec.c @ 9353:70c3982d0bad libavcodec

Move scale factor computation to its own function. Patch by Kenan Gillet.
author reynaldo
date Tue, 07 Apr 2009 01:39:17 +0000
parents dfe2d348aa50
children 54bc8a2727b0
comparison
equal deleted inserted replaced
9352:03fd7ea4926b 9353:70c3982d0bad
410 break; 410 break;
411 } 411 }
412 } 412 }
413 413
414 /** 414 /**
415 * Compute the gain control
416 *
417 * @param v_in gain-controlled vector
418 * @param v_ref vector to control gain of
419 *
420 * @return gain control
421 *
422 * FIXME: If v_ref is a zero vector, it energy is zero
423 * and the behavior of the gain control is
424 * undefined in the specs.
425 *
426 * TIA/EIA/IS-733 2.4.8.3-2/3/4/5, 2.4.8.6
427 */
428 static float compute_gain_ctrl(const float *v_ref, const float *v_in, const int len)
429 {
430 float scalefactor = ff_dot_productf(v_in, v_in, len);
431
432 if(scalefactor)
433 scalefactor = sqrt(ff_dot_productf(v_ref, v_ref, len) / scalefactor);
434 else
435 ff_log_missing_feature(NULL, "Zero energy for gain control", 1);
436 return scalefactor;
437 }
438
439 /**
415 * Apply generic gain control. 440 * Apply generic gain control.
416 * 441 *
417 * @param v_out output vector 442 * @param v_out output vector
418 * @param v_in gain-controlled vector 443 * @param v_in gain-controlled vector
419 * @param v_ref vector to control gain of 444 * @param v_ref vector to control gain of
420 * 445 *
421 * FIXME: If v_ref is a zero vector, it energy is zero 446 * TIA/EIA/IS-733 2.4.8.3, 2.4.8.6
422 * and the behavior of the gain control is
423 * undefined in the specs.
424 *
425 * TIA/EIA/IS-733 2.4.8.3-2/3/4/5, 2.4.8.6
426 */ 447 */
427 static void apply_gain_ctrl(float *v_out, const float *v_ref, 448 static void apply_gain_ctrl(float *v_out, const float *v_ref,
428 const float *v_in) 449 const float *v_in)
429 { 450 {
430 int i, j, len; 451 int i, j, len;
431 float scalefactor; 452 float scalefactor;
432 453
433 for(i=0, j=0; i<4; i++) 454 for(i=0, j=0; i<4; i++)
434 { 455 {
435 scalefactor = ff_dot_productf(v_in + j, v_in + j, 40); 456 scalefactor = compute_gain_ctrl(v_ref + j, v_in + j, 40);
436 if(scalefactor)
437 scalefactor = sqrt(ff_dot_productf(v_ref + j, v_ref + j, 40)
438 / scalefactor);
439 else
440 ff_log_missing_feature(NULL, "Zero energy for gain control", 1);
441 for(len=j+40; j<len; j++) 457 for(len=j+40; j<len; j++)
442 v_out[j] = scalefactor * v_in[j]; 458 v_out[j] = scalefactor * v_in[j];
443 } 459 }
444 } 460 }
445 461