source: roaraudio/roarclients/roardtmf.c @ 5546:faff3e9677c4

Last change on this file since 5546:faff3e9677c4 was 5546:faff3e9677c4, checked in by phi, 12 years ago

Started DTMF library

File size: 3.5 KB
RevLine 
[3343]1//roardtmf.c:
2
3/*
[5381]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012
[3343]5 *
6 *  This file is part of roarclients a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
[3517]21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
[3343]23 *
24 */
25
26#include <roaraudio.h>
[5546]27#include <libroardsp/libroardsp.h>
[3344]28
29#ifdef ROAR_HAVE_LIBM
[3343]30#include <math.h>
31
32// in ms:
[5546]33#if 0
[3343]34#define ON_TIME  (180)
35#define OFF_TIME ( 80)
[5546]36#else
37#define ON_TIME  (180)
38#define OFF_TIME ( 80)
39#endif
[3343]40#define SUM_TIME (ON_TIME+OFF_TIME)
41
42void usage (void) {
[3508]43 printf("roardtmf [OPTIONS]... PHONE NUMBER\n");
[3343]44
45 printf("\nOptions:\n\n");
46
47 printf("  --server SERVER    - Set server hostname\n"
[5533]48        "  --rate  -R RATE    - Set sample rate\n"
[3343]49        "  --help             - Show this help\n"
50       );
51
52}
53
54int main (int argc, char * argv[]) {
55 int    rate     = ROAR_RATE_DEFAULT;
[5534]56 const char * server   = NULL;
57 const char * k;
[3343]58 int    i;
[5534]59 const char * name = "roardtmf";
[4929]60 roar_vs_t * vss = NULL;
[5534]61 const char * tones = NULL;
[3343]62 void * buf;
[5546]63 size_t len_break;
64 size_t len_tone;
[3343]65 size_t samples;
66 size_t len;
[3346]67 char   c;
[5249]68 int err;
[3343]69
70 for (i = 1; i < argc; i++) {
71  k = argv[i];
72
73  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
74   server = argv[++i];
[5533]75  } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) {
[4883]76   rate = roar_str2rate(argv[++i]);
[3343]77  } else if ( !strcmp(k, "--help") ) {
78   usage();
79   return 0;
80  } else if ( tones == NULL ) {
81   tones = argv[i++];
82  } else {
83   fprintf(stderr, "Error: unknown argument: %s\n", k);
84   usage();
85   return 1;
86  }
87 }
88
89 if ( tones == NULL ) {
90  return 1;
91 }
92
[5546]93 len_break = roar_dtmf_mus2samples(OFF_TIME * 1000, rate);
94 len_tone  = roar_dtmf_mus2samples(ON_TIME  * 1000, rate);
95 samples = len_break + len_tone;
[3343]96
[5546]97 printf("samples=%llu\n", (long long unsigned int)samples);
[3343]98/*
99 return 0;
100*/
101
[4929]102 if ( (buf = roar_mm_malloc((len = 16*samples/8))) == NULL )
[3343]103  return 4;
104
[5249]105 if ( (vss = roar_vs_new_playback(server, name, rate, 1, ROAR_CODEC_DEFAULT, 16, &err)) == NULL ) {
106  fprintf(stderr, "Error: can not start playback: %s\n", roar_vs_strerr(err));
[4014]107  roar_mm_free(buf);
[3343]108  return 1;
109 }
110
[3346]111 while ( (c = *tones) != 0 ) {
112  tones++;
113
[5249]114  if ( c == '+' || c == '.' || c == '_' )
[3346]115   continue;
116
[5249]117  if ( c == ' ' ) {
[5546]118   roar_dtmf_break(buf, len_tone, rate, ROAR_DTMF_OPTIONS_NONE);
[5249]119  } else {
[5546]120   if ( roar_dtmf_tone(buf, len_tone, rate, ROAR_DTMF_OPTIONS_NONE, c) == -1 ) {
[5249]121    roar_mm_free(buf);
122    return 5;
123   }
124  }
[5546]125  roar_dtmf_break(buf+len_tone*sizeof(int16_t), len_break, rate, ROAR_DTMF_OPTIONS_NONE);
[5249]126  if ( roar_vs_write(vss, buf, len, &err) != (ssize_t)len ) {
127   fprintf(stderr, "Error: can not write data: %s\n", roar_vs_strerr(err));
[4014]128   roar_mm_free(buf);
[3343]129   return 5;
[4014]130  }
[3343]131 }
132
[4929]133 roar_vs_sync(vss, ROAR_VS_WAIT, NULL);
134
135 roar_vs_close(vss, ROAR_VS_FALSE, 0);
[3343]136
[4014]137 roar_mm_free(buf);
138
[3343]139 return 0;
140}
141
[3344]142#else
143int main (void) {
144 fprintf(stderr, "Error: No Math library support compiled in.\n");
145 return 1;
146}
147#endif
148
[3343]149//ll
Note: See TracBrowser for help on using the repository browser.