diff -ur ast-08135/asterisk/channels/chan_zap.c ast-08135-patched/asterisk/channels/chan_zap.c --- ast-08135/asterisk/channels/chan_zap.c 2005-07-25 18:16:35.000000000 -0400 +++ ast-08135-patched/asterisk/channels/chan_zap.c 2005-08-19 15:09:16.543255544 -0400 @@ -2789,6 +2789,8 @@ q931_call *q931c0 = NULL, *q931c1 = NULL; #endif + /* disable zap native bridging - incompatible with rxtone hack */ + return -2; /* if need DTMF, cant native bridge */ if (flags & (AST_BRIDGE_DTMF_CHANNEL_0 | AST_BRIDGE_DTMF_CHANNEL_1)) @@ -4334,10 +4336,13 @@ #if 0 ast_log(LOG_DEBUG, "Read %d of voice on %s\n", p->subs[index].f.datalen, ast->name); #endif +#if 0 if (p->dialing || /* Transmitting something */ (index && (ast->_state != AST_STATE_UP)) || /* Three-way or callwait that isn't up */ ((index == SUB_CALLWAIT) && !p->subs[SUB_CALLWAIT].inthreeway) /* Inactive and non-confed call-wait */ ) { +#endif + if ((index == SUB_CALLWAIT) && !p->subs[SUB_CALLWAIT].inthreeway) { /* Inactive and non-confed call-wait */ /* Whoops, we're still dialing, or in a state where we shouldn't transmit.... don't send anything */ p->subs[index].f.frametype = AST_FRAME_NULL; diff -ur ast-08135/zaptel/zaptel.c ast-08135-patched/zaptel/zaptel.c --- ast-08135/zaptel/zaptel.c 2005-07-31 17:18:45.000000000 -0400 +++ ast-08135-patched/zaptel/zaptel.c 2005-08-19 15:22:20.545069152 -0400 @@ -217,9 +217,13 @@ ZT_TXSTATE_FLASH,ZT_TXSTATE_DEBOUNCE,ZT_TXSTATE_AFTERSTART, ZT_TXSTATE_RINGON,ZT_TXSTATE_RINGOFF,ZT_TXSTATE_KEWL, ZT_TXSTATE_AFTERKEWL,ZT_TXSTATE_PULSEBREAK,ZT_TXSTATE_PULSEMAKE, - ZT_TXSTATE_PULSEAFTER + ZT_TXSTATE_PULSEAFTER, + ZT_TXSTATE_SF_TONEON,ZT_TXSTATE_SF_ONHOOK, + ZT_TXSTATE_SF_TONEOFF } ZT_TXSTATE_t; +#define ZT_SF_TIMEOUT 15 /* 15 msec. */ + typedef short sumtype[ZT_MAX_CHUNKSIZE]; static sumtype sums[(ZT_MAX_CONF + 1) * 3]; @@ -4633,6 +4637,55 @@ #endif } +/* return 0 if nothing detected, 1 if lack of tone, 2 if presence of tone */ +/* modifies buffer pointed to by 'amp' with notched-out values */ +static inline int sf_detect (sf_detect_state_t *s, + short *amp, + int samples,long p1, long p2, long p3) +{ +int i,rv = 0; +long x,y; + +#define SF_DETECT_SAMPLES (ZT_CHUNKSIZE * 5) +#define SF_DETECT_MIN_ENERGY 500 +#define NB 14 /* number of bits to shift left */ + + /* determine energy level before filtering */ + for(i = 0; i < samples; i++) + { + if (amp[i] < 0) s->e1 -= amp[i]; + else s->e1 += amp[i]; + } + /* do 2nd order IIR notch filter at given freq. and calculate + energy */ + for(i = 0; i < samples; i++) + { + x = amp[i] << NB; + y = s->x2 + (p1 * (s->x1 >> NB)) + x; + y += (p2 * (s->y2 >> NB)) + + (p3 * (s->y1 >> NB)); + s->x2 = s->x1; + s->x1 = x; + s->y2 = s->y1; + s->y1 = y; + amp[i] = y >> NB; + if (amp[i] < 0) s->e2 -= amp[i]; + else s->e2 += amp[i]; + } + s->samps += i; + /* if time to do determination */ + if ((s->samps) >= SF_DETECT_SAMPLES) + { + rv = 1; /* default to no tone */ + /* if enough energy, it is determined to be a tone */ + if (((s->e1 - s->e2) / s->samps) > SF_DETECT_MIN_ENERGY) rv = 2; + /* reset energy processing variables */ + s->samps = 0; + s->e1 = s->e2 = 0; + } + return(rv); +} + static inline void __zt_process_getaudio_chunk(struct zt_chan *ss, unsigned char *txb) { /* We transmit data from our master channel */ @@ -4640,11 +4693,43 @@ struct zt_chan *ms = ss->master; /* Linear representation */ short getlin[ZT_CHUNKSIZE], k[ZT_CHUNKSIZE]; - int x; + int x,r; /* Okay, now we've got something to transmit */ for (x=0;xrxp1 = 14876; /* values are for 2600.0 Hz, 30.0 bw */ + ms->rxp2 = -16002; + ms->rxp3 = -14703; + if (ms->rxp1 && ms->rxp2 && ms->rxp3 && ((ms->sig == ZT_SIG_FXSLS) || (ms->sig == ZT_SIG_FXSKS) || (ms->sig == ZT_SIG_FXSGS))) + { + r = sf_detect(&ms->rd,getlin,ZT_CHUNKSIZE,ms->rxp1, + ms->rxp2,ms->rxp3); + /* Convert back */ + for(x=0;xrd.lastdetect) + { + if (debug) + printk("zaptel: sf_detect %d [%lu]\n", r, jiffies); + if (r == 1 && ms->txstate == ZT_TXSTATE_SF_ONHOOK) { + /* rx tone ended */ + ms->txstate = ZT_TXSTATE_SF_TONEOFF; + ms->otimer = ZT_SF_TIMEOUT * 8; + } + if (r == 2 && ms->txstate == ZT_TXSTATE_OFFHOOK) { + /* rx tone started */ + ms->txstate = ZT_TXSTATE_SF_TONEON; + ms->otimer = ZT_SF_TIMEOUT * 8; + } + ms->rd.lastdetect = r; + } + } + } #ifndef NO_ECHOCAN_DISABLE if (ms->ec) { for (x=0;xtxstateq); break; + case ZT_TXSTATE_SF_TONEON: + if (debug) + printk("zaptel: SF_TONEON %d [%lu]\n", chan->rd.lastdetect, jiffies); + if (chan->rd.lastdetect == 1) { + /* tone lost, assume was false hit */ + chan->txstate = ZT_TXSTATE_OFFHOOK; + break; + } + zt_rbs_sethook(chan, ZT_TXSIG_ONHOOK, ZT_TXSTATE_SF_ONHOOK, 0); + break; + + case ZT_TXSTATE_SF_TONEOFF: + if (debug) + printk("zaptel: SF_TONEOFF %d [%lu]\n", chan->rd.lastdetect, jiffies); + if (chan->rd.lastdetect == 2) { + /* tone still present, assume was momentary hit */ + chan->txstate = ZT_TXSTATE_SF_ONHOOK; + break; + } + zt_rbs_sethook(chan, ZT_TXSIG_OFFHOOK, ZT_TXSTATE_OFFHOOK, 0); + break; + default: break; } @@ -5387,55 +5494,6 @@ } } -/* return 0 if nothing detected, 1 if lack of tone, 2 if presence of tone */ -/* modifies buffer pointed to by 'amp' with notched-out values */ -static inline int sf_detect (sf_detect_state_t *s, - short *amp, - int samples,long p1, long p2, long p3) -{ -int i,rv = 0; -long x,y; - -#define SF_DETECT_SAMPLES (ZT_CHUNKSIZE * 5) -#define SF_DETECT_MIN_ENERGY 500 -#define NB 14 /* number of bits to shift left */ - - /* determine energy level before filtering */ - for(i = 0; i < samples; i++) - { - if (amp[i] < 0) s->e1 -= amp[i]; - else s->e1 += amp[i]; - } - /* do 2nd order IIR notch filter at given freq. and calculate - energy */ - for(i = 0; i < samples; i++) - { - x = amp[i] << NB; - y = s->x2 + (p1 * (s->x1 >> NB)) + x; - y += (p2 * (s->y2 >> NB)) + - (p3 * (s->y1 >> NB)); - s->x2 = s->x1; - s->x1 = x; - s->y2 = s->y1; - s->y1 = y; - amp[i] = y >> NB; - if (amp[i] < 0) s->e2 -= amp[i]; - else s->e2 += amp[i]; - } - s->samps += i; - /* if time to do determination */ - if ((s->samps) >= SF_DETECT_SAMPLES) - { - rv = 1; /* default to no tone */ - /* if enough energy, it is determined to be a tone */ - if (((s->e1 - s->e2) / s->samps) > SF_DETECT_MIN_ENERGY) rv = 2; - /* reset energy processing variables */ - s->samps = 0; - s->e1 = s->e2 = 0; - } - return(rv); -} - static inline void __zt_process_putaudio_chunk(struct zt_chan *ss, unsigned char *rxb) { /* We transmit data from our master channel */ @@ -5443,8 +5501,8 @@ struct zt_chan *ms = ss->master; /* Linear version of received data */ short putlin[ZT_CHUNKSIZE],k[ZT_CHUNKSIZE]; - int x,r; - + int x; +#if 0 if (ms->dialing) ms->afterdialingtimer = 50; else if (ms->afterdialingtimer) ms->afterdialingtimer--; if (ms->afterdialingtimer && (!(ms->flags & ZT_FLAG_PSEUDO))) { @@ -5452,6 +5510,7 @@ rxb[0] = ZT_LIN2X(0, ms); memset(&rxb[1], rxb[0], ZT_CHUNKSIZE - 1); /* receive as silence if dialing */ } +#endif for (x=0;xrxgain[rxb[x]]; putlin[x] = ZT_XLAW(rxb[x], ms); @@ -5473,6 +5532,7 @@ } } #endif +#if 0 /* if doing rx tone decoding */ if (ms->rxp1 && ms->rxp2 && ms->rxp3) { @@ -5498,6 +5558,7 @@ } } } +#endif if (!(ms->flags & ZT_FLAG_PSEUDO)) { memcpy(ms->putlin, putlin, ZT_CHUNKSIZE * sizeof(short));