2010-01-15 19:22:49 +00:00
|
|
|
//#include "freetdm.h"
|
2007-11-17 01:39:28 +00:00
|
|
|
#include "libteletone_detect.h"
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int fd, b;
|
|
|
|
short sln[512] = {0};
|
|
|
|
teletone_dtmf_detect_state_t dtmf_detect = {0};
|
2011-09-16 17:13:25 +00:00
|
|
|
teletone_hit_type_t hit;
|
2007-11-17 01:39:28 +00:00
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
fprintf(stderr, "Arg Error!\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
teletone_dtmf_detect_init (&dtmf_detect, 8000);
|
|
|
|
|
|
|
|
if ((fd = open(argv[1], O_RDONLY)) < 0) {
|
2008-09-06 05:46:14 +00:00
|
|
|
fprintf(stderr, "File Error! [%s]\n", strerror(errno));
|
2007-11-17 01:39:28 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
while((b = read(fd, sln, 320)) > 0) {
|
2011-09-16 15:05:43 +00:00
|
|
|
char digit_char;
|
|
|
|
unsigned int dur;
|
|
|
|
|
2007-11-17 01:39:28 +00:00
|
|
|
teletone_dtmf_detect(&dtmf_detect, sln, b / 2);
|
2011-09-16 15:05:43 +00:00
|
|
|
if ((hit = teletone_dtmf_get(&dtmf_detect, &digit_char, &dur))) {
|
2011-09-16 17:13:25 +00:00
|
|
|
const char *hs = NULL;
|
2011-09-16 15:05:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
switch(hit) {
|
|
|
|
case TT_HIT_BEGIN:
|
|
|
|
hs = "begin";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TT_HIT_MIDDLE:
|
|
|
|
hs = "middle";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TT_HIT_END:
|
|
|
|
hs = "end";
|
|
|
|
break;
|
2011-09-16 17:13:25 +00:00
|
|
|
default:
|
|
|
|
break;
|
2011-09-16 15:05:43 +00:00
|
|
|
}
|
|
|
|
|
2011-09-16 17:13:25 +00:00
|
|
|
printf("%s digit: %c\n", hs, digit_char);
|
2007-11-17 01:39:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close(fd);
|
2008-09-06 05:46:14 +00:00
|
|
|
return 0;
|
2007-11-17 01:39:28 +00:00
|
|
|
}
|
|
|
|
|