Review Board 1.7.16


dsp.c ast_dsp_call_progress use local short variable in loop, plus other cleanup

Review Request #2107 - Created Sept. 12, 2012 and submitted

Alec Davis
trunk
Reviewers
asterisk-dev
Asterisk
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
compiles.

Diff revision 3 (Latest)

1 2 3
1 2 3

  1. trunk/main/dsp.c: Loading...
trunk/main/dsp.c
Revision 373202 New Change
[20] 477 lines
[+20] [+] static void ast_fax_detect_init(struct ast_dsp *s)
478

    
   
478

   
479
static void ast_dtmf_detect_init(dtmf_detect_state_t *s, unsigned int sample_rate)
479
static void ast_dtmf_detect_init(dtmf_detect_state_t *s, unsigned int sample_rate)
480
{
480
{
481
	int i;
481
	int i;
482

    
   
482

   
483
	s->lasthit = 0;

   
484
	s->current_hit = 0;

   
485
	for (i = 0; i < 4; i++) {
483
	for (i = 0; i < 4; i++) {
486
		goertzel_init(&s->row_out[i], dtmf_row[i], sample_rate);
484
		goertzel_init(&s->row_out[i], dtmf_row[i], sample_rate);
487
		goertzel_init(&s->col_out[i], dtmf_col[i], sample_rate);
485
		goertzel_init(&s->col_out[i], dtmf_col[i], sample_rate);
488
		s->energy = 0.0;

   
489
	}
486
	}
Moved from 483

    
   
487
	s->lasthit = 0;
Moved from 484

    
   
488
	s->current_hit = 0;

    
   
489
	s->energy = 0.0;
490
	s->current_sample = 0;
490
	s->current_sample = 0;
491
	s->hits = 0;
491
	s->hits = 0;
492
	s->misses = 0;
492
	s->misses = 0;
493

    
   
493

   
494
	s->hits_to_begin = DTMF_HITS_TO_BEGIN;
494
	s->hits_to_begin = DTMF_HITS_TO_BEGIN;
495
	s->misses_to_end = DTMF_MISSES_TO_END;
495
	s->misses_to_end = DTMF_MISSES_TO_END;
496
}
496
}
497

    
   
497

   
498
static void ast_mf_detect_init(mf_detect_state_t *s, unsigned int sample_rate)
498
static void ast_mf_detect_init(mf_detect_state_t *s, unsigned int sample_rate)
499
{
499
{
500
	int i;
500
	int i;
501
	s->hits[0] = s->hits[1] = s->hits[2] = s->hits[3] = s->hits[4] = 0;
501

   
502
	for (i = 0; i < 6; i++) {
502
	for (i = 0; i < 6; i++) {
503
		goertzel_init(&s->tone_out[i], mf_tones[i], sample_rate);
503
		goertzel_init(&s->tone_out[i], mf_tones[i], sample_rate);
504
	}
504
	}

    
   
505
	s->hits[0] = s->hits[1] = s->hits[2] = s->hits[3] = s->hits[4] = 0;
505
	s->current_sample = 0;
506
	s->current_sample = 0;
506
	s->current_hit = 0;
507
	s->current_hit = 0;
507
}
508
}
508

    
   
509

   
509
static void ast_digit_detect_init(digit_detect_state_t *s, int mf, unsigned int sample_rate)
510
static void ast_digit_detect_init(digit_detect_state_t *s, int mf, unsigned int sample_rate)
[+20] [20] 504 lines
[+20] [+] static inline int pair_there(float p1, float p2, float i1, float i2, float e)
1014
	return 1;
1015
	return 1;
1015
}
1016
}
1016

    
   
