Wed Jan 8 2020 09:50:11

Asterisk developer's documentation


dsp.h File Reference

Convenient Signal Processing routines. More...

Go to the source code of this file.

Macros

#define DSP_DIGITMODE_DTMF   0
 
#define DSP_DIGITMODE_MF   1
 
#define DSP_DIGITMODE_MUTECONF   (1 << 9)
 
#define DSP_DIGITMODE_MUTEMAX   (1 << 10)
 
#define DSP_DIGITMODE_NOQUELCH   (1 << 8)
 
#define DSP_DIGITMODE_RELAXDTMF   (1 << 11)
 
#define DSP_FAXMODE_DETECT_ALL   (DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED)
 
#define DSP_FAXMODE_DETECT_CED   (1 << 1)
 
#define DSP_FAXMODE_DETECT_CNG   (1 << 0)
 
#define DSP_FEATURE_BUSY_DETECT   (1 << 1)
 
#define DSP_FEATURE_CALL_PROGRESS   (DSP_PROGRESS_TALK | DSP_PROGRESS_RINGING | DSP_PROGRESS_BUSY | DSP_PROGRESS_CONGESTION)
 
#define DSP_FEATURE_DIGIT_DETECT   (1 << 3)
 
#define DSP_FEATURE_FAX_DETECT   (1 << 4)
 
#define DSP_FEATURE_SILENCE_SUPPRESS   (1 << 0)
 
#define DSP_FEATURE_WAITDIALTONE   (1 << 20)
 
#define DSP_PROGRESS_BUSY   (1 << 18)
 
#define DSP_PROGRESS_CONGESTION   (1 << 19)
 
#define DSP_PROGRESS_RINGING   (1 << 17)
 
#define DSP_PROGRESS_TALK   (1 << 16)
 
#define DSP_TONE_STATE_BUSY   4
 
#define DSP_TONE_STATE_DIALTONE   2
 
#define DSP_TONE_STATE_HUNGUP   8
 
#define DSP_TONE_STATE_RINGING   1
 
#define DSP_TONE_STATE_SILENCE   0
 
#define DSP_TONE_STATE_SPECIAL1   5
 
#define DSP_TONE_STATE_SPECIAL2   6
 
#define DSP_TONE_STATE_SPECIAL3   7
 
#define DSP_TONE_STATE_TALKING   3
 

Enumerations

enum  threshold { THRESHOLD_SILENCE = 0, THRESHOLD_MAX = 1 }
 

Functions

int ast_dsp_busydetect (struct ast_dsp *dsp)
 Return non-zero if historically this should be a busy, request that ast_dsp_silence has already been called. More...
 
int ast_dsp_call_progress (struct ast_dsp *dsp, struct ast_frame *inf)
 Scans for progress indication in audio. More...
 
int ast_dsp_digitdetect (struct ast_dsp *dsp, struct ast_frame *f)
 Return non-zero if DTMF hit was found. More...
 
void ast_dsp_digitreset (struct ast_dsp *dsp)
 Reset DTMF detector. More...
 
void ast_dsp_free (struct ast_dsp *dsp)
 
int ast_dsp_get_tcount (struct ast_dsp *dsp)
 Get tcount (Threshold counter) More...
 
int ast_dsp_get_threshold_from_settings (enum threshold which)
 Get silence threshold from dsp.conf. More...
 
int ast_dsp_get_tstate (struct ast_dsp *dsp)
 Get tstate (Tone State) More...
 
int ast_dsp_getdigits (struct ast_dsp *dsp, char *buf, int max)
 Get pending DTMF/MF digits. More...
 
int ast_dsp_init (void)
 Load dsp settings from dsp.conf. More...
 
struct ast_dspast_dsp_new (void)
 
int ast_dsp_noise (struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise)
 Return non-zero if this is noise. Updates "totalnoise" with the total number of seconds of noise. More...
 
struct ast_frameast_dsp_process (struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *inf)
 Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on busies, and call progress, all dependent upon which features are enabled. More...
 
int ast_dsp_reload (void)
 Reloads dsp settings from dsp.conf. More...
 
void ast_dsp_reset (struct ast_dsp *dsp)
 Reset total silence count. More...
 
void ast_dsp_set_busy_compare (struct ast_dsp *dsp, int compare)
 Set if silence and noice lengths must be compared for busy. More...
 
void ast_dsp_set_busy_count (struct ast_dsp *dsp, int cadences)
 Set number of required cadences for busy. More...
 
void ast_dsp_set_busy_pattern (struct ast_dsp *dsp, int tonelength, int quietlength, int fuzzy)
 Set expected lengths of the busy tones. More...
 
int ast_dsp_set_call_progress_zone (struct ast_dsp *dsp, char *zone)
 Set zone for doing progress detection. More...
 
int ast_dsp_set_digitmode (struct ast_dsp *dsp, int digitmode)
 Set digit mode. More...
 
int ast_dsp_set_faxmode (struct ast_dsp *dsp, int faxmode)
 Set fax mode. More...
 
void ast_dsp_set_features (struct ast_dsp *dsp, int features)
 Select feature set. More...
 
void ast_dsp_set_threshold (struct ast_dsp *dsp, int threshold)
 Set threshold value for silence. More...
 
int ast_dsp_silence (struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence)
 Return non-zero if this is silence. Updates "totalsilence" with the total number of seconds of silence. More...
 
int ast_dsp_was_muted (struct ast_dsp *dsp)
 Returns true if DSP code was muting any fragment of the last processed frame. Muting (squelching) happens when DSP code removes DTMF/MF/generic tones from the audio. More...
 

Detailed Description

Convenient Signal Processing routines.

Definition in file dsp.h.

Macro Definition Documentation

#define DSP_DIGITMODE_DTMF   0
#define DSP_DIGITMODE_MF   1
#define DSP_DIGITMODE_MUTECONF   (1 << 9)

Mute conference

Definition at line 35 of file dsp.h.

Referenced by ast_dsp_set_digitmode(), and dahdi_setoption().

#define DSP_DIGITMODE_MUTEMAX   (1 << 10)

Delay audio by a frame to try to extra quelch

Definition at line 36 of file dsp.h.

Referenced by ast_dsp_set_digitmode(), and dahdi_setoption().

#define DSP_DIGITMODE_NOQUELCH   (1 << 8)

Do not quelch DTMF from in-band

Definition at line 34 of file dsp.h.

Referenced by ast_dsp_process(), and mgcp_new().

#define DSP_DIGITMODE_RELAXDTMF   (1 << 11)

"Radio" mode (relaxed DTMF)

Definition at line 37 of file dsp.h.

Referenced by ast_dsp_process(), dahdi_setoption(), enable_dsp_detect(), and process_dahdi().

