Sat Mar 26 11:19:22 2011

Asterisk developer's documentation


dsp.h File Reference

Convenient Signal Processing routines. More...

This graph shows which files directly or indirectly include this file:

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.
struct 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.
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.
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_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)
 Set expected lengths of the busy tone.
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.


Detailed Description

Convenient Signal Processing routines.

Definition in file dsp.h.


Define Documentation

#define DSP_DIGITMODE_DTMF   0

#define DSP_DIGITMODE_MF   1

#define DSP_DIGITMODE_MUTECONF   (1 << 9)

Mute conference

Definition at line 35 of file dsp.h.

Referenced by ast_dsp_set_digitmode(), 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)

Do not quelch DTMF from in-band

Definition at line 34 of file dsp.h.

Referenced by ast_dsp_process(), and mgcp_new().

#define DSP_DIGITMODE_RELAXDTMF   (1 << 11)

"Radio" mode (relaxed DTMF)

Definition at line 37 of file dsp.h.

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

#define DSP_FAXMODE_DETECT_ALL   (DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED)

Definition at line 48 of file dsp.h.

#define DSP_FAXMODE_DETECT_CED   (1 << 1)

Definition at line 47 of file dsp.h.

Referenced by ast_dsp_process().

#define DSP_FAXMODE_DETECT_CNG   (1 << 0)

Definition at line 46 of file dsp.h.

Referenced by ast_dsp_new(), and ast_dsp_process().

#define DSP_FEATURE_BUSY_DETECT   (1 << 1)

Definition at line 27 of file dsp.h.

Referenced by ast_dsp_process(), and dahdi_new().

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

Definition at line 43 of file dsp.h.

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

#define DSP_FEATURE_DIGIT_DETECT   (1 << 3)

#define DSP_FEATURE_FAX_DETECT   (1 << 4)

#define DSP_FEATURE_SILENCE_SUPPRESS   (1 << 0)

Definition at line 26 of file dsp.h.

Referenced by ast_dsp_new(), and ast_dsp_process().

#define DSP_FEATURE_WAITDIALTONE   (1 << 20)

Enable dial tone detection

Definition at line 44 of file dsp.h.

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

#define DSP_PROGRESS_BUSY   (1 << 18)

Enable busy tone detection

Definition at line 41 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_PROGRESS_CONGESTION   (1 << 19)

Enable congestion tone detection

Definition at line 42 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_PROGRESS_RINGING   (1 << 17)

Enable calling tone detection

Definition at line 40 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_PROGRESS_TALK   (1 << 16)

Enable talk detection

Definition at line 39 of file dsp.h.

Referenced by __ast_dsp_call_progress(), and dahdi_new().

#define DSP_TONE_STATE_BUSY   4

Definition at line 54 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_DIALTONE   2

Definition at line 52 of file dsp.h.

Referenced by __ast_dsp_call_progress(), and dahdi_read().

#define DSP_TONE_STATE_HUNGUP   8

Definition at line 58 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_RINGING   1

Definition at line 51 of file dsp.h.

Referenced by __ast_dsp_call_progress(), and dahdi_read().

#define DSP_TONE_STATE_SILENCE   0

Definition at line 50 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_SPECIAL1   5

Definition at line 55 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_SPECIAL2   6

Definition at line 56 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_SPECIAL3   7

Definition at line 57 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_TALKING   3

Definition at line 53 of file dsp.h.

Referenced by __ast_dsp_call_progress().


Enumeration Type Documentation

enum threshold

Enumerator:
THRESHOLD_SILENCE 
THRESHOLD_MAX 

Definition at line 62 of file dsp.h.

00062                {
00063    /* Array offsets */
00064    THRESHOLD_SILENCE = 0,
00065    /* Always the last */
00066    THRESHOLD_MAX = 1,
00067 };


Function Documentation

int ast_dsp_busydetect ( struct ast_dsp *  dsp  ) 

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

Definition at line 1179 of file dsp.c.

References ast_debug, BUSY_MAX, BUSY_MIN, BUSY_PAT_PERCENT, BUSY_PERCENT, ast_dsp::busy_quietlength, ast_dsp::busy_tonelength, ast_dsp::busycount, ast_dsp::busymaybe, DSP_HISTORY, ast_dsp::historicnoise, and ast_dsp::historicsilence.

