<h1>Project "FreeSWITCH Source" received a push.</h1>

<h2>branch: master updated</h2>
<pre>
       via: 180e3d4ab1943361610ca241d150565aad8d16fd (commit)
      from: 78472897cdf1432fd3ceb9814ebee6b8376fd6e7 (commit)


</pre>= COMMIT LOG ===========================================================
<div class="highlight"><pre>committer: Anthony Minessale
comments: 
agc tweaks

<span style="color: #000080; font-weight: bold">diff --git a/src/include/switch_resample.h b/src/include/switch_resample.h</span>
<span style="color: #000080; font-weight: bold">index b38e094..3dff620 100644</span>
<span style="color: #A00000">--- a/src/include/switch_resample.h</span>
<span style="color: #00A000">+++ b/src/include/switch_resample.h</span>
<span style="color: #800080; font-weight: bold">@@ -39,6 +39,7 @@</span>
         
 */
 #define switch_normalize_volume(x) if (x &gt; 4) x = 4; if (x &lt; -4) x = -4;
<span style="color: #00A000">+#define switch_normalize_volume_granular(x) if (x &gt; 12) x = 12; if (x &lt; -12) x = -12;</span>
 
 #ifndef SWITCH_RESAMPLE_H
 #define SWITCH_RESAMPLE_H
