[Asterisk-code-review] dsp: Add define macro for DTMF_MATRIX_SIZE (asterisk[18])

N A asteriskteam at digium.com
Wed Jan 5 06:47:19 CST 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/17822 )


Change subject: dsp: Add define macro for DTMF_MATRIX_SIZE
......................................................................

dsp: Add define macro for DTMF_MATRIX_SIZE

Adds the macro DTMF_MATRIX_SIZE to replace
the magic number 4 sprinkled throughout
dsp.c.

ASTERISK-29815 #close

Change-Id: Ie3bddb92c6b16204ece0f758009e9490eb33b9ba
---
M main/dsp.c
1 file changed, 14 insertions(+), 11 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/22/17822/1

diff --git a/main/dsp.c b/main/dsp.c
index 33f3b68..8b4e3ee 100644
--- a/main/dsp.c
+++ b/main/dsp.c
@@ -165,6 +165,8 @@
 
 #define	MAX_DTMF_DIGITS		128
 
+#define DTMF_MATRIX_SIZE	4
+
 /* Basic DTMF (AT&T) specs:
  *
  * Minimum tone on = 40ms
@@ -280,8 +282,8 @@
 
 typedef struct
 {
-	goertzel_state_t row_out[4];
-	goertzel_state_t col_out[4];
+	goertzel_state_t row_out[DTMF_MATRIX_SIZE];
+	goertzel_state_t col_out[DTMF_MATRIX_SIZE];
 	int hits;			/* How many successive hits we have seen already */
 	int misses;			/* How many successive misses we have seen already */
 	int lasthit;
@@ -532,7 +534,7 @@
 {
 	int i;
 
-	for (i = 0; i < 4; i++) {
+	for (i = 0; i < DTMF_MATRIX_SIZE; i++) {
 		goertzel_init(&s->row_out[i], dtmf_row[i], sample_rate);
 		goertzel_init(&s->col_out[i], dtmf_col[i], sample_rate);
 	}
@@ -692,8 +694,8 @@
 
 static int dtmf_detect(struct ast_dsp *dsp, digit_detect_state_t *s, int16_t amp[], int samples, int squelch, int relax)
 {
-	float row_energy[4];
-	float col_energy[4];
+	float row_energy[DTMF_MATRIX_SIZE];
+	float col_energy[DTMF_MATRIX_SIZE];
 	int i;
 	int j;
 	int sample;
@@ -732,6 +734,7 @@
 			goertzel_sample(s->td.dtmf.col_out + 2, samp);
 			goertzel_sample(s->td.dtmf.row_out + 3, samp);
 			goertzel_sample(s->td.dtmf.col_out + 3, samp);
+			/* go up to DTMF_MATRIX_SIZE - 1 */
 		}
 		s->td.dtmf.current_sample += (limit - sample);
 		if (s->td.dtmf.current_sample < DTMF_GSIZE) {
@@ -742,7 +745,7 @@
 		row_energy[0] = goertzel_result(&s->td.dtmf.row_out[0]);
 		col_energy[0] = goertzel_result(&s->td.dtmf.col_out[0]);
 
-		for (best_row = best_col = 0, i = 1; i < 4; i++) {
+		for (best_row = best_col = 0, i = 1; i < DTMF_MATRIX_SIZE; i++) {
 			row_energy[i] = goertzel_result(&s->td.dtmf.row_out[i]);
 			if (row_energy[i] > row_energy[best_row]) {
 				best_row = i;
@@ -763,7 +766,7 @@
 		    col_energy[best_col] < row_energy[best_row] * (relax ? relax_dtmf_reverse_twist : dtmf_reverse_twist) &&
 		    row_energy[best_row] < col_energy[best_col] * (relax ? relax_dtmf_normal_twist : dtmf_normal_twist)) {
 			/* Relative peak test */
-			for (i = 0; i < 4; i++) {
+			for (i = 0; i < DTMF_MATRIX_SIZE; i++) {
 				if ((i != best_col &&
 				    col_energy[i] * DTMF_RELATIVE_PEAK_COL > col_energy[best_col]) ||
 				    (i != best_row
@@ -772,7 +775,7 @@
 				}
 			}
 			/* ... and fraction of total energy test */
-			if (i >= 4 &&
+			if (i >= DTMF_MATRIX_SIZE &&
 			    (row_energy[best_row] + col_energy[best_col]) > DTMF_TO_TOTAL_ENERGY * s->td.dtmf.energy) {
 				/* Got a hit */
 				hit = dtmf_positions[(best_row << 2) + best_col];
@@ -878,7 +881,7 @@
 		}
 
 		/* Reinitialise the detector for the next block */
-		for (i = 0; i < 4; i++) {
+		for (i = 0; i < DTMF_MATRIX_SIZE; i++) {
 			goertzel_reset(&s->td.dtmf.row_out[i]);
 			goertzel_reset(&s->td.dtmf.col_out[i]);
 		}
@@ -1922,8 +1925,8 @@
 	dtmf_reverse_twist = DEF_DTMF_REVERSE_TWIST;
 	relax_dtmf_normal_twist = DEF_RELAX_DTMF_NORMAL_TWIST;
 	relax_dtmf_reverse_twist = DEF_RELAX_DTMF_REVERSE_TWIST;
-        dtmf_hits_to_begin = DEF_DTMF_HITS_TO_BEGIN;
-        dtmf_misses_to_end = DEF_DTMF_MISSES_TO_END;
+	dtmf_hits_to_begin = DEF_DTMF_HITS_TO_BEGIN;
+	dtmf_misses_to_end = DEF_DTMF_MISSES_TO_END;
 
 	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
 		return 0;

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17822
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: Ie3bddb92c6b16204ece0f758009e9490eb33b9ba
Gerrit-Change-Number: 17822
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220105/7225c331/attachment.html>


More information about the asterisk-code-review mailing list