Referenced by ast_dsp_process().

01180 {
01181    int res = 0, x;
01182 #ifndef BUSYDETECT_TONEONLY
01183    int avgsilence = 0, hitsilence = 0;
01184 #endif
01185    int avgtone = 0, hittone = 0;
01186    if (!dsp->busymaybe) {
01187       return res;
01188    }
01189    for (x = DSP_HISTORY - dsp->busycount; x < DSP_HISTORY; x++) {
01190 #ifndef BUSYDETECT_TONEONLY
01191       avgsilence += dsp->historicsilence[x];
01192 #endif
01193       avgtone += dsp->historicnoise[x];
01194    }
01195 #ifndef BUSYDETECT_TONEONLY
01196    avgsilence /= dsp->busycount;
01197 #endif
01198    avgtone /= dsp->busycount;
01199    for (x = DSP_HISTORY - dsp->busycount; x < DSP_HISTORY; x++) {
01200 #ifndef BUSYDETECT_TONEONLY
01201       if (avgsilence > dsp->historicsilence[x]) {
01202          if (avgsilence - (avgsilence * BUSY_PERCENT / 100) <= dsp->historicsilence[x]) {
01203             hitsilence++;
01204          }
01205       } else {
01206          if (avgsilence + (avgsilence * BUSY_PERCENT / 100) >= dsp->historicsilence[x]) {
01207             hitsilence++;
01208          }
01209       }
01210 #endif
01211       if (avgtone > dsp->historicnoise[x]) {
01212          if (avgtone - (avgtone * BUSY_PERCENT / 100) <= dsp->historicnoise[x]) {
01213             hittone++;
01214          }
01215       } else {
01216          if (avgtone + (avgtone * BUSY_PERCENT / 100) >= dsp->historicnoise[x]) {
01217             hittone++;
01218          }
01219       }
01220    }
01221 #ifndef BUSYDETECT_TONEONLY
01222    if ((hittone >= dsp->busycount - 1) && (hitsilence >= dsp->busycount - 1) && 
01223        (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX) && 
01224        (avgsilence >= BUSY_MIN && avgsilence <= BUSY_MAX)) {
01225 #else
01226    if ((hittone >= dsp->busycount - 1) && (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX)) {
01227 #endif
01228 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE
01229       if (avgtone > avgsilence) {
01230          if (avgtone - avgtone*BUSY_PERCENT/100 <= avgsilence) {
01231             res = 1;
01232          }
01233       } else {
01234          if (avgtone + avgtone*BUSY_PERCENT/100 >= avgsilence) {
01235             res = 1;
01236          }
01237       }
01238 #else
01239       res = 1;
01240 #endif
01241    }
01242    /* If we know the expected busy tone length, check we are in the range */
01243    if (res && (dsp->busy_tonelength > 0)) {
01244       if (abs(avgtone - dsp->busy_tonelength) > (dsp->busy_tonelength*BUSY_PAT_PERCENT/100)) {
01245 #ifdef BUSYDETECT_DEBUG
01246          ast_debug(5, "busy detector: avgtone of %d not close enough to desired %d\n",
01247             avgtone, dsp->busy_tonelength);
01248 #endif
01249          res = 0;
01250       }
01251    }
01252 #ifndef BUSYDETECT_TONEONLY
01253    /* If we know the expected busy tone silent-period length, check we are in the range */
01254    if (res && (dsp->busy_quietlength > 0)) {
01255       if (abs(avgsilence - dsp->busy_quietlength) > (dsp->busy_quietlength*BUSY_PAT_PERCENT/100)) {
01256 #ifdef BUSYDETECT_DEBUG
01257       ast_debug(5, "busy detector: avgsilence of %d not close enough to desired %d\n",
01258          avgsilence, dsp->busy_quietlength);
01259 #endif
01260          res = 0;
01261       }
01262    }
01263 #endif
01264 #if !defined(BUSYDETECT_TONEONLY) && defined(BUSYDETECT_DEBUG)
01265    if (res) {
01266       ast_debug(5, "ast_dsp_busydetect detected busy, avgtone: %d, avgsilence %d\n", avgtone, avgsilence);
01267    } else {
01268       ast_debug(5, "busy detector: FAILED with avgtone: %d, avgsilence %d\n", avgtone, avgsilence);
01269    }
01270 #endif
01271    return res;
01272 }

int ast_dsp_call_progress ( struct ast_dsp *  dsp,
struct ast_frame *  inf 
)

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 }