1017

   
1017
static int __ast_dsp_call_progress(struct ast_dsp *dsp, short *s, int len)
1018
static int __ast_dsp_call_progress(struct ast_dsp *dsp, short *s, int len)
1018
{
1019
{

    
   
1020
	short samp;
1019
	int x;
1021
	int x;
1020
	int y;
1022
	int y;
1021
	int pass;
1023
	int pass;
1022
	int newstate = DSP_TONE_STATE_SILENCE;
1024
	int newstate = DSP_TONE_STATE_SILENCE;
1023
	int res = 0;
1025
	int res = 0;
1024
	while (len) {
1026
	while (len) {
1025
		/* Take the lesser of the number of samples we need and what we have */
1027
		/* Take the lesser of the number of samples we need and what we have */
1026
		pass = len;
1028
		pass = len;
1027
		if (pass > dsp->gsamp_size - dsp->gsamps) {
1029
		if (pass > dsp->gsamp_size - dsp->gsamps) {
1028
			pass = dsp->gsamp_size - dsp->gsamps;
1030
			pass = dsp->gsamp_size - dsp->gsamps;
1029
		}
1031
		}
1030
		for (x = 0; x < pass; x++) {
1032
		for (x = 0; x < pass; x++) {

    
   
1033
			samp = s[x];

    
   
1034
			dsp->genergy += (int32_t) samp * (int32_t) samp;
1031
			for (y = 0; y < dsp->freqcount; y++) {
1035
			for (y = 0; y < dsp->freqcount; y++) {
1032
				goertzel_sample(&dsp->freqs[y], s[x]);
1036
				goertzel_sample(&dsp->freqs[y], samp);
1033
			}
1037
			}
1034
			dsp->genergy += s[x] * s[x];

   
1035
		}
1038
		}
1036
		s += pass;
1039
		s += pass;
1037
		dsp->gsamps += pass;
1040
		dsp->gsamps += pass;
1038
		len -= pass;
1041
		len -= pass;
1039
		if (dsp->gsamps == dsp->gsamp_size) {
1042
		if (dsp->gsamps == dsp->gsamp_size) {
[+20] [20] 688 lines
[+20] [+] void ast_dsp_digitreset(struct ast_dsp *dsp)
1728
		mf_detect_state_t *s = &dsp->digit_state.td.mf;
1731
		mf_detect_state_t *s = &dsp->digit_state.td.mf;
1729
		/* Reinitialise the detector for the next block */
1732
		/* Reinitialise the detector for the next block */
1730
		for (i = 0; i < 6; i++) {
1733
		for (i = 0; i < 6; i++) {
1731
			goertzel_reset(&s->tone_out[i]);
1734
			goertzel_reset(&s->tone_out[i]);
1732
		}
1735
		}
1733
		s->hits[4] = s->hits[3] = s->hits[2] = s->hits[1] = s->hits[0] = s->current_hit = 0;
1736
		s->hits[4] = s->hits[3] = s->hits[2] = s->hits[1] = s->hits[0] = 0;

    
   
1737
		s->current_hit = 0;
1734
		s->current_sample = 0;
1738
		s->current_sample = 0;
1735
	} else {
1739
	} else {
1736
		dtmf_detect_state_t *s = &dsp->digit_state.td.dtmf;
1740
		dtmf_detect_state_t *s = &dsp->digit_state.td.dtmf;
1737
		/* Reinitialise the detector for the next block */
1741
		/* Reinitialise the detector for the next block */
1738
		for (i = 0; i < 4; i++) {
1742
		for (i = 0; i < 4; i++) {
1739
			goertzel_reset(&s->row_out[i]);
1743
			goertzel_reset(&s->row_out[i]);
1740
			goertzel_reset(&s->col_out[i]);
1744
			goertzel_reset(&s->col_out[i]);
1741
		}
1745
		}
1742
		s->lasthit = s->current_hit = 0;
1746
		s->lasthit = 0;

    
   
1747
		s->current_hit = 0;
1743
		s->energy = 0.0;
1748
		s->energy = 0.0;
1744
		s->current_sample = 0;
1749
		s->current_sample = 0;
1745
		s->hits = 0;
1750
		s->hits = 0;
1746
		s->misses = 0;
1751
		s->misses = 0;
1747
	}
1752
	}
[+20] [20] 119 lines
  1. trunk/main/dsp.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.