<span style="color: #800080; font-weight: bold">@@ -158,6 +159,14 @@ SWITCH_DECLARE(void) switch_generate_sln_silence(int16_t *data, uint32_t samples</span>
   \param vol the volume factor -4 -&gt; 4
  */
 SWITCH_DECLARE(void) switch_change_sln_volume(int16_t *data, uint32_t samples, int32_t vol);
<span style="color: #00A000">+</span>
<span style="color: #00A000">+/*!</span>
<span style="color: #00A000">+  \brief Change the volume of a signed linear audio frame with more granularity</span>
<span style="color: #00A000">+  \param data the audio data</span>
<span style="color: #00A000">+  \param samples the number of 2 byte samples</span>
<span style="color: #00A000">+  \param vol the volume factor -12 -&gt; 12</span>
<span style="color: #00A000">+ */</span>
<span style="color: #00A000">+SWITCH_DECLARE(void) switch_change_sln_volume_granular(int16_t *data, uint32_t samples, int32_t vol);</span>
 ///\}
 
 SWITCH_DECLARE(uint32_t) switch_merge_sln(int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples);
<span style="color: #000080; font-weight: bold">diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c</span>
<span style="color: #000080; font-weight: bold">index 5eeae5c..8a3f53e 100644</span>
<span style="color: #A00000">--- a/src/mod/applications/mod_conference/mod_conference.c</span>
<span style="color: #00A000">+++ b/src/mod/applications/mod_conference/mod_conference.c</span>
<span style="color: #800080; font-weight: bold">@@ -318,6 +318,7 @@ struct conference_member {</span>
         switch_mutex_t *audio_in_mutex;
         switch_mutex_t *audio_out_mutex;
         switch_mutex_t *read_mutex;
<span style="color: #00A000">+        switch_codec_implementation_t read_impl;</span>
         switch_codec_implementation_t orig_read_impl;
         switch_codec_t read_codec;
         switch_codec_t write_codec;
<span style="color: #800080; font-weight: bold">@@ -1942,14 +1943,37 @@ static void conference_loop_fn_hangup(conference_member_t *member, caller_contro</span>
         switch_clear_flag_locked(member, MFLAG_RUNNING);
 }
 
<span style="color: #00A000">+static void check_agc_levels(conference_member_t *member)</span>
<span style="color: #00A000">+{</span>
<span style="color: #00A000">+        if (!member-&gt;avg_score) return;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (member-&gt;avg_score &lt; member-&gt;conference-&gt;agc_level - 200) {</span>
<span style="color: #00A000">+                member-&gt;agc_volume_in_level++;</span>
<span style="color: #00A000">+                switch_normalize_volume_granular(member-&gt;agc_volume_in_level);</span>
<span style="color: #00A000">+        } else if (member-&gt;avg_score &gt; member-&gt;conference-&gt;agc_level + 200) {</span>
<span style="color: #00A000">+                member-&gt;agc_volume_in_level--;</span>
<span style="color: #00A000">+                switch_normalize_volume_granular(member-&gt;agc_volume_in_level);</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+                //} else {</span>
<span style="color: #00A000">+                //member-&gt;vol_period = (member-&gt;read_impl.actual_samples_per_second / member-&gt;read_impl.samples_per_packet) * 5;</span>
<span style="color: #00A000">+                //}</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
 static void clear_avg(conference_member_t *member)
 {
 
<span style="color: #A00000">-        member-&gt;agc_volume_in_level = 0;</span>
<span style="color: #00A000">+        if (member-&gt;agc_volume_in_level &lt; -5) {</span>
<span style="color: #00A000">+                member-&gt;agc_volume_in_level = 0;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (member-&gt;conference-&gt;agc_level) {</span>
<span style="color: #00A000">+                check_agc_levels(member);</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
         member-&gt;avg_score = 0;
         member-&gt;avg_itt = 0;
         member-&gt;avg_tally = 0;
<span style="color: #A00000">-        member-&gt;nt_tally = 0;</span>
<span style="color: #00A000">+        member-&gt;agc_concur = 0;</span>
 }
 
 
<span style="color: #800080; font-weight: bold">@@ -1962,7 +1986,6 @@ static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, v</span>
         switch_status_t status;
         switch_frame_t *read_frame = NULL;
         uint32_t hangover = 40, hangunder = 5, hangover_hits = 0, hangunder_hits = 0, energy_level = 0, diff_level = 400;
<span style="color: #A00000">-        switch_codec_implementation_t read_impl = { 0 };</span>
         switch_core_session_t *session = member-&gt;session;
         int check_floor_change;
 
<span style="color: #800080; font-weight: bold">@@ -1972,7 +1995,7 @@ static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, v</span>
 
         channel = switch_core_session_get_channel(session);
 
<span style="color: #A00000">-        switch_core_session_get_read_impl(session, &amp;read_impl);</span>
<span style="color: #00A000">+        switch_core_session_get_read_impl(session, &amp;member-&gt;read_impl);</span>
 
         /* As long as we have a valid read, feed that data into an input buffer where the conference thread will take it 
            and mux it with any audio from other channels. */
<span style="color: #800080; font-weight: bold">@@ -1997,6 +2020,10 @@ static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, v</span>
                 }
 
                 if (switch_test_flag(read_frame, SFF_CNG)) {
<span style="color: #00A000">+                        if (member-&gt;conference-&gt;agc_level) {</span>
<span style="color: #00A000">+                                member-&gt;nt_tally++;</span>
<span style="color: #00A000">+                        }</span>
<span style="color: #00A000">+</span>
                         if (hangunder_hits) {
                                 hangunder_hits--;
                         }
<span style="color: #800080; font-weight: bold">@@ -2017,6 +2044,11 @@ static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, v</span>
 
                         goto do_continue;
                 }
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                if (member-&gt;nt_tally &gt; (member-&gt;read_impl.actual_samples_per_second / member-&gt;read_impl.samples_per_packet) * 3) {</span>
<span style="color: #00A000">+                        member-&gt;agc_volume_in_level = 0;</span>
<span style="color: #00A000">+                        clear_avg(member);</span>
<span style="color: #00A000">+                }</span>
                 
                 /* Check for input volume adjustments */
                 if (!member-&gt;conference-&gt;agc_level) {
<span style="color: #800080; font-weight: bold">@@ -2031,30 +2063,29 @@ static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, v</span>
                         uint32_t energy = 0, i = 0, samples = 0, j = 0;
                         int16_t *data;
                         int divisor = 0;
<span style="color: #A00000">-                        int agc_period = (read_impl.actual_samples_per_second / read_impl.samples_per_packet) / 2;</span>
<span style="color: #A00000">-                        int combined_vol = 0;</span>
<span style="color: #00A000">+                        int agc_period = (member-&gt;read_impl.actual_samples_per_second / member-&gt;read_impl.samples_per_packet) / 4;</span>
<span style="color: #00A000">+                        </span>
 
                         data = read_frame-&gt;data;
 
<span style="color: #A00000">-                        if (!(divisor = read_impl.actual_samples_per_second / 8000)) {</span>
<span style="color: #00A000">+                        if (!(divisor = member-&gt;read_impl.actual_samples_per_second / 8000)) {</span>
                                 divisor = 1;
                         }
 
                         member-&gt;score = 0;
 
<span style="color: #A00000">-                        combined_vol = member-&gt;agc_volume_in_level;</span>
<span style="color: #A00000">-                        if (member-&gt;conference-&gt;agc_level) {</span>
<span style="color: #A00000">-                                combined_vol += member-&gt;agc_volume_in_level;</span>
<span style="color: #00A000">+                        if (member-&gt;volume_in_level) {</span>
<span style="color: #00A000">+                                switch_change_sln_volume(read_frame-&gt;data, read_frame-&gt;datalen / 2, member-&gt;volume_in_level);</span>
                         }
 
<span style="color: #A00000">-                        if (combined_vol) {</span>
<span style="color: #A00000">-                                switch_change_sln_volume(read_frame-&gt;data, read_frame-&gt;datalen / 2, combined_vol);</span>
<span style="color: #00A000">+                        if (member-&gt;agc_volume_in_level) {</span>
<span style="color: #00A000">+                                switch_change_sln_volume_granular(read_frame-&gt;data, read_frame-&gt;datalen / 2, member-&gt;agc_volume_in_level);</span>
                         }
                         
                         if ((samples = read_frame-&gt;datalen / sizeof(*data))) {
                                 for (i = 0; i &lt; samples; i++) {
                                         energy += abs(data[j]);
<span style="color: #A00000">-                                        j += read_impl.number_of_channels;</span>
<span style="color: #00A000">+                                        j += member-&gt;read_impl.number_of_channels;</span>
                                 }
                                 member-&gt;score = energy / (samples / divisor);
                         }
<span style="color: #800080; font-weight: bold">@@ -2082,22 +2113,14 @@ static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, v</span>
 
 
                                 
<span style="color: #A00000">-                                if (++member-&gt;nt_tally &gt;= agc_period) {</span>
<span style="color: #00A000">+                                if (++member-&gt;agc_concur &gt;= agc_period) {</span>
                                         if (!member-&gt;vol_period) {
<span style="color: #A00000">-                                                if (member-&gt;avg_score &lt; member-&gt;conference-&gt;agc_level) {</span>
<span style="color: #A00000">-                                                        member-&gt;agc_volume_in_level++;</span>
<span style="color: #A00000">-                                                        switch_normalize_volume(member-&gt;agc_volume_in_level);</span>
<span style="color: #A00000">-                                                        member-&gt;vol_period = (read_impl.actual_samples_per_second / read_impl.samples_per_packet) * 2;</span>
<span style="color: #A00000">-                                                }</span>
<span style="color: #A00000">-                                        </span>
<span style="color: #A00000">-                                                if (member-&gt;avg_score &gt; member-&gt;conference-&gt;agc_level) {</span>
<span style="color: #A00000">-                                                        member-&gt;agc_volume_in_level--;</span>
<span style="color: #A00000">-                                                        switch_normalize_volume(member-&gt;agc_volume_in_level);</span>
<span style="color: #A00000">-                                                        member-&gt;vol_period = (read_impl.actual_samples_per_second / read_impl.samples_per_packet) * 2;</span>
<span style="color: #A00000">-                                                }</span>
<span style="color: #00A000">+                                                check_agc_levels(member);</span>
                                         }
<span style="color: #A00000">-                                        member-&gt;nt_tally = 0;</span>
<span style="color: #00A000">+                                        member-&gt;agc_concur = 0;</span>
                                 }
<span style="color: #00A000">+                        } else {</span>
<span style="color: #00A000">+                                member-&gt;nt_tally++;</span>
                         }
 
                         member-&gt;score_iir = (int) (((1.0 - SCORE_DECAY) * (float) member-&gt;score) + (SCORE_DECAY * (float) member-&gt;score_iir));
<span style="color: #800080; font-weight: bold">@@ -2112,6 +2135,10 @@ static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, v</span>
                                         hangover_hits--;
                                 }
 
<span style="color: #00A000">+                                if (member-&gt;conference-&gt;agc_level) {</span>
<span style="color: #00A000">+                                        member-&gt;nt_tally = 0;</span>
<span style="color: #00A000">+                                }</span>
<span style="color: #00A000">+</span>
                                 if (diff &gt;= diff_level || ++hangunder_hits &gt;= hangunder) { 
                                         check_floor_change = 1;
 
<span style="color: #800080; font-weight: bold">@@ -2147,6 +2174,11 @@ static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, v</span>
                                 if (hangunder_hits) {
                                         hangunder_hits--;
                                 }
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                                if (member-&gt;conference-&gt;agc_level) {</span>
<span style="color: #00A000">+                                        member-&gt;nt_tally++;</span>
<span style="color: #00A000">+                                }</span>
<span style="color: #00A000">+</span>
                                 if (switch_test_flag(member, MFLAG_TALKING) &amp;&amp; switch_test_flag(member, MFLAG_CAN_SPEAK)) {
                                         switch_event_t *event;
                                         if (++hangover_hits &gt;= hangover) {
<span style="color: #000080; font-weight: bold">diff --git a/src/switch_resample.c b/src/switch_resample.c</span>
<span style="color: #000080; font-weight: bold">index 10c633c..64656b6 100644</span>
<span style="color: #A00000">--- a/src/switch_resample.c</span>
<span style="color: #00A000">+++ b/src/switch_resample.c</span>
<span style="color: #800080; font-weight: bold">@@ -269,6 +269,43 @@ SWITCH_DECLARE(void) switch_mux_channels(int16_t *data, switch_size_t samples, u</span>
 
 }
 
<span style="color: #00A000">+SWITCH_DECLARE(void) switch_change_sln_volume_granular(int16_t *data, uint32_t samples, int32_t vol)</span>
<span style="color: #00A000">+{</span>
<span style="color: #00A000">+        double newrate = 0;</span>
<span style="color: #00A000">+        double pos[12] = {1.25, 1.50, 1.75, 2.0, 2.25, 2.50, 2.75, 3.0, 3.25, 3.50, 3.75, 4.0};</span>
<span style="color: #00A000">+        double neg[12] = {.917, .834, .751, .668, .585, .502, .419, .336, .253, .017, .087, .004};</span>
<span style="color: #00A000">+        double *chart;</span>
<span style="color: #00A000">+        uint32_t i;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (vol == 0) return;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        switch_normalize_volume_granular(vol);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (vol &gt; 0) {</span>
<span style="color: #00A000">+                chart = pos;</span>
<span style="color: #00A000">+        } else {</span>
<span style="color: #00A000">+                chart = neg;</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+        </span>
<span style="color: #00A000">+        i = abs(vol) - 1;</span>
<span style="color: #00A000">+        </span>
<span style="color: #00A000">+        switch_assert(i &lt; 12);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        newrate = chart[i];</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        if (newrate) {</span>
<span style="color: #00A000">+                int32_t tmp;</span>
<span style="color: #00A000">+                uint32_t x;</span>
<span style="color: #00A000">+                int16_t *fp = data;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                for (x = 0; x &lt; samples; x++) {</span>
<span style="color: #00A000">+                        tmp = (int32_t) fp[x] * newrate;</span>
<span style="color: #00A000">+                        switch_normalize_to_16bit(tmp);</span>
<span style="color: #00A000">+                        fp[x] = (int16_t) tmp;</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
 SWITCH_DECLARE(void) switch_change_sln_volume(int16_t *data, uint32_t samples, int32_t vol)
 {
         double newrate = 0;
</pre></div>
========================================================================<pre>

Summary of changes:
 src/include/switch_resample.h                      |    9 ++
 .../applications/mod_conference/mod_conference.c   |   84 ++++++++++++++------
 src/switch_resample.c                              |   37 +++++++++
 3 files changed, 104 insertions(+), 26 deletions(-)
</pre>
<p>this email was generated because of /git/your-repo.git/hooks/post-receive by the file /git-core/contrib/hooks/post-receive-email<br />
For more info, see <a href="http://blog.chomperstomp.com/?p=630">http://blog.chomperstomp.com/?p=630</a>
-- <br />
FreeSWITCH Source</p>