int ast_dsp_digitdetect ( struct ast_dsp *  dsp,
struct ast_frame *  f 
)

Return non-zero if DTMF hit was found.

void ast_dsp_digitreset ( struct ast_dsp *  dsp  ) 

Reset DTMF detector.

Definition at line 1579 of file dsp.c.

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

Referenced by analog_ss_thread(), and my_dsp_reset_and_flush_digits().

01580 {
01581    int i;
01582    
01583    dsp->dtmf_began = 0;
01584    if (dsp->digitmode & DSP_DIGITMODE_MF) {
01585       mf_detect_state_t *s = &dsp->digit_state.td.mf;
01586       /* Reinitialise the detector for the next block */
01587       for (i = 0;  i < 6;  i++) {
01588          goertzel_reset(&s->tone_out[i]);
01589       }
01590       s->hits[4] = s->hits[3] = s->hits[2] = s->hits[1] = s->hits[0] = s->current_hit = 0;
01591       s->current_sample = 0;
01592    } else {
01593       dtmf_detect_state_t *s = &dsp->digit_state.td.dtmf;
01594       /* Reinitialise the detector for the next block */
01595       for (i = 0;  i < 4;  i++) {
01596          goertzel_reset(&s->row_out[i]);
01597          goertzel_reset(&s->col_out[i]);
01598       }
01599       s->lasthit = s->current_hit = 0;
01600       s->energy = 0.0;
01601       s->current_sample = 0;
01602       s->hits = 0;
01603       s->misses = 0;
01604    }
01605 
01606    dsp->digit_state.digits[0] = '\0';
01607    dsp->digit_state.current_digits = 0;
01608 }

void ast_dsp_free ( struct ast_dsp *  dsp  ) 

int ast_dsp_get_tcount ( struct ast_dsp *  dsp  ) 

Get tcount (Threshold counter).

Definition at line 1672 of file dsp.c.

References ast_dsp::tcount.

Referenced by dahdi_read().

01673 {
01674    return dsp->tcount;
01675 }

int ast_dsp_get_threshold_from_settings ( enum threshold  which  ) 

Get silence threshold from dsp.conf.

Since:
1.6.1

Definition at line 1709 of file dsp.c.

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

01710 {
01711    return thresholds[which];
01712 }

int ast_dsp_get_tstate ( struct ast_dsp *  dsp  ) 

Get tstate (Tone State).

Definition at line 1667 of file dsp.c.

References ast_dsp::tstate.

Referenced by dahdi_read().

01668 {
01669    return dsp->tstate;
01670 }

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

Get pending DTMF/MF digits.

int ast_dsp_init ( void   ) 

Load dsp settings from dsp.conf.

Since:
1.6.1

Definition at line 1714 of file dsp.c.

References _dsp_init().

Referenced by main().

01715 {
01716    return _dsp_init(0);
01717 }

struct ast_dsp* ast_dsp_new ( void   )  [read]

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

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

Since:
1.6.1

Definition at line 1292 of file dsp.c.

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

Referenced by do_waiting().

01293 {
01294        short *s;
01295        int len;
01296 
01297        if (f->frametype != AST_FRAME_VOICE) {
01298                ast_log(LOG_WARNING, "Can't calculate noise on a non-voice frame\n");
01299                return 0;
01300        }
01301        if (f->subclass.codec != AST_FORMAT_SLINEAR) {
01302                ast_log(LOG_WARNING, "Can only calculate noise on signed-linear frames :(\n");
01303                return 0;
01304        }
01305        s = f->data.ptr;
01306        len = f->datalen/2;
01307        return __ast_dsp_silence_noise(dsp, s, len, NULL, totalnoise);
01308 }

struct ast_frame* ast_dsp_process ( struct ast_channel *  chan,
struct ast_dsp *  dsp,
struct ast_frame *  inf 
) [read]

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

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

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

