Wed Oct 28 11:52:19 2009

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_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_dspast_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_frameast_dsp_process (struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *inf)
 Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on busies, and call progress, all dependent upon which features are enabled.
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

Detect DTMF digits

Definition at line 31 of file dsp.h.

Referenced by ast_dsp_new(), ast_dsp_set_digitmode(), dahdi_hangup(), dahdi_new(), dahdi_setoption(), mkintf(), sip_new(), ss_thread(), and store_config().

#define DSP_DIGITMODE_MF   1

Detect MF digits

Definition at line 32 of file dsp.h.

Referenced by ast_dsp_digitreset(), ast_dsp_new(), ast_dsp_process(), ast_dsp_set_digitmode(), and ss_thread().

#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(), process_dahdi(), sip_new(), and store_config().

#define DSP_FAXMODE_DETECT_ALL   (DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED)

Definition at line 47 of file dsp.h.

#define DSP_FAXMODE_DETECT_CED   (1 << 1)

Definition at line 46 of file dsp.h.

Referenced by ast_dsp_process().

#define DSP_FAXMODE_DETECT_CNG   (1 << 0)

Definition at line 45 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)

Definition at line 29 of file dsp.h.

Referenced by ast_dsp_process(), dahdi_new(), misdn_set_opt_exec(), and read_config().

#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_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 53 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_DIALTONE   2

Definition at line 51 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_HUNGUP   8

Definition at line 57 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_RINGING   1

Definition at line 50 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_SILENCE   0

Definition at line 49 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_SPECIAL1   5

Definition at line 54 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_SPECIAL2   6

Definition at line 55 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_SPECIAL3   7

Definition at line 56 of file dsp.h.

Referenced by __ast_dsp_call_progress().

#define DSP_TONE_STATE_TALKING   3

Definition at line 52 of file dsp.h.

Referenced by __ast_dsp_call_progress().


Enumeration Type Documentation

enum threshold

Enumerator:
THRESHOLD_SILENCE 
THRESHOLD_MAX 

Definition at line 61 of file dsp.h.

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


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

