@@ -425,6 +425,7 @@ struct ast_dsp {
425
425
int tcount ;
426
426
int digitmode ;
427
427
int faxmode ;
428
+ int freqmode ;
428
429
int dtmf_began ;
429
430
int display_inband_dtmf_warning ;
430
431
float genergy ;
@@ -476,7 +477,7 @@ static void ast_tone_detect_init(tone_detect_state_t *s, int freq, int duration,
476
477
/* Now calculate final block size. It will contain integer number of periods */
477
478
s -> block_size = periods_in_block * sample_rate / freq ;
478
479
479
- /* tone_detect is currently only used to detect fax tones and we
480
+ /* tone_detect is generally only used to detect fax tones and we
480
481
do not need squelching the fax tones */
481
482
s -> squelch = 0 ;
482
483
@@ -518,6 +519,15 @@ static void ast_fax_detect_init(struct ast_dsp *s)
518
519
519
520
}
520
521
522
+ static void ast_freq_detect_init (struct ast_dsp * s , int freq , int dur , int db , int squelch )
523
+ {
524
+ /* we can conveniently just use one of the two fax tone states */
525
+ ast_tone_detect_init (& s -> cng_tone_state , freq , dur , db , s -> sample_rate );
526
+ if (s -> freqmode & squelch ) {
527
+ s -> cng_tone_state .squelch = 1 ;
528
+ }
529
+ }
530
+
521
531
static void ast_dtmf_detect_init (dtmf_detect_state_t * s , unsigned int sample_rate )
522
532
{
523
533
int i ;
@@ -1485,7 +1495,7 @@ struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp,
1485
1495
{
1486
1496
int silence ;
1487
1497
int res ;
1488
- int digit = 0 , fax_digit = 0 ;
1498
+ int digit = 0 , fax_digit = 0 , custom_freq_digit = 0 ;
1489
1499
int x ;
1490
1500
short * shortdata ;
1491
1501
unsigned char * odata ;
@@ -1558,6 +1568,12 @@ struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp,
1558
1568
}
1559
1569
}
1560
1570
1571
+ if ((dsp -> features & DSP_FEATURE_FREQ_DETECT )) {
1572
+ if ((dsp -> freqmode ) && tone_detect (dsp , & dsp -> cng_tone_state , shortdata , len )) {
1573
+ custom_freq_digit = 'q' ;
1574
+ }
1575
+ }
1576
+
1561
1577
if (dsp -> features & (DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_BUSY_DETECT )) {
1562
1578
if (dsp -> digitmode & DSP_DIGITMODE_MF ) {
1563
1579
digit = mf_detect (dsp , & dsp -> digit_state , shortdata , len , (dsp -> digitmode & DSP_DIGITMODE_NOQUELCH ) == 0 , (dsp -> digitmode & DSP_DIGITMODE_RELAXDTMF ));
@@ -1619,6 +1635,16 @@ struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp,
1619
1635
goto done ;
1620
1636
}
1621
1637
1638
+ if (custom_freq_digit ) {
1639
+ /* Custom frequency was detected - digit is 'q' */
1640
+
1641
+ memset (& dsp -> f , 0 , sizeof (dsp -> f ));
1642
+ dsp -> f .frametype = AST_FRAME_DTMF ;
1643
+ dsp -> f .subclass .integer = custom_freq_digit ;
1644
+ outf = & dsp -> f ;
1645
+ goto done ;
1646
+ }
1647
+
1622
1648
if ((dsp -> features & DSP_FEATURE_CALL_PROGRESS )) {
1623
1649
res = __ast_dsp_call_progress (dsp , shortdata , len );
1624
1650
if (res ) {
@@ -1830,6 +1856,17 @@ int ast_dsp_set_digitmode(struct ast_dsp *dsp, int digitmode)
1830
1856
return 0 ;
1831
1857
}
1832
1858
1859
+ int ast_dsp_set_freqmode (struct ast_dsp * dsp , int freq , int dur , int db , int squelch )
1860
+ {
1861
+ if (freq > 0 ) {
1862
+ dsp -> freqmode = 1 ;
1863
+ ast_freq_detect_init (dsp , freq , dur , db , squelch );
1864
+ } else {
1865
+ dsp -> freqmode = 0 ;
1866
+ }
1867
+ return 0 ;
1868
+ }
1869
+
1833
1870
int ast_dsp_set_faxmode (struct ast_dsp * dsp , int faxmode )
1834
1871
{
1835
1872
if (dsp -> faxmode != faxmode ) {
0 commit comments