]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-9922: [mod_conference] Auto Energy Level -- some clean up
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 27 Apr 2017 20:28:59 +0000 (15:28 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 27 Apr 2017 20:28:59 +0000 (15:28 -0500)
src/include/switch_resample.h
src/mod/applications/mod_conference/conference_api.c
src/mod/applications/mod_conference/conference_loop.c
src/mod/applications/mod_conference/mod_conference.c
src/switch_resample.c

index a1e823527de9fcd2ecb38ce8a71cacf5ff20241d..6656c205d73732f11f66bfe5ca16d965bc5dab73 100644 (file)
@@ -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:
index c85fa44dad61d867f7ea5b44625771d390dd86cf..0954d9e206f0c2ec5f7e0d7190e9cab3730ef932 100644 (file)
@@ -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);
index 022f89e07d31b87c60cd156c468eb9a731df97f4..9067f7a44eb755ccd7e6c3fcada10a50e46e013f 100644 (file)
@@ -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) {
index 89a35b38dc48a054ab255f1855431652985b72bb..042bd9ccfe3a33dae2d0621c70e55738d2e1d457 100644 (file)
@@ -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;
 
index e26a0769f99ad946a99a79579b55f221bad436ca..bd981f626f778e746dd2b0eef8590d40f421a89f 100644 (file)
@@ -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);
                        }
 
                }