01144 {
01145    int res = 0, x;
01146 #ifndef BUSYDETECT_TONEONLY
01147    int avgsilence = 0, hitsilence = 0;
01148 #endif
01149    int avgtone = 0, hittone = 0;
01150    if (!dsp->busymaybe)
01151       return res;
01152    for (x=DSP_HISTORY - dsp->busycount;x<DSP_HISTORY;x++) {
01153 #ifndef BUSYDETECT_TONEONLY
01154       avgsilence += dsp->historicsilence[x];
01155 #endif
01156       avgtone += dsp->historicnoise[x];
01157    }
01158 #ifndef BUSYDETECT_TONEONLY
01159    avgsilence /= dsp->busycount;
01160 #endif
01161    avgtone /= dsp->busycount;
01162    for (x=DSP_HISTORY - dsp->busycount;x<DSP_HISTORY;x++) {
01163 #ifndef BUSYDETECT_TONEONLY
01164       if (avgsilence > dsp->historicsilence[x]) {
01165          if (avgsilence - (avgsilence*BUSY_PERCENT/100) <= dsp->historicsilence[x])
01166             hitsilence++;
01167       } else {
01168          if (avgsilence + (avgsilence*BUSY_PERCENT/100) >= dsp->historicsilence[x])
01169             hitsilence++;
01170       }
01171 #endif
01172       if (avgtone > dsp->historicnoise[x]) {
01173          if (avgtone - (avgtone*BUSY_PERCENT/100) <= dsp->historicnoise[x])
01174             hittone++;
01175       } else {
01176          if (avgtone + (avgtone*BUSY_PERCENT/100) >= dsp->historicnoise[x])
01177             hittone++;
01178       }
01179    }
01180 #ifndef BUSYDETECT_TONEONLY
01181    if ((hittone >= dsp->busycount - 1) && (hitsilence >= dsp->busycount - 1) && 
01182        (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX) && 
01183        (avgsilence >= BUSY_MIN && avgsilence <= BUSY_MAX)) {
01184 #else
01185    if ((hittone >= dsp->busycount - 1) && (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX)) {
01186 #endif
01187 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE
01188       if (avgtone > avgsilence) {
01189          if (avgtone - avgtone*BUSY_PERCENT/100 <= avgsilence)
01190             res = 1;
01191       } else {
01192          if (avgtone + avgtone*BUSY_PERCENT/100 >= avgsilence)
01193             res = 1;
01194       }
01195 #else
01196       res = 1;
01197 #endif
01198    }
01199    /* If we know the expected busy tone length, check we are in the range */
01200    if (res && (dsp->busy_tonelength > 0)) {
01201       if (abs(avgtone - dsp->busy_tonelength) > (dsp->busy_tonelength*BUSY_PAT_PERCENT/100)) {
01202 #ifdef BUSYDETECT_DEBUG
01203          ast_debug(5, "busy detector: avgtone of %d not close enough to desired %d\n",
01204             avgtone, dsp->busy_tonelength);
01205 #endif
01206          res = 0;
01207       }
01208    }
01209 #ifndef BUSYDETECT_TONEONLY
01210    /* If we know the expected busy tone silent-period length, check we are in the range */
01211    if (res && (dsp->busy_quietlength > 0)) {
01212       if (abs(avgsilence - dsp->busy_quietlength) > (dsp->busy_quietlength*BUSY_PAT_PERCENT/100)) {
01213 #ifdef BUSYDETECT_DEBUG
01214       ast_debug(5, "busy detector: avgsilence of %d not close enough to desired %d\n",
01215          avgsilence, dsp->busy_quietlength);
01216 #endif
01217          res = 0;
01218       }
01219    }
01220 #endif
01221 #if !defined(BUSYDETECT_TONEONLY) && defined(BUSYDETECT_DEBUG)
01222    if (res) {
01223       ast_debug(5, "ast_dsp_busydetect detected busy, avgtone: %d, avgsilence %d\n", avgtone, avgsilence);
01224    } else {
01225       ast_debug(5, "busy detector: FAILED with avgtone: %d, avgsilence %d\n", avgtone, avgsilence);
01226    }
01227 #endif
01228    return res;
01229 }

int ast_dsp_call_progress ( struct ast_dsp dsp,
struct ast_frame inf 
)

Scans for progress indication in audio.

Definition at line 1073 of file dsp.c.

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

01074 {
01075    if (inf->frametype != AST_FRAME_VOICE) {
01076       ast_log(LOG_WARNING, "Can't check call progress of non-voice frames\n");
01077       return 0;
01078    }
01079    if (inf->subclass != AST_FORMAT_SLINEAR) {
01080       ast_log(LOG_WARNING, "Can only check call progress in signed-linear frames\n");
01081       return 0;
01082    }
01083    return __ast_dsp_call_progress(dsp, inf->data.ptr, inf->datalen / 2);
01084 }

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 1507 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, s, digit_detect_state_t::td, and mf_detect_state_t::tone_out.

Referenced by ss_thread().

01508 {
01509    int i;
01510    
01511    dsp->dtmf_began = 0;
01512    if (dsp->digitmode & DSP_DIGITMODE_MF) {
01513       mf_detect_state_t *s = &dsp->digit_state.td.mf;
01514       /* Reinitialise the detector for the next block */
01515       for (i = 0;  i < 6;  i++) {
01516          goertzel_reset(&s->tone_out[i]);
01517       }
01518       s->hits[4] = s->hits[3] = s->hits[2] = s->hits[1] = s->hits[0] = s->current_hit = 0;
01519       s->current_sample = 0;
01520    } else {
01521       dtmf_detect_state_t *s = &dsp->digit_state.td.dtmf;
01522       /* Reinitialise the detector for the next block */
01523       for (i = 0;  i < 4;  i++) {
01524          goertzel_reset(&s->row_out[i]);
01525          goertzel_reset(&s->col_out[i]);
01526       }
01527       s->lasthit = s->current_hit = 0;
01528       s->energy = 0.0;
01529       s->current_sample = 0;
01530       s->hits = 0;
01531       s->misses = 0;
01532    }
01533 
01534    dsp->digit_state.digits[0] = '\0';
01535    dsp->digit_state.current_digits = 0;
01536 }

void ast_dsp_free ( struct ast_dsp dsp  ) 

int ast_dsp_get_tcount ( struct ast_dsp dsp  ) 

Get tcount (Threshold counter).

Definition at line 1599 of file dsp.c.

References ast_dsp::tcount.

01600 {
01601    return dsp->tcount;
01602 }

int ast_dsp_get_threshold_from_settings ( enum threshold  which  ) 

Get silence threshold from dsp.conf.

Since:
1.6.1

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

01627 {
01628    return thresholds[which];
01629 }

int ast_dsp_get_tstate ( struct ast_dsp dsp  ) 

Get tstate (Tone State).

Definition at line 1594 of file dsp.c.

References ast_dsp::tstate.

01595 {
01596    return dsp->tstate;
01597 }

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

References _dsp_init().

Referenced by main().

01632 {
01633    return _dsp_init(0);
01634 }

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

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

Referenced by do_waiting().

01250 {
01251        short *s;
01252        int len;
01253 
01254        if (f->frametype != AST_FRAME_VOICE) {
01255                ast_log(LOG_WARNING, "Can't calculate noise on a non-voice frame\n");
01256                return 0;
01257        }
01258        if (f->subclass != AST_FORMAT_SLINEAR) {
01259                ast_log(LOG_WARNING, "Can only calculate noise on signed-linear frames :(\n");
01260                return 0;
01261        }
01262        s = f->data.ptr;
01263        len = f->datalen/2;
01264        return __ast_dsp_silence_noise(dsp, s, len, NULL, totalnoise);
01265 }

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 1268 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_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, digit_detect_state_t::current_digits, ast_frame::data, ast_frame::datalen, ast_dsp::digit_state, ast_dsp::digitmode, digit_detect_state_t::digits, 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, ast_dsp::dtmf_began, dtmf_detect(), fragment_t::end, ast_dsp::f, ast_dsp::faxmode, ast_dsp::features, ast_frame::frametype, len(), LOG_WARNING, mf_detect(), ast_dsp::mute_data, ast_dsp::mute_fragments, ast_channel::name, ast_frame::ptr, 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().

01269 {
01270    int silence;
01271    int res;
01272    int digit = 0, fax_digit = 0;
01273    int x;
01274    short *shortdata;
01275    unsigned char *odata;
01276    int len;
01277    struct ast_frame *outf = NULL;
01278 
01279    if (!af)
01280       return NULL;
01281    if (af->frametype != AST_FRAME_VOICE)
01282       return af;
01283 
01284    odata = af->data.ptr;
01285    len = af->datalen;
01286    /* Make sure we have short data */
01287    switch (af->subclass) {
01288    case AST_FORMAT_SLINEAR:
01289       shortdata = af->data.ptr;
01290       len = af->datalen / 2;
01291       break;
01292    case AST_FORMAT_ULAW:
01293       shortdata = alloca(af->datalen * 2);
01294       for (x = 0;x < len; x++) 
01295          shortdata[x] = AST_MULAW(odata[x]);
01296       break;
01297    case AST_FORMAT_ALAW:
01298       shortdata = alloca(af->datalen * 2);
01299       for (x = 0; x < len; x++) 
01300          shortdata[x] = AST_ALAW(odata[x]);
01301       break;
01302    default:
01303       ast_log(LOG_WARNING, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(af->subclass));
01304       return af;
01305    }
01306 
01307    /* Initially we do not want to mute anything */
01308    dsp->mute_fragments = 0;
01309 
01310    /* Need to run the silence detection stuff for silence suppression and busy detection */
01311    if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) || (dsp->features & DSP_FEATURE_BUSY_DETECT)) {
01312       res = __ast_dsp_silence_noise(dsp, shortdata, len, &silence, NULL);
01313    }
01314 
01315    if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) && silence) {
01316       memset(&dsp->f, 0, sizeof(dsp->f));
01317       dsp->f.frametype = AST_FRAME_NULL;
01318       ast_frfree(af);
01319       return ast_frisolate(&dsp->f);
01320    }
01321    if ((dsp->features & DSP_FEATURE_BUSY_DETECT) && ast_dsp_busydetect(dsp)) {
01322       chan->_softhangup |= AST_SOFTHANGUP_DEV;
01323       memset(&dsp->f, 0, sizeof(dsp->f));
01324       dsp->f.frametype = AST_FRAME_CONTROL;
01325       dsp->f.subclass = AST_CONTROL_BUSY;
01326       ast_frfree(af);
01327       ast_debug(1, "Requesting Hangup because the busy tone was detected on channel %s\n", chan->name);
01328       return ast_frisolate(&dsp->f);
01329    }
01330 
01331    if ((dsp->features & DSP_FEATURE_FAX_DETECT)) {
01332       if ((dsp->faxmode & DSP_FAXMODE_DETECT_CNG) && tone_detect(dsp, &dsp->cng_tone_state, shortdata, len)) {
01333          fax_digit = 'f';
01334       }
01335 
01336       if ((dsp->faxmode & DSP_FAXMODE_DETECT_CED) && tone_detect(dsp, &dsp->ced_tone_state, shortdata, len)) {
01337          fax_digit = 'e';
01338       }
01339    }
01340 
01341    if ((dsp->features & DSP_FEATURE_DIGIT_DETECT)) {
01342       if ((dsp->digitmode & DSP_DIGITMODE_MF))
01343          digit = mf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF));
01344       else
01345          digit = dtmf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF));
01346 
01347       if (dsp->digit_state.current_digits) {
01348          int event = 0;
01349          char event_digit = 0;
01350 
01351          if (!dsp->dtmf_began) {
01352             /* We have not reported DTMF_BEGIN for anything yet */
01353 
01354             event = AST_FRAME_DTMF_BEGIN;
01355             event_digit = dsp->digit_state.digits[0];
01356             dsp->dtmf_began = 1;
01357 
01358          } else if (dsp->digit_state.current_digits > 1 || digit != dsp->digit_state.digits[0]) {
01359             /* Digit changed. This means digit we have reported with DTMF_BEGIN ended */
01360    
01361             event = AST_FRAME_DTMF_END;
01362             event_digit = dsp->digit_state.digits[0];
01363             memmove(dsp->digit_state.digits, dsp->digit_state.digits + 1, dsp->digit_state.current_digits);
01364             dsp->digit_state.current_digits--;
01365             dsp->dtmf_began = 0;
01366          }
01367 
01368          if (event) {
01369             memset(&dsp->f, 0, sizeof(dsp->f));
01370             dsp->f.frametype = event;
01371             dsp->f.subclass = event_digit;
01372             outf = &dsp->f;
01373             goto done;
01374          }
01375       }
01376    }
01377 
01378    if (fax_digit) {
01379       /* Fax was detected - digit is either 'f' or 'e' */
01380 
01381       memset(&dsp->f, 0, sizeof(dsp->f));
01382       dsp->f.frametype = AST_FRAME_DTMF;
01383       dsp->f.subclass = fax_digit;
01384       outf = &dsp->f;
01385       goto done;
01386    }
01387 
01388    if ((dsp->features & DSP_FEATURE_CALL_PROGRESS)) {
01389       res = __ast_dsp_call_progress(dsp, shortdata, len);
01390       if (res) {
01391          switch (res) {
01392          case AST_CONTROL_ANSWER:
01393          case AST_CONTROL_BUSY:
01394          case AST_CONTROL_RINGING:
01395          case AST_CONTROL_CONGESTION:
01396          case AST_CONTROL_HANGUP:
01397             memset(&dsp->f, 0, sizeof(dsp->f));
01398             dsp->f.frametype = AST_FRAME_CONTROL;
01399             dsp->f.subclass = res;
01400             dsp->f.src = "dsp_progress";
01401             if (chan) 
01402                ast_queue_frame(chan, &dsp->f);
01403             break;
01404          default:
01405             ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res);
01406          }
01407       }
01408    }
01409 
01410 done:
01411    /* Mute fragment of the frame */
01412    for (x = 0; x < dsp->mute_fragments; x++) {
01413       memset(shortdata + dsp->mute_data[x].start, 0, sizeof(int16_t) * (dsp->mute_data[x].end - dsp->mute_data[x].start));
01414    }
01415 
01416    switch (af->subclass) {
01417    case AST_FORMAT_SLINEAR:
01418       break;
01419    case AST_FORMAT_ULAW:
01420       for (x = 0; x < len; x++)
01421          odata[x] = AST_LIN2MU((unsigned short) shortdata[x]);
01422       break;
01423    case AST_FORMAT_ALAW:
01424       for (x = 0; x < len; x++)
01425          odata[x] = AST_LIN2A((unsigned short) shortdata[x]);
01426       break;
01427    }
01428 
01429    if (outf) {
01430       if (chan) 
01431          ast_queue_frame(chan, af);
01432       ast_frfree(af);
01433       return ast_frisolate(outf);
01434    } else {
01435       return af;
01436    }
01437 }

