<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16615">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved
  George Joseph: Looks good to me, but someone else must approve
  Friendly Automation: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">func_talkdetect.c: Fix logical errors in silence detection.<br><br>There are 3 separate changes here:<br><br>1. The documentation erroneously stated that the dsp_talking_threshold<br>   argument was a number of milliseconds when it is actually an energy<br>   level used by the DSP code to classify talking vs. silence.<br><br>2. Fixes a copy paste error in the argument handling code.<br><br>3. Don't erroneously switch to the talking state if we aren't actively<br>   handling a frame we've classified as talking.<br><br>Patch inspired by one provided by Moritz Fain (License #6961).<br><br>ASTERISK-27816 #close<br><br>Change-Id: I5953fd570b98b49c41cee55bfe3b941753fb2511<br>---<br>M funcs/func_talkdetect.c<br>1 file changed, 17 insertions(+), 7 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/funcs/func_talkdetect.c b/funcs/func_talkdetect.c</span><br><span>index bb61bb0..22f4d35 100644</span><br><span>--- a/funcs/func_talkdetect.c</span><br><span>+++ b/funcs/func_talkdetect.c</span><br><span>@@ -56,10 +56,20 @@</span><br><span>                                               parameters. Can be called multiple times to change parameters</span><br><span>                                                on a channel with talk detection already enabled.</para></span><br><span>                                               <argument name="dsp_silence_threshold" required="false"></span><br><span style="color: hsl(0, 100%, 40%);">-                                                      <para>The time in milliseconds before which a user is considered silent.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                                   <para>The time in milliseconds of sound falling below the</span><br><span style="color: hsl(120, 100%, 40%);">+                                                       <replaceable>dsp_talking_threshold</replaceable> option when</span><br><span style="color: hsl(120, 100%, 40%);">+                                                      a user is considered to stop talking. The default value is</span><br><span style="color: hsl(120, 100%, 40%);">+                                                    2500.</para></span><br><span>                                           </argument></span><br><span>                                            <argument name="dsp_talking_threshold" required="false"></span><br><span style="color: hsl(0, 100%, 40%);">-                                                      <para>The time in milliseconds after which a user is considered talking.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                                   <para>The minimum average magnitude per sample in a frame</span><br><span style="color: hsl(120, 100%, 40%);">+                                                       for the DSP to consider talking/noise present. A value below</span><br><span style="color: hsl(120, 100%, 40%);">+                                                  this level is considered silence. If not specified, the</span><br><span style="color: hsl(120, 100%, 40%);">+                                                       value comes from the <filename>dsp.conf</filename></span><br><span style="color: hsl(120, 100%, 40%);">+                                                        <replaceable>silencethreshold</replaceable> option or 256</span><br><span style="color: hsl(120, 100%, 40%);">+                                                 if <filename>dsp.conf</filename> doesn't exist or the</span><br><span style="color: hsl(120, 100%, 40%);">+                                                 <replaceable>silencethreshold</replaceable> option is not</span><br><span style="color: hsl(120, 100%, 40%);">+                                                 set.</para></span><br><span>                                            </argument></span><br><span>                                    </option></span><br><span>                              </optionlist></span><br><span>@@ -159,6 +169,7 @@</span><br><span> static int talk_detect_audiohook_cb(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)</span><br><span> {</span><br><span>    int total_silence;</span><br><span style="color: hsl(120, 100%, 40%);">+    int is_talking;</span><br><span>      int update_talking = 0;</span><br><span>      struct ast_datastore *datastore;</span><br><span>     struct talk_detect_params *td_params;</span><br><span>@@ -181,15 +192,14 @@</span><br><span>        }</span><br><span>    td_params = datastore->data;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-     ast_dsp_silence(td_params->dsp, frame, &total_silence);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-  if (total_silence < td_params->dsp_silence_threshold) {</span><br><span style="color: hsl(120, 100%, 40%);">+ is_talking = !ast_dsp_silence(td_params->dsp, frame, &total_silence);</span><br><span style="color: hsl(120, 100%, 40%);">+  if (is_talking) {</span><br><span>            if (!td_params->talking) {</span><br><span>                        update_talking = 1;</span><br><span>                  td_params->talking_start = ast_tvnow();</span><br><span>           }</span><br><span>            td_params->talking = 1;</span><br><span style="color: hsl(0, 100%, 40%);">-      } else {</span><br><span style="color: hsl(120, 100%, 40%);">+      } else if (total_silence >= td_params->dsp_silence_threshold) {</span><br><span>                if (td_params->talking) {</span><br><span>                         update_talking = 1;</span><br><span>          }</span><br><span>@@ -357,7 +367,7 @@</span><br><span> </span><br><span>                          if (dsp_talking_threshold < 1) {</span><br><span>                                  ast_log(AST_LOG_WARNING, "Invalid value %d for dsp_talking_threshold\n",</span><br><span style="color: hsl(0, 100%, 40%);">-                                              dsp_silence_threshold);</span><br><span style="color: hsl(120, 100%, 40%);">+                                               dsp_talking_threshold);</span><br><span>                                      return -1;</span><br><span>                           }</span><br><span>                    }</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16615">change 16615</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/16615"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I5953fd570b98b49c41cee55bfe3b941753fb2511 </div>
<div style="display:none"> Gerrit-Change-Number: 16615 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean@seanbright.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>