Go to the source code of this file.
Defines | |
#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. | |
int | ast_dsp_call_progress (struct ast_dsp *dsp, struct ast_frame *inf) |
Scans for progress indication in audio. | |
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. | |
void | ast_dsp_free (struct ast_dsp *dsp) |
int | ast_dsp_get_tcount (struct ast_dsp *dsp) |
Get tcount (Threshold counter). | |
int | ast_dsp_get_threshold_from_settings (enum threshold which) |
Get silence threshold from dsp.conf. | |
int | ast_dsp_get_tstate (struct ast_dsp *dsp) |
Get tstate (Tone State). | |
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. | |
ast_dsp * | ast_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. | |
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. | |
int | ast_dsp_reload (void) |
Reloads dsp settings from dsp.conf. | |
void | ast_dsp_reset (struct ast_dsp *dsp) |
Reset total silence count. | |
void | ast_dsp_set_busy_compare (struct ast_dsp *dsp, int compare) |
Set if silence and noice lengths must be compared for busy. | |
void | ast_dsp_set_busy_count (struct ast_dsp *dsp, int cadences) |
Set number of required cadences for busy. | |
void | ast_dsp_set_busy_pattern (struct ast_dsp *dsp, int tonelength, int quietlength, int fuzzy) |
Set expected lengths of the busy tones. | |
int | ast_dsp_set_call_progress_zone (struct ast_dsp *dsp, char *zone) |
Set zone for doing progress detection. | |
int | ast_dsp_set_digitmode (struct ast_dsp *dsp, int digitmode) |
Set digit mode. | |
int | ast_dsp_set_faxmode (struct ast_dsp *dsp, int faxmode) |
Set fax mode. | |
void | ast_dsp_set_features (struct ast_dsp *dsp, int features) |
Select feature set. | |
void | ast_dsp_set_threshold (struct ast_dsp *dsp, int threshold) |
Set threshold value for silence. | |
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. | |
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. |
Definition in file dsp.h.
#define DSP_DIGITMODE_DTMF 0 |
Detect DTMF digits
Definition at line 31 of file dsp.h.
Referenced by analog_ss_thread(), ast_dsp_new(), ast_dsp_set_digitmode(), dahdi_hangup(), dahdi_new(), dahdi_setoption(), enable_dsp_detect(), and my_dsp_set_digitmode().
#define DSP_DIGITMODE_MF 1 |
Detect MF digits
Definition at line 32 of file dsp.h.
Referenced by analog_ss_thread(), and my_dsp_set_digitmode().
#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) |
#define DSP_DIGITMODE_RELAXDTMF (1 << 11) |
"Radio" mode (relaxed DTMF)
Definition at line 37 of file dsp.h.
Referenced by dahdi_setoption(), and enable_dsp_detect().
#define DSP_FAXMODE_DETECT_ALL (DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED) |
#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) |
Definition at line 28 of file dsp.h.
Referenced by __oh323_new(), ast_dsp_set_features(), dahdi_new(), disable_dtmf_detect(), enable_dsp_detect(), enable_dtmf_detect(), mgcp_new(), misdn_set_opt_exec(), read_config(), and sip_rtp_read().
#define DSP_FEATURE_FAX_DETECT (1 << 4) |
Definition at line 29 of file dsp.h.
Referenced by dahdi_handle_dtmf(), dahdi_new(), dahdi_queryoption(), dahdi_setoption(), enable_dsp_detect(), misdn_set_opt_exec(), my_handle_dtmf(), and read_config().
#define DSP_FEATURE_SILENCE_SUPPRESS (1 << 0) |
#define DSP_FEATURE_WAITDIALTONE (1 << 20) |
Enable dial tone detection
Definition at line 44 of file dsp.h.
Referenced by dahdi_new(), and dahdi_read().
#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_RINGING 1 |
#define DSP_TONE_STATE_SILENCE 0 |
enum threshold |
Definition at line 62 of file dsp.h.
00062 { 00063 /* Array offsets */ 00064 THRESHOLD_SILENCE = 0, 00065 /* Always the last */ 00066 THRESHOLD_MAX = 1, 00067 };
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 1183 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.
01184 { 01185 int res = 0, x; 01186 int avgsilence = 0, hitsilence = 0; 01187 int avgtone = 0, hittone = 0; 01188 #ifdef DEBUG_DSP_BUSYDETECT 01189 char buf[16]; 01190 char silence_list[64]="", tone_list[64]=""; 01191 #endif 01192 01193 if (!dsp->busymaybe) { 01194 return res; 01195 } 01196 dsp->busymaybe = 0; 01197 01198 for (x = DSP_HISTORY - dsp->busycount; x < DSP_HISTORY; x++) { 01199 avgsilence += dsp->historicsilence[x]; 01200 avgtone += dsp->historicnoise[x]; 01201 } 01202 avgsilence /= dsp->busycount; 01203 avgtone /= dsp->busycount; 01204 #ifdef DEBUG_DSP_BUSYDETECT 01205 sprintf(silence_list,"Silences: "); 01206 sprintf(tone_list,"Tones: "); 01207 #endif 01208 for (x=DSP_HISTORY - dsp->busycount; x<DSP_HISTORY; x++) { 01209 #ifdef DEBUG_DSP_BUSYDETECT 01210 snprintf(buf, sizeof(buf), "%5d ", dsp->historicsilence[x]); 01211 strcat(silence_list, buf); 01212 snprintf(buf, sizeof(buf), "%5d ", dsp->historicnoise[x]); 01213 strcat(tone_list, buf); 01214 #endif 01215 if (!dsp->busytoneonly) { 01216 if (avgsilence > dsp->historicsilence[x]) { 01217 if (avgsilence - (avgsilence*BUSY_PERCENT/100) <= dsp->historicsilence[x]) 01218 hitsilence++; 01219 } else { 01220 if (avgsilence + (avgsilence*BUSY_PERCENT/100) >= dsp->historicsilence[x]) 01221 hitsilence++; 01222 } 01223 } 01224 if (avgtone > dsp->historicnoise[x]) { 01225 if (avgtone - (avgtone * BUSY_PERCENT / 100) <= dsp->historicnoise[x]) { 01226 hittone++; 01227 } 01228 } else { 01229 if (avgtone + (avgtone * BUSY_PERCENT / 100) >= dsp->historicnoise[x]) { 01230 hittone++; 01231 } 01232 } 01233 } 01234 #ifdef DEBUG_DSP_BUSYDETECT 01235 fprintf(stderr, "BUSY DETECTOR\n"); 01236 fprintf(stderr, "%s\n", tone_list); 01237 fprintf(stderr, "%s\n", silence_list) 01238 #endif 01239 if ((dsp->busytoneonly || 01240 (hitsilence >= dsp->busycount - 1 && avgsilence >= BUSY_MIN && avgsilence <= BUSY_MAX)) && 01241 (hittone >= dsp->busycount - 1 && avgtone >= BUSY_MIN && avgtone <= BUSY_MAX)) { 01242 if (dsp->busycompare) { 01243 if (dsp->busytoneonly) { 01244 res = 1; 01245 ast_log(LOG_ERROR, "You can't use busytoneonly together with busycompare"); 01246 } else { 01247 if (avgtone > avgsilence) { 01248 if (avgtone - avgtone*BUSY_PERCENT/100 <= avgsilence) 01249 res = 1; 01250 } else { 01251 if (avgtone + avgtone*BUSY_PERCENT/100 >= avgsilence) 01252 res = 1; 01253 } 01254 } 01255 } else { 01256 res = 1; 01257 } 01258 } 01259 /* If we know the expected busy tone length, check we are in the range */ 01260 if (res && (dsp->busy_tonelength > 0)) { 01261 if (abs(avgtone - dsp->busy_tonelength) > MAX(dsp->busy_tonelength*dsp->busy_pattern_fuzzy/100, 20)) { 01262 #ifdef BUSYDETECT_DEBUG 01263 ast_debug(5, "busy detector: avgtone of %d not close enough to desired %d\n", 01264 avgtone, dsp->busy_tonelength); 01265 #endif 01266 res = 0; 01267 } 01268 } 01269 /* If we know the expected busy tone silent-period length, check we are in the range */ 01270 if (res && (!dsp->busytoneonly) && (dsp->busy_quietlength > 0)) { 01271 if (abs(avgsilence - dsp->busy_quietlength) > MAX(dsp->busy_quietlength*dsp->busy_pattern_fuzzy/100, 20)) { 01272 #ifdef BUSYDETECT_DEBUG 01273 ast_debug(5, "busy detector: avgsilence of %d not close enough to desired %d\n", 01274 avgsilence, dsp->busy_quietlength); 01275 #endif 01276 res = 0; 01277 } 01278 } 01279 if (res) { 01280 if (option_debug) 01281 ast_log(LOG_NOTICE, "ast_dsp_busydetect detected busy sequence, avgtone: %d, avgsilence %d\n", avgtone, avgsilence); 01282 } else { 01283 ast_debug(5, "busy detector: FAILED with avgtone: %d, avgsilence %d\n", avgtone, avgsilence); 01284 } 01285 return res; 01286 }
Scans for progress indication in audio.
Definition at line 1107 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.
01108 { 01109 if (inf->frametype != AST_FRAME_VOICE) { 01110 ast_log(LOG_WARNING, "Can't check call progress of non-voice frames\n"); 01111 return 0; 01112 } 01113 if (inf->subclass.codec != AST_FORMAT_SLINEAR) { 01114 ast_log(LOG_WARNING, "Can only check call progress in signed-linear frames\n"); 01115 return 0; 01116 } 01117 return __ast_dsp_call_progress(dsp, inf->data.ptr, inf->datalen / 2); 01118 }
Return non-zero if DTMF hit was found.
void ast_dsp_digitreset | ( | struct ast_dsp * | dsp | ) |
Reset DTMF detector.
Definition at line 1627 of file dsp.c.
References dtmf_detect_state_t::col_out, digit_detect_state_t::current_digits, mf_detect_state_t::current_hit, dtmf_detect_state_t::current_hit, mf_detect_state_t::current_sample, dtmf_detect_state_t::current_sample, ast_dsp::digit_state, ast_dsp::digitmode, digit_detect_state_t::digits, digit_detect_state_t::dtmf, ast_dsp::dtmf_began, dtmf_detect_state_t::energy, goertzel_reset(), mf_detect_state_t::hits, dtmf_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().
01628 { 01629 int i; 01630 01631 dsp->dtmf_began = 0; 01632 if (dsp->digitmode & DSP_DIGITMODE_MF) { 01633 mf_detect_state_t *s = &dsp->digit_state.td.mf; 01634 /* Reinitialise the detector for the next block */ 01635 for (i = 0; i < 6; i++) { 01636 goertzel_reset(&s->tone_out[i]); 01637 } 01638 s->hits[4] = s->hits[3] = s->hits[2] = s->hits[1] = s->hits[0] = s->current_hit = 0; 01639 s->current_sample = 0; 01640 } else { 01641 dtmf_detect_state_t *s = &dsp->digit_state.td.dtmf; 01642 /* Reinitialise the detector for the next block */ 01643 for (i = 0; i < 4; i++) { 01644 goertzel_reset(&s->row_out[i]); 01645 goertzel_reset(&s->col_out[i]); 01646 } 01647 s->lasthit = s->current_hit = 0; 01648 s->energy = 0.0; 01649 s->current_sample = 0; 01650 s->hits = 0; 01651 s->misses = 0; 01652 } 01653 01654 dsp->digit_state.digits[0] = '\0'; 01655 dsp->digit_state.current_digits = 0; 01656 }
void ast_dsp_free | ( | struct ast_dsp * | dsp | ) |
Definition at line 1583 of file dsp.c.
References ast_free.
Referenced by __ast_play_and_record(), __oh323_destroy(), analog_ss_thread(), background_detect_exec(), chan_list_destructor(), cleanup_connection(), conf_run(), dahdi_hangup(), destroy_session(), disable_dsp_detect(), do_waiting(), handle_recordfile(), isAnsweringMachine(), mgcp_hangup(), my_all_subchannels_hungup(), my_dsp_set_digitmode(), and sip_rtp_read().
01584 { 01585 ast_free(dsp); 01586 }
int ast_dsp_get_tcount | ( | struct ast_dsp * | dsp | ) |
Get tcount (Threshold counter).
Definition at line 1720 of file dsp.c.
References ast_dsp::tcount.
Referenced by dahdi_read().
01721 { 01722 return dsp->tcount; 01723 }
int ast_dsp_get_threshold_from_settings | ( | enum threshold | which | ) |
Get silence threshold from dsp.conf.
Definition at line 1757 of file dsp.c.
Referenced by actual_load_config(), app_exec(), ast_record_review(), conf_run(), do_waiting(), handle_recordfile(), load_config(), and setup_privacy_args().
01758 { 01759 return thresholds[which]; 01760 }
int ast_dsp_get_tstate | ( | struct ast_dsp * | dsp | ) |
Get tstate (Tone State).
Definition at line 1715 of file dsp.c.
References ast_dsp::tstate.
Referenced by dahdi_read().
01716 { 01717 return dsp->tstate; 01718 }
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.
Definition at line 1762 of file dsp.c.
References _dsp_init().
Referenced by main().
01763 { 01764 return _dsp_init(0); 01765 }
struct ast_dsp* ast_dsp_new | ( | void | ) |
Definition at line 1540 of file dsp.c.
References ast_calloc, ast_digit_detect_init(), ast_dsp_prog_reset(), ast_fax_detect_init(), BUSY_PAT_PERCENT, DEFAULT_THRESHOLD, DSP_DIGITMODE_DTMF, DSP_HISTORY, 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(), and read_config().
01541 { 01542 struct ast_dsp *dsp; 01543 01544 if ((dsp = ast_calloc(1, sizeof(*dsp)))) { 01545 dsp->threshold = DEFAULT_THRESHOLD; 01546 dsp->features = DSP_FEATURE_SILENCE_SUPPRESS; 01547 dsp->busycount = DSP_HISTORY; 01548 dsp->digitmode = DSP_DIGITMODE_DTMF; 01549 dsp->faxmode = DSP_FAXMODE_DETECT_CNG; 01550 dsp->busy_pattern_fuzzy = BUSY_PAT_PERCENT; 01551 #ifdef BUSYDETECT_TONEONLY 01552 dsp->busytoneonly = 1; 01553 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE 01554 #error "You can't use BUSYDETECT_TONEONLY together with BUSYDETECT_COMPARE_TONE_AND_SILENCE"); 01555 #endif 01556 #else 01557 dsp->busytoneonly = 0; 01558 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE 01559 dsp->busycompare = 1; 01560 #else 01561 dsp->busycompare = 0; 01562 #endif 01563 #endif 01564 /* Initialize digit detector */ 01565 ast_digit_detect_init(&dsp->digit_state, dsp->digitmode & DSP_DIGITMODE_MF); 01566 dsp->display_inband_dtmf_warning = 1; 01567 /* Initialize initial DSP progress detect parameters */ 01568 ast_dsp_prog_reset(dsp); 01569 /* Initialize fax detector */ 01570 ast_fax_detect_init(dsp); 01571 } 01572 return dsp; 01573 }
Return non-zero if this is noise. Updates "totalnoise" with the total number of seconds of noise.
Definition at line 1306 of file dsp.c.
References __ast_dsp_silence_noise(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), f, len(), and LOG_WARNING.
Referenced by do_waiting().
01307 { 01308 short *s; 01309 int len; 01310 01311 if (f->frametype != AST_FRAME_VOICE) { 01312 ast_log(LOG_WARNING, "Can't calculate noise on a non-voice frame\n"); 01313 return 0; 01314 } 01315 if (f->subclass.codec != AST_FORMAT_SLINEAR) { 01316 ast_log(LOG_WARNING, "Can only calculate noise on signed-linear frames :(\n"); 01317 return 0; 01318 } 01319 s = f->data.ptr; 01320 len = f->datalen/2; 01321 return __ast_dsp_silence_noise(dsp, s, len, NULL, totalnoise); 01322 }
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 1325 of file dsp.c.
References __ast_dsp_silence_noise(), AST_ALAW, AST_FORMAT_ALAW, AST_FORMAT_SLINEAR, AST_FORMAT_TESTLAW, AST_FORMAT_ULAW, AST_FRAME_VOICE, ast_getformatname(), ast_log(), AST_MULAW, ast_frame_subclass::codec, ast_frame::data, ast_frame::datalen, ast_dsp::display_inband_dtmf_warning, DSP_FEATURE_BUSY_DETECT, DSP_FEATURE_SILENCE_SUPPRESS, ast_dsp::features, ast_frame::frametype, len(), LOG_WARNING, ast_dsp::mute_fragments, ast_frame::ptr, and ast_frame::subclass.
Referenced by dahdi_read(), mgcp_rtp_read(), oh323_rtp_read(), process_ast_dsp(), and sip_rtp_read().
01326 { 01327 int silence; 01328 int res; 01329 int digit = 0, fax_digit = 0; 01330 int x; 01331 short *shortdata; 01332 unsigned char *odata; 01333 int len; 01334 struct ast_frame *outf = NULL; 01335 01336 if (!af) { 01337 return NULL; 01338 } 01339 if (af->frametype != AST_FRAME_VOICE) { 01340 return af; 01341 } 01342 01343 odata = af->data.ptr; 01344 len = af->datalen; 01345 /* Make sure we have short data */ 01346 switch (af->subclass.codec) { 01347 case AST_FORMAT_SLINEAR: 01348 shortdata = af->data.ptr; 01349 len = af->datalen / 2; 01350 break; 01351 case AST_FORMAT_ULAW: 01352 case AST_FORMAT_TESTLAW: 01353 shortdata = alloca(af->datalen * 2); 01354 for (x = 0;x < len; x++) { 01355 shortdata[x] = AST_MULAW(odata[x]); 01356 } 01357 break; 01358 case AST_FORMAT_ALAW: 01359 shortdata = alloca(af->datalen * 2); 01360 for (x = 0; x < len; x++) { 01361 shortdata[x] = AST_ALAW(odata[x]); 01362 } 01363 break; 01364 default: 01365 /*Display warning only once. Otherwise you would get hundreds of warnings every second */ 01366 if (dsp->display_inband_dtmf_warning) 01367 ast_log(LOG_WARNING, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(af->subclass.codec)); 01368 dsp->display_inband_dtmf_warning = 0; 01369 return af; 01370 } 01371 01372 /* Initially we do not want to mute anything */ 01373 dsp->mute_fragments = 0; 01374 01375 /* Need to run the silence detection stuff for silence suppression and busy detection */ 01376 if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) || (dsp->features & DSP_FEATURE_BUSY_DETECT)) { 01377 res = __ast_dsp_silence_noise(dsp, shortdata, len, &silence, NULL); 01378 } 01379 01380 if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) && silence) { 01381 memset(&dsp->f, 0, sizeof(dsp->f)); 01382 dsp->f.frametype = AST_FRAME_NULL; 01383 ast_frfree(af); 01384 return ast_frisolate(&dsp->f); 01385 } 01386 if ((dsp->features & DSP_FEATURE_BUSY_DETECT) && ast_dsp_busydetect(dsp)) { 01387 chan->_softhangup |= AST_SOFTHANGUP_DEV; 01388 memset(&dsp->f, 0, sizeof(dsp->f)); 01389 dsp->f.frametype = AST_FRAME_CONTROL; 01390 /* Signal this as it was a channel hangup, to avoid msg "channel.c:3473 ast_waitfordigit_full: Unexpected control subclass '5'" */ 01391 dsp->f.subclass.integer = AST_CONTROL_HANGUP; 01392 ast_frfree(af); 01393 ast_debug(1, "Requesting Hangup because the busy tone was detected on channel %s\n", chan->name); 01394 return ast_frisolate(&dsp->f); 01395 } 01396 01397 if ((dsp->features & DSP_FEATURE_FAX_DETECT)) { 01398 if ((dsp->faxmode & DSP_FAXMODE_DETECT_CNG) && tone_detect(dsp, &dsp->cng_tone_state, shortdata, len)) { 01399 fax_digit = 'f'; 01400 } 01401 01402 if ((dsp->faxmode & DSP_FAXMODE_DETECT_CED) && tone_detect(dsp, &dsp->ced_tone_state, shortdata, len)) { 01403 fax_digit = 'e'; 01404 } 01405 } 01406 01407 if (dsp->features & (DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_BUSY_DETECT)) { 01408 if (dsp->digitmode & DSP_DIGITMODE_MF) 01409 digit = mf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF)); 01410 else 01411 digit = dtmf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF)); 01412 01413 if (dsp->digit_state.current_digits) { 01414 int event = 0, event_len = 0; 01415 char event_digit = 0; 01416 01417 if (!dsp->dtmf_began) { 01418 /* We have not reported DTMF_BEGIN for anything yet */ 01419 01420 if (dsp->features & DSP_FEATURE_DIGIT_DETECT) { 01421 event = AST_FRAME_DTMF_BEGIN; 01422 event_digit = dsp->digit_state.digits[0]; 01423 } 01424 dsp->dtmf_began = 1; 01425 01426 } else if (dsp->digit_state.current_digits > 1 || digit != dsp->digit_state.digits[0]) { 01427 /* Digit changed. This means digit we have reported with DTMF_BEGIN ended */ 01428 if (dsp->features & DSP_FEATURE_DIGIT_DETECT) { 01429 event = AST_FRAME_DTMF_END; 01430 event_digit = dsp->digit_state.digits[0]; 01431 event_len = dsp->digit_state.digitlen[0] * 1000 / SAMPLE_RATE; 01432 } 01433 memmove(&dsp->digit_state.digits[0], &dsp->digit_state.digits[1], dsp->digit_state.current_digits); 01434 memmove(&dsp->digit_state.digitlen[0], &dsp->digit_state.digitlen[1], dsp->digit_state.current_digits * sizeof(dsp->digit_state.digitlen[0])); 01435 dsp->digit_state.current_digits--; 01436 dsp->dtmf_began = 0; 01437 01438 if (dsp->features & DSP_FEATURE_BUSY_DETECT) { 01439 /* Reset Busy Detector as we have some confirmed activity */ 01440 memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence)); 01441 memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise)); 01442 ast_debug(1, "DTMF Detected - Reset busydetector\n"); 01443 } 01444 } 01445 01446 if (event) { 01447 memset(&dsp->f, 0, sizeof(dsp->f)); 01448 dsp->f.frametype = event; 01449 dsp->f.subclass.integer = event_digit; 01450 dsp->f.len = event_len; 01451 outf = &dsp->f; 01452 goto done; 01453 } 01454 } 01455 } 01456 01457 if (fax_digit) { 01458 /* Fax was detected - digit is either 'f' or 'e' */ 01459 01460 memset(&dsp->f, 0, sizeof(dsp->f)); 01461 dsp->f.frametype = AST_FRAME_DTMF; 01462 dsp->f.subclass.integer = fax_digit; 01463 outf = &dsp->f; 01464 goto done; 01465 } 01466 01467 if ((dsp->features & DSP_FEATURE_CALL_PROGRESS)) { 01468 res = __ast_dsp_call_progress(dsp, shortdata, len); 01469 if (res) { 01470 switch (res) { 01471 case AST_CONTROL_ANSWER: 01472 case AST_CONTROL_BUSY: 01473 case AST_CONTROL_RINGING: 01474 case AST_CONTROL_CONGESTION: 01475 case AST_CONTROL_HANGUP: 01476 memset(&dsp->f, 0, sizeof(dsp->f)); 01477 dsp->f.frametype = AST_FRAME_CONTROL; 01478 dsp->f.subclass.integer = res; 01479 dsp->f.src = "dsp_progress"; 01480 if (chan) 01481 ast_queue_frame(chan, &dsp->f); 01482 break; 01483 default: 01484 ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res); 01485 } 01486 } 01487 } else if ((dsp->features & DSP_FEATURE_WAITDIALTONE)) { 01488 res = __ast_dsp_call_progress(dsp, shortdata, len); 01489 } 01490 01491 done: 01492 /* Mute fragment of the frame */ 01493 for (x = 0; x < dsp->mute_fragments; x++) { 01494 memset(shortdata + dsp->mute_data[x].start, 0, sizeof(int16_t) * (dsp->mute_data[x].end - dsp->mute_data[x].start)); 01495 } 01496 01497 switch (af->subclass.codec) { 01498 case AST_FORMAT_SLINEAR: 01499 break; 01500 case AST_FORMAT_ULAW: 01501 for (x = 0; x < len; x++) { 01502 odata[x] = AST_LIN2MU((unsigned short) shortdata[x]); 01503 } 01504 break; 01505 case AST_FORMAT_ALAW: 01506 for (x = 0; x < len; x++) { 01507 odata[x] = AST_LIN2A((unsigned short) shortdata[x]); 01508 } 01509 break; 01510 } 01511 01512 if (outf) { 01513 if (chan) { 01514 ast_queue_frame(chan, af); 01515 } 01516 ast_frfree(af); 01517 return ast_frisolate(outf); 01518 } else { 01519 return af; 01520 } 01521 }
int ast_dsp_reload | ( | void | ) |
Reloads dsp settings from dsp.conf.
Definition at line 1767 of file dsp.c.
References _dsp_init().
01768 { 01769 return _dsp_init(1); 01770 }
void ast_dsp_reset | ( | struct ast_dsp * | dsp | ) |
Reset total silence count.
Definition at line 1658 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().
01659 { 01660 int x; 01661 01662 dsp->totalsilence = 0; 01663 dsp->gsamps = 0; 01664 for (x = 0; x < 4; x++) { 01665 dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0; 01666 } 01667 memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence)); 01668 memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise)); 01669 dsp->ringtimeout= 0; 01670 }
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 1607 of file dsp.c.
References ast_dsp::busycompare.
Referenced by dahdi_new().
01608 { 01609 if (compare > 0) 01610 dsp->busycompare = 1; 01611 else 01612 dsp->busycompare = 0; 01613 }
void ast_dsp_set_busy_count | ( | struct ast_dsp * | dsp, | |
int | cadences | |||
) |
Set number of required cadences for busy.
Definition at line 1596 of file dsp.c.
References ast_dsp::busycount, and DSP_HISTORY.
Referenced by dahdi_new().
01597 { 01598 if (cadences < 4) { 01599 cadences = 4; 01600 } 01601 if (cadences > DSP_HISTORY) { 01602 cadences = DSP_HISTORY; 01603 } 01604 dsp->busycount = cadences; 01605 }
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 1615 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().
01616 { 01617 dsp->busy_tonelength = tonelength; 01618 if (quietlength > 0) 01619 dsp->busy_quietlength = quietlength; 01620 else 01621 dsp->busytoneonly = 1; 01622 ast_debug(1, "dsp busy pattern set to %d,%d\n", tonelength, quietlength); 01623 if( fuzzy > 0 && fuzzy < 50 ) 01624 dsp->busy_pattern_fuzzy = fuzzy; 01625 }
int ast_dsp_set_call_progress_zone | ( | struct ast_dsp * | dsp, | |
char * | zone | |||
) |
Set zone for doing progress detection.
Definition at line 1696 of file dsp.c.
References aliases, ARRAY_LEN, ast_dsp_prog_reset(), progalias::mode, name, and ast_dsp::progmode.
Referenced by dahdi_new().
01697 { 01698 int x; 01699 01700 for (x = 0; x < ARRAY_LEN(aliases); x++) { 01701 if (!strcasecmp(aliases[x].name, zone)) { 01702 dsp->progmode = aliases[x].mode; 01703 ast_dsp_prog_reset(dsp); 01704 return 0; 01705 } 01706 } 01707 return -1; 01708 }
int ast_dsp_set_digitmode | ( | struct ast_dsp * | dsp, | |
int | digitmode | |||
) |
Set digit mode.
Definition at line 1672 of file dsp.c.
References ast_digit_detect_init(), ast_dsp::digit_state, ast_dsp::digitmode, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_MUTECONF, and DSP_DIGITMODE_MUTEMAX.
Referenced by analog_ss_thread(), dahdi_hangup(), dahdi_new(), dahdi_setoption(), enable_dsp_detect(), mgcp_new(), and my_dsp_set_digitmode().
01673 { 01674 int new; 01675 int old; 01676 01677 old = dsp->digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX); 01678 new = digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX); 01679 if (old != new) { 01680 /* Must initialize structures if switching from MF to DTMF or vice-versa */ 01681 ast_digit_detect_init(&dsp->digit_state, new & DSP_DIGITMODE_MF); 01682 } 01683 dsp->digitmode = digitmode; 01684 return 0; 01685 }
int ast_dsp_set_faxmode | ( | struct ast_dsp * | dsp, | |
int | faxmode | |||
) |
Set fax mode.
Definition at line 1687 of file dsp.c.
References ast_fax_detect_init(), and ast_dsp::faxmode.
01688 { 01689 if (dsp->faxmode != faxmode) { 01690 ast_fax_detect_init(dsp); 01691 } 01692 dsp->faxmode = faxmode; 01693 return 0; 01694 }
void ast_dsp_set_features | ( | struct ast_dsp * | dsp, | |
int | features | |||
) |
Select feature set.
Definition at line 1575 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().
01576 { 01577 dsp->features = features; 01578 if (!(features & DSP_FEATURE_DIGIT_DETECT)) { 01579 dsp->display_inband_dtmf_warning = 0; 01580 } 01581 }
void ast_dsp_set_threshold | ( | struct ast_dsp * | dsp, | |
int | threshold | |||
) |
Set threshold value for silence.
Definition at line 1588 of file dsp.c.
References ast_dsp::threshold.
Referenced by __ast_play_and_record(), dahdi_new(), do_waiting(), fax_session_new(), handle_recordfile(), and isAnsweringMachine().
01589 { 01590 if (threshold < 256) 01591 dsp->threshold = 256; 01592 else 01593 dsp->threshold = threshold; 01594 }
Return non-zero if this is silence. Updates "totalsilence" with the total number of seconds of silence.
Definition at line 1288 of file dsp.c.
References __ast_dsp_silence_noise(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), f, len(), and LOG_WARNING.
Referenced by __ast_play_and_record(), background_detect_exec(), conf_run(), debug_check_frame_for_silence(), do_waiting(), handle_recordfile(), and isAnsweringMachine().
01289 { 01290 short *s; 01291 int len; 01292 01293 if (f->frametype != AST_FRAME_VOICE) { 01294 ast_log(LOG_WARNING, "Can't calculate silence on a non-voice frame\n"); 01295 return 0; 01296 } 01297 if (f->subclass.codec != AST_FORMAT_SLINEAR) { 01298 ast_log(LOG_WARNING, "Can only calculate silence on signed-linear frames :(\n"); 01299 return 0; 01300 } 01301 s = f->data.ptr; 01302 len = f->datalen/2; 01303 return __ast_dsp_silence_noise(dsp, s, len, totalsilence, NULL); 01304 }
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.
Definition at line 1710 of file dsp.c.
References ast_dsp::mute_fragments.
Referenced by dahdi_read().
01711 { 01712 return (dsp->mute_fragments > 0); 01713 }