[asterisk-commits] alecdavis: trunk r373275 - /trunk/main/dsp.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 21 01:51:31 CDT 2012


Author: alecdavis
Date: Fri Sep 21 01:51:25 2012
New Revision: 373275

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=373275
Log:
dsp.c ast_dsp_call_progress use local short variable in loop, plus other cleanup

janitor cleanup. No functional change.

1). ast_dsp_call_progress: use 'short samp' instead of s[x] inside loop.
    apply same casting as other _init, dsp->energy = (int32_t) samp * (int32_t) samp

2). ast_dtmf_detect_init: move repeated setting of s->energy to outside of loop.
    do goertzel_init loop first before setting s->lasthit and s->current_hit, consistant with ast_dsp_digitreset()

3). ast_mf_detect_init:
    do goertzel_init loop first before setting s->hits[] and s->current_hit, consistant with ast_dsp_digitreset()

4). Don't chain init different variables, as the type may change

Review https://reviewboard.asterisk.org/r/2107/


Modified:
    trunk/main/dsp.c

Modified: trunk/main/dsp.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/dsp.c?view=diff&rev=373275&r1=373274&r2=373275
==============================================================================
--- trunk/main/dsp.c (original)
+++ trunk/main/dsp.c Fri Sep 21 01:51:25 2012
@@ -480,13 +480,13 @@
 {
 	int i;
 
-	s->lasthit = 0;
-	s->current_hit = 0;
 	for (i = 0; i < 4; i++) {
 		goertzel_init(&s->row_out[i], dtmf_row[i], sample_rate);
 		goertzel_init(&s->col_out[i], dtmf_col[i], sample_rate);
-		s->energy = 0.0;
-	}
+	}
+	s->lasthit = 0;
+	s->current_hit = 0;
+	s->energy = 0.0;
 	s->current_sample = 0;
 	s->hits = 0;
 	s->misses = 0;
@@ -498,10 +498,11 @@
 static void ast_mf_detect_init(mf_detect_state_t *s, unsigned int sample_rate)
 {
 	int i;
-	s->hits[0] = s->hits[1] = s->hits[2] = s->hits[3] = s->hits[4] = 0;
+
 	for (i = 0; i < 6; i++) {
 		goertzel_init(&s->tone_out[i], mf_tones[i], sample_rate);
 	}
+	s->hits[0] = s->hits[1] = s->hits[2] = s->hits[3] = s->hits[4] = 0;
 	s->current_sample = 0;
 	s->current_hit = 0;
 }
@@ -1016,6 +1017,7 @@
 
 static int __ast_dsp_call_progress(struct ast_dsp *dsp, short *s, int len)
 {
+	short samp;
 	int x;
 	int y;
 	int pass;
@@ -1028,10 +1030,11 @@
 			pass = dsp->gsamp_size - dsp->gsamps;
 		}
 		for (x = 0; x < pass; x++) {
+			samp = s[x];
+			dsp->genergy += (int32_t) samp * (int32_t) samp;
 			for (y = 0; y < dsp->freqcount; y++) {
-				goertzel_sample(&dsp->freqs[y], s[x]);
-			}
-			dsp->genergy += s[x] * s[x];
+				goertzel_sample(&dsp->freqs[y], samp);
+			}
 		}
 		s += pass;
 		dsp->gsamps += pass;
@@ -1730,7 +1733,8 @@
 		for (i = 0; i < 6; i++) {
 			goertzel_reset(&s->tone_out[i]);
 		}
-		s->hits[4] = s->hits[3] = s->hits[2] = s->hits[1] = s->hits[0] = s->current_hit = 0;
+		s->hits[4] = s->hits[3] = s->hits[2] = s->hits[1] = s->hits[0] = 0;
+		s->current_hit = 0;
 		s->current_sample = 0;
 	} else {
 		dtmf_detect_state_t *s = &dsp->digit_state.td.dtmf;
@@ -1739,7 +1743,8 @@
 			goertzel_reset(&s->row_out[i]);
 			goertzel_reset(&s->col_out[i]);
 		}
-		s->lasthit = s->current_hit = 0;
+		s->lasthit = 0;
+		s->current_hit = 0;
 		s->energy = 0.0;
 		s->current_sample = 0;
 		s->hits = 0;




More information about the asterisk-commits mailing list