root/src/testtones.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. teletone_handler
  2. main
  3. main

   1 #include "private/ftdm_core.h"
   2 
   3 struct ttmp {
   4         int fd;
   5 };
   6 
   7 static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
   8 {
   9         struct ttmp *tmp = ts->user_data;
  10         int wrote;
  11         size_t len;
  12 
  13         wrote = teletone_mux_tones(ts, map);
  14         len = write(tmp->fd, ts->buffer, wrote * 2);
  15         
  16         if (!len) return -1;
  17 
  18         return 0;
  19 }
  20 
  21 #if 1
  22 int main(int argc, char *argv[])
  23 {
  24         teletone_generation_session_t ts;
  25         struct ttmp tmp;
  26 
  27         if (argc < 3) {
  28                 fprintf(stderr, "Arg Error! <file> <tones>\n");
  29                 exit(-1);
  30         }
  31 
  32         if ((tmp.fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR)) < 0) {
  33                 fprintf(stderr, "File Error! [%s]\n", strerror(errno));
  34                 exit(-1);
  35         }
  36 
  37         teletone_init_session(&ts, 0, teletone_handler, &tmp);
  38         ts.rate = 8000;
  39         ts.debug = 1;
  40         ts.debug_stream = stdout;
  41         teletone_run(&ts, argv[2]);
  42         close(tmp.fd);
  43 
  44         return 0;
  45 }
  46 #else 
  47 int32_t main(int argc, char *argv[])
  48 {
  49         int32_t j, i, fd = -1;
  50         int32_t rate = 8000;
  51         /* SIT tones and durations */
  52         float tones[] = { 913.8, 1370.6, 1776.7, 0 };
  53         int32_t durations[] = {274, 274, 380, 0};
  54         teletone_dds_state_t dds = {0};
  55         int16_t sample;
  56         size_t len = 1;
  57 
  58         if (argc < 2 || (fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR)) < 0) {
  59                 fprintf(stderr, "File Error!\n", strerror(errno));
  60                 exit(-1);
  61         }
  62 
  63         for (j = 0; tones[j] && durations[j]; j++) {
  64 
  65                 teletone_dds_state_set_tone(&dds, tones[j], rate, -50);
  66                 
  67                 for(i = 0; (i < durations[j] * rate / 1000) && len != 0; i++) {
  68                         sample = teletone_dds_modulate_sample(&dds) * 20;
  69                         len = write(fd, &sample, sizeof(sample));
  70                 }
  71 
  72         }
  73         
  74         close(fd);
  75 }
  76 #endif

/* [<][>][^][v][top][bottom][index][help] */