Changeset 5546:faff3e9677c4 in roaraudio


Ignore:
Timestamp:
06/17/12 15:31:52 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Started DTMF library

Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r5544 r5546  
    66        * Done more hardending work. 
    77        * Improved error handling (including on win32) (Closes: #235) 
     8        * Added small DTMF library. 
    89 
    910v. 1.0beta2 - Wed Jun 06 2012 19:56 CEST 
  • include/libroardsp/libroardsp.h

    r5381 r5546  
    5858#include "filters.h" 
    5959#include "codecs.h" 
     60#include "dtmf.h" 
    6061#include "transcode.h" 
    6162#include "vio_transcode.h" 
  • libroardsp/Makefile

    r5270 r5546  
    55 
    66TARGETS=$(SLIB) libroardsp.a 
    7 OBJS=libroardsp.o convert.o midside.o poly.o filter.o filterchain.o remove.o transcode.o vio_transcode.o rms.o fader.o mixer.o amp.o interleave.o channels.o resampler_poly3.o float.o 
     7OBJS=libroardsp.o convert.o midside.o poly.o filter.o filterchain.o remove.o transcode.o vio_transcode.o rms.o fader.o mixer.o amp.o interleave.o channels.o resampler_poly3.o float.o dtmf.o 
    88OLDROAR=midi.o 
    99FILTER=filter_lowp.o filter_highp.o filter_amp.o filter_quantify.o filter_add.o filter_clip.o filter_downmix.o filter_dcblock.o filter_swap.o filter_agc.o filter_speex_prep.o filter_responsecurve.o 
  • roarclients/Makefile

    r5516 r5546  
    33TARGETS_IO=roarcat roarcatplay roarcatvio roarbidir roarmon roarmonhttp roarradio 
    44TARGETS_CTL=roarctl roarlight roarinterconnect roarclientpass 
    5 TARGETS_DSP=roarfilt roarvumeter 
     5TARGETS_DSP=roarfilt roarvumeter roardtmf 
    66TARGETS_MISC=roarsockconnect roarphone roarshout 
    7 TARGETS_M=roardtmf 
     7TARGETS_M= 
    88TARGETS_VIO=roarvio 
    99TARGETS_PLUGINS=roarpluginrunner roarpluginapplication 
     
    7878        ${CC} ${LDFLAGS} -o roarvumeter roarvumeter.o $(LIBS) $(LIBROARDSP) $(lib_m) 
    7979roardtmf: roardtmf.o 
    80         ${CC} ${LDFLAGS} -o roardtmf roardtmf.o $(LIBS) $(lib_m) 
     80        ${CC} ${LDFLAGS} -o roardtmf roardtmf.o $(LIBS) $(LIBROARDSP) 
    8181roarsockconnect: roarsockconnect.o 
    8282        $L 
  • roarclients/roardtmf.c

    r5545 r5546  
    2525 
    2626#include <roaraudio.h> 
     27#include <libroardsp/libroardsp.h> 
    2728 
    2829#ifdef ROAR_HAVE_LIBM 
     
    3031 
    3132// in ms: 
     33#if 0 
    3234#define ON_TIME  (180) 
    3335#define OFF_TIME ( 80) 
     36#else 
     37#define ON_TIME  (180) 
     38#define OFF_TIME ( 80) 
     39#endif 
    3440#define SUM_TIME (ON_TIME+OFF_TIME) 
    35  
    36 struct tone { 
    37  char c; 
    38  float f0; 
    39  float f1; 
    40 } g_tones[] = { 
    41  {'1', 697, 1209}, 
    42  {'2', 697, 1336}, 
    43  {'3', 697, 1477}, 
    44  {'A', 697, 1633}, 
    45  
    46  {'4', 770, 1209}, 
    47  {'5', 770, 1336}, 
    48  {'6', 770, 1477}, 
    49  {'B', 770, 1633}, 
    50  
    51  {'7', 852, 1209}, 
    52  {'8', 852, 1336}, 
    53  {'9', 852, 1477}, 
    54  {'C', 852, 1633}, 
    55  
    56  {'*', 941, 1209}, 
    57  {'0', 941, 1336}, 
    58  {'#', 941, 1477}, 
    59  {'D', 941, 1633}, 
    60  
    61  {0, -1, -1} 
    62 }; 
    6341 
    6442void usage (void) { 
     
    7452} 
    7553 
    76 int calc_break (int16_t * samples, size_t len, int rate, char c) { 
    77  (void)rate, (void)c; 
    78 // printf("calc_break(*): len=%zu\n", len); 
    79  memset(samples, 0, len); 
    80  return 0; 
    81 } 
    82  
    83 int calc_tone (int16_t * samples, size_t len, int rate, char c) { 
    84  struct tone * ct = NULL; 
    85  int i; 
    86  float t; 
    87  float t_inc = 1./rate; 
    88  float t_max = ON_TIME / 1000.; 
    89  float fc0, fc1; 
    90  
    91 // printf("calc_tone(*): len=%zu\n", len); 
    92  
    93 // printf("calc(*): t_inc=%f, t_max=%f\n", t_inc, t_max); 
    94  
    95  if ( c >= 'a' ) 
    96   c -= 'a' - 'A'; 
    97  
    98  for (i = 0; g_tones[i].c != 0; i++) { 
    99   if ( g_tones[i].c == c ) { 
    100    ct = &(g_tones[i]); 
    101    break; 
    102   } 
    103  } 
    104  
    105 // printf("calc(*): ct=%p\n", ct); 
    106  
    107  if ( ct == NULL ) 
    108   return -1; 
    109  
    110  fc0 = 2 * M_PI * ct->f0; 
    111  fc1 = 2 * M_PI * ct->f1; 
    112  
    113 // printf("fc0=%f, fc1=%f\n", fc0, fc1); 
    114  
    115  memset(samples, 0, len); 
    116  
    117  for (i = 0, t = 0; t < t_max; t += t_inc, i++) { 
    118 //  printf("i=%i, t=%f\n", i, t); 
    119   samples[i] = (sinf(fc0*t) + sinf(fc1*t))*8192.0; 
    120  } 
    121  
    122 // printf("i=%i\n", i); 
    123  
    124  return 0; 
    125 } 
    126  
    12754int main (int argc, char * argv[]) { 
    12855 int    rate     = ROAR_RATE_DEFAULT; 
     
    13461 const char * tones = NULL; 
    13562 void * buf; 
     63 size_t len_break; 
     64 size_t len_tone; 
    13665 size_t samples; 
    13766 size_t len; 
     
    16291 } 
    16392 
    164  samples = SUM_TIME * rate / 1000; 
     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; 
    16596 
     97 printf("samples=%llu\n", (long long unsigned int)samples); 
    16698/* 
    167  printf("samples=%llu\n", (long long unsigned int)samples); 
    16899 return 0; 
    169100*/ 
     
    185116 
    186117  if ( c == ' ' ) { 
    187    calc_break(buf, len, rate, c); 
     118   roar_dtmf_break(buf, len_tone, rate, ROAR_DTMF_OPTIONS_NONE); 
    188119  } else { 
    189    if ( calc_tone(buf, len, rate, c) == -1 ) { 
     120   if ( roar_dtmf_tone(buf, len_tone, rate, ROAR_DTMF_OPTIONS_NONE, c) == -1 ) { 
    190121    roar_mm_free(buf); 
    191122    return 5; 
    192123   } 
    193124  } 
     125  roar_dtmf_break(buf+len_tone*sizeof(int16_t), len_break, rate, ROAR_DTMF_OPTIONS_NONE); 
    194126  if ( roar_vs_write(vss, buf, len, &err) != (ssize_t)len ) { 
    195127   fprintf(stderr, "Error: can not write data: %s\n", roar_vs_strerr(err)); 
Note: See TracChangeset for help on using the changeset viewer.