01312 {
01313    int silence;
01314    int res;
01315    int digit = 0, fax_digit = 0;
01316    int x;
01317    short *shortdata;
01318    unsigned char *odata;
01319    int len;
01320    struct ast_frame *outf = NULL;
01321 
01322    if (!af) {
01323       return NULL;
01324    }
01325    if (af->frametype != AST_FRAME_VOICE) {
01326       return af;
01327    }
01328 
01329    odata = af->data.ptr;
01330    len = af->datalen;
01331    /* Make sure we have short data */
01332    switch (af->subclass.codec) {
01333    case AST_FORMAT_SLINEAR:
01334       shortdata = af->data.ptr;
01335       len = af->datalen / 2;
01336       break;
01337    case AST_FORMAT_ULAW:
01338    case AST_FORMAT_TESTLAW:
01339       shortdata = alloca(af->datalen * 2);
01340       for (x = 0;x < len; x++) {
01341          shortdata[x] = AST_MULAW(odata[x]);
01342       }
01343       break;
01344    case AST_FORMAT_ALAW:
01345       shortdata = alloca(af->datalen * 2);
01346       for (x = 0; x < len; x++) {
01347          shortdata[x] = AST_ALAW(odata[x]);
01348       }
01349       break;
01350    default:
01351       /*Display warning only once. Otherwise you would get hundreds of warnings every second */
01352       if (dsp->display_inband_dtmf_warning)
01353          ast_log(LOG_WARNING, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(af->subclass.codec));
01354       dsp->display_inband_dtmf_warning = 0;
01355       return af;
01356    }
01357 
01358    /* Initially we do not want to mute anything */
01359    dsp->mute_fragments = 0;
01360 
01361    /* Need to run the silence detection stuff for silence suppression and busy detection */
01362    if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) || (dsp->features & DSP_FEATURE_BUSY_DETECT)) {
01363       res = __ast_dsp_silence_noise(dsp, shortdata, len, &silence, NULL);
01364    }
01365 
01366    if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) && silence) {
01367       memset(&dsp->f, 0, sizeof(dsp->f));
01368       dsp->f.frametype = AST_FRAME_NULL;
01369       ast_frfree(af);
01370       return ast_frisolate(&dsp->f);
01371    }
01372    if ((dsp->features & DSP_FEATURE_BUSY_DETECT) && ast_dsp_busydetect(dsp)) {
01373       chan->_softhangup |= AST_SOFTHANGUP_DEV;
01374       memset(&dsp->f, 0, sizeof(dsp->f));
01375       dsp->f.frametype = AST_FRAME_CONTROL;
01376       dsp->f.subclass.integer = AST_CONTROL_BUSY;
01377       ast_frfree(af);
01378       ast_debug(1, "Requesting Hangup because the busy tone was detected on channel %s\n", chan->name);
01379       return ast_frisolate(&dsp->f);
01380    }
01381 
01382    if ((dsp->features & DSP_FEATURE_FAX_DETECT)) {
01383       if ((dsp->faxmode & DSP_FAXMODE_DETECT_CNG) && tone_detect(dsp, &dsp->cng_tone_state, shortdata, len)) {
01384          fax_digit = 'f';
01385       }
01386 
01387       if ((dsp->faxmode & DSP_FAXMODE_DETECT_CED) && tone_detect(dsp, &dsp->ced_tone_state, shortdata, len)) {
01388          fax_digit = 'e';
01389       }
01390    }
01391 
01392    if (dsp->features & (DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_BUSY_DETECT)) {
01393       if (dsp->digitmode & DSP_DIGITMODE_MF)
01394          digit = mf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF));
01395       else
01396          digit = dtmf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF));
01397 
01398       if (dsp->digit_state.current_digits) {
01399          int event = 0, event_len = 0;
01400          char event_digit = 0;
01401 
01402          if (!dsp->dtmf_began) {
01403             /* We have not reported DTMF_BEGIN for anything yet */
01404 
01405             if (dsp->features & DSP_FEATURE_DIGIT_DETECT) {
01406                event = AST_FRAME_DTMF_BEGIN;
01407                event_digit = dsp->digit_state.digits[0];
01408             }
01409             dsp->dtmf_began = 1;
01410 
01411          } else if (dsp->digit_state.current_digits > 1 || digit != dsp->digit_state.digits[0]) {
01412             /* Digit changed. This means digit we have reported with DTMF_BEGIN ended */
01413             if (dsp->features & DSP_FEATURE_DIGIT_DETECT) {
01414                event = AST_FRAME_DTMF_END;
01415                event_digit = dsp->digit_state.digits[0];
01416                event_len = dsp->digit_state.digitlen[0] * 1000 / SAMPLE_RATE;
01417             }
01418             memmove(&dsp->digit_state.digits[0], &dsp->digit_state.digits[1], dsp->digit_state.current_digits);
01419             memmove(&dsp->digit_state.digitlen[0], &dsp->digit_state.digitlen[1], dsp->digit_state.current_digits * sizeof(dsp->digit_state.digitlen[0]));
01420             dsp->digit_state.current_digits--;
01421             dsp->dtmf_began = 0;
01422 
01423             if (dsp->features & DSP_FEATURE_BUSY_DETECT) {
01424                /* Reset Busy Detector as we have some confirmed activity */ 
01425                memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence));
01426                memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise));
01427                ast_debug(1, "DTMF Detected - Reset busydetector\n");
01428             }
01429          }
01430 
01431          if (event) {
01432             memset(&dsp->f, 0, sizeof(dsp->f));
01433             dsp->f.frametype = event;
01434             dsp->f.subclass.integer = event_digit;
01435             dsp->f.len = event_len;
01436             outf = &dsp->f;
01437             goto done;
01438          }
01439       }
01440    }
01441 
01442    if (fax_digit) {
01443       /* Fax was detected - digit is either 'f' or 'e' */
01444 
01445       memset(&dsp->f, 0, sizeof(dsp->f));
01446       dsp->f.frametype = AST_FRAME_DTMF;
01447       dsp->f.subclass.integer = fax_digit;
01448       outf = &dsp->f;
01449       goto done;
01450    }
01451 
01452    if ((dsp->features & DSP_FEATURE_CALL_PROGRESS)) {
01453       res = __ast_dsp_call_progress(dsp, shortdata, len);
01454       if (res) {
01455          switch (res) {
01456          case AST_CONTROL_ANSWER:
01457          case AST_CONTROL_BUSY:
01458          case AST_CONTROL_RINGING:
01459          case AST_CONTROL_CONGESTION:
01460          case AST_CONTROL_HANGUP:
01461             memset(&dsp->f, 0, sizeof(dsp->f));
01462             dsp->f.frametype = AST_FRAME_CONTROL;
01463             dsp->f.subclass.integer = res;
01464             dsp->f.src = "dsp_progress";
01465             if (chan) 
01466                ast_queue_frame(chan, &dsp->f);
01467             break;
01468          default:
01469             ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res);
01470          }
01471       }
01472    } else if ((dsp->features & DSP_FEATURE_WAITDIALTONE)) {
01473       res = __ast_dsp_call_progress(dsp, shortdata, len);
01474    }
01475 
01476 done:
01477    /* Mute fragment of the frame */
01478    for (x = 0; x < dsp->mute_fragments; x++) {
01479       memset(shortdata + dsp->mute_data[x].start, 0, sizeof(int16_t) * (dsp->mute_data[x].end - dsp->mute_data[x].start));
01480    }
01481 
01482    switch (af->subclass.codec) {
01483    case AST_FORMAT_SLINEAR:
01484       break;
01485    case AST_FORMAT_ULAW:
01486       for (x = 0; x < len; x++) {
01487          odata[x] = AST_LIN2MU((unsigned short) shortdata[x]);
01488       }
01489       break;
01490    case AST_FORMAT_ALAW:
01491       for (x = 0; x < len; x++) {
01492          odata[x] = AST_LIN2A((unsigned short) shortdata[x]);
01493       }
01494       break;
01495    }
01496 
01497    if (outf) {
01498       if (chan) {
01499          ast_queue_frame(chan, af);
01500       }
01501       ast_frfree(af);
01502       return ast_frisolate(outf);
01503    } else {
01504       return af;
01505    }
01506 }

