Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
return res;
}
int ast_dsp_digitdetect(struct ast_dsp *dsp, struct ast_frame *inf)
{
short *s;
int len;
int ign=0;
if (inf->frametype != AST_FRAME_VOICE) {
ast_log(LOG_WARNING, "Can't check call progress of non-voice frames\n");
return 0;
}
if (inf->subclass != AST_FORMAT_SLINEAR) {
ast_log(LOG_WARNING, "Can only check call progress in signed-linear frames\n");
return 0;
}
s = inf->data;
len = inf->datalen / 2;
return __ast_dsp_digitdetect(dsp, s, len, &ign);
}
static inline int pair_there(float p1, float p2, float i1, float i2, float e)
{
/* See if p1 and p2 are there, relative to i1 and i2 and total energy */
/* Make sure absolute levels are high enough */
if ((p1 < TONE_MIN_THRESH) || (p2 < TONE_MIN_THRESH))
return 0;
/* Amplify ignored stuff */
i2 *= TONE_THRESH;
i1 *= TONE_THRESH;
e *= TONE_THRESH;
/* Check first tone */
if ((p1 < i1) || (p1 < i2) || (p1 < e))
return 0;
/* And second */
if ((p2 < i1) || (p2 < i2) || (p2 < e))
return 0;
/* Guess it's there... */
return 1;
}
int ast_dsp_getdigits (struct ast_dsp *dsp,
char *buf,
int max)
{
if (dsp->digitmode & DSP_DIGITMODE_MF) {
if (max > dsp->td.mf.current_digits)
max = dsp->td.mf.current_digits;
if (max > 0)
{
memcpy (buf, dsp->td.mf.digits, max);
memmove (dsp->td.mf.digits, dsp->td.mf.digits + max, dsp->td.mf.current_digits - max);
dsp->td.mf.current_digits -= max;
}
buf[max] = '\0';
return max;
} else {
if (max > dsp->td.dtmf.current_digits)
max = dsp->td.dtmf.current_digits;
if (max > 0)
{
memcpy (buf, dsp->td.dtmf.digits, max);
memmove (dsp->td.dtmf.digits, dsp->td.dtmf.digits + max, dsp->td.dtmf.current_digits - max);
dsp->td.dtmf.current_digits -= max;
}
buf[max] = '\0';
return max;
}
}
static int __ast_dsp_call_progress(struct ast_dsp *dsp, short *s, int len)
{
int x;
int pass;
int newstate = TONE_STATE_SILENCE;
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
int res = 0;
while(len) {
/* Take the lesser of the number of samples we need and what we have */
pass = len;
if (pass > GSAMP_SIZE - dsp->gsamps)
pass = GSAMP_SIZE - dsp->gsamps;
for (x=0;x<pass;x++) {
goertzel_sample(&dsp->freqs[HZ_350], s[x]);
goertzel_sample(&dsp->freqs[HZ_440], s[x]);
goertzel_sample(&dsp->freqs[HZ_480], s[x]);
goertzel_sample(&dsp->freqs[HZ_620], s[x]);
goertzel_sample(&dsp->freqs[HZ_950], s[x]);
goertzel_sample(&dsp->freqs[HZ_1400], s[x]);
goertzel_sample(&dsp->freqs[HZ_1800], s[x]);
dsp->genergy += s[x] * s[x];
}
s += pass;
dsp->gsamps += pass;
len -= pass;
if (dsp->gsamps == GSAMP_SIZE) {
float hz_350;
float hz_440;
float hz_480;
float hz_620;
float hz_950;
float hz_1400;
float hz_1800;
hz_350 = goertzel_result(&dsp->freqs[HZ_350]);
hz_440 = goertzel_result(&dsp->freqs[HZ_440]);
hz_480 = goertzel_result(&dsp->freqs[HZ_480]);
hz_620 = goertzel_result(&dsp->freqs[HZ_620]);
hz_950 = goertzel_result(&dsp->freqs[HZ_950]);
hz_1400 = goertzel_result(&dsp->freqs[HZ_1400]);
hz_1800 = goertzel_result(&dsp->freqs[HZ_1800]);
#if 0
printf("Got whole dsp state: 350: %e, 440: %e, 480: %e, 620: %e, 950: %e, 1400: %e, 1800: %e, Energy: %e\n",
hz_350, hz_440, hz_480, hz_620, hz_950, hz_1400, hz_1800, dsp->genergy);
#endif
if (pair_there(hz_480, hz_620, hz_350, hz_440, dsp->genergy)) {
newstate = TONE_STATE_BUSY;
} else if (pair_there(hz_440, hz_480, hz_350, hz_620, dsp->genergy)) {
newstate = TONE_STATE_RINGING;
} else if (pair_there(hz_350, hz_440, hz_480, hz_620, dsp->genergy)) {
newstate = TONE_STATE_DIALTONE;
} else if (hz_950 > TONE_MIN_THRESH * TONE_THRESH) {
newstate = TONE_STATE_SPECIAL1;
} else if (hz_1400 > TONE_MIN_THRESH * TONE_THRESH) {
if (dsp->tstate == TONE_STATE_SPECIAL1)
newstate = TONE_STATE_SPECIAL2;
} else if (hz_1800 > TONE_MIN_THRESH * TONE_THRESH) {
if (dsp->tstate == TONE_STATE_SPECIAL2)
newstate = TONE_STATE_SPECIAL3;
} else if (dsp->genergy > TONE_MIN_THRESH * TONE_THRESH) {
newstate = TONE_STATE_TALKING;
} else
newstate = TONE_STATE_SILENCE;
if (newstate == dsp->tstate) {
dsp->tcount++;
if (dsp->tcount == COUNT_THRESH) {
if (dsp->tstate == TONE_STATE_BUSY) {
res = AST_CONTROL_BUSY;
dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
} else if (dsp->tstate == TONE_STATE_TALKING) {
res = AST_CONTROL_ANSWER;
dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
} else if (dsp->tstate == TONE_STATE_RINGING)
res = AST_CONTROL_RINGING;
else if (dsp->tstate == TONE_STATE_SPECIAL3) {
res = AST_CONTROL_CONGESTION;
dsp->features &= ~DSP_FEATURE_CALL_PROGRESS;
}
}
} else {
#if 0
printf("Newstate: %d\n", newstate);
#endif
dsp->tstate = newstate;
dsp->tcount = 1;
}
/* Reset goertzel */
for (x=0;x<7;x++)
dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0;
dsp->gsamps = 0;
dsp->genergy = 0.0;
}
}
#if 0
if (res)
printf("Returning %d\n", res);
#endif
return res;
}
int ast_dsp_call_progress(struct ast_dsp *dsp, struct ast_frame *inf)
{
if (inf->frametype != AST_FRAME_VOICE) {
ast_log(LOG_WARNING, "Can't check call progress of non-voice frames\n");
return 0;
}
if (inf->subclass != AST_FORMAT_SLINEAR) {
ast_log(LOG_WARNING, "Can only check call progress in signed-linear frames\n");
return 0;
}
return __ast_dsp_call_progress(dsp, inf->data, inf->datalen / 2);
}
static int __ast_dsp_silence(struct ast_dsp *dsp, short *s, int len, int *totalsilence)
{
int accum;
int x;
int res = 0;
accum = 0;
for (x=0;x<len; x++)
accum += abs(s[x]);
Martin Pycko
committed
accum /= len;
if (accum < dsp->threshold) {
dsp->totalsilence += len/8;
if (dsp->totalnoise) {
/* Move and save history */
Martin Pycko
committed
memmove(dsp->historicnoise + DSP_HISTORY - dsp->busycount, dsp->historicnoise + DSP_HISTORY - dsp->busycount +1, dsp->busycount*sizeof(dsp->historicnoise[0]));
dsp->historicnoise[DSP_HISTORY - 1] = dsp->totalnoise;
Martin Pycko
committed
/* we don't want to check for busydetect that frequently */
#if 0
Martin Pycko
committed
#endif
}
dsp->totalnoise = 0;
res = 1;
} else {
dsp->totalnoise += len/8;
if (dsp->totalsilence) {
Martin Pycko
committed
int silence1 = dsp->historicsilence[DSP_HISTORY - 1];
int silence2 = dsp->historicsilence[DSP_HISTORY - 2];
Martin Pycko
committed
memmove(dsp->historicsilence + DSP_HISTORY - dsp->busycount, dsp->historicsilence + DSP_HISTORY - dsp->busycount + 1, dsp->busycount*sizeof(dsp->historicsilence[0]));
dsp->historicsilence[DSP_HISTORY - 1] = dsp->totalsilence;
Martin Pycko
committed
/* check if the previous sample differs only by BUSY_PERCENT from the one before it */
if (silence1 < silence2) {
if (silence1 + silence1/BUSY_PERCENT >= silence2)
dsp->busymaybe = 1;
else
dsp->busymaybe = 0;
} else {
if (silence1 - silence1/BUSY_PERCENT <= silence2)
dsp->busymaybe = 1;
else
dsp->busymaybe = 0;
}
}
dsp->totalsilence = 0;
}
if (totalsilence)
*totalsilence = dsp->totalsilence;
return res;
}
Martin Pycko
committed
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
#ifdef BUSYDETECT_MARTIN
int ast_dsp_busydetect(struct ast_dsp *dsp)
{
int res = 0, x;
#ifndef BUSYDETECT_TONEONLY
int avgsilence = 0, hitsilence = 0;
#endif
int avgtone = 0, hittone = 0;
if (!dsp->busymaybe)
return res;
for (x=DSP_HISTORY - dsp->busycount;x<DSP_HISTORY;x++) {
#ifndef BUSYDETECT_TONEONLY
avgsilence += dsp->historicsilence[x];
#endif
avgtone += dsp->historicnoise[x];
}
#ifndef BUSYDETECT_TONEONLY
avgsilence /= dsp->busycount;
#endif
avgtone /= dsp->busycount;
for (x=DSP_HISTORY - dsp->busycount;x<DSP_HISTORY;x++) {
#ifndef BUSYDETECT_TONEONLY
if (avgsilence > dsp->historicsilence[x]) {
if (avgsilence - (avgsilence / BUSY_PERCENT) <= dsp->historicsilence[x])
hitsilence++;
} else {
if (avgsilence + (avgsilence / BUSY_PERCENT) >= dsp->historicsilence[x])
hitsilence++;
}
#endif
if (avgtone > dsp->historicnoise[x]) {
if (avgtone - (avgtone / BUSY_PERCENT) <= dsp->historicsilence[x])
hittone++;
} else {
if (avgtone + (avgtone / BUSY_PERCENT) >= dsp->historicsilence[x])
hittone++;
}
}
#ifndef BUSYDETECT_TONEONLY
if ((hittone >= dsp->busycount - 1) && (hitsilence >= dsp->busycount - 1) && (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX) && (avgsilence >= BUSY_MIN && avgsilence <= BUSY_MAX)) {
#else
if ((hittone >= dsp->busycount - 1) && (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX)) {
#endif
#ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE
#ifdef BUSYDETECT_TONEONLY
#error You cant use BUSYDETECT_TONEONLY together with BUSYDETECT_COMPARE_TONE_AND_SILENCE
Martin Pycko
committed
#endif
if (avgtone > avgsilence) {
if (avgtone - avgtone/(BUSY_PERCENT*2) <= avgsilence)
res = 1;
} else {
if (avgtone + avgtone/(BUSY_PERCENT*2) >= avgsilence)
res = 1;
}
#else
res = 1;
#endif
}
#if 0
if (res)
ast_log(LOG_NOTICE, "detected busy, avgtone: %d, avgsilence %d\n", avgtone, avgsilence);
#endif
return res;
}
#endif
Martin Pycko
committed
#ifdef BUSYDETECT
int ast_dsp_busydetect(struct ast_dsp *dsp)
{
int x;
int res = 0;
int max, min;
Martin Pycko
committed
#if 0
if (dsp->busy_hits > 5);
return 0;
#endif
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
if (dsp->busymaybe) {
#if 0
printf("Maybe busy!\n");
#endif
dsp->busymaybe = 0;
min = 9999;
max = 0;
for (x=DSP_HISTORY - dsp->busycount;x<DSP_HISTORY;x++) {
#if 0
printf("Silence: %d, Noise: %d\n", dsp->historicsilence[x], dsp->historicnoise[x]);
#endif
if (dsp->historicsilence[x] < min)
min = dsp->historicsilence[x];
if (dsp->historicnoise[x] < min)
min = dsp->historicnoise[x];
if (dsp->historicsilence[x] > max)
max = dsp->historicsilence[x];
if (dsp->historicnoise[x] > max)
max = dsp->historicnoise[x];
}
if ((max - min < BUSY_THRESHOLD) && (max < BUSY_MAX) && (min > BUSY_MIN)) {
#if 0
printf("Busy!\n");
#endif
res = 1;
}
#if 0
printf("Min: %d, max: %d\n", min, max);
#endif
}
return res;
}
Martin Pycko
committed
#endif
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence)
{
short *s;
int len;
if (f->frametype != AST_FRAME_VOICE) {
ast_log(LOG_WARNING, "Can't calculate silence on a non-voice frame\n");
return 0;
}
if (f->subclass != AST_FORMAT_SLINEAR) {
ast_log(LOG_WARNING, "Can only calculate silence on signed-linear frames :(\n");
return 0;
}
s = f->data;
len = f->datalen/2;
return __ast_dsp_silence(dsp, s, len, totalsilence);
}
struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *af, int needlock)
{
int silence;
int res;
int digit;
int x;
unsigned short *shortdata;
unsigned char *odata;
int len;
int writeback = 0;
#define FIX_INF(inf) do { \
if (writeback) { \
switch(inf->subclass) { \
case AST_FORMAT_SLINEAR: \
break; \
case AST_FORMAT_ULAW: \
for (x=0;x<len;x++) \
odata[x] = AST_LIN2MU(shortdata[x]); \
break; \
case AST_FORMAT_ALAW: \
for (x=0;x<len;x++) \
odata[x] = AST_LIN2A(shortdata[x]); \
break; \
} \
} \
} while(0)
if (!af)
return NULL;
if (af->frametype != AST_FRAME_VOICE)
return af;
odata = af->data;
len = af->datalen;
/* Make sure we have short data */
switch(af->subclass) {
case AST_FORMAT_SLINEAR:
shortdata = af->data;
len = af->datalen / 2;
break;
case AST_FORMAT_ULAW:
shortdata = alloca(af->datalen * 2);
if (!shortdata) {
ast_log(LOG_WARNING, "Unable to allocate stack space for data: %s\n", strerror(errno));
return af;
}
for (x=0;x<len;x++)
shortdata[x] = AST_MULAW(odata[x]);
break;
case AST_FORMAT_ALAW:
shortdata = alloca(af->datalen * 2);
if (!shortdata) {
ast_log(LOG_WARNING, "Unable to allocate stack space for data: %s\n", strerror(errno));
return af;
}
for (x=0;x<len;x++)
shortdata[x] = AST_ALAW(odata[x]);
break;
default:
ast_log(LOG_WARNING, "Unable to process inband DTMF on %d frames\n", af->subclass);
return af;
}
silence = __ast_dsp_silence(dsp, shortdata, len, NULL);
if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) && silence) {
memset(&dsp->f, 0, sizeof(dsp->f));
dsp->f.frametype = AST_FRAME_NULL;
return &dsp->f;
}
if ((dsp->features & DSP_FEATURE_BUSY_DETECT) && ast_dsp_busydetect(dsp)) {
Martin Pycko
committed
chan->_softhangup |= AST_SOFTHANGUP_DEV;
memset(&dsp->f, 0, sizeof(dsp->f));
dsp->f.frametype = AST_FRAME_CONTROL;
dsp->f.subclass = AST_CONTROL_BUSY;
Martin Pycko
committed
ast_log(LOG_DEBUG, "Requesting Hangup because the busy tone was detected on channel %s\n", chan->name);
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
return &dsp->f;
}
if ((dsp->features & DSP_FEATURE_DTMF_DETECT)) {
digit = __ast_dsp_digitdetect(dsp, shortdata, len, &writeback);
#if 0
if (digit)
printf("Performing digit detection returned %d, digitmode is %d\n", digit, dsp->digitmode);
#endif
if (dsp->digitmode & (DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX)) {
if (!dsp->thinkdigit) {
if (digit) {
/* Looks like we might have something. Request a conference mute for the moment */
memset(&dsp->f, 0, sizeof(dsp->f));
dsp->f.frametype = AST_FRAME_DTMF;
dsp->f.subclass = 'm';
dsp->thinkdigit = 'x';
FIX_INF(af);
if (chan)
ast_queue_frame(chan, af, needlock);
ast_frfree(af);
return &dsp->f;
}
} else {
if (digit) {
/* Thought we saw one last time. Pretty sure we really have now */
if (dsp->thinkdigit) {
if ((dsp->thinkdigit != 'x') && (dsp->thinkdigit != digit)) {
/* If we found a digit, and we're changing digits, go
ahead and send this one, but DON'T stop confmute because
we're detecting something else, too... */
memset(&dsp->f, 0, sizeof(dsp->f));
dsp->f.frametype = AST_FRAME_DTMF;
dsp->f.subclass = dsp->thinkdigit;
FIX_INF(af);
if (chan)
ast_queue_frame(chan, af, needlock);
ast_frfree(af);
}
return &dsp->f;
}
} else {
if (dsp->thinkdigit) {
memset(&dsp->f, 0, sizeof(dsp->f));
if (dsp->thinkdigit != 'x') {
/* If we found a digit, send it now */
dsp->f.frametype = AST_FRAME_DTMF;
dsp->f.subclass = dsp->thinkdigit;
dsp->thinkdigit = 0;
} else {
dsp->f.frametype = AST_FRAME_DTMF;
dsp->f.subclass = 'u';
dsp->thinkdigit = 0;
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
}
FIX_INF(af);
if (chan)
ast_queue_frame(chan, af, needlock);
ast_frfree(af);
return &dsp->f;
}
}
}
} else if (!digit) {
/* Only check when there is *not* a hit... */
if (dsp->digitmode & DSP_DIGITMODE_MF) {
if (dsp->td.mf.current_digits) {
memset(&dsp->f, 0, sizeof(dsp->f));
dsp->f.frametype = AST_FRAME_DTMF;
dsp->f.subclass = dsp->td.mf.digits[0];
memmove(dsp->td.mf.digits, dsp->td.mf.digits + 1, dsp->td.mf.current_digits);
dsp->td.mf.current_digits--;
FIX_INF(af);
if (chan)
ast_queue_frame(chan, af, needlock);
ast_frfree(af);
return &dsp->f;
}
} else {
if (dsp->td.dtmf.current_digits) {
memset(&dsp->f, 0, sizeof(dsp->f));
dsp->f.frametype = AST_FRAME_DTMF;
dsp->f.subclass = dsp->td.dtmf.digits[0];
memmove(dsp->td.dtmf.digits, dsp->td.dtmf.digits + 1, dsp->td.dtmf.current_digits);
dsp->td.dtmf.current_digits--;
FIX_INF(af);
if (chan)
ast_queue_frame(chan, af, needlock);
ast_frfree(af);
return &dsp->f;
}
}
}
}
if ((dsp->features & DSP_FEATURE_CALL_PROGRESS)) {
res = __ast_dsp_call_progress(dsp, shortdata, len);
memset(&dsp->f, 0, sizeof(dsp->f));
dsp->f.frametype = AST_FRAME_CONTROL;
if (res) {
switch(res) {
case AST_CONTROL_ANSWER:
case AST_CONTROL_BUSY:
case AST_CONTROL_RINGING:
case AST_CONTROL_CONGESTION:
dsp->f.subclass = res;
if (chan)
ast_queue_frame(chan, &dsp->f, needlock);
break;
default:
ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res);
}
}
}
FIX_INF(af);
return af;
}
struct ast_dsp *ast_dsp_new(void)
{
struct ast_dsp *dsp;
dsp = malloc(sizeof(struct ast_dsp));
if (dsp) {
memset(dsp, 0, sizeof(struct ast_dsp));
dsp->threshold = DEFAULT_THRESHOLD;
dsp->features = DSP_FEATURE_SILENCE_SUPPRESS;
Martin Pycko
committed
dsp->busycount = DSP_HISTORY;
goertzel_init(&dsp->freqs[HZ_350], 350.0, GSAMP_SIZE);
goertzel_init(&dsp->freqs[HZ_440], 440.0, GSAMP_SIZE);
goertzel_init(&dsp->freqs[HZ_480], 480.0, GSAMP_SIZE);
goertzel_init(&dsp->freqs[HZ_620], 620.0, GSAMP_SIZE);
goertzel_init(&dsp->freqs[HZ_950], 950.0, GSAMP_SIZE);
goertzel_init(&dsp->freqs[HZ_1400], 1400.0, GSAMP_SIZE);
goertzel_init(&dsp->freqs[HZ_1800], 1800.0, GSAMP_SIZE);
/* Initialize DTMF detector */
ast_dtmf_detect_init(&dsp->td.dtmf);
}
return dsp;
}
void ast_dsp_set_features(struct ast_dsp *dsp, int features)
{
dsp->features = features;
}
void ast_dsp_free(struct ast_dsp *dsp)
{
free(dsp);
}
void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold)
{
dsp->threshold = threshold;
}
void ast_dsp_set_busy_count(struct ast_dsp *dsp, int cadences)
{
Martin Pycko
committed
if (cadences < 4)
cadences = 4;
if (cadences > DSP_HISTORY)
cadences = DSP_HISTORY;
dsp->busycount = cadences;
}
void ast_dsp_digitreset(struct ast_dsp *dsp)
{
int i;
dsp->thinkdigit = 0;
if (dsp->digitmode & DSP_DIGITMODE_MF) {
memset(dsp->td.mf.digits, 0, sizeof(dsp->td.mf.digits));
dsp->td.mf.current_digits = 0;
/* Reinitialise the detector for the next block */
for (i = 0; i < 6; i++) {
goertzel_reset(&dsp->td.mf.tone_out[i]);
#ifdef OLD_DSP_ROUTINES
#endif
#ifdef OLD_DSP_ROUTINES
dsp->td.mf.energy = 0.0;
dsp->td.mf.hit1 = dsp->td.mf.hit2 = dsp->td.mf.hit3 = dsp->td.mf.hit4 = dsp->td.mf.mhit = 0;
#else
dsp->td.mf.hits[4] = dsp->td.mf.hits[3] = dsp->td.mf.hits[2] = dsp->td.mf.hits[1] = dsp->td.mf.hits[0] = dsp->td.mf.mhit = 0;
#endif
dsp->td.mf.current_sample = 0;
} else {
memset(dsp->td.dtmf.digits, 0, sizeof(dsp->td.dtmf.digits));
dsp->td.dtmf.current_digits = 0;
/* Reinitialise the detector for the next block */
for (i = 0; i < 4; i++) {
goertzel_reset(&dsp->td.dtmf.row_out[i]);
goertzel_reset(&dsp->td.dtmf.col_out[i]);
#ifdef OLD_DSP_ROUTINES
goertzel_reset(&dsp->td.dtmf.row_out2nd[i]);
goertzel_reset(&dsp->td.dtmf.col_out2nd[i]);
#endif
#ifdef OLD_DSP_ROUTINES
dsp->td.dtmf.hit1 = dsp->td.dtmf.hit2 = dsp->td.dtmf.hit3 = dsp->td.dtmf.hit4 = dsp->td.dtmf.mhit = 0;
#else
dsp->td.dtmf.hits[2] = dsp->td.dtmf.hits[1] = dsp->td.dtmf.hits[0] = dsp->td.dtmf.mhit = 0;
#endif
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
dsp->td.dtmf.energy = 0.0;
dsp->td.dtmf.current_sample = 0;
}
}
void ast_dsp_reset(struct ast_dsp *dsp)
{
int x;
dsp->totalsilence = 0;
dsp->gsamps = 0;
for (x=0;x<4;x++)
dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0;
memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence));
memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise));
}
int ast_dsp_digitmode(struct ast_dsp *dsp, int digitmode)
{
int new, old;
old = dsp->digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX);
new = digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX);
if (old != new) {
/* Must initialize structures if switching from MF to DTMF or vice-versa */
if (new & DSP_DIGITMODE_MF)
ast_mf_detect_init(&dsp->td.mf);
else
ast_dtmf_detect_init(&dsp->td.dtmf);
}
dsp->digitmode = digitmode;
return 0;
}