int ast_dsp_reload ( void   ) 

Reloads dsp settings from dsp.conf.

Since:
1.6.1

Definition at line 1636 of file dsp.c.

References _dsp_init().

01637 {
01638    return _dsp_init(1);
01639 }

void ast_dsp_reset ( struct ast_dsp dsp  ) 

Reset total silence count.

Definition at line 1538 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.

01539 {
01540    int x;
01541    
01542    dsp->totalsilence = 0;
01543    dsp->gsamps = 0;
01544    for (x=0;x<4;x++)
01545       dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0;
01546    memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence));
01547    memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise));  
01548    dsp->ringtimeout= 0;
01549 }

void ast_dsp_set_busy_count ( struct ast_dsp dsp,
int  cadences 
)

Set number of required cadences for busy.

Definition at line 1491 of file dsp.c.

References ast_dsp::busycount, and DSP_HISTORY.

Referenced by dahdi_new().

01492 {
01493    if (cadences < 4)
01494       cadences = 4;
01495    if (cadences > DSP_HISTORY)
01496       cadences = DSP_HISTORY;
01497    dsp->busycount = cadences;
01498 }

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

Set expected lengths of the busy tone.

Definition at line 1500 of file dsp.c.

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

Referenced by dahdi_new().

01501 {
01502    dsp->busy_tonelength = tonelength;
01503    dsp->busy_quietlength = quietlength;
01504    ast_debug(1, "dsp busy pattern set to %d,%d\n", tonelength, quietlength);
01505 }

