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(), ast_dsp_set_features(), 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 1179 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.
01180 { 01181 int res = 0, x; 01182 int avgsilence = 0, hitsilence = 0; 01183 int avgtone = 0, hittone = 0; 01184 #ifdef DEBUG_DSP_BUSYDETECT 01185 char buf[16]; 01186 char silence_list[64]="", tone_list[64]=""; 01187 #endif 01188 01189 if (!dsp->busymaybe) { 01190 return res; 01191 } 01192 dsp->busymaybe = 0; 01193 01194 for (x = DSP_HISTORY - dsp->busycount; x < DSP_HISTORY; x++) { 01195 avgsilence += dsp->historicsilence[x]; 01196 avgtone += dsp->historicnoise[x]; 01197 } 01198 avgsilence /= dsp->busycount; 01199 avgtone /= dsp->busycount; 01200 #ifdef DEBUG_DSP_BUSYDETECT 01201 sprintf(silence_list,"Silences: "); 01202 sprintf(tone_list,"Tones: "); 01203 #endif 01204 for (x=DSP_HISTORY - dsp->busycount; x<DSP_HISTORY; x++) { 01205 #ifdef DEBUG_DSP_BUSYDETECT 01206 snprintf(buf, sizeof(buf), "%5d ", dsp->historicsilence[x]); 01207 strcat(silence_list, buf); 01208 snprintf(buf, sizeof(buf), "%5d ", dsp->historicnoise[x]); 01209 strcat(tone_list, buf); 01210 #endif 01211 if (!dsp->busytoneonly) { 01212 if (avgsilence > dsp->historicsilence[x]) { 01213 if (avgsilence - (avgsilence*BUSY_PERCENT/100) <= dsp->historicsilence[x]) 01214 hitsilence++; 01215 } else { 01216 if (avgsilence + (avgsilence*BUSY_PERCENT/100) >= dsp->historicsilence[x]) 01217 hitsilence++; 01218 } 01219 } 01220 if (avgtone > dsp->historicnoise[x]) { 01221 if (avgtone - (avgtone * BUSY_PERCENT / 100) <= dsp->historicnoise[x]) { 01222 hittone++; 01223 } 01224 } else { 01225 if (avgtone + (avgtone * BUSY_PERCENT / 100) >= dsp->historicnoise[x]) { 01226 hittone++; 01227 } 01228 } 01229 } 01230 #ifdef DEBUG_DSP_BUSYDETECT 01231 fprintf(stderr, "BUSY DETECTOR\n"); 01232 fprintf(stderr, "%s\n", tone_list); 01233 fprintf(stderr, "%s\n", silence_list) 01234 #endif 01235 if ((dsp->busytoneonly || 01236 (hitsilence >= dsp->busycount - 1 && avgsilence >= BUSY_MIN && avgsilence <= BUSY_MAX)) && 01237 (hittone >= dsp->busycount - 1 && avgtone >= BUSY_MIN && avgtone <= BUSY_MAX)) { 01238 if (dsp->busycompare) { 01239 if (dsp->busytoneonly) { 01240 res = 1; 01241 ast_log(LOG_ERROR, "You can't use busytoneonly together with busycompare"); 01242 } else { 01243 if (avgtone > avgsilence) { 01244 if (avgtone - avgtone*BUSY_PERCENT/100 <= avgsilence) 01245 res = 1; 01246 } else { 01247 if (avgtone + avgtone*BUSY_PERCENT/100 >= avgsilence) 01248 res = 1; 01249 } 01250 } 01251 } else { 01252 res = 1; 01253 } 01254 } 01255 /* If we know the expected busy tone length, check we are in the range */ 01256 if (res && (dsp->busy_tonelength > 0)) { 01257 if (abs(avgtone - dsp->busy_tonelength) > MAX(dsp->busy_tonelength*dsp->busy_pattern_fuzzy/100, 20)) { 01258 #ifdef BUSYDETECT_DEBUG 01259 ast_debug(5, "busy detector: avgtone of %d not close enough to desired %d\n", 01260 avgtone, dsp->busy_tonelength); 01261 #endif 01262 res = 0; 01263 } 01264 } 01265 /* If we know the expected busy tone silent-period length, check we are in the range */ 01266 if (res && (!dsp->busytoneonly) && (dsp->busy_quietlength > 0)) { 01267 if (abs(avgsilence - dsp->busy_quietlength) > MAX(dsp->busy_quietlength*dsp->busy_pattern_fuzzy/100, 20)) { 01268 #ifdef BUSYDETECT_DEBUG 01269 ast_debug(5, "busy detector: avgsilence of %d not close enough to desired %d\n", 01270 avgsilence, dsp->busy_quietlength); 01271 #endif 01272 res = 0; 01273 } 01274 } 01275 if (res) { 01276 if (option_debug) 01277 ast_log(LOG_NOTICE, "ast_dsp_busydetect detected busy sequence, avgtone: %d, avgsilence %d\n", avgtone, avgsilence); 01278 } else { 01279 ast_debug(5, "busy detector: FAILED with avgtone: %d, avgsilence %d\n", avgtone, avgsilence); 01280 } 01281 return res; 01282 }
Scans for progress indication in audio.
Definition at line 1103 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.
01104 { 01105 if (inf->frametype != AST_FRAME_VOICE) { 01106 ast_log(LOG_WARNING, "Can't check call progress of non-voice frames\n"); 01107 return 0; 01108 } 01109 if (inf->subclass.codec != AST_FORMAT_SLINEAR) { 01110 ast_log(LOG_WARNING, "Can only check call progress in signed-linear frames\n"); 01111 return 0; 01112 } 01113 return __ast_dsp_call_progress(dsp, inf->data.ptr, inf->datalen / 2); 01114 }
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 actual_load_config(), 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 1536 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().
01537 { 01538 struct ast_dsp *dsp; 01539 01540 if ((dsp = ast_calloc(1, sizeof(*dsp)))) { 01541 dsp->threshold = DEFAULT_THRESHOLD; 01542 dsp->features = DSP_FEATURE_SILENCE_SUPPRESS; 01543 dsp->busycount = DSP_HISTORY; 01544 dsp->digitmode = DSP_DIGITMODE_DTMF; 01545 dsp->faxmode = DSP_FAXMODE_DETECT_CNG; 01546 dsp->busy_pattern_fuzzy = BUSY_PAT_PERCENT; 01547 #ifdef BUSYDETECT_TONEONLY 01548 dsp->busytoneonly = 1; 01549 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE 01550 #error "You can't use BUSYDETECT_TONEONLY together with BUSYDETECT_COMPARE_TONE_AND_SILENCE"); 01551 #endif 01552 #else 01553 dsp->busytoneonly = 0; 01554 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE 01555 dsp->busycompare = 1; 01556 #else 01557 dsp->busycompare = 0; 01558 #endif 01559 #endif 01560 /* Initialize digit detector */ 01561 ast_digit_detect_init(&dsp->digit_state, dsp->digitmode & DSP_DIGITMODE_MF); 01562 dsp->display_inband_dtmf_warning = 1; 01563 /* Initialize initial DSP progress detect parameters */ 01564 ast_dsp_prog_reset(dsp); 01565 /* Initialize fax detector */ 01566 ast_fax_detect_init(dsp); 01567 } 01568 return dsp; 01569 }
Return non-zero if this is noise. Updates "totalnoise" with the total number of seconds of noise.
Definition at line 1302 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().
01303 { 01304 short *s; 01305 int len; 01306 01307 if (f->frametype != AST_FRAME_VOICE) { 01308 ast_log(LOG_WARNING, "Can't calculate noise on a non-voice frame\n"); 01309 return 0; 01310 } 01311 if (f->subclass.codec != AST_FORMAT_SLINEAR) { 01312 ast_log(LOG_WARNING, "Can only calculate noise on signed-linear frames :(\n"); 01313 return 0; 01314 } 01315 s = f->data.ptr; 01316 len = f->datalen/2; 01317 return __ast_dsp_silence_noise(dsp, s, len, NULL, totalnoise); 01318 }
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 1321 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().
01322 { 01323 int silence; 01324 int res; 01325 int digit = 0, fax_digit = 0; 01326 int x; 01327 short *shortdata; 01328 unsigned char *odata; 01329 int len; 01330 struct ast_frame *outf = NULL; 01331 01332 if (!af) { 01333 return NULL; 01334 } 01335 if (af->frametype != AST_FRAME_VOICE) { 01336 return af; 01337 } 01338 01339 odata = af->data.ptr; 01340 len = af->datalen; 01341 /* Make sure we have short data */ 01342 switch (af->subclass.codec) { 01343 case AST_FORMAT_SLINEAR: 01344 shortdata = af->data.ptr; 01345 len = af->datalen / 2; 01346 break; 01347 case AST_FORMAT_ULAW: 01348 case AST_FORMAT_TESTLAW: 01349 shortdata = alloca(af->datalen * 2); 01350 for (x = 0;x < len; x++) { 01351 shortdata[x] = AST_MULAW(odata[x]); 01352 } 01353 break; 01354 case AST_FORMAT_ALAW: 01355 shortdata = alloca(af->datalen * 2); 01356 for (x = 0; x < len; x++) { 01357 shortdata[x] = AST_ALAW(odata[x]); 01358 } 01359 break; 01360 default: 01361 /*Display warning only once. Otherwise you would get hundreds of warnings every second */ 01362 if (dsp->display_inband_dtmf_warning) 01363 ast_log(LOG_WARNING, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(af->subclass.codec)); 01364 dsp->display_inband_dtmf_warning = 0; 01365 return af; 01366 } 01367 01368 /* Initially we do not want to mute anything */ 01369 dsp->mute_fragments = 0; 01370 01371 /* Need to run the silence detection stuff for silence suppression and busy detection */ 01372 if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) || (dsp->features & DSP_FEATURE_BUSY_DETECT)) { 01373 res = __ast_dsp_silence_noise(dsp, shortdata, len, &silence, NULL); 01374 } 01375 01376 if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) && silence) { 01377 memset(&dsp->f, 0, sizeof(dsp->f)); 01378 dsp->f.frametype = AST_FRAME_NULL; 01379 ast_frfree(af); 01380 return ast_frisolate(&dsp->f); 01381 } 01382 if ((dsp->features & DSP_FEATURE_BUSY_DETECT) && ast_dsp_busydetect(dsp)) { 01383 chan->_softhangup |= AST_SOFTHANGUP_DEV; 01384 memset(&dsp->f, 0, sizeof(dsp->f)); 01385 dsp->f.frametype = AST_FRAME_CONTROL; 01386 /* Signal this as it was a channel hangup, to avoid msg "channel.c:3473 ast_waitfordigit_full: Unexpected control subclass '5'" */ 01387 dsp->f.subclass.integer = AST_CONTROL_HANGUP; 01388 ast_frfree(af); 01389 ast_debug(1, "Requesting Hangup because the busy tone was detected on channel %s\n", chan->name); 01390 return ast_frisolate(&dsp->f); 01391 } 01392 01393 if ((dsp->features & DSP_FEATURE_FAX_DETECT)) { 01394 if ((dsp->faxmode & DSP_FAXMODE_DETECT_CNG) && tone_detect(dsp, &dsp->cng_tone_state, shortdata, len)) { 01395 fax_digit = 'f'; 01396 } 01397 01398 if ((dsp->faxmode & DSP_FAXMODE_DETECT_CED) && tone_detect(dsp, &dsp->ced_tone_state, shortdata, len)) { 01399 fax_digit = 'e'; 01400 } 01401 } 01402 01403 if (dsp->features & (DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_BUSY_DETECT)) { 01404 if (dsp->digitmode & DSP_DIGITMODE_MF) 01405 digit = mf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF)); 01406 else 01407 digit = dtmf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF)); 01408 01409 if (dsp->digit_state.current_digits) { 01410 int event = 0, event_len = 0; 01411 char event_digit = 0; 01412 01413 if (!dsp->dtmf_began) { 01414 /* We have not reported DTMF_BEGIN for anything yet */ 01415 01416 if (dsp->features & DSP_FEATURE_DIGIT_DETECT) { 01417 event = AST_FRAME_DTMF_BEGIN; 01418 event_digit = dsp->digit_state.digits[0]; 01419 } 01420 dsp->dtmf_began = 1; 01421 01422 } else if (dsp->digit_state.current_digits > 1 || digit != dsp->digit_state.digits[0]) { 01423 /* Digit changed. This means digit we have reported with DTMF_BEGIN ended */ 01424 if (dsp->features & DSP_FEATURE_DIGIT_DETECT) { 01425 event = AST_FRAME_DTMF_END; 01426 event_digit = dsp->digit_state.digits[0]; 01427 event_len = dsp->digit_state.digitlen[0] * 1000 / SAMPLE_RATE; 01428 } 01429 memmove(&dsp->digit_state.digits[0], &dsp->digit_state.digits[1], dsp->digit_state.current_digits); 01430 memmove(&dsp->digit_state.digitlen[0], &dsp->digit_state.digitlen[1], dsp->digit_state.current_digits * sizeof(dsp->digit_state.digitlen[0])); 01431 dsp->digit_state.current_digits--; 01432 dsp->dtmf_began = 0; 01433 01434 if (dsp->features & DSP_FEATURE_BUSY_DETECT) { 01435 /* Reset Busy Detector as we have some confirmed activity */ 01436 memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence)); 01437 memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise)); 01438 ast_debug(1, "DTMF Detected - Reset busydetector\n"); 01439 } 01440 } 01441 01442 if (event) { 01443 memset(&dsp->f, 0, sizeof(dsp->f)); 01444 dsp->f.frametype = event; 01445 dsp->f.subclass.integer = event_digit; 01446 dsp->f.len = event_len; 01447 outf = &dsp->f; 01448 goto done; 01449 } 01450 } 01451 } 01452 01453 if (fax_digit) { 01454 /* Fax was detected - digit is either 'f' or 'e' */ 01455 01456 memset(&dsp->f, 0, sizeof(dsp->f)); 01457 dsp->f.frametype = AST_FRAME_DTMF; 01458 dsp->f.subclass.integer = fax_digit; 01459 outf = &dsp->f; 01460 goto done; 01461 } 01462 01463 if ((dsp->features & DSP_FEATURE_CALL_PROGRESS)) { 01464 res = __ast_dsp_call_progress(dsp, shortdata, len); 01465 if (res) { 01466 switch (res) { 01467 case AST_CONTROL_ANSWER: 01468 case AST_CONTROL_BUSY: 01469 case AST_CONTROL_RINGING: 01470 case AST_CONTROL_CONGESTION: 01471 case AST_CONTROL_HANGUP: 01472 memset(&dsp->f, 0, sizeof(dsp->f)); 01473 dsp->f.frametype = AST_FRAME_CONTROL; 01474 dsp->f.subclass.integer = res; 01475 dsp->f.src = "dsp_progress"; 01476 if (chan) 01477 ast_queue_frame(chan, &dsp->f); 01478 break; 01479 default: 01480 ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res); 01481 } 01482 } 01483 } else if ((dsp->features & DSP_FEATURE_WAITDIALTONE)) { 01484 res = __ast_dsp_call_progress(dsp, shortdata, len); 01485 } 01486 01487 done: 01488 /* Mute fragment of the frame */ 01489 for (x = 0; x < dsp->mute_fragments; x++) { 01490 memset(shortdata + dsp->mute_data[x].start, 0, sizeof(int16_t) * (dsp->mute_data[x].end - dsp->mute_data[x].start)); 01491 } 01492 01493 switch (af->subclass.codec) { 01494 case AST_FORMAT_SLINEAR: 01495 break; 01496 case AST_FORMAT_ULAW: 01497 for (x = 0; x < len; x++) { 01498 odata[x] = AST_LIN2MU((unsigned short) shortdata[x]); 01499 } 01500 break; 01501 case AST_FORMAT_ALAW: 01502 for (x = 0; x < len; x++) { 01503 odata[x] = AST_LIN2A((unsigned short) shortdata[x]); 01504 } 01505 break; 01506 } 01507 01508 if (outf) { 01509 if (chan) { 01510 ast_queue_frame(chan, af); 01511 } 01512 ast_frfree(af); 01513 return ast_frisolate(outf); 01514 } else { 01515 return af; 01516 } 01517 }
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 1571 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_open_media(), read_config(), sip_rtp_read(), and store_config().
01572 { 01573 dsp->features = features; 01574 if (!(features & DSP_FEATURE_DIGIT_DETECT)) { 01575 dsp->display_inband_dtmf_warning = 0; 01576 } 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 1284 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().
01285 { 01286 short *s; 01287 int len; 01288 01289 if (f->frametype != AST_FRAME_VOICE) { 01290 ast_log(LOG_WARNING, "Can't calculate silence on a non-voice frame\n"); 01291 return 0; 01292 } 01293 if (f->subclass.codec != AST_FORMAT_SLINEAR) { 01294 ast_log(LOG_WARNING, "Can only calculate silence on signed-linear frames :(\n"); 01295 return 0; 01296 } 01297 s = f->data.ptr; 01298 len = f->datalen/2; 01299 return __ast_dsp_silence_noise(dsp, s, len, totalsilence, NULL); 01300 }
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 }