#define DSP_FAXMODE_DETECT_ALL   (DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED)

Definition at line 48 of file dsp.h.

#define DSP_FAXMODE_DETECT_CED   (1 << 1)

Definition at line 47 of file dsp.h.

Referenced by ast_dsp_process().

#define DSP_FAXMODE_DETECT_CNG   (1 << 0)

Definition at line 46 of file dsp.h.

Referenced by ast_dsp_new(), and ast_dsp_process().

#define DSP_FEATURE_BUSY_DETECT   (1 << 1)

Definition at line 27 of file dsp.h.

Referenced by ast_dsp_process(), and dahdi_new().

#define DSP_FEATURE_CALL_PROGRESS   (DSP_PROGRESS_TALK | DSP_PROGRESS_RINGING | DSP_PROGRESS_BUSY | DSP_PROGRESS_CONGESTION)

Definition at line 43 of file dsp.h.

Referenced by __ast_dsp_call_progress(), ast_dsp_process(), and dahdi_new().

#define DSP_FEATURE_FAX_DETECT   (1 << 4)
#define DSP_FEATURE_SILENCE_SUPPRESS   (1 << 0)

Definition at line 26 of file dsp.h.

Referenced by ast_dsp_new(), and ast_dsp_process().

#define DSP_FEATURE_WAITDIALTONE   (1 << 20)

Enable dial tone detection

Definition at line 44 of file dsp.h.

Referenced by ast_dsp_process(), dahdi_new(), and dahdi_read().

#define DSP_PROGRESS_BUSY   (1 << 18)

Enable busy tone detection

Definition at line 41 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_PROGRESS_CONGESTION   (1 << 19)

Enable congestion tone detection

Definition at line 42 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_PROGRESS_RINGING   (1 << 17)

Enable calling tone detection

Definition at line 40 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_PROGRESS_TALK   (1 << 16)

Enable talk detection

Definition at line 39 of file dsp.h.

Referenced by __ast_dsp_call_progress(), and dahdi_new().

#define DSP_TONE_STATE_BUSY   4

Definition at line 54 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_DIALTONE   2

Definition at line 52 of file dsp.h.

Referenced by __ast_dsp_call_progress(), and dahdi_read().

#define DSP_TONE_STATE_HUNGUP   8

Definition at line 58 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_RINGING   1

Definition at line 51 of file dsp.h.

Referenced by __ast_dsp_call_progress(), and dahdi_read().

#define DSP_TONE_STATE_SILENCE   0

Definition at line 50 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_SPECIAL1   5

Definition at line 55 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_SPECIAL2   6

Definition at line 56 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_SPECIAL3   7

Definition at line 57 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_TALKING   3

Definition at line 53 of file dsp.h.

Referenced by __ast_dsp_call_progress().

Enumeration Type Documentation

enum threshold
Enumerator
THRESHOLD_SILENCE 
THRESHOLD_MAX 

Definition at line 62 of file dsp.h.

62  {
63  /* Array offsets */
65  /* Always the last */
66  THRESHOLD_MAX = 1,
67 };

Function Documentation

int ast_dsp_busydetect ( struct ast_dsp dsp)

Return non-zero if historically this should be a busy, request that ast_dsp_silence has already been called.

Definition at line 1250 of file dsp.c.

References ast_debug, ast_log(), BUSY_MAX, BUSY_MIN, ast_dsp::busy_pattern_fuzzy, BUSY_PERCENT, ast_dsp::busy_quietlength, ast_dsp::busy_tonelength, ast_dsp::busycompare, ast_dsp::busycount, ast_dsp::busymaybe, ast_dsp::busytoneonly, DSP_HISTORY, ast_dsp::historicnoise, ast_dsp::historicsilence, LOG_ERROR, LOG_NOTICE, MAX, and option_debug.

Referenced by ast_dsp_process().

1251 {
1252  int res = 0, x;
1253  int avgsilence = 0, hitsilence = 0;
1254  int avgtone = 0, hittone = 0;
1255 #ifdef DEBUG_DSP_BUSYDETECT
1256  char buf[16];
1257  char silence_list[64]="", tone_list[64]="";
1258 #endif
1259 
1260  if (!dsp->busymaybe) {
1261  return res;
1262  }
1263  dsp->busymaybe = 0;
1264 
1265  for (x = DSP_HISTORY - dsp->busycount; x < DSP_HISTORY; x++) {
1266  avgsilence += dsp->historicsilence[x];
1267  avgtone += dsp->historicnoise[x];
1268  }
1269  avgsilence /= dsp->busycount;
1270  avgtone /= dsp->busycount;
1271 #ifdef DEBUG_DSP_BUSYDETECT
1272  sprintf(silence_list,"Silences: ");
1273  sprintf(tone_list,"Tones: ");
1274 #endif
1275  for (x=DSP_HISTORY - dsp->busycount; x<DSP_HISTORY; x++) {
1276 #ifdef DEBUG_DSP_BUSYDETECT
1277  snprintf(buf, sizeof(buf), "%5d ", dsp->historicsilence[x]);
1278  strcat(silence_list, buf);
1279  snprintf(buf, sizeof(buf), "%5d ", dsp->historicnoise[x]);
1280  strcat(tone_list, buf);
1281 #endif
1282  if (!dsp->busytoneonly) {
1283  if (avgsilence > dsp->historicsilence[x]) {
1284  if (avgsilence - (avgsilence*BUSY_PERCENT/100) <= dsp->historicsilence[x])
1285  hitsilence++;
1286  } else {
1287  if (avgsilence + (avgsilence*BUSY_PERCENT/100) >= dsp->historicsilence[x])
1288  hitsilence++;
1289  }
1290  }
1291  if (avgtone > dsp->historicnoise[x]) {
1292  if (avgtone - (avgtone * BUSY_PERCENT / 100) <= dsp->historicnoise[x]) {
1293  hittone++;
1294  }
1295  } else {
1296  if (avgtone + (avgtone * BUSY_PERCENT / 100) >= dsp->historicnoise[x]) {
1297  hittone++;
1298  }
1299  }
1300  }
1301 #ifdef DEBUG_DSP_BUSYDETECT
1302  fprintf(stderr, "BUSY DETECTOR\n");
1303  fprintf(stderr, "%s\n", tone_list);
1304  fprintf(stderr, "%s\n", silence_list)
1305 #endif
1306  if ((dsp->busytoneonly ||
1307  (hitsilence >= dsp->busycount - 1 && avgsilence >= BUSY_MIN && avgsilence <= BUSY_MAX)) &&
1308  (hittone >= dsp->busycount - 1 && avgtone >= BUSY_MIN && avgtone <= BUSY_MAX)) {
1309  if (dsp->busycompare) {
1310  if (dsp->busytoneonly) {
1311  res = 1;
1312  ast_log(LOG_ERROR, "You can't use busytoneonly together with busycompare");
1313  } else {
1314  if (avgtone > avgsilence) {
1315  if (avgtone - avgtone*BUSY_PERCENT/100 <= avgsilence)
1316  res = 1;
1317  } else {
1318  if (avgtone + avgtone*BUSY_PERCENT/100 >= avgsilence)
1319  res = 1;
1320  }
1321  }
1322  } else {
1323  res = 1;
1324  }
1325  }
1326  /* If we know the expected busy tone length, check we are in the range */
1327  if (res && (dsp->busy_tonelength > 0)) {
1328  if (abs(avgtone - dsp->busy_tonelength) > MAX(dsp->busy_tonelength*dsp->busy_pattern_fuzzy/100, 20)) {
1329 #ifdef BUSYDETECT_DEBUG
1330  ast_debug(5, "busy detector: avgtone of %d not close enough to desired %d\n",
1331  avgtone, dsp->busy_tonelength);
1332 #endif
1333  res = 0;
1334  }
1335  }
1336  /* If we know the expected busy tone silent-period length, check we are in the range */
1337  if (res && (!dsp->busytoneonly) && (dsp->busy_quietlength > 0)) {
1338  if (abs(avgsilence - dsp->busy_quietlength) > MAX(dsp->busy_quietlength*dsp->busy_pattern_fuzzy/100, 20)) {
1339 #ifdef BUSYDETECT_DEBUG
1340  ast_debug(5, "busy detector: avgsilence of %d not close enough to desired %d\n",
1341  avgsilence, dsp->busy_quietlength);
1342 #endif
1343  res = 0;
1344  }
1345  }
1346  if (res) {
1347  if (option_debug)
1348  ast_log(LOG_NOTICE, "ast_dsp_busydetect detected busy sequence, avgtone: %d, avgsilence %d\n", avgtone, avgsilence);
1349  } else {
1350  ast_debug(5, "busy detector: FAILED with avgtone: %d, avgsilence %d\n", avgtone, avgsilence);
1351  }
1352  return res;
1353 }
int busymaybe
Definition: dsp.c:397
Definition: dsp.c:128
Definition: dsp.c:127
int option_debug
Definition: asterisk.c:182
int busytoneonly
Definition: dsp.c:399
int historicsilence[DSP_HISTORY]
Definition: dsp.c:405
int busy_pattern_fuzzy
Definition: dsp.c:403
int historicnoise[DSP_HISTORY]
Definition: dsp.c:404
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define MAX(a, b)
Definition: utils.h:228
int busycount
Definition: dsp.c:398
int busy_tonelength
Definition: dsp.c:401
int busy_quietlength
Definition: dsp.c:402
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
int busycompare
Definition: dsp.c:400
#define DSP_HISTORY
Definition: dsp.c:132
int ast_dsp_call_progress ( struct ast_dsp dsp,
struct ast_frame inf 
)

Scans for progress indication in audio.

Definition at line 1174 of file dsp.c.

References __ast_dsp_call_progress(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), ast_frame_subclass::codec, ast_frame::data, ast_frame::datalen, ast_frame::frametype, LOG_WARNING, ast_frame::ptr, and ast_frame::subclass.

1175 {
1176  if (inf->frametype != AST_FRAME_VOICE) {
1177  ast_log(LOG_WARNING, "Can't check call progress of non-voice frames\n");
1178  return 0;
1179  }
1180  if (inf->subclass.codec != AST_FORMAT_SLINEAR) {
1181  ast_log(LOG_WARNING, "Can only check call progress in signed-linear frames\n");
1182  return 0;
1183  }
1184  return __ast_dsp_call_progress(dsp, inf->data.ptr, inf->datalen / 2);
1185 }
union ast_frame_subclass subclass
Definition: frame.h:146
void * ptr
Definition: frame.h:160
#define LOG_WARNING
Definition: logger.h:144
static int __ast_dsp_call_progress(struct ast_dsp *dsp, short *s, int len)
Definition: dsp.c:1036
format_t codec
Definition: frame.h:137
int datalen
Definition: frame.h:148
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AST_FORMAT_SLINEAR
Definition: frame.h:254
enum ast_frame_type frametype
Definition: frame.h:144
union ast_frame::@172 data
int ast_dsp_digitdetect ( struct ast_dsp dsp,
struct ast_frame f 
)

Return non-zero if DTMF hit was found.

void ast_dsp_digitreset ( struct ast_dsp dsp)

Reset DTMF detector.

Definition at line 1694 of file dsp.c.

References dtmf_detect_state_t::col_out, digit_detect_state_t::current_digits, dtmf_detect_state_t::current_hit, mf_detect_state_t::current_hit, dtmf_detect_state_t::current_sample, mf_detect_state_t::current_sample, ast_dsp::digit_state, ast_dsp::digitmode, digit_detect_state_t::digits, DSP_DIGITMODE_MF, digit_detect_state_t::dtmf, ast_dsp::dtmf_began, dtmf_detect_state_t::energy, goertzel_reset(), dtmf_detect_state_t::hits, mf_detect_state_t::hits, dtmf_detect_state_t::lasthit, digit_detect_state_t::mf, dtmf_detect_state_t::misses, dtmf_detect_state_t::row_out, digit_detect_state_t::td, and mf_detect_state_t::tone_out.

Referenced by analog_ss_thread(), and my_dsp_reset_and_flush_digits().

1695 {
1696  int i;
1697 
1698  dsp->dtmf_began = 0;
1699  if (dsp->digitmode & DSP_DIGITMODE_MF) {
1700  mf_detect_state_t *s = &dsp->digit_state.td.mf;
1701  /* Reinitialise the detector for the next block */
1702  for (i = 0; i < 6; i++) {
1703  goertzel_reset(&s->tone_out[i]);
1704  }
1705  s->hits[4] = s->hits[3] = s->hits[2] = s->hits[1] = s->hits[0] = s->current_hit = 0;
1706  s->current_sample = 0;
1707  } else {
1709  /* Reinitialise the detector for the next block */
1710  for (i = 0; i < 4; i++) {
1711  goertzel_reset(&s->row_out[i]);
1712  goertzel_reset(&s->col_out[i]);
1713  }
1714  s->lasthit = s->current_hit = 0;
1715  s->energy = 0.0;
1716  s->current_sample = 0;
1717  s->hits = 0;
1718  s->misses = 0;
1719  }
1720 
1721  dsp->digit_state.digits[0] = '\0';
1722  dsp->digit_state.current_digits = 0;
1723 }
#define DSP_DIGITMODE_MF
Definition: dsp.h:32
int current_digits
Definition: dsp.c:296
goertzel_state_t tone_out[6]
Definition: dsp.c:285
static void goertzel_reset(goertzel_state_t *s)
Definition: dsp.c:367
digit_detect_state_t digit_state
Definition: dsp.c:420
char digits[MAX_DTMF_DIGITS+1]
Definition: dsp.c:294
dtmf_detect_state_t dtmf
Definition: dsp.c:301
int current_sample
Definition: dsp.c:279
goertzel_state_t col_out[4]
Definition: dsp.c:273
int hits[5]
Definition: dsp.c:287
int dtmf_began
Definition: dsp.c:415
int digitmode
Definition: dsp.c:413
int current_sample
Definition: dsp.c:288
float energy
Definition: dsp.c:278
int current_hit
Definition: dsp.c:286
union digit_detect_state_t::@254 td
mf_detect_state_t mf
Definition: dsp.c:302
goertzel_state_t row_out[4]
Definition: dsp.c:272
int ast_dsp_get_tcount ( struct ast_dsp dsp)

Get tcount (Threshold counter)

Definition at line 1787 of file dsp.c.

References ast_dsp::tcount.

Referenced by dahdi_read().

1788 {
1789  return dsp->tcount;
1790 }
int tcount
Definition: dsp.c:412
int ast_dsp_get_threshold_from_settings ( enum threshold  which)

Get silence threshold from dsp.conf.

Since
1.6.1

Definition at line 1880 of file dsp.c.

Referenced by actual_load_config(), app_exec(), ast_record_review(), conf_run(), do_waiting(), handle_recordfile(), load_config(), record_exec(), and setup_privacy_args().

1881 {
1882  return thresholds[which];
1883 }
static int thresholds[THRESHOLD_MAX]
Definition: dsp.c:317
int ast_dsp_get_tstate ( struct ast_dsp dsp)

Get tstate (Tone State)

Definition at line 1782 of file dsp.c.

References ast_dsp::tstate.

Referenced by dahdi_read().

1783 {
1784  return dsp->tstate;
1785 }
int tstate
Definition: dsp.c:411
int ast_dsp_getdigits ( struct ast_dsp dsp,
char *  buf,
int  max 
)

Get pending DTMF/MF digits.

int ast_dsp_init ( void  )

Load dsp settings from dsp.conf.

Since
1.6.1

Definition at line 1885 of file dsp.c.

References _dsp_init().

Referenced by main().

1886 {
1887  return _dsp_init(0);
1888 }
static int _dsp_init(int reload)
Definition: dsp.c:1792
struct ast_dsp* ast_dsp_new ( void  )

Definition at line 1607 of file dsp.c.

References ast_calloc, ast_digit_detect_init(), ast_dsp_prog_reset(), ast_fax_detect_init(), BUSY_PAT_PERCENT, ast_dsp::busy_pattern_fuzzy, ast_dsp::busycompare, ast_dsp::busycount, ast_dsp::busytoneonly, DEFAULT_THRESHOLD, ast_dsp::digit_state, ast_dsp::digitmode, ast_dsp::display_inband_dtmf_warning, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_MF, DSP_FAXMODE_DETECT_CNG, DSP_FEATURE_SILENCE_SUPPRESS, DSP_HISTORY, ast_dsp::faxmode, ast_dsp::features, and ast_dsp::threshold.

Referenced by __ast_play_and_record(), __oh323_new(), background_detect_exec(), conf_run(), dahdi_new(), do_waiting(), enable_dsp_detect(), fax_session_new(), handle_recordfile(), isAnsweringMachine(), mgcp_new(), misdn_set_opt_exec(), my_dsp_set_digitmode(), read_config(), and record_exec().

1608 {
1609  struct ast_dsp *dsp;
1610 
1611  if ((dsp = ast_calloc(1, sizeof(*dsp)))) {
1614  dsp->busycount = DSP_HISTORY;
1618 #ifdef BUSYDETECT_TONEONLY
1619  dsp->busytoneonly = 1;
1620 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE
1621 #error "You can't use BUSYDETECT_TONEONLY together with BUSYDETECT_COMPARE_TONE_AND_SILENCE");
1622 #endif
1623 #else
1624  dsp->busytoneonly = 0;
1625 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE
1626  dsp->busycompare = 1;
1627 #else
1628  dsp->busycompare = 0;
1629 #endif
1630 #endif
1631  /* Initialize digit detector */
1633  dsp->display_inband_dtmf_warning = 1;
1634  /* Initialize initial DSP progress detect parameters */
1635  ast_dsp_prog_reset(dsp);
1636  /* Initialize fax detector */
1637  ast_fax_detect_init(dsp);
1638  }
1639  return dsp;
1640 }
int busytoneonly
Definition: dsp.c:399
#define DSP_DIGITMODE_DTMF
Definition: dsp.h:31
#define DSP_DIGITMODE_MF
Definition: dsp.h:32
int busy_pattern_fuzzy
Definition: dsp.c:403
static void ast_dsp_prog_reset(struct ast_dsp *dsp)
Definition: dsp.c:1590
digit_detect_state_t digit_state
Definition: dsp.c:420
static void ast_digit_detect_init(digit_detect_state_t *s, int mf)
Definition: dsp.c:528
int faxmode
Definition: dsp.c:414
int busycount
Definition: dsp.c:398
Definition: dsp.c:390
#define DSP_FEATURE_SILENCE_SUPPRESS
Definition: dsp.h:26
#define DEFAULT_THRESHOLD
This value is the minimum threshold, calculated by averaging all of the samples within a frame...
Definition: dsp.c:121
int threshold
Definition: dsp.c:392
int digitmode
Definition: dsp.c:413
static void ast_fax_detect_init(struct ast_dsp *s)
Definition: dsp.c:495
int features
Definition: dsp.c:395
#define ast_calloc(a, b)
Definition: astmm.h:82
int display_inband_dtmf_warning
Definition: dsp.c:416
int busycompare
Definition: dsp.c:400
#define DSP_FAXMODE_DETECT_CNG
Definition: dsp.h:46
#define DSP_HISTORY
Definition: dsp.c:132
int ast_dsp_noise ( struct ast_dsp dsp,
struct ast_frame f,
int *  totalnoise 
)

Return non-zero if this is noise. Updates "totalnoise" with the total number of seconds of noise.

Since
1.6.1

Definition at line 1373 of file dsp.c.

References __ast_dsp_silence_noise(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), ast_frame_subclass::codec, ast_frame::data, ast_frame::datalen, ast_frame::frametype, len(), LOG_WARNING, ast_frame::ptr, and ast_frame::subclass.

Referenced by do_waiting().

1374 {
1375  short *s;
1376  int len;
1377 
1378  if (f->frametype != AST_FRAME_VOICE) {
1379  ast_log(LOG_WARNING, "Can't calculate noise on a non-voice frame\n");
1380  return 0;
1381  }
1382  if (f->subclass.codec != AST_FORMAT_SLINEAR) {
1383  ast_log(LOG_WARNING, "Can only calculate noise on signed-linear frames :(\n");
1384  return 0;
1385  }
1386  s = f->data.ptr;
1387  len = f->datalen/2;
1388  return __ast_dsp_silence_noise(dsp, s, len, NULL, totalnoise);
1389 }
union ast_frame_subclass subclass
Definition: frame.h:146
void * ptr
Definition: frame.h:160
#define LOG_WARNING
Definition: logger.h:144
static int __ast_dsp_silence_noise(struct ast_dsp *dsp, short *s, int len, int *totalsilence, int *totalnoise)
Definition: dsp.c:1187
format_t codec
Definition: frame.h:137
int datalen
Definition: frame.h:148
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AST_FORMAT_SLINEAR
Definition: frame.h:254
enum ast_frame_type frametype
Definition: frame.h:144
union ast_frame::@172 data
int totalnoise
Definition: dsp.c:394
struct ast_frame* ast_dsp_process ( struct ast_channel chan,
struct ast_dsp dsp,
struct ast_frame inf 
)

Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on busies, and call progress, all dependent upon which features are enabled.

Definition at line 1392 of file dsp.c.

References __ast_dsp_call_progress(), __ast_dsp_silence_noise(), ast_channel::_softhangup, AST_ALAW, ast_alloca, AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, ast_debug, ast_dsp_busydetect(), AST_FORMAT_ALAW, AST_FORMAT_SLINEAR, AST_FORMAT_TESTLAW, AST_FORMAT_ULAW, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_NULL, AST_FRAME_VOICE, ast_frfree, ast_frisolate(), ast_getformatname(), AST_LIN2A, AST_LIN2MU, ast_log(), AST_MULAW, ast_queue_frame(), AST_SOFTHANGUP_DEV, ast_dsp::ced_tone_state, ast_dsp::cng_tone_state, ast_frame_subclass::codec, digit_detect_state_t::current_digits, ast_frame::data, ast_frame::datalen, ast_dsp::digit_state, digit_detect_state_t::digitlen, ast_dsp::digitmode, digit_detect_state_t::digits, ast_dsp::display_inband_dtmf_warning, DSP_DIGITMODE_MF, DSP_DIGITMODE_NOQUELCH, DSP_DIGITMODE_RELAXDTMF, DSP_FAXMODE_DETECT_CED, DSP_FAXMODE_DETECT_CNG, DSP_FEATURE_BUSY_DETECT, DSP_FEATURE_CALL_PROGRESS, DSP_FEATURE_DIGIT_DETECT, DSP_FEATURE_FAX_DETECT, DSP_FEATURE_SILENCE_SUPPRESS, DSP_FEATURE_WAITDIALTONE, ast_dsp::dtmf_began, dtmf_detect(), fragment_t::end, ast_dsp::f, ast_dsp::faxmode, ast_dsp::features, ast_frame::frametype, ast_dsp::historicnoise, ast_dsp::historicsilence, ast_frame_subclass::integer, ast_frame::len, len(), LOG_WARNING, mf_detect(), ast_dsp::mute_data, ast_dsp::mute_fragments, ast_channel::name, ast_frame::ptr, SAMPLE_RATE, ast_frame::src, fragment_t::start, ast_frame::subclass, and tone_detect().

Referenced by dahdi_read(), mgcp_rtp_read(), oh323_rtp_read(), process_ast_dsp(), and sip_rtp_read().

1393 {
1394  int silence;
1395  int res;
1396  int digit = 0, fax_digit = 0;
1397  int x;
1398  short *shortdata;
1399  unsigned char *odata;
1400  int len;
1401  struct ast_frame *outf = NULL;
1402 
1403  if (!af) {
1404  return NULL;
1405  }
1406  if (af->frametype != AST_FRAME_VOICE) {
1407  return af;
1408  }
1409 
1410  odata = af->data.ptr;
1411  len = af->datalen;
1412  /* Make sure we have short data */
1413  switch (af->subclass.codec) {
1414  case AST_FORMAT_SLINEAR:
1415  shortdata = af->data.ptr;
1416  len = af->datalen / 2;
1417  break;
1418  case AST_FORMAT_ULAW:
1419  case AST_FORMAT_TESTLAW:
1420  shortdata = ast_alloca(af->datalen * 2);
1421  for (x = 0;x < len; x++) {
1422  shortdata[x] = AST_MULAW(odata[x]);
1423  }
1424  break;
1425  case AST_FORMAT_ALAW:
1426  shortdata = ast_alloca(af->datalen * 2);
1427  for (x = 0; x < len; x++) {
1428  shortdata[x] = AST_ALAW(odata[x]);
1429  }
1430  break;
1431  default:
1432  /*Display warning only once. Otherwise you would get hundreds of warnings every second */
1433  if (dsp->display_inband_dtmf_warning)
1434  ast_log(LOG_WARNING, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(af->subclass.codec));
1435  dsp->display_inband_dtmf_warning = 0;
1436  return af;
1437  }
1438 
1439  /* Initially we do not want to mute anything */
1440  dsp->mute_fragments = 0;
1441 
1442  /* Need to run the silence detection stuff for silence suppression and busy detection */
1444  res = __ast_dsp_silence_noise(dsp, shortdata, len, &silence, NULL);
1445  }
1446 
1447  if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) && silence) {
1448  memset(&dsp->f, 0, sizeof(dsp->f));
1449  dsp->f.frametype = AST_FRAME_NULL;
1450  ast_frfree(af);
1451  return ast_frisolate(&dsp->f);
1452  }
1453  if ((dsp->features & DSP_FEATURE_BUSY_DETECT) && ast_dsp_busydetect(dsp)) {
1455  memset(&dsp->f, 0, sizeof(dsp->f));
1456  dsp->f.frametype = AST_FRAME_CONTROL;
1457  /* Signal this as it was a channel hangup, to avoid msg "channel.c:3473 ast_waitfordigit_full: Unexpected control subclass '5'" */
1459  ast_frfree(af);
1460  ast_debug(1, "Requesting Hangup because the busy tone was detected on channel %s\n", chan->name);
1461  return ast_frisolate(&dsp->f);
1462  }
1463 
1464  if ((dsp->features & DSP_FEATURE_FAX_DETECT)) {
1465  if ((dsp->faxmode & DSP_FAXMODE_DETECT_CNG) && tone_detect(dsp, &dsp->cng_tone_state, shortdata, len)) {
1466  fax_digit = 'f';
1467  }
1468 
1469  if ((dsp->faxmode & DSP_FAXMODE_DETECT_CED) && tone_detect(dsp, &dsp->ced_tone_state, shortdata, len)) {
1470  fax_digit = 'e';
1471  }
1472  }
1473 
1475  if (dsp->digitmode & DSP_DIGITMODE_MF)
1476  digit = mf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF));
1477  else
1478  digit = dtmf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF));
1479 
1480  if (dsp->digit_state.current_digits) {
1481  int event = 0, event_len = 0;
1482  char event_digit = 0;
1483 
1484  if (!dsp->dtmf_began) {
1485  /* We have not reported DTMF_BEGIN for anything yet */
1486 
1487  if (dsp->features & DSP_FEATURE_DIGIT_DETECT) {
1488  event = AST_FRAME_DTMF_BEGIN;
1489  event_digit = dsp->digit_state.digits[0];
1490  }
1491  dsp->dtmf_began = 1;
1492 
1493  } else if (dsp->digit_state.current_digits > 1 || digit != dsp->digit_state.digits[0]) {
1494  /* Digit changed. This means digit we have reported with DTMF_BEGIN ended */
1495  if (dsp->features & DSP_FEATURE_DIGIT_DETECT) {
1496  event = AST_FRAME_DTMF_END;
1497  event_digit = dsp->digit_state.digits[0];
1498  event_len = dsp->digit_state.digitlen[0] * 1000 / SAMPLE_RATE;
1499  }
1500  memmove(&dsp->digit_state.digits[0], &dsp->digit_state.digits[1], dsp->digit_state.current_digits);
1501  memmove(&dsp->digit_state.digitlen[0], &dsp->digit_state.digitlen[1], dsp->digit_state.current_digits * sizeof(dsp->digit_state.digitlen[0]));
1502  dsp->digit_state.current_digits--;
1503  dsp->dtmf_began = 0;
1504 
1505  if (dsp->features & DSP_FEATURE_BUSY_DETECT) {
1506  /* Reset Busy Detector as we have some confirmed activity */
1507  memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence));
1508  memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise));
1509  ast_debug(1, "DTMF Detected - Reset busydetector\n");
1510  }
1511  }
1512 
1513  if (event) {
1514  memset(&dsp->f, 0, sizeof(dsp->f));
1515  dsp->f.frametype = event;
1516  dsp->f.subclass.integer = event_digit;
1517  dsp->f.len = event_len;
1518  outf = &dsp->f;
1519  goto done;
1520  }
1521  }
1522  }
1523 
1524  if (fax_digit) {
1525  /* Fax was detected - digit is either 'f' or 'e' */
1526 
1527  memset(&dsp->f, 0, sizeof(dsp->f));
1528  dsp->f.frametype = AST_FRAME_DTMF;
1529  dsp->f.subclass.integer = fax_digit;
1530  outf = &dsp->f;
1531  goto done;
1532  }
1533 
1534  if ((dsp->features & DSP_FEATURE_CALL_PROGRESS)) {
1535  res = __ast_dsp_call_progress(dsp, shortdata, len);
1536  if (res) {
1537  switch (res) {
1538  case AST_CONTROL_ANSWER:
1539  case AST_CONTROL_BUSY:
1540  case AST_CONTROL_RINGING:
1542  case AST_CONTROL_HANGUP:
1543  memset(&dsp->f, 0, sizeof(dsp->f));
1544  dsp->f.frametype = AST_FRAME_CONTROL;
1545  dsp->f.subclass.integer = res;
1546  dsp->f.src = "dsp_progress";
1547  if (chan)
1548  ast_queue_frame(chan, &dsp->f);
1549  break;
1550  default:
1551  ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res);
1552  }
1553  }
1554  } else if ((dsp->features & DSP_FEATURE_WAITDIALTONE)) {
1555  res = __ast_dsp_call_progress(dsp, shortdata, len);
1556  }
1557 
1558 done:
1559  /* Mute fragment of the frame */
1560  for (x = 0; x < dsp->mute_fragments; x++) {
1561  memset(shortdata + dsp->mute_data[x].start, 0, sizeof(int16_t) * (dsp->mute_data[x].end - dsp->mute_data[x].start));
1562  }
1563 
1564  switch (af->subclass.codec) {
1565  case AST_FORMAT_SLINEAR:
1566  break;
1567  case AST_FORMAT_ULAW:
1568  for (x = 0; x < len; x++) {
1569  odata[x] = AST_LIN2MU((unsigned short) shortdata[x]);
1570  }
1571  break;
1572  case AST_FORMAT_ALAW:
1573  for (x = 0; x < len; x++) {
1574  odata[x] = AST_LIN2A((unsigned short) shortdata[x]);
1575  }
1576  break;
1577  }
1578 
1579  if (outf) {
1580  if (chan) {
1581  ast_queue_frame(chan, af);
1582  }
1583  ast_frfree(af);
1584  return ast_frisolate(outf);
1585  } else {
1586  return af;
1587  }
1588 }
union ast_frame_subclass subclass
Definition: frame.h:146
int start
Definition: dsp.c:373
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: utils.h:653
#define DSP_FEATURE_DIGIT_DETECT
Definition: dsp.h:28
void * ptr
Definition: frame.h:160
struct ast_frame f
Definition: dsp.c:391
#define DSP_DIGITMODE_MF
Definition: dsp.h:32
#define LOG_WARNING
Definition: logger.h:144
#define AST_ALAW(a)
Definition: alaw.h:84
#define DSP_FEATURE_CALL_PROGRESS
Definition: dsp.h:43
#define AST_FRAME_DTMF
Definition: frame.h:128
static int __ast_dsp_call_progress(struct ast_dsp *dsp, short *s, int len)
Definition: dsp.c:1036
int historicsilence[DSP_HISTORY]
Definition: dsp.c:405
static int __ast_dsp_silence_noise(struct ast_dsp *dsp, short *s, int len, int *totalsilence, int *totalnoise)
Definition: dsp.c:1187
int current_digits
Definition: dsp.c:296
static int dtmf_detect(struct ast_dsp *dsp, digit_detect_state_t *s, int16_t amp[], int samples, int squelch, int relax)
Definition: dsp.c:661
struct ast_frame * ast_frisolate(struct ast_frame *fr)
Makes a frame independent of any static storage.
Definition: frame.c:391
digit_detect_state_t digit_state
Definition: dsp.c:420
int historicnoise[DSP_HISTORY]
Definition: dsp.c:404
char digits[MAX_DTMF_DIGITS+1]
Definition: dsp.c:294
#define DSP_DIGITMODE_RELAXDTMF
Definition: dsp.h:37
int faxmode
Definition: dsp.c:414
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
const char * src
Definition: frame.h:158
#define AST_FORMAT_ALAW
Definition: frame.h:248
#define AST_MULAW(a)
Definition: ulaw.h:85
#define DSP_FEATURE_SILENCE_SUPPRESS
Definition: dsp.h:26
#define DSP_FEATURE_FAX_DETECT
Definition: dsp.h:29
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel&#39;s frame queue.
Definition: channel.c:1558
int end
Definition: dsp.c:374
static int mf_detect(struct ast_dsp *dsp, digit_detect_state_t *s, int16_t amp[], int samples, int squelch, int relax)
Definition: dsp.c:863
char * ast_getformatname(format_t format)
Get the name of a format.
Definition: frame.c:578
int dtmf_began
Definition: dsp.c:415
#define AST_FORMAT_ULAW
Definition: frame.h:246
#define DSP_FAXMODE_DETECT_CED
Definition: dsp.h:47
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define AST_FORMAT_TESTLAW
Definition: frame.h:303
int digitmode
Definition: dsp.c:413
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int _softhangup
Definition: channel.h:832
#define DSP_FEATURE_BUSY_DETECT
Definition: dsp.h:27
int mute_fragments
Definition: dsp.c:418
int features
Definition: dsp.c:395
tone_detect_state_t ced_tone_state
Definition: dsp.c:422
static int tone_detect(struct ast_dsp *dsp, tone_detect_state_t *s, int16_t *amp, int samples)
Definition: dsp.c:542
#define AST_FORMAT_SLINEAR
Definition: frame.h:254
int display_inband_dtmf_warning
Definition: dsp.c:416
#define SAMPLE_RATE
Definition: dsp.c:205
tone_detect_state_t cng_tone_state
Definition: dsp.c:421
Data structure associated with a single frame of data.
Definition: frame.h:142
int digitlen[MAX_DTMF_DIGITS+1]
Definition: dsp.c:295
#define DSP_FAXMODE_DETECT_CNG
Definition: dsp.h:46
fragment_t mute_data[5]
Definition: dsp.c:419
enum ast_frame_type frametype
Definition: frame.h:144
#define DSP_DIGITMODE_NOQUELCH
Definition: dsp.h:34
#define ast_frfree(fr)
Definition: frame.h:583
#define DSP_FEATURE_WAITDIALTONE
Definition: dsp.h:44
int ast_dsp_busydetect(struct ast_dsp *dsp)
Return non-zero if historically this should be a busy, request that ast_dsp_silence has already been ...
Definition: dsp.c:1250
union ast_frame::@172 data
long len
Definition: frame.h:170
#define AST_LIN2MU(a)
Definition: ulaw.h:49
#define AST_LIN2A(a)
Definition: alaw.h:50
int ast_dsp_reload ( void  )

Reloads dsp settings from dsp.conf.

Since
1.6.1

Definition at line 1890 of file dsp.c.

References _dsp_init().

1891 {
1892  return _dsp_init(1);
1893 }
static int _dsp_init(int reload)
Definition: dsp.c:1792
void ast_dsp_reset ( struct ast_dsp dsp)

Reset total silence count.

Definition at line 1725 of file dsp.c.

References ast_dsp::freqs, ast_dsp::gsamps, ast_dsp::historicnoise, ast_dsp::historicsilence, ast_dsp::ringtimeout, ast_dsp::totalsilence, goertzel_state_t::v2, and goertzel_state_t::v3.

Referenced by debug_check_frame_for_silence().

1726 {
1727  int x;
1728 
1729  dsp->totalsilence = 0;
1730  dsp->gsamps = 0;
1731  for (x = 0; x < 4; x++) {
1732  dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0;
1733  }
1734  memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence));
1735  memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise));
1736  dsp->ringtimeout= 0;
1737 }
int historicsilence[DSP_HISTORY]
Definition: dsp.c:405
int historicnoise[DSP_HISTORY]
Definition: dsp.c:404
int totalsilence
Definition: dsp.c:393
goertzel_state_t freqs[7]
Definition: dsp.c:406
int gsamps
Definition: dsp.c:408
int ringtimeout
Definition: dsp.c:396
void ast_dsp_set_busy_compare ( struct ast_dsp dsp,
int  compare 
)

Set if silence and noice lengths must be compared for busy.

Definition at line 1674 of file dsp.c.

References ast_dsp::busycompare.

Referenced by dahdi_new().

1675 {
1676  if (compare > 0)
1677  dsp->busycompare = 1;
1678  else
1679  dsp->busycompare = 0;
1680 }
static int compare(const char *text, const char *template)
int busycompare
Definition: dsp.c:400
void ast_dsp_set_busy_count ( struct ast_dsp dsp,
int  cadences 
)

Set number of required cadences for busy.

Definition at line 1663 of file dsp.c.

References ast_dsp::busycount, cadences, and DSP_HISTORY.

Referenced by dahdi_new().

1664 {
1665  if (cadences < 4) {
1666  cadences = 4;
1667  }
1668  if (cadences > DSP_HISTORY) {
1670  }
1671  dsp->busycount = cadences;
1672 }
int busycount
Definition: dsp.c:398
static struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX]
Definition: chan_dahdi.c:393
#define DSP_HISTORY
Definition: dsp.c:132
void ast_dsp_set_busy_pattern ( struct ast_dsp dsp,
int  tonelength,
int  quietlength,
int  fuzzy 
)

Set expected lengths of the busy tones.

Definition at line 1682 of file dsp.c.

References ast_debug, ast_dsp::busy_pattern_fuzzy, ast_dsp::busy_quietlength, ast_dsp::busy_tonelength, and ast_dsp::busytoneonly.

Referenced by dahdi_new().

1683 {
1684  dsp->busy_tonelength = tonelength;
1685  if (quietlength > 0)
1686  dsp->busy_quietlength = quietlength;
1687  else
1688  dsp->busytoneonly = 1;
1689  ast_debug(1, "dsp busy pattern set to %d,%d\n", tonelength, quietlength);
1690  if( fuzzy > 0 && fuzzy < 50 )
1691  dsp->busy_pattern_fuzzy = fuzzy;
1692 }
int busytoneonly
Definition: dsp.c:399
int busy_pattern_fuzzy
Definition: dsp.c:403
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
int busy_tonelength
Definition: dsp.c:401
int busy_quietlength
Definition: dsp.c:402
int ast_dsp_set_call_progress_zone ( struct ast_dsp dsp,
char *  zone 
)

Set zone for doing progress detection.

Definition at line 1763 of file dsp.c.

References aliases, ARRAY_LEN, ast_dsp_prog_reset(), progalias::mode, name, and ast_dsp::progmode.