int ast_dsp_set_call_progress_zone ( struct ast_dsp dsp,
char *  zone 
)

Set zone for doing progress detection.

Definition at line 1575 of file dsp.c.

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

Referenced by dahdi_new().

01576 {
01577    int x;
01578    
01579    for (x = 0; x < ARRAY_LEN(aliases); x++) {
01580       if (!strcasecmp(aliases[x].name, zone)) {
01581          dsp->progmode = aliases[x].mode;
01582          ast_dsp_prog_reset(dsp);
01583          return 0;
01584       }
01585    }
01586    return -1;
01587 }

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 1551 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 dahdi_hangup(), dahdi_new(), dahdi_setoption(), mgcp_new(), mkintf(), sip_new(), ss_thread(), and store_config().

01552 {
01553    int new;
01554    int old;
01555    
01556    old = dsp->digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX);
01557    new = digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX);
01558    if (old != new) {
01559       /* Must initialize structures if switching from MF to DTMF or vice-versa */
01560       ast_digit_detect_init(&dsp->digit_state, new & DSP_DIGITMODE_MF);
01561    }
01562    dsp->digitmode = digitmode;
01563    return 0;
01564 }

int ast_dsp_set_faxmode ( struct ast_dsp dsp,
int  faxmode 
)

Set fax mode.

