Changeset 5553:a17285dc6fd6 in roaraudio
- Timestamp:
- 07/05/12 16:12:28 (11 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
include/libroardsp/dtmf.h
r5547 r5553 41 41 #define ROAR_DTMF_OPTIONS_NONE 0 42 42 43 #define ROAR_DTMF_CHAR_DTMF(x) (((x) & 0x FF) + 0x0000)44 #define ROAR_DTMF_CHAR_ROAR(x) (((x) & 0x FF) + 0x0100)45 #define ROAR_DTMF_CHAR_BYTE(x) (((x) & 0x FF) + 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) 46 46 47 #define ROAR_DTMF_CHAR_BREAK ((uint16_t)0) 47 48 #define ROAR_DTMF_CHAR_NOOP ROAR_DTMF_CHAR_ROAR(0) 48 49 #define ROAR_DTMF_CHAR_ESCAPE ROAR_DTMF_CHAR_ROAR(27) … … 53 54 int roar_dtmf_tone (int16_t * samples, const size_t len, const uint32_t rate, const int options, const uint16_t c); 54 55 56 uint16_t roar_dtmf_freqs2char(const int options, float f0, float f1); 57 55 58 #endif 56 59 -
libroardsp/dtmf.c
r5547 r5553 158 158 }; 159 159 160 static const struct tone * __lookup_tone (const int options, uint16_t c) {160 static const struct tone * __lookup_tone_by_char(const int options, uint16_t c) { 161 161 size_t i; 162 162 163 163 (void)options; 164 164 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 ) 166 168 c -= 'a' - 'A'; 167 169 … … 170 172 return &(_roardsp_tones[i]); 171 173 } 174 } 175 176 roar_err_set(ROAR_ERROR_NOENT); 177 return NULL; 178 } 179 180 static 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; 172 203 } 173 204 … … 190 221 } 191 222 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); 193 227 194 228 if ( ct == NULL ) { … … 209 243 } 210 244 245 uint16_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 } 211 252 212 253 //ll -
roarclients/roardtmf.c
r5547 r5553 137 137 } 138 138 } 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); 140 141 if ( roar_vs_write(vss, buf, len, &err) != (ssize_t)len ) { 141 142 fprintf(stderr, "Error: can not write data: %s\n", roar_vs_strerr(err));
Note: See TracChangeset
for help on using the changeset viewer.