int ast_dsp_reload ( void   ) 

Reloads dsp settings from dsp.conf.

Since:
1.6.1

Definition at line 1719 of file dsp.c.

References _dsp_init().

01720 {
01721    return _dsp_init(1);
01722 }

void ast_dsp_reset ( struct ast_dsp *  dsp  ) 

Reset total silence count.

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

01611 {
01612    int x;
01613    
01614    dsp->totalsilence = 0;
01615    dsp->gsamps = 0;
01616    for (x = 0; x < 4; x++) {
01617       dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0;
01618    }
01619    memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence));
01620    memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise));  
01621    dsp->ringtimeout= 0;
01622 }

void ast_dsp_set_busy_count ( struct ast_dsp *  dsp,
int  cadences 
)

Set number of required cadences for busy.

Definition at line 1561 of file dsp.c.

References ast_dsp::busycount, and DSP_HISTORY.

Referenced by dahdi_new().

01562 {
01563    if (cadences < 4) {
01564       cadences = 4;
01565    }
01566    if (cadences > DSP_HISTORY) {
01567       cadences = DSP_HISTORY;
01568    }
01569    dsp->busycount = cadences;
01570 }

void ast_dsp_set_busy_pattern ( struct ast_dsp *  dsp,
int  tonelength,
int  quietlength 
)