Definition at line 1566 of file dsp.c.

References ast_fax_detect_init(), and ast_dsp::faxmode.

01567 {
01568    if (dsp->faxmode != faxmode) {
01569       ast_fax_detect_init(dsp);
01570    }
01571    dsp->faxmode = faxmode;
01572    return 0;
01573 }

void ast_dsp_set_features ( struct ast_dsp dsp,
int  features 
)

Select feature set.

Definition at line 1476 of file dsp.c.

References ast_dsp::features.

Referenced by __oh323_new(), dahdi_new(), disable_dtmf_detect(), enable_dtmf_detect(), mgcp_new(), misdn_set_opt_exec(), read_config(), sip_dtmfmode(), sip_new(), and store_config().

01477 {
01478    dsp->features = features;
01479 }

void ast_dsp_set_threshold ( struct ast_dsp dsp,
int  threshold 
)

Set threshold value for silence.

Definition at line 1486 of file dsp.c.

References ast_dsp::threshold.

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

01487 {
01488    dsp->threshold = threshold;
01489 }

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

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

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

01232 {
01233    short *s;
01234    int len;
01235    
01236    if (f->frametype != AST_FRAME_VOICE) {
01237       ast_log(LOG_WARNING, "Can't calculate silence on a non-voice frame\n");
01238       return 0;
01239    }
01240    if (f->subclass != AST_FORMAT_SLINEAR) {
01241       ast_log(LOG_WARNING, "Can only calculate silence on signed-linear frames :(\n");
01242       return 0;
01243    }
01244    s = f->data.ptr;
01245    len = f->datalen/2;
01246    return __ast_dsp_silence_noise(dsp, s, len, totalsilence, NULL);
01247 }

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

References ast_dsp::mute_fragments.

Referenced by dahdi_read().

01590 {
01591    return (dsp->mute_fragments > 0);
01592 }


Generated on Wed Oct 28 11:52:19 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6