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