Set expected lengths of the busy tone.

Definition at line 1572 of file dsp.c.

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

Referenced by dahdi_new().

01573 {
01574    dsp->busy_tonelength = tonelength;
01575    dsp->busy_quietlength = quietlength;
01576    ast_debug(1, "dsp busy pattern set to %d,%d\n", tonelength, quietlength);
01577 }

int ast_dsp_set_call_progress_zone ( struct ast_dsp *  dsp,
char *  zone 
)

Set zone for doing progress detection.

Definition at line 1648 of file dsp.c.

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

Referenced by dahdi_new().

01649 {
01650    int x;
01651    
01652    for (x = 0; x < ARRAY_LEN(aliases); x++) {
01653       if (!strcasecmp(aliases[x].name, zone)) {
01654          dsp->progmode = aliases[x].mode;
01655          ast_dsp_prog_reset(dsp);
01656          return 0;
01657       }
01658    }
01659    return -1;
01660 }

int ast_dsp_set_digitmode ( struct ast_dsp *  dsp,
int  digitmode 
)

Set digit mode.

Version:
1.6.1 renamed from ast_dsp_digitmode to ast_dsp_set_digitmode

Definition at line 1624 of file dsp.c.

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

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

01625 {
01626    int new;
01627    int old;
01628    
01629    old = dsp->digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX);
01630    new = digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX);
01631    if (old != new) {
01632       /* Must initialize structures if switching from MF to DTMF or vice-versa */
01633       ast_digit_detect_init(&dsp->digit_state, new & DSP_DIGITMODE_MF);
01634    }
01635    dsp->digitmode = digitmode;
01636    return 0;
01637 }

int ast_dsp_set_faxmode ( struct ast_dsp *  dsp,
int  faxmode 
)

Set fax mode.

Definition at line 1639 of file dsp.c.

References ast_fax_detect_init(), and ast_dsp::faxmode.

01640 {
01641    if (dsp->faxmode != faxmode) {
01642       ast_fax_detect_init(dsp);
01643    }
01644    dsp->faxmode = faxmode;
01645    return 0;
01646 }

void ast_dsp_set_features ( struct ast_dsp *  dsp,
int  features 
)

void ast_dsp_set_threshold ( struct ast_dsp *  dsp,
int  threshold 
)

Set threshold value for silence.

Definition at line 1556 of file dsp.c.

References ast_dsp::threshold.

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

01557 {
01558    dsp->threshold = threshold;
01559 }

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

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

Definition at line 1274 of file dsp.c.

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

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

01275 {
01276    short *s;
01277    int len;
01278    
01279    if (f->frametype != AST_FRAME_VOICE) {
01280       ast_log(LOG_WARNING, "Can't calculate silence on a non-voice frame\n");
01281       return 0;
01282    }
01283    if (f->subclass.codec != AST_FORMAT_SLINEAR) {
01284       ast_log(LOG_WARNING, "Can only calculate silence on signed-linear frames :(\n");
01285       return 0;
01286    }
01287    s = f->data.ptr;
01288    len = f->datalen/2;
01289    return __ast_dsp_silence_noise(dsp, s, len, totalsilence, NULL);
01290 }

int ast_dsp_was_muted ( struct ast_dsp *  dsp  ) 

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

Since:
1.6.1

Definition at line 1662 of file dsp.c.

References ast_dsp::mute_fragments.

Referenced by dahdi_read().

01663 {
01664    return (dsp->mute_fragments > 0);
01665 }


Generated on Sat Mar 26 11:19:23 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.9