Changeset 5553:a17285dc6fd6 in roaraudio


Ignore:
Timestamp:
07/05/12 16:12:28 (5 years ago)
Author:
phi
Branch:
default
Message:

some random improvements to DTMF stuff

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • include/libroardsp/dtmf.h

    r5547 r5553  
    4141#define ROAR_DTMF_OPTIONS_NONE 0 
    4242 
    43 #define ROAR_DTMF_CHAR_DTMF(x) (((x) & 0xFF) + 0x0000) 
    44 #define ROAR_DTMF_CHAR_ROAR(x) (((x) & 0xFF) + 0x0100) 
    45 #define ROAR_DTMF_CHAR_BYTE(x) (((x) & 0xFF) + 0x0200) 
     43#define ROAR_DTMF_CHAR_DTMF(x) (((x) & 0x00FF) + 0x0000) 
     44#define ROAR_DTMF_CHAR_ROAR(x) (((x) & 0x00FF) + 0x0100) 
     45#define ROAR_DTMF_CHAR_BYTE(x) (((x) & 0x00FF) + 0x0200) 
    4646 
     47#define ROAR_DTMF_CHAR_BREAK   ((uint16_t)0) 
    4748#define ROAR_DTMF_CHAR_NOOP    ROAR_DTMF_CHAR_ROAR(0) 
    4849#define ROAR_DTMF_CHAR_ESCAPE  ROAR_DTMF_CHAR_ROAR(27) 
     
    5354int roar_dtmf_tone (int16_t * samples, const size_t len, const uint32_t rate, const int options, const uint16_t c); 
    5455 
     56uint16_t roar_dtmf_freqs2char(const int options, float f0, float f1); 
     57 
    5558#endif 
    5659 
  • libroardsp/dtmf.c

    r5547 r5553  
    158158}; 
    159159 
    160 static const struct tone * __lookup_tone(const int options, uint16_t c) { 
     160static const struct tone * __lookup_tone_by_char(const int options, uint16_t c) { 
    161161 size_t i; 
    162162 
    163163 (void)options; 
    164164 
    165  if ( c >= 'a' ) 
     165 if ( (c >= ROAR_DTMF_CHAR_DTMF('a') && c <= ROAR_DTMF_CHAR_DTMF('z')) || 
     166      (c >= ROAR_DTMF_CHAR_ROAR('a') && c <= ROAR_DTMF_CHAR_ROAR('z')) 
     167    ) 
    166168  c -= 'a' - 'A'; 
    167169 
     
    170172   return &(_roardsp_tones[i]); 
    171173  } 
     174 } 
     175 
     176 roar_err_set(ROAR_ERROR_NOENT); 
     177 return NULL; 
     178} 
     179 
     180static const struct tone * __lookup_tone_by_freq(const int options, float f0, float f1) { 
     181 const struct tone * ct; 
     182 size_t i; 
     183 float tmp; 
     184 
     185 (void)options; 
     186 
     187 if ( f0 > f1 ) { 
     188  tmp = f0; 
     189  f0 = f1; 
     190  f1 = tmp; 
     191 } 
     192 
     193 for (i = 0; _roardsp_tones[i].c != 0; i++) { 
     194  ct = &(_roardsp_tones[i]); 
     195 
     196  // allow 3.5% freq error as defined in ITU-T Q.23 and Q.24. 
     197 
     198  if ( ct->f0 < f0*.965 || ct->f0 > f0*1.035 ) 
     199   continue; 
     200  if ( ct->f1 < f1*.965 || ct->f1 > f1*1.035 ) 
     201   continue; 
     202  return ct; 
    172203 } 
    173204 
     
    190221 } 
    191222 
    192  ct = __lookup_tone(options, c); 
     223 if ( c == ROAR_DTMF_CHAR_BREAK ) 
     224  return roar_dtmf_break(samples, len, rate, options); 
     225 
     226 ct = __lookup_tone_by_char(options, c); 
    193227 
    194228 if ( ct == NULL ) { 
     
    209243} 
    210244 
     245uint16_t roar_dtmf_freqs2char(const int options, float f0, float f1) { 
     246 const struct tone * ct = __lookup_tone_by_freq(options, f0, f1); 
     247 
     248 if ( ct == NULL ) 
     249  return ROAR_DTMF_CHAR_BREAK; 
     250 return ct->c; 
     251} 
    211252 
    212253//ll 
  • roarclients/roardtmf.c

    r5547 r5553  
    137137   } 
    138138  } 
    139   roar_dtmf_break(buf+len_tone*sizeof(int16_t), len_break, rate, ROAR_DTMF_OPTIONS_NONE); 
     139  roar_dtmf_tone(buf+len_tone*sizeof(int16_t), len_break, rate, ROAR_DTMF_OPTIONS_NONE, 
     140                 mode == MODE_DTMF ? ROAR_DTMF_CHAR_BREAK : ROAR_DTMF_CHAR_NOOP); 
    140141  if ( roar_vs_write(vss, buf, len, &err) != (ssize_t)len ) { 
    141142   fprintf(stderr, "Error: can not write data: %s\n", roar_vs_strerr(err)); 
Note: See TracChangeset for help on using the changeset viewer.