FS-9922: [mod_conference] Auto Energy Level -- some clean up
This commit is contained in:
parent
c6839a44f3
commit
f691d139ea
|
@ -185,6 +185,7 @@ SWITCH_DECLARE(void) switch_agc_destroy(switch_agc_t **agcP);
|
|||
SWITCH_DECLARE(switch_status_t) switch_agc_feed(switch_agc_t *agc, int16_t *data, uint32_t samples, uint32_t channels);
|
||||
SWITCH_DECLARE(void) switch_agc_set_energy_avg(switch_agc_t *agc, uint32_t energy_avg);
|
||||
SWITCH_DECLARE(void) switch_agc_set_energy_low(switch_agc_t *agc, uint32_t low_energy_point);
|
||||
SWITCH_DECLARE(void) switch_agc_set_token(switch_agc_t *agc, const char *token);
|
||||
SWITCH_END_EXTERN_C
|
||||
#endif
|
||||
/* For Emacs:
|
||||
|
|
|
@ -957,6 +957,7 @@ void conference_api_set_agc(conference_member_t *member, const char *data)
|
|||
if (!member->agc) {
|
||||
switch_agc_create(&member->agc, member->agc_level, member->agc_low_energy_level, member->agc_margin,
|
||||
member->agc_change_factor, member->agc_period_len);
|
||||
switch_agc_set_token(member->agc, switch_channel_get_name(member->channel));
|
||||
} else {
|
||||
switch_agc_set(member->agc, member->agc_level, member->agc_low_energy_level, member->agc_margin,
|
||||
member->agc_change_factor, member->agc_period_len);
|
||||
|
|
|
@ -932,10 +932,6 @@ void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, void *ob
|
|||
switch_change_sln_volume(read_frame->data, (read_frame->datalen / 2) * member->conference->channels, member->volume_in_level);
|
||||
}
|
||||
|
||||
if (member->agc) {
|
||||
switch_agc_feed(member->agc, (int16_t *)read_frame->data, (read_frame->datalen / 2) * member->conference->channels, 1);
|
||||
}
|
||||
|
||||
if ((samples = read_frame->datalen / sizeof(*data))) {
|
||||
for (i = 0; i < samples; i++) {
|
||||
energy += abs(data[j]);
|
||||
|
@ -951,6 +947,10 @@ void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, void *ob
|
|||
|
||||
gate_check = conference_member_noise_gate_check(member);
|
||||
|
||||
if (gate_check && member->agc) {
|
||||
switch_agc_feed(member->agc, (int16_t *)read_frame->data, (read_frame->datalen / 2) * member->conference->channels, 1);
|
||||
}
|
||||
|
||||
member->score_iir = (int) (((1.0 - SCORE_DECAY) * (float) member->score) + (SCORE_DECAY * (float) member->score_iir));
|
||||
|
||||
if (member->score_iir > SCORE_MAX_IIR) {
|
||||
|
|
|
@ -3456,7 +3456,7 @@ conference_obj_t *conference_new(char *name, conference_xml_cfg_t cfg, switch_co
|
|||
|
||||
conference->agc_level = 0;
|
||||
conference->agc_low_energy_level = 0;
|
||||
conference->agc_margin = 500;
|
||||
conference->agc_margin = 20;
|
||||
conference->agc_change_factor = 3;
|
||||
conference->agc_period_len = (1000 / conference->interval) * 2;
|
||||
|
||||
|
|
|
@ -404,7 +404,7 @@ struct switch_agc_s {
|
|||
uint32_t energy_avg;
|
||||
uint32_t margin;
|
||||
uint32_t change_factor;
|
||||
|
||||
char *token;
|
||||
int vol;
|
||||
uint32_t score;
|
||||
uint32_t score_count;
|
||||
|
@ -432,6 +432,7 @@ SWITCH_DECLARE(switch_status_t) switch_agc_create(switch_agc_t **agcP, uint32_t
|
|||
{
|
||||
switch_agc_t *agc;
|
||||
switch_memory_pool_t *pool;
|
||||
char id[80] = "";
|
||||
|
||||
switch_assert(agcP);
|
||||
|
||||
|
@ -442,6 +443,10 @@ SWITCH_DECLARE(switch_status_t) switch_agc_create(switch_agc_t **agcP, uint32_t
|
|||
|
||||
switch_agc_set(agc, energy_avg, low_energy_point, margin, change_factor, period_len);
|
||||
|
||||
|
||||
switch_snprintf(id, sizeof(id), "%p", (void *)agc);
|
||||
switch_agc_set_token(agc, id);
|
||||
|
||||
*agcP = agc;
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
@ -476,6 +481,11 @@ SWITCH_DECLARE(void) switch_agc_set_energy_low(switch_agc_t *agc, uint32_t low_e
|
|||
agc->low_energy_point = low_energy_point;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(void) switch_agc_set_token(switch_agc_t *agc, const char *token)
|
||||
{
|
||||
agc->token = switch_core_strdup(agc->pool, token);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_agc_feed(switch_agc_t *agc, int16_t *data, uint32_t samples, uint32_t channels)
|
||||
{
|
||||
|
||||
|
@ -504,27 +514,32 @@ SWITCH_DECLARE(switch_status_t) switch_agc_feed(switch_agc_t *agc, int16_t *data
|
|||
agc->score_sum = 0;
|
||||
|
||||
if (agc->score_avg > agc->energy_avg + agc->margin) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "[%s] OVER++ SCORE AVG: %d ENERGY AVG: %d MARGIN: %d\n",
|
||||
agc->token, agc->score_avg, agc->energy_avg, agc->margin);
|
||||
agc->score_over++;
|
||||
} else {
|
||||
agc->score_over = 0;
|
||||
}
|
||||
|
||||
if (agc->score_avg < agc->energy_avg - agc->margin && (agc->vol < 0 || agc->score_avg > agc->low_energy_point)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "[%s] UNDER++ SCORE AVG: %d ENERGY AVG: %d MARGIN: %d\n",
|
||||
agc->token, agc->score_avg, agc->energy_avg, agc->margin);
|
||||
agc->score_under++;
|
||||
} else {
|
||||
agc->score_under = 0;
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "AVG %d over: %d under: %d\n", agc->score_avg, agc->score_over, agc->score_under);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "[%s] AVG %d over: %d under: %d\n",
|
||||
agc->token, agc->score_avg, agc->score_over, agc->score_under);
|
||||
|
||||
if (agc->score_over > agc->change_factor) {
|
||||
agc->vol--;
|
||||
switch_normalize_volume_granular(agc->vol);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "VOL DOWN %d\n", agc->vol);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "[%s] VOL DOWN %d\n", agc->token, agc->vol);
|
||||
} else if (agc->score_under > agc->change_factor) {
|
||||
agc->vol++;
|
||||
switch_normalize_volume_granular(agc->vol);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "VOL UP %d\n", agc->vol);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "[%s] VOL UP %d\n", agc->token, agc->vol);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue