Asterisk - The Open Source Telephony Project  GIT-master-b91fb3c
Data Structures | Macros | Enumerations | Functions
dsp.h File Reference

Convenient Signal Processing routines. More...

Go to the source code of this file.

Data Structures

struct  ast_dsp_busy_pattern
 

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_FAXMODE_DETECT_SQUELCH   (1 << 2)
 
#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_features (struct ast_dsp *dsp)
 Get features. More...
 
unsigned int ast_dsp_get_sample_rate (const struct ast_dsp *dsp)
 Retrieve the sample rate this DSP structure was created with. More...
 
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...
 
struct ast_dspast_dsp_new (void)
 Allocates a new dsp, assumes 8khz for internal sample rate. More...
 
struct ast_dspast_dsp_new_with_rate (unsigned int sample_rate)
 Allocates a new dsp with a specific internal sample rate used during processing. More...
 
int ast_dsp_noise (struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise)
 Process the audio frame for 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...
 
void ast_dsp_reset (struct ast_dsp *dsp)
 Reset total silence count. 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, const struct ast_dsp_busy_pattern *cadence)
 Set expected lengths of the busy tone. 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 the minimum average magnitude threshold to determine talking by the DSP. More...
 
int ast_dsp_silence (struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence)
 Process the audio frame for silence. More...
 
int ast_dsp_silence_with_energy (struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence, int *frames_energy)
 Process the audio frame for 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

◆ DSP_DIGITMODE_DTMF

#define DSP_DIGITMODE_DTMF   0

◆ DSP_DIGITMODE_MF

#define DSP_DIGITMODE_MF   1

◆ DSP_DIGITMODE_MUTECONF

#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().

◆ DSP_DIGITMODE_MUTEMAX

#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().

◆ DSP_DIGITMODE_NOQUELCH

#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().

◆ DSP_DIGITMODE_RELAXDTMF

#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(), mbl_load_device(), ooh323_new(), and process_dahdi().

◆ DSP_FAXMODE_DETECT_ALL

#define DSP_FAXMODE_DETECT_ALL   (DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED)

Definition at line 49 of file dsp.h.

◆ DSP_FAXMODE_DETECT_CED

#define DSP_FAXMODE_DETECT_CED   (1 << 1)

Definition at line 47 of file dsp.h.

Referenced by ast_dsp_process(), and ooh323_new().

◆ DSP_FAXMODE_DETECT_CNG

#define DSP_FAXMODE_DETECT_CNG   (1 << 0)

Definition at line 46 of file dsp.h.

Referenced by __ast_dsp_new(), ast_dsp_process(), fax_detect_new(), and ooh323_new().

◆ DSP_FAXMODE_DETECT_SQUELCH

#define DSP_FAXMODE_DETECT_SQUELCH   (1 << 2)

Definition at line 48 of file dsp.h.

Referenced by ast_fax_detect_init(), and fax_detect_new().

◆ DSP_FEATURE_BUSY_DETECT

#define DSP_FEATURE_BUSY_DETECT   (1 << 1)

Definition at line 27 of file dsp.h.

Referenced by ast_dsp_process(), and dahdi_new().

◆ DSP_FEATURE_CALL_PROGRESS

#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().

◆ DSP_FEATURE_DIGIT_DETECT

#define DSP_FEATURE_DIGIT_DETECT   (1 << 3)

◆ DSP_FEATURE_FAX_DETECT

#define DSP_FEATURE_FAX_DETECT   (1 << 4)

◆ DSP_FEATURE_SILENCE_SUPPRESS

#define DSP_FEATURE_SILENCE_SUPPRESS   (1 << 0)

Definition at line 26 of file dsp.h.

Referenced by __ast_dsp_new(), and ast_dsp_process().

◆ DSP_FEATURE_WAITDIALTONE

#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().

◆ DSP_PROGRESS_BUSY

#define DSP_PROGRESS_BUSY   (1 << 18)

Enable busy tone detection

Definition at line 41 of file dsp.h.

Referenced by __ast_dsp_call_progress().

◆ DSP_PROGRESS_CONGESTION

#define DSP_PROGRESS_CONGESTION   (1 << 19)

Enable congestion tone detection

Definition at line 42 of file dsp.h.

Referenced by __ast_dsp_call_progress().

◆ DSP_PROGRESS_RINGING

#define DSP_PROGRESS_RINGING   (1 << 17)

Enable calling tone detection

Definition at line 40 of file dsp.h.

Referenced by __ast_dsp_call_progress().

◆ DSP_PROGRESS_TALK

#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().

◆ DSP_TONE_STATE_BUSY

#define DSP_TONE_STATE_BUSY   4

Definition at line 55 of file dsp.h.

Referenced by __ast_dsp_call_progress().

◆ DSP_TONE_STATE_DIALTONE

#define DSP_TONE_STATE_DIALTONE   2

Definition at line 53 of file dsp.h.

Referenced by __ast_dsp_call_progress(), and dahdi_read().

◆ DSP_TONE_STATE_HUNGUP

#define DSP_TONE_STATE_HUNGUP   8

Definition at line 59 of file dsp.h.

Referenced by __ast_dsp_call_progress().

◆ DSP_TONE_STATE_RINGING

#define DSP_TONE_STATE_RINGING   1

Definition at line 52 of file dsp.h.

Referenced by __ast_dsp_call_progress(), and dahdi_read().

◆ DSP_TONE_STATE_SILENCE

#define DSP_TONE_STATE_SILENCE   0

Definition at line 51 of file dsp.h.

Referenced by __ast_dsp_call_progress().

◆ DSP_TONE_STATE_SPECIAL1

#define DSP_TONE_STATE_SPECIAL1   5

Definition at line 56 of file dsp.h.

Referenced by __ast_dsp_call_progress().

◆ DSP_TONE_STATE_SPECIAL2

#define DSP_TONE_STATE_SPECIAL2   6

Definition at line 57 of file dsp.h.

Referenced by __ast_dsp_call_progress().

◆ DSP_TONE_STATE_SPECIAL3

#define DSP_TONE_STATE_SPECIAL3   7

Definition at line 58 of file dsp.h.

Referenced by __ast_dsp_call_progress().

◆ DSP_TONE_STATE_TALKING

#define DSP_TONE_STATE_TALKING   3

Definition at line 54 of file dsp.h.

Referenced by __ast_dsp_call_progress().

Enumeration Type Documentation

◆ threshold

enum threshold
Enumerator
THRESHOLD_SILENCE 
THRESHOLD_MAX 

Definition at line 70 of file dsp.h.

70  {
71  /* Array offsets */
73  /* Always the last */
74  THRESHOLD_MAX = 1,
75 };

Function Documentation

◆ ast_dsp_busydetect()

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 1285 of file dsp.c.

References abs, ast_debug, ast_dsp::busy_cadence, BUSY_MAX, BUSY_MIN, BUSY_PAT_PERCENT, BUSY_PERCENT, ast_dsp::busycount, ast_dsp::busymaybe, DSP_HISTORY, ast_dsp::historicnoise, ast_dsp::historicsilence, ast_dsp_busy_pattern::length, MAX, and ast_dsp_busy_pattern::pattern.

Referenced by ast_dsp_process().

1286 {
1287  int res = 0, x;
1288 #ifndef BUSYDETECT_TONEONLY
1289  int avgsilence = 0, hitsilence = 0;
1290 #endif
1291  int avgtone = 0, hittone = 0;
1292 
1293  /* if we have a 4 length pattern, the way busymaybe is set doesn't help us. */
1294  if (dsp->busy_cadence.length != 4) {
1295  if (!dsp->busymaybe) {
1296  return res;
1297  }
1298  }
1299 
1300  for (x = DSP_HISTORY - dsp->busycount; x < DSP_HISTORY; x++) {
1301 #ifndef BUSYDETECT_TONEONLY
1302  avgsilence += dsp->historicsilence[x];
1303 #endif
1304  avgtone += dsp->historicnoise[x];
1305  }
1306 #ifndef BUSYDETECT_TONEONLY
1307  avgsilence /= dsp->busycount;
1308 #endif
1309  avgtone /= dsp->busycount;
1310  for (x = DSP_HISTORY - dsp->busycount; x < DSP_HISTORY; x++) {
1311 #ifndef BUSYDETECT_TONEONLY
1312  if (avgsilence > dsp->historicsilence[x]) {
1313  if (avgsilence - (avgsilence * BUSY_PERCENT / 100) <= dsp->historicsilence[x]) {
1314  hitsilence++;
1315  }
1316  } else {
1317  if (avgsilence + (avgsilence * BUSY_PERCENT / 100) >= dsp->historicsilence[x]) {
1318  hitsilence++;
1319  }
1320  }
1321 #endif
1322  if (avgtone > dsp->historicnoise[x]) {
1323  if (avgtone - (avgtone * BUSY_PERCENT / 100) <= dsp->historicnoise[x]) {
1324  hittone++;
1325  }
1326  } else {
1327  if (avgtone + (avgtone * BUSY_PERCENT / 100) >= dsp->historicnoise[x]) {
1328  hittone++;
1329  }
1330  }
1331  }
1332 #ifndef BUSYDETECT_TONEONLY
1333  if ((hittone >= dsp->busycount - 1) && (hitsilence >= dsp->busycount - 1) &&
1334  (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX) &&
1335  (avgsilence >= BUSY_MIN && avgsilence <= BUSY_MAX))
1336 #else
1337  if ((hittone >= dsp->busycount - 1) && (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX))
1338 #endif
1339  {
1340 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE
1341  if (avgtone > avgsilence) {
1342  if (avgtone - avgtone*BUSY_PERCENT/100 <= avgsilence) {
1343  res = 1;
1344  }
1345  } else {
1346  if (avgtone + avgtone*BUSY_PERCENT/100 >= avgsilence) {
1347  res = 1;
1348  }
1349  }
1350 #else
1351  res = 1;
1352 #endif
1353  }
1354 
1355  /* If we have a 4-length pattern, we can go ahead and just check it in a different way. */
1356  if (dsp->busy_cadence.length == 4) {
1357  int x;
1358  int errors = 0;
1359  int errors_max = ((4 * dsp->busycount) / 100.0) * BUSY_PAT_PERCENT;
1360 
1361  for (x = DSP_HISTORY - (dsp->busycount); x < DSP_HISTORY; x += 2) {
1362  int temp_error;
1363  temp_error = abs(dsp->historicnoise[x] - dsp->busy_cadence.pattern[0]);
1364  if ((temp_error * 100) / dsp->busy_cadence.pattern[0] > BUSY_PERCENT) {
1365  errors++;
1366  }
1367 
1368  temp_error = abs(dsp->historicnoise[x + 1] - dsp->busy_cadence.pattern[2]);
1369  if ((temp_error * 100) / dsp->busy_cadence.pattern[2] > BUSY_PERCENT) {
1370  errors++;
1371  }
1372 
1373  temp_error = abs(dsp->historicsilence[x] - dsp->busy_cadence.pattern[1]);
1374  if ((temp_error * 100) / dsp->busy_cadence.pattern[1] > BUSY_PERCENT) {
1375  errors++;
1376  }
1377 
1378  temp_error = abs(dsp->historicsilence[x + 1] - dsp->busy_cadence.pattern[3]);
1379  if ((temp_error * 100) / dsp->busy_cadence.pattern[3] > BUSY_PERCENT) {
1380  errors++;
1381  }
1382  }
1383 
1384  ast_debug(5, "errors = %d max = %d\n", errors, errors_max);
1385 
1386  if (errors <= errors_max) {
1387  return 1;
1388  }
1389  }
1390 
1391  /* If we know the expected busy tone length, check we are in the range */
1392  if (res && (dsp->busy_cadence.pattern[0] > 0)) {
1393  if (abs(avgtone - dsp->busy_cadence.pattern[0]) > MAX(dsp->busy_cadence.pattern[0]*BUSY_PAT_PERCENT/100, 20)) {
1394 #ifdef BUSYDETECT_DEBUG
1395  ast_debug(5, "busy detector: avgtone of %d not close enough to desired %d\n",
1396  avgtone, dsp->busy_cadence.pattern[0]);
1397 #endif
1398  res = 0;
1399  }
1400  }
1401 #ifndef BUSYDETECT_TONEONLY
1402  /* If we know the expected busy tone silent-period length, check we are in the range */
1403  if (res && (dsp->busy_cadence.pattern[1] > 0)) {
1404  if (abs(avgsilence - dsp->busy_cadence.pattern[1]) > MAX(dsp->busy_cadence.pattern[1]*BUSY_PAT_PERCENT/100, 20)) {
1405 #ifdef BUSYDETECT_DEBUG
1406  ast_debug(5, "busy detector: avgsilence of %d not close enough to desired %d\n",
1407  avgsilence, dsp->busy_cadence.pattern[1]);
1408 #endif
1409  res = 0;
1410  }
1411  }
1412 #endif
1413 #if !defined(BUSYDETECT_TONEONLY) && defined(BUSYDETECT_DEBUG)
1414  if (res) {
1415  ast_debug(5, "ast_dsp_busydetect detected busy, avgtone: %d, avgsilence %d\n", avgtone, avgsilence);
1416  } else {
1417  ast_debug(5, "busy detector: FAILED with avgtone: %d, avgsilence %d\n", avgtone, avgsilence);
1418  }
1419 #endif
1420  return res;
1421 }
int busymaybe
Definition: dsp.c:414
Definition: dsp.c:147
Definition: dsp.c:146
int pattern[4]
Definition: dsp.h:67
int historicsilence[DSP_HISTORY]
Definition: dsp.c:418
int historicnoise[DSP_HISTORY]
Definition: dsp.c:417
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:444
#define MAX(a, b)
Definition: utils.h:228
int busycount
Definition: dsp.c:415
struct ast_dsp_busy_pattern busy_cadence
Definition: dsp.c:416
#define abs(x)
Definition: f2c.h:195
#define DSP_HISTORY
Definition: dsp.c:151

◆ ast_dsp_call_progress()

int ast_dsp_call_progress ( struct ast_dsp dsp,
struct ast_frame inf 
)

Scans for progress indication in audio.

Definition at line 1206 of file dsp.c.

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

1207 {
1208  if (inf->frametype != AST_FRAME_VOICE) {
1209  ast_log(LOG_WARNING, "Can't check call progress of non-voice frames\n");
1210  return 0;
1211  }
1213  ast_log(LOG_WARNING, "Can only check call progress in signed-linear frames\n");
1214  return 0;
1215  }
1216  return __ast_dsp_call_progress(dsp, inf->data.ptr, inf->datalen / 2);
1217 }
#define LOG_WARNING
Definition: logger.h:274
union ast_frame::@257 data
static int __ast_dsp_call_progress(struct ast_dsp *dsp, short *s, int len)
Definition: dsp.c:1064
struct ast_frame_subclass subclass
#define ast_log
Definition: astobj2.c:42
int ast_format_cache_is_slinear(struct ast_format *format)
Determines if a format is one of the cached slin formats.
Definition: format_cache.c:542
enum ast_frame_type frametype
struct ast_format * format

◆ ast_dsp_digitdetect()

int ast_dsp_digitdetect ( struct ast_dsp dsp,
struct ast_frame f 
)

Return non-zero if DTMF hit was found.

◆ ast_dsp_digitreset()

void ast_dsp_digitreset ( struct ast_dsp dsp)

Reset DTMF detector.

Definition at line 1771 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(), ast_dsp_get_threshold_from_settings(), mbl_new(), and my_dsp_reset_and_flush_digits().

1772 {
1773  int i;
1774 
1775  dsp->dtmf_began = 0;
1776  if (dsp->digitmode & DSP_DIGITMODE_MF) {
1777  mf_detect_state_t *s = &dsp->digit_state.td.mf;
1778  /* Reinitialise the detector for the next block */
1779  for (i = 0; i < 6; i++) {
1780  goertzel_reset(&s->tone_out[i]);
1781  }
1782  s->hits[4] = s->hits[3] = s->hits[2] = s->hits[1] = s->hits[0] = 0;
1783  s->current_hit = 0;
1784  s->current_sample = 0;
1785  } else {
1787  /* Reinitialise the detector for the next block */
1788  for (i = 0; i < 4; i++) {
1789  goertzel_reset(&s->row_out[i]);
1790  goertzel_reset(&s->col_out[i]);
1791  }
1792  s->lasthit = 0;
1793  s->current_hit = 0;
1794  s->energy = 0.0;
1795  s->current_sample = 0;
1796  s->hits = 0;
1797  s->misses = 0;
1798  }
1799 
1800  dsp->digit_state.digits[0] = '\0';
1801  dsp->digit_state.current_digits = 0;
1802 }
union digit_detect_state_t::@377 td
#define DSP_DIGITMODE_MF
Definition: dsp.h:32
int current_digits
Definition: dsp.c:307
goertzel_state_t tone_out[6]
Definition: dsp.c:296
static void goertzel_reset(goertzel_state_t *s)
Definition: dsp.c:382
digit_detect_state_t digit_state
Definition: dsp.c:434
char digits[MAX_DTMF_DIGITS+1]
Definition: dsp.c:305
dtmf_detect_state_t dtmf
Definition: dsp.c:312
int current_sample
Definition: dsp.c:290
goertzel_state_t col_out[4]
Definition: dsp.c:284
int hits[5]
Definition: dsp.c:298
int dtmf_began
Definition: dsp.c:428
int digitmode
Definition: dsp.c:426
int current_sample
Definition: dsp.c:299
float energy
Definition: dsp.c:289
int current_hit
Definition: dsp.c:297
mf_detect_state_t mf
Definition: dsp.c:313
goertzel_state_t row_out[4]
Definition: dsp.c:283

◆ ast_dsp_free()

void ast_dsp_free ( struct ast_dsp dsp)

◆ ast_dsp_get_features()

int ast_dsp_get_features ( struct ast_dsp dsp)

Get features.

Definition at line 1738 of file dsp.c.

References ast_dsp::features.

Referenced by chan_pjsip_cng_tone_detected(), chan_pjsip_read_stream(), pjsip_acf_dtmf_mode_write(), and set_caps().

1739 {
1740  return (dsp->features);
1741 }
int features
Definition: dsp.c:412

◆ ast_dsp_get_sample_rate()

unsigned int ast_dsp_get_sample_rate ( const struct ast_dsp dsp)

Retrieve the sample rate this DSP structure was created with.

Definition at line 1691 of file dsp.c.

References ast_dsp::sample_rate.

1692 {
1693  return dsp->sample_rate;
1694 }
unsigned int sample_rate
Definition: dsp.c:432

◆ ast_dsp_get_tcount()

int ast_dsp_get_tcount ( struct ast_dsp dsp)

Get tcount (Threshold counter)

Definition at line 1866 of file dsp.c.

References ast_dsp::tcount.

Referenced by dahdi_read().

1867 {
1868  return dsp->tcount;
1869 }
int tcount
Definition: dsp.c:425

◆ ast_dsp_get_threshold_from_settings()

int ast_dsp_get_threshold_from_settings ( enum threshold  which)

◆ ast_dsp_get_tstate()

int ast_dsp_get_tstate ( struct ast_dsp dsp)

Get tstate (Tone State)

Definition at line 1861 of file dsp.c.

References ast_dsp::tstate.

Referenced by dahdi_read().

1862 {
1863  return dsp->tstate;
1864 }
int tstate
Definition: dsp.c:424

◆ ast_dsp_getdigits()

int ast_dsp_getdigits ( struct ast_dsp dsp,
char *  buf,
int  max 
)

Get pending DTMF/MF digits.

◆ ast_dsp_new()

struct ast_dsp* ast_dsp_new ( void  )

◆ ast_dsp_new_with_rate()

struct ast_dsp* ast_dsp_new_with_rate ( unsigned int  sample_rate)

Allocates a new dsp with a specific internal sample rate used during processing.

Definition at line 1724 of file dsp.c.

References __ast_dsp_new().

Referenced by set_softmix_bridge_data(), and set_talk_detect().

1725 {
1726  return __ast_dsp_new(sample_rate);
1727 }
static struct ast_dsp * __ast_dsp_new(unsigned int sample_rate)
Definition: dsp.c:1696

◆ ast_dsp_noise()

int ast_dsp_noise ( struct ast_dsp dsp,
struct ast_frame f,
int *  totalnoise 
)

Process the audio frame for noise.

Since
1.6.1
Parameters
dspDSP processing audio media.
fAudio frame to process.
totalnoiseVariable to set to the total accumulated noise in ms seen by the DSP since the last silence.
Returns
Non-zero if the frame is silence.

Definition at line 1478 of file dsp.c.

References ast_dsp_silence_noise_with_energy(), and NULL.

1479 {
1480  return ast_dsp_silence_noise_with_energy(dsp, f, totalnoise, NULL, 1);
1481 }
static int ast_dsp_silence_noise_with_energy(struct ast_dsp *dsp, struct ast_frame *f, int *total, int *frames_energy, int noise)
Definition: dsp.c:1423
#define NULL
Definition: resample.c:96

◆ ast_dsp_process()

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 1484 of file dsp.c.

References __ast_dsp_call_progress(), __ast_dsp_silence_noise(), AST_ALAW, ast_alloca, ast_channel_name(), ast_channel_softhangup_internal_flag_add(), 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_cache_is_slinear(), ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_get_name(), 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_LIN2A, AST_LIN2MU, ast_log, AST_MULAW, ast_queue_frame(), AST_SOFTHANGUP_DEV, ast_dsp::ced_tone_state, ast_dsp::cng_tone_state, digit_detect_state_t::current_digits, ast_frame::data, ast_frame::datalen, digit, ast_dsp::digit_state, digit_detect_state_t::digitlen, ast_dsp::digitmode, digit_detect_state_t::digits, ast_dsp::display_inband_dtmf_warning, done, 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_subclass::format, 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, NULL, ast_frame::ptr, ast_dsp::sample_rate, ast_frame::src, fragment_t::start, ast_frame::subclass, and tone_detect().

Referenced by chan_pjsip_read_stream(), dahdi_read(), fax_detect_framehook(), mbl_read(), mgcp_rtp_read(), ooh323_rtp_read(), process_ast_dsp(), and sip_rtp_read().

1485 {
1486  int silence;
1487  int res;
1488  int digit = 0, fax_digit = 0;
1489  int x;
1490  short *shortdata;
1491  unsigned char *odata;
1492  int len;
1493  struct ast_frame *outf = NULL;
1494 
1495  if (!af) {
1496  return NULL;
1497  }
1498  if (af->frametype != AST_FRAME_VOICE) {
1499  return af;
1500  }
1501 
1502  odata = af->data.ptr;
1503  len = af->datalen;
1504  /* Make sure we have short data */
1505  if (ast_format_cache_is_slinear(af->subclass.format)) {
1506  shortdata = af->data.ptr;
1507  len = af->datalen / 2;
1508  } else if (ast_format_cmp(af->subclass.format, ast_format_ulaw) == AST_FORMAT_CMP_EQUAL) {
1509  shortdata = ast_alloca(af->datalen * 2);
1510  for (x = 0; x < len; x++) {
1511  shortdata[x] = AST_MULAW(odata[x]);
1512  }
1513  } else if (ast_format_cmp(af->subclass.format, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) {
1514  shortdata = ast_alloca(af->datalen * 2);
1515  for (x = 0; x < len; x++) {
1516  shortdata[x] = AST_ALAW(odata[x]);
1517  }
1518  } else {
1519  /*Display warning only once. Otherwise you would get hundreds of warnings every second */
1520  if (dsp->display_inband_dtmf_warning) {
1521  ast_log(LOG_WARNING, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_format_get_name(af->subclass.format));
1522  }
1523  dsp->display_inband_dtmf_warning = 0;
1524  return af;
1525  }
1526 
1527  /* Initially we do not want to mute anything */
1528  dsp->mute_fragments = 0;
1529 
1530  /* Need to run the silence detection stuff for silence suppression and busy detection */
1532  res = __ast_dsp_silence_noise(dsp, shortdata, len, &silence, NULL, NULL);
1533  }
1534 
1535  if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) && silence) {
1536  memset(&dsp->f, 0, sizeof(dsp->f));
1537  dsp->f.frametype = AST_FRAME_NULL;
1538  ast_frfree(af);
1539  return ast_frisolate(&dsp->f);
1540  }
1541  if ((dsp->features & DSP_FEATURE_BUSY_DETECT) && ast_dsp_busydetect(dsp)) {
1543  memset(&dsp->f, 0, sizeof(dsp->f));
1544  dsp->f.frametype = AST_FRAME_CONTROL;
1546  ast_frfree(af);
1547  ast_debug(1, "Requesting Hangup because the busy tone was detected on channel %s\n", ast_channel_name(chan));
1548  return ast_frisolate(&dsp->f);
1549  }
1550 
1551  if ((dsp->features & DSP_FEATURE_FAX_DETECT)) {
1552  if ((dsp->faxmode & DSP_FAXMODE_DETECT_CNG) && tone_detect(dsp, &dsp->cng_tone_state, shortdata, len)) {
1553  fax_digit = 'f';
1554  }
1555 
1556  if ((dsp->faxmode & DSP_FAXMODE_DETECT_CED) && tone_detect(dsp, &dsp->ced_tone_state, shortdata, len)) {
1557  fax_digit = 'e';
1558  }
1559  }
1560 
1562  if (dsp->digitmode & DSP_DIGITMODE_MF) {
1563  digit = mf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF));
1564  } else {
1565  digit = dtmf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF));
1566  }
1567 
1568  if (dsp->digit_state.current_digits) {
1569  int event = 0, event_len = 0;
1570  char event_digit = 0;
1571 
1572  if (!dsp->dtmf_began) {
1573  /* We have not reported DTMF_BEGIN for anything yet */
1574 
1575  if (dsp->features & DSP_FEATURE_DIGIT_DETECT) {
1576  event = AST_FRAME_DTMF_BEGIN;
1577  event_digit = dsp->digit_state.digits[0];
1578  }
1579  dsp->dtmf_began = 1;
1580 
1581  } else if (dsp->digit_state.current_digits > 1 || digit != dsp->digit_state.digits[0]) {
1582  /* Digit changed. This means digit we have reported with DTMF_BEGIN ended */
1583  if (dsp->features & DSP_FEATURE_DIGIT_DETECT) {
1584  event = AST_FRAME_DTMF_END;
1585  event_digit = dsp->digit_state.digits[0];
1586  event_len = dsp->digit_state.digitlen[0] * 1000 / dsp->sample_rate;
1587  }
1588  memmove(&dsp->digit_state.digits[0], &dsp->digit_state.digits[1], dsp->digit_state.current_digits);
1589  memmove(&dsp->digit_state.digitlen[0], &dsp->digit_state.digitlen[1], dsp->digit_state.current_digits * sizeof(dsp->digit_state.digitlen[0]));
1590  dsp->digit_state.current_digits--;
1591  dsp->dtmf_began = 0;
1592 
1593  if (dsp->features & DSP_FEATURE_BUSY_DETECT) {
1594  /* Reset Busy Detector as we have some confirmed activity */
1595  memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence));
1596  memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise));
1597  ast_debug(1, "DTMF Detected - Reset busydetector\n");
1598  }
1599  }
1600 
1601  if (event) {
1602  memset(&dsp->f, 0, sizeof(dsp->f));
1603  dsp->f.frametype = event;
1604  dsp->f.subclass.integer = event_digit;
1605  dsp->f.len = event_len;
1606  outf = &dsp->f;
1607  goto done;
1608  }
1609  }
1610  }
1611 
1612  if (fax_digit) {
1613  /* Fax was detected - digit is either 'f' or 'e' */
1614 
1615  memset(&dsp->f, 0, sizeof(dsp->f));
1616  dsp->f.frametype = AST_FRAME_DTMF;
1617  dsp->f.subclass.integer = fax_digit;
1618  outf = &dsp->f;
1619  goto done;
1620  }
1621 
1622  if ((dsp->features & DSP_FEATURE_CALL_PROGRESS)) {
1623  res = __ast_dsp_call_progress(dsp, shortdata, len);
1624  if (res) {
1625  switch (res) {
1626  case AST_CONTROL_ANSWER:
1627  case AST_CONTROL_BUSY:
1628  case AST_CONTROL_RINGING:
1630  case AST_CONTROL_HANGUP:
1631  memset(&dsp->f, 0, sizeof(dsp->f));
1632  dsp->f.frametype = AST_FRAME_CONTROL;
1633  dsp->f.subclass.integer = res;
1634  dsp->f.src = "dsp_progress";
1635  if (chan) {
1636  ast_queue_frame(chan, &dsp->f);
1637  }
1638  break;
1639  default:
1640  ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res);
1641  }
1642  }
1643  } else if ((dsp->features & DSP_FEATURE_WAITDIALTONE)) {
1644  res = __ast_dsp_call_progress(dsp, shortdata, len);
1645  }
1646 
1647 done:
1648  /* Mute fragment of the frame */
1649  for (x = 0; x < dsp->mute_fragments; x++) {
1650  memset(shortdata + dsp->mute_data[x].start, 0, sizeof(int16_t) * (dsp->mute_data[x].end - dsp->mute_data[x].start));
1651  }
1652 
1653  if (ast_format_cmp(af->subclass.format, ast_format_ulaw) == AST_FORMAT_CMP_EQUAL) {
1654  for (x = 0; x < len; x++) {
1655  odata[x] = AST_LIN2MU((unsigned short) shortdata[x]);
1656  }
1657  } else if (ast_format_cmp(af->subclass.format, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) {
1658  for (x = 0; x < len; x++) {
1659  odata[x] = AST_LIN2A((unsigned short) shortdata[x]);
1660  }
1661  }
1662 
1663  if (outf) {
1664  if (chan) {
1665  ast_queue_frame(chan, af);
1666  }
1667  ast_frfree(af);
1668  return ast_frisolate(outf);
1669  } else {
1670  return af;
1671  }
1672 }
char digit
int start
Definition: dsp.c:388
short int16_t
Definition: db.h:59
#define DSP_FEATURE_DIGIT_DETECT
Definition: dsp.h:28
struct ast_frame f
Definition: dsp.c:406
#define DSP_DIGITMODE_MF
Definition: dsp.h:32
struct ast_format * ast_format_ulaw
Built-in cached ulaw format.
Definition: format_cache.c:86
#define LOG_WARNING
Definition: logger.h:274
#define AST_ALAW(a)
Definition: alaw.h:84
#define DSP_FEATURE_CALL_PROGRESS
Definition: dsp.h:43
static int __ast_dsp_call_progress(struct ast_dsp *dsp, short *s, int len)
Definition: dsp.c:1064
int historicsilence[DSP_HISTORY]
Definition: dsp.c:418
Definition: astman.c:222
int current_digits
Definition: dsp.c:307
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:683
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
#define NULL
Definition: resample.c:96
#define AST_FRAME_DTMF
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:1285
digit_detect_state_t digit_state
Definition: dsp.c:434
int historicnoise[DSP_HISTORY]
Definition: dsp.c:417
struct ast_frame_subclass subclass
char digits[MAX_DTMF_DIGITS+1]
Definition: dsp.c:305
int done
Definition: test_amihooks.c:48
#define DSP_DIGITMODE_RELAXDTMF
Definition: dsp.h:37
int faxmode
Definition: dsp.c:427
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:444
#define ast_log
Definition: astobj2.c:42
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
const char * src
#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
unsigned int sample_rate
Definition: dsp.c:432
int ast_format_cache_is_slinear(struct ast_format *format)
Determines if a format is one of the cached slin formats.
Definition: format_cache.c:542
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:1135
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
int end
Definition: dsp.c:389
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:890
int dtmf_began
Definition: dsp.c:428
#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)
int digitmode
Definition: dsp.c:426
#define DSP_FEATURE_BUSY_DETECT
Definition: dsp.h:27
static int __ast_dsp_silence_noise(struct ast_dsp *dsp, short *s, int len, int *totalsilence, int *totalnoise, int *frames_energy)
Definition: dsp.c:1219
int mute_fragments
Definition: dsp.c:431
#define ast_frisolate(fr)
Makes a frame independent of any static storage.
int features
Definition: dsp.c:412
tone_detect_state_t ced_tone_state
Definition: dsp.c:436
static int tone_detect(struct ast_dsp *dsp, tone_detect_state_t *s, int16_t *amp, int samples)
Definition: dsp.c:563
struct ast_format * ast_format_alaw
Built-in cached alaw format.
Definition: format_cache.c:91
const char * ast_channel_name(const struct ast_channel *chan)
int display_inband_dtmf_warning
Definition: dsp.c:429
#define ast_frfree(fr)
tone_detect_state_t cng_tone_state
Definition: dsp.c:435
Data structure associated with a single frame of data.
void ast_channel_softhangup_internal_flag_add(struct ast_channel *chan, int value)
int digitlen[MAX_DTMF_DIGITS+1]
Definition: dsp.c:306
#define DSP_FAXMODE_DETECT_CNG
Definition: dsp.h:46
fragment_t mute_data[5]
Definition: dsp.c:433
enum ast_frame_type frametype
#define DSP_DIGITMODE_NOQUELCH
Definition: dsp.h:34
#define DSP_FEATURE_WAITDIALTONE
Definition: dsp.h:44
#define AST_LIN2MU(a)
Definition: ulaw.h:49
#define AST_LIN2A(a)
Definition: alaw.h:50

◆ ast_dsp_reset()

void ast_dsp_reset ( struct ast_dsp dsp)

Reset total silence count.

Definition at line 1804 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().

1805 {
1806  int x;
1807 
1808  dsp->totalsilence = 0;
1809  dsp->gsamps = 0;
1810  for (x = 0; x < 4; x++) {
1811  dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0;
1812  }
1813  memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence));
1814  memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise));
1815  dsp->ringtimeout = 0;
1816 }
goertzel_state_t freqs[FREQ_ARRAY_SIZE]
Definition: dsp.c:419
int historicsilence[DSP_HISTORY]
Definition: dsp.c:418
int historicnoise[DSP_HISTORY]
Definition: dsp.c:417
int totalsilence
Definition: dsp.c:409
int gsamps
Definition: dsp.c:421
int ringtimeout
Definition: dsp.c:413

◆ ast_dsp_set_busy_count()

void ast_dsp_set_busy_count ( struct ast_dsp dsp,
int  cadences 
)

Set number of required cadences for busy.

Definition at line 1754 of file dsp.c.

References ast_dsp::busycount, cadences, and DSP_HISTORY.

Referenced by dahdi_new().

1755 {
1756  if (cadences < 4) {
1757  cadences = 4;
1758  }
1759  if (cadences > DSP_HISTORY) {
1761  }
1762  dsp->busycount = cadences;
1763 }
int busycount
Definition: dsp.c:415
static struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX]
Definition: chan_dahdi.c:569
#define DSP_HISTORY
Definition: dsp.c:151

◆ ast_dsp_set_busy_pattern()

void ast_dsp_set_busy_pattern ( struct ast_dsp dsp,
const struct ast_dsp_busy_pattern cadence 
)

Set expected lengths of the busy tone.

Definition at line 1765 of file dsp.c.

References ast_debug, ast_dsp::busy_cadence, ast_dsp_busy_pattern::length, and ast_dsp_busy_pattern::pattern.

Referenced by dahdi_new().

1766 {
1767  dsp->busy_cadence = *cadence;
1768  ast_debug(1, "dsp busy pattern set to %d,%d,%d,%d\n", cadence->pattern[0], cadence->pattern[1], (cadence->length == 4) ? cadence->pattern[2] : 0, (cadence->length == 4) ? cadence->pattern[3] : 0);
1769 }
int pattern[4]
Definition: dsp.h:67
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:444
struct ast_dsp_busy_pattern busy_cadence
Definition: dsp.c:416

