<p>Joshua Colp <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/17822">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
George Joseph: Looks good to me, approved
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">dsp: Add define macro for DTMF_MATRIX_SIZE<br><br>Adds the macro DTMF_MATRIX_SIZE to replace<br>the magic number 4 sprinkled throughout<br>dsp.c.<br><br>ASTERISK-29815 #close<br><br>Change-Id: Ie3bddb92c6b16204ece0f758009e9490eb33b9ba<br>---<br>M main/dsp.c<br>1 file changed, 14 insertions(+), 11 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/dsp.c b/main/dsp.c</span><br><span>index 33f3b68..8b4e3ee 100644</span><br><span>--- a/main/dsp.c</span><br><span>+++ b/main/dsp.c</span><br><span>@@ -165,6 +165,8 @@</span><br><span> </span><br><span> #define MAX_DTMF_DIGITS 128</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define DTMF_MATRIX_SIZE 4</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Basic DTMF (AT&T) specs:</span><br><span> *</span><br><span> * Minimum tone on = 40ms</span><br><span>@@ -280,8 +282,8 @@</span><br><span> </span><br><span> typedef struct</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- goertzel_state_t row_out[4];</span><br><span style="color: hsl(0, 100%, 40%);">- goertzel_state_t col_out[4];</span><br><span style="color: hsl(120, 100%, 40%);">+ goertzel_state_t row_out[DTMF_MATRIX_SIZE];</span><br><span style="color: hsl(120, 100%, 40%);">+ goertzel_state_t col_out[DTMF_MATRIX_SIZE];</span><br><span> int hits; /* How many successive hits we have seen already */</span><br><span> int misses; /* How many successive misses we have seen already */</span><br><span> int lasthit;</span><br><span>@@ -532,7 +534,7 @@</span><br><span> {</span><br><span> int i;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 0; i < 4; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < DTMF_MATRIX_SIZE; i++) {</span><br><span> goertzel_init(&s->row_out[i], dtmf_row[i], sample_rate);</span><br><span> goertzel_init(&s->col_out[i], dtmf_col[i], sample_rate);</span><br><span> }</span><br><span>@@ -692,8 +694,8 @@</span><br><span> </span><br><span> static int dtmf_detect(struct ast_dsp *dsp, digit_detect_state_t *s, int16_t amp[], int samples, int squelch, int relax)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- float row_energy[4];</span><br><span style="color: hsl(0, 100%, 40%);">- float col_energy[4];</span><br><span style="color: hsl(120, 100%, 40%);">+ float row_energy[DTMF_MATRIX_SIZE];</span><br><span style="color: hsl(120, 100%, 40%);">+ float col_energy[DTMF_MATRIX_SIZE];</span><br><span> int i;</span><br><span> int j;</span><br><span> int sample;</span><br><span>@@ -732,6 +734,7 @@</span><br><span> goertzel_sample(s->td.dtmf.col_out + 2, samp);</span><br><span> goertzel_sample(s->td.dtmf.row_out + 3, samp);</span><br><span> goertzel_sample(s->td.dtmf.col_out + 3, samp);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* go up to DTMF_MATRIX_SIZE - 1 */</span><br><span> }</span><br><span> s->td.dtmf.current_sample += (limit - sample);</span><br><span> if (s->td.dtmf.current_sample < DTMF_GSIZE) {</span><br><span>@@ -742,7 +745,7 @@</span><br><span> row_energy[0] = goertzel_result(&s->td.dtmf.row_out[0]);</span><br><span> col_energy[0] = goertzel_result(&s->td.dtmf.col_out[0]);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- for (best_row = best_col = 0, i = 1; i < 4; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ for (best_row = best_col = 0, i = 1; i < DTMF_MATRIX_SIZE; i++) {</span><br><span> row_energy[i] = goertzel_result(&s->td.dtmf.row_out[i]);</span><br><span> if (row_energy[i] > row_energy[best_row]) {</span><br><span> best_row = i;</span><br><span>@@ -763,7 +766,7 @@</span><br><span> col_energy[best_col] < row_energy[best_row] * (relax ? relax_dtmf_reverse_twist : dtmf_reverse_twist) &&</span><br><span> row_energy[best_row] < col_energy[best_col] * (relax ? relax_dtmf_normal_twist : dtmf_normal_twist)) {</span><br><span> /* Relative peak test */</span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 0; i < 4; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < DTMF_MATRIX_SIZE; i++) {</span><br><span> if ((i != best_col &&</span><br><span> col_energy[i] * DTMF_RELATIVE_PEAK_COL > col_energy[best_col]) ||</span><br><span> (i != best_row</span><br><span>@@ -772,7 +775,7 @@</span><br><span> }</span><br><span> }</span><br><span> /* ... and fraction of total energy test */</span><br><span style="color: hsl(0, 100%, 40%);">- if (i >= 4 &&</span><br><span style="color: hsl(120, 100%, 40%);">+ if (i >= DTMF_MATRIX_SIZE &&</span><br><span> (row_energy[best_row] + col_energy[best_col]) > DTMF_TO_TOTAL_ENERGY * s->td.dtmf.energy) {</span><br><span> /* Got a hit */</span><br><span> hit = dtmf_positions[(best_row << 2) + best_col];</span><br><span>@@ -878,7 +881,7 @@</span><br><span> }</span><br><span> </span><br><span> /* Reinitialise the detector for the next block */</span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 0; i < 4; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < DTMF_MATRIX_SIZE; i++) {</span><br><span> goertzel_reset(&s->td.dtmf.row_out[i]);</span><br><span> goertzel_reset(&s->td.dtmf.col_out[i]);</span><br><span> }</span><br><span>@@ -1922,8 +1925,8 @@</span><br><span> dtmf_reverse_twist = DEF_DTMF_REVERSE_TWIST;</span><br><span> relax_dtmf_normal_twist = DEF_RELAX_DTMF_NORMAL_TWIST;</span><br><span> relax_dtmf_reverse_twist = DEF_RELAX_DTMF_REVERSE_TWIST;</span><br><span style="color: hsl(0, 100%, 40%);">- dtmf_hits_to_begin = DEF_DTMF_HITS_TO_BEGIN;</span><br><span style="color: hsl(0, 100%, 40%);">- dtmf_misses_to_end = DEF_DTMF_MISSES_TO_END;</span><br><span style="color: hsl(120, 100%, 40%);">+ dtmf_hits_to_begin = DEF_DTMF_HITS_TO_BEGIN;</span><br><span style="color: hsl(120, 100%, 40%);">+ dtmf_misses_to_end = DEF_DTMF_MISSES_TO_END;</span><br><span> </span><br><span> if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {</span><br><span> return 0;</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/+/17822">change 17822</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/+/17822"/><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: Ie3bddb92c6b16204ece0f758009e9490eb33b9ba </div>
<div style="display:none"> Gerrit-Change-Number: 17822 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.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-MessageType: merged </div>