Referenced by dahdi_new().

1764 {
1765  int x;
1766 
1767  for (x = 0; x < ARRAY_LEN(aliases); x++) {
1768  if (!strcasecmp(aliases[x].name, zone)) {
1769  dsp->progmode = aliases[x].mode;
1770  ast_dsp_prog_reset(dsp);
1771  return 0;
1772  }
1773  }
1774  return -1;
1775 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static void ast_dsp_prog_reset(struct ast_dsp *dsp)
Definition: dsp.c:1590
static struct progalias aliases[]
static const char name[]
enum prog_mode mode
Definition: dsp.c:96
enum prog_mode progmode
Definition: dsp.c:410
int ast_dsp_set_digitmode ( struct ast_dsp dsp,
int  digitmode 
)

Set digit mode.

Version
1.6.1 renamed from ast_dsp_digitmode to ast_dsp_set_digitmode

Definition at line 1739 of file dsp.c.

References ast_digit_detect_init(), ast_dsp::digit_state, ast_dsp::digitmode, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_MF, DSP_DIGITMODE_MUTECONF, and DSP_DIGITMODE_MUTEMAX.

Referenced by analog_ss_thread(), dahdi_hangup(), dahdi_new(), dahdi_setoption(), enable_dsp_detect(), mgcp_new(), mkintf(), and my_dsp_set_digitmode().

1740 {
1741  int new;
1742  int old;
1743 
1746  if (old != new) {
1747  /* Must initialize structures if switching from MF to DTMF or vice-versa */
1749  }
1750  dsp->digitmode = digitmode;
1751  return 0;
1752 }
#define DSP_DIGITMODE_DTMF
Definition: dsp.h:31
#define DSP_DIGITMODE_MF
Definition: dsp.h:32
#define DSP_DIGITMODE_MUTECONF
Definition: dsp.h:35
digit_detect_state_t digit_state
Definition: dsp.c:420
static void ast_digit_detect_init(digit_detect_state_t *s, int mf)
Definition: dsp.c:528
#define DSP_DIGITMODE_MUTEMAX
Definition: dsp.h:36
int digitmode
Definition: dsp.c:413
int ast_dsp_set_faxmode ( struct ast_dsp dsp,
int  faxmode 
)

Set fax mode.

Definition at line 1754 of file dsp.c.

References ast_fax_detect_init(), and ast_dsp::faxmode.

1755 {
1756  if (dsp->faxmode != faxmode) {
1757  ast_fax_detect_init(dsp);
1758  }
1759  dsp->faxmode = faxmode;
1760  return 0;
1761 }
int faxmode
Definition: dsp.c:414
static void ast_fax_detect_init(struct ast_dsp *s)
Definition: dsp.c:495
void ast_dsp_set_features ( struct ast_dsp dsp,
int  features 
)

Select feature set.

Definition at line 1642 of file dsp.c.

References ast_dsp::display_inband_dtmf_warning, DSP_FEATURE_DIGIT_DETECT, and ast_dsp::features.

Referenced by __oh323_new(), dahdi_handle_dtmf(), dahdi_new(), dahdi_read(), dahdi_setoption(), disable_dtmf_detect(), enable_dsp_detect(), enable_dtmf_detect(), mgcp_new(), misdn_set_opt_exec(), my_handle_dtmf(), my_pri_ss7_open_media(), read_config(), and sip_rtp_read().

1643 {
1644  dsp->features = features;
1645  if (!(features & DSP_FEATURE_DIGIT_DETECT)) {
1646  dsp->display_inband_dtmf_warning = 0;
1647  }
1648 }
#define DSP_FEATURE_DIGIT_DETECT
Definition: dsp.h:28
int features
Definition: dsp.c:395
int display_inband_dtmf_warning
Definition: dsp.c:416
void ast_dsp_set_threshold ( struct ast_dsp dsp,
int  threshold 
)

Set threshold value for silence.

Definition at line 1655 of file dsp.c.

References ast_dsp::threshold.

Referenced by __ast_play_and_record(), dahdi_new(), do_waiting(), fax_session_new(), handle_recordfile(), isAnsweringMachine(), and record_exec().

1656 {
1657  if (threshold < 256)
1658  dsp->threshold = 256;
1659  else
1660  dsp->threshold = threshold;
1661 }
threshold
Definition: dsp.h:62
int threshold
Definition: dsp.c:392
int ast_dsp_silence ( struct ast_dsp dsp,
struct ast_frame f,
int *  totalsilence 
)

Return non-zero if this is silence. Updates "totalsilence" with the total number of seconds of silence.

Definition at line 1355 of file dsp.c.

References __ast_dsp_silence_noise(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), ast_frame_subclass::codec, ast_frame::data, ast_frame::datalen, ast_frame::frametype, len(), LOG_WARNING, ast_frame::ptr, and ast_frame::subclass.

Referenced by __ast_play_and_record(), background_detect_exec(), conf_run(), debug_check_frame_for_silence(), do_waiting(), handle_recordfile(), isAnsweringMachine(), and record_exec().

1356 {
1357  short *s;
1358  int len;
1359 
1360  if (f->frametype != AST_FRAME_VOICE) {
1361  ast_log(LOG_WARNING, "Can't calculate silence on a non-voice frame\n");
1362  return 0;
1363  }
1364  if (f->subclass.codec != AST_FORMAT_SLINEAR) {
1365  ast_log(LOG_WARNING, "Can only calculate silence on signed-linear frames :(\n");
1366  return 0;
1367  }
1368  s = f->data.ptr;
1369  len = f->datalen/2;
1370  return __ast_dsp_silence_noise(dsp, s, len, totalsilence, NULL);
1371 }
union ast_frame_subclass subclass
Definition: frame.h:146
void * ptr
Definition: frame.h:160
#define LOG_WARNING
Definition: logger.h:144
static int __ast_dsp_silence_noise(struct ast_dsp *dsp, short *s, int len, int *totalsilence, int *totalnoise)
Definition: dsp.c:1187
format_t codec
Definition: frame.h:137
int datalen
Definition: frame.h:148
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AST_FORMAT_SLINEAR
Definition: frame.h:254
enum ast_frame_type frametype
Definition: frame.h:144
union ast_frame::@172 data
int ast_dsp_was_muted ( struct ast_dsp dsp)

Returns true if DSP code was muting any fragment of the last processed frame. Muting (squelching) happens when DSP code removes DTMF/MF/generic tones from the audio.

Since
1.6.1

Definition at line 1777 of file dsp.c.

References ast_dsp::mute_fragments.

Referenced by dahdi_read().

1778 {
1779  return (dsp->mute_fragments > 0);
1780 }
int mute_fragments
Definition: dsp.c:418