◆ ast_dsp_set_call_progress_zone()

int ast_dsp_set_call_progress_zone ( struct ast_dsp dsp,
char *  zone 
)

Set zone for doing progress detection.

Definition at line 1842 of file dsp.c.

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

Referenced by dahdi_new().

1843 {
1844  int x;
1845 
1846  for (x = 0; x < ARRAY_LEN(aliases); x++) {
1847  if (!strcasecmp(aliases[x].name, zone)) {
1848  dsp->progmode = aliases[x].mode;
1849  ast_dsp_prog_reset(dsp);
1850  return 0;
1851  }
1852  }
1853  return -1;
1854 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static void ast_dsp_prog_reset(struct ast_dsp *dsp)
Definition: dsp.c:1674
static struct progalias aliases[]
static const char name[]
Definition: cdr_mysql.c:74
enum prog_mode mode
Definition: dsp.c:106
enum prog_mode progmode
Definition: dsp.c:423

◆ ast_dsp_set_digitmode()

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 1818 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, DSP_DIGITMODE_MUTEMAX, and ast_dsp::sample_rate.

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

1819 {
1820  int new;
1821  int old;
1822 
1825  if (old != new) {
1826  /* Must initialize structures if switching from MF to DTMF or vice-versa */
1828  }
1829  dsp->digitmode = digitmode;
1830  return 0;
1831 }
static void ast_digit_detect_init(digit_detect_state_t *s, int mf, unsigned int sample_rate)
Definition: dsp.c:549
#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:434
unsigned int sample_rate
Definition: dsp.c:432
#define DSP_DIGITMODE_MUTEMAX
Definition: dsp.h:36
int digitmode
Definition: dsp.c:426

◆ ast_dsp_set_faxmode()

int ast_dsp_set_faxmode ( struct ast_dsp dsp,
int  faxmode 
)

Set fax mode.

Definition at line 1833 of file dsp.c.

References ast_fax_detect_init(), and ast_dsp::faxmode.

Referenced by fax_detect_new(), and ooh323_new().

1834 {
1835  if (dsp->faxmode != faxmode) {
1836  dsp->faxmode = faxmode;
1837  ast_fax_detect_init(dsp);
1838  }
1839  return 0;
1840 }
int faxmode
Definition: dsp.c:427
static void ast_fax_detect_init(struct ast_dsp *s)
Definition: dsp.c:510

◆ ast_dsp_set_features()

void ast_dsp_set_features ( struct ast_dsp dsp,
int  features 
)

◆ ast_dsp_set_threshold()

void ast_dsp_set_threshold ( struct ast_dsp dsp,
int  threshold 
)

Set the minimum average magnitude threshold to determine talking by the DSP.

Examples:
/tmp/asterisk-shallow/main/app.c.

Definition at line 1749 of file dsp.c.

References ast_dsp::threshold.

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

1750 {
1751  dsp->threshold = threshold;
1752 }
threshold
Definition: dsp.h:70
int threshold
Definition: dsp.c:407

◆ ast_dsp_silence()

int ast_dsp_silence ( struct ast_dsp dsp,
struct ast_frame f,
int *  totalsilence 
)

Process the audio frame for silence.

Parameters
dspDSP processing audio media.
fAudio frame to process.
totalsilenceVariable to set to the total accumulated silence in ms seen by the DSP since the last noise.
Returns
Non-zero if the frame is silence.
Examples:
/tmp/asterisk-shallow/main/app.c.

Definition at line 1473 of file dsp.c.

References ast_dsp_silence_noise_with_energy(), and NULL.

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

1474 {
1475  return ast_dsp_silence_noise_with_energy(dsp, f, totalsilence, NULL, 0);
1476 }
static int ast_dsp_silence_noise_with_energy(struct ast_dsp *dsp, struct ast_frame *f, int *total, int *frames_energy, int noise)
Definition: dsp.c:1423
#define NULL
Definition: resample.c:96

◆ ast_dsp_silence_with_energy()

int ast_dsp_silence_with_energy ( struct ast_dsp dsp,
struct ast_frame f,
int *  totalsilence,
int *  frames_energy 
)

Process the audio frame for silence.

Parameters
dspDSP processing audio media.
fAudio frame to process.
totalsilenceVariable to set to the total accumulated silence in ms seen by the DSP since the last noise.
frames_energyVariable to set to the average energy of the samples in the frame.
Returns
Non-zero if the frame is silence.

Definition at line 1468 of file dsp.c.

References ast_dsp_silence_noise_with_energy().

Referenced by softmix_bridge_write_voice().

1469 {
1470  return ast_dsp_silence_noise_with_energy(dsp, f, totalsilence, frames_energy, 0);
1471 }
static int ast_dsp_silence_noise_with_energy(struct ast_dsp *dsp, struct ast_frame *f, int *total, int *frames_energy, int noise)
Definition: dsp.c:1423

◆ ast_dsp_was_muted()

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 1856 of file dsp.c.

References ast_dsp::mute_fragments.

Referenced by dahdi_read().

1857 {
1858  return (dsp->mute_fragments > 0);
1859 }
int mute_fragments
Definition: dsp.c:431