athena_signal/kernels/dios_ssp_agc/dios_ssp_agc_api.c
int gain_calc(float *input_time, objGainCalc *st_gc, float* gain_buffer, float* noclipgain)
{
	float energy = 0;        // Sum(RxInput[]^2) over the current frame
	float maxabs_level = 0;
	float rms_energy = 0;
	float noclip_gain = 0;
	float rms_gain = 0;
	float peak_gain = 0.0f;
	float final_gain = 0;    // Max(|RxInput[]|) over the current frame
	float sample_value0 = 0;
	float sample_value1 = 0;
	float sample_value2 = 0;
	float sample_value3 = 0;
	int sample_index = 0;

	for (sample_index = 0; sample_index < st_gc->frame_len; sample_index += 4) 
    {
		sample_value0 = (float)input_time[sample_index];
		sample_value1 = (float)input_time[sample_index + 1];
		sample_value2 = (float)input_time[sample_index + 2];
		sample_value3 = (float)input_time[sample_index + 3];
		maxabs_level = xmax(maxabs_level, xabs(sample_value0));
		maxabs_level = xmax(maxabs_level, xabs(sample_value1));
		maxabs_level = xmax(maxabs_level, xabs(sample_value2));
		maxabs_level = xmax(maxabs_level, xabs(sample_value3));
		energy += ((sample_value0 * sample_value0) + (sample_value1 * sample_value1)) +
			((sample_value2 * sample_value2) + (sample_value3 * sample_value3));
	}
	rms_energy = xsqrt(energy / st_gc->frame_len);
	if (st_gc->first_flag == 1) 
    {
		st_gc->peak_val = maxabs_level;
		st_gc->first_flag = 0;
	}
	if (maxabs_level > st_gc->peak_val) 
    {
		st_gc->peak_val = maxabs_level;
		st_gc->peak_hold_cnt = 0;
	}
	else if (st_gc->peak_hold_cnt++ > st_gc->peak_hold_time) 
    {
		st_gc->peak_val = xsmooth_proc(st_gc->peak_val, st_gc->peak_smooth_fac, maxabs_level);
	}

	noclip_gain = st_gc->defs_clip_val / (1.0f + st_gc->peak_val);
	rms_gain = st_gc->defs_max_rms_enrg / (1.0f + rms_energy);
	peak_gain = st_gc->def_max_peak_val / (1.0f + st_gc->peak_val);
	final_gain = xmin(peak_gain, rms_gain);
	gain_buffer[0] = final_gain;
	noclipgain[0] = noclip_gain;
	return 0;
}
// calculate the gain of each frame
calculate the gain of each frame
calculate the gain of each frame
int gain_calc(float *input_time, objGainCalc *st_gc, float* gain_buffer, float* noclipgain)
{
	float energy = 0;        
	float maxabs_level = 0;
	float rms_energy = 0;
	float noclip_gain = 0;
	float rms_gain = 0;
	float peak_gain = 0.0f;
	float final_gain = 0;    
	float sample_value0 = 0;
	float sample_value1 = 0;
	float sample_value2 = 0;
	float sample_value3 = 0;
	int sample_index = 0;
	for (sample_index = 0; sample_index < st_gc->frame_len; sample_index += 4) 
    {
		sample_value0 = (float)input_time[sample_index];
		sample_value1 = (float)input_time[sample_index + 1];
		sample_value2 = (float)input_time[sample_index + 2];
		sample_value3 = (float)input_time[sample_index + 3];
		maxabs_level = xmax(maxabs_level, xabs(sample_value0));
		maxabs_level = xmax(maxabs_level, xabs(sample_value1));
		maxabs_level = xmax(maxabs_level, xabs(sample_value2));
		maxabs_level = xmax(maxabs_level, xabs(sample_value3));
		energy += ((sample_value0 * sample_value0) + (sample_value1 * sample_value1)) +
			((sample_value2 * sample_value2) + (sample_value3 * sample_value3));
	}
	rms_energy = xsqrt(energy / st_gc->frame_len);
	if (st_gc->first_flag == 1) 
    {
		st_gc->peak_val = maxabs_level;
		st_gc->first_flag = 0;
	}
	if (maxabs_level > st_gc->peak_val) 
    {
		st_gc->peak_val = maxabs_level;
		st_gc->peak_hold_cnt = 0;
	}
	else if (st_gc->peak_hold_cnt++ > st_gc->peak_hold_time) 
    {
		st_gc->peak_val = xsmooth_proc(st_gc->peak_val, st_gc->peak_smooth_fac, maxabs_level);
	}
	noclip_gain = st_gc->defs_clip_val / (1.0f + st_gc->peak_val);
	rms_gain = st_gc->defs_max_rms_enrg / (1.0f + rms_energy);
	peak_gain = st_gc->def_max_peak_val / (1.0f + st_gc->peak_val);
	final_gain = xmin(peak_gain, rms_gain);
	gain_buffer[0] = final_gain;
	noclipgain[0] = noclip_gain;
	return 0;
}
int gain_calc ( float * input_time , objGainCalc * st_gc , float * gain_buffer , float * noclipgain ) { float energy = 0 ; float maxabs_level = 0 ; float rms_energy = 0 ; float noclip_gain = 0 ; float rms_gain = 0 ; float peak_gain = 0.0f ; float final_gain = 0 ; float sample_value0 = 0 ; float sample_value1 = 0 ; float sample_value2 = 0 ; float sample_value3 = 0 ; int sample_index = 0 ; for ( sample_index = 0 ; sample_index < st_gc -> frame_len ; sample_index += 4 ) { sample_value0 = ( float ) input_time [ sample_index ] ; sample_value1 = ( float ) input_time [ sample_index + 1 ] ; sample_value2 = ( float ) input_time [ sample_index + 2 ] ; sample_value3 = ( float ) input_time [ sample_index + 3 ] ; maxabs_level = xmax ( maxabs_level , xabs ( sample_value0 ) ) ; maxabs_level = xmax ( maxabs_level , xabs ( sample_value1 ) ) ; maxabs_level = xmax ( maxabs_level , xabs ( sample_value2 ) ) ; maxabs_level = xmax ( maxabs_level , xabs ( sample_value3 ) ) ; energy += ( ( sample_value0 * sample_value0 ) + ( sample_value1 * sample_value1 ) ) + ( ( sample_value2 * sample_value2 ) + ( sample_value3 * sample_value3 ) ) ; } rms_energy = xsqrt ( energy / st_gc -> frame_len ) ; if ( st_gc -> first_flag == 1 ) { st_gc -> peak_val = maxabs_level ; st_gc -> first_flag = 0 ; } if ( maxabs_level > st_gc -> peak_val ) { st_gc -> peak_val = maxabs_level ; st_gc -> peak_hold_cnt = 0 ; } else if ( st_gc -> peak_hold_cnt ++ > st_gc -> peak_hold_time ) { st_gc -> peak_val = xsmooth_proc ( st_gc -> peak_val , st_gc -> peak_smooth_fac , maxabs_level ) ; } noclip_gain = st_gc -> defs_clip_val / ( 1.0f + st_gc -> peak_val ) ; rms_gain = st_gc -> defs_max_rms_enrg / ( 1.0f + rms_energy ) ; peak_gain = st_gc -> def_max_peak_val / ( 1.0f + st_gc -> peak_val ) ; final_gain = xmin ( peak_gain , rms_gain ) ; gain_buffer [ 0 ] = final_gain ; noclipgain [ 0 ] = noclip_gain ; return 0 ; }
calculate the gain of each frame
calculate the gain of each frame
// Sum(RxInput[]^2) over the current frame // Max(|RxInput[]|) over the current frame