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

N A asteriskteam at digium.com
Thu Dec 23 08:53:04 CST 2021


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


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, 12 insertions(+), 9 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/11/17711/1

diff --git a/main/dsp.c b/main/dsp.c
index 33f3b68..6772e70 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]);
 		}

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ie3bddb92c6b16204ece0f758009e9490eb33b9ba
Gerrit-Change-Number: 17711
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/20211223/3c0922ed/attachment.html>


More information about the asterisk-code-review mailing list