76 #define normalize_to_16bit(n) if (n > SMAX) n = SMAX; else if (n < SMIN) n = SMIN;
79 #pragma warning(disable:4706)
83 0x00c9, 0x025b, 0x03ed, 0x057f, 0x0711, 0x08a2, 0x0a33, 0x0bc4,
84 0x0d54, 0x0ee4, 0x1073, 0x1201, 0x138f, 0x151c, 0x16a8, 0x1833,
85 0x19be, 0x1b47, 0x1cd0, 0x1e57, 0x1fdd, 0x2162, 0x22e5, 0x2467,
86 0x25e8, 0x2768, 0x28e5, 0x2a62, 0x2bdc, 0x2d55, 0x2ecc, 0x3042,
87 0x31b5, 0x3327, 0x3497, 0x3604, 0x3770, 0x38d9, 0x3a40, 0x3ba5,
88 0x3d08, 0x3e68, 0x3fc6, 0x4121, 0x427a, 0x43d1, 0x4524, 0x4675,
89 0x47c4, 0x490f, 0x4a58, 0x4b9e, 0x4ce1, 0x4e21, 0x4f5e, 0x5098,
90 0x51cf, 0x5303, 0x5433, 0x5560, 0x568a, 0x57b1, 0x58d4, 0x59f4,
91 0x5b10, 0x5c29, 0x5d3e, 0x5e50, 0x5f5e, 0x6068, 0x616f, 0x6272,
92 0x6371, 0x646c, 0x6564, 0x6657, 0x6747, 0x6832, 0x691a, 0x69fd,
93 0x6add, 0x6bb8, 0x6c8f, 0x6d62, 0x6e31, 0x6efb, 0x6fc2, 0x7083,
94 0x7141, 0x71fa, 0x72af, 0x735f, 0x740b, 0x74b3, 0x7556, 0x75f4,
95 0x768e, 0x7723, 0x77b4, 0x7840, 0x78c8, 0x794a, 0x79c9, 0x7a42,
96 0x7ab7, 0x7b27, 0x7b92, 0x7bf9, 0x7c5a, 0x7cb7, 0x7d0f, 0x7d63,
97 0x7db1, 0x7dfb, 0x7e3f, 0x7e7f, 0x7eba, 0x7ef0, 0x7f22, 0x7f4e,
98 0x7f75, 0x7f98, 0x7fb5, 0x7fce, 0x7fe2, 0x7ff1, 0x7ffa, 0x7fff
110 ts->TONES[index].freqs[i++] = x;
136 memset(ts, 0,
sizeof(*ts));
141 ts->tmp_duration = -1;
143 ts->handler = handler;
144 ts->user_data = user_data;
147 ts->decay_factor = 1;
217 float vol = ts->volume;
220 duration = (ts->tmp_duration > -1) ? ts->tmp_duration : ts->duration;
221 wait = (ts->tmp_wait > -1) ? ts->tmp_wait : ts->wait;
223 if (map->freqs[0] > 0) {
224 for (freqlen = 0; freqlen < TELETONE_MAX_TONES && map->freqs[freqlen]; freqlen++) {
229 if (ts->channels > 1) {
230 duration *= ts->channels;
239 for (ts->samples = 0; ts->samples < ts->datalen && ts->samples < duration; ts->samples++) {
240 if (ts->decay_direction && ++dc >= ts->decay_step) {
241 float nvol = vol + ts->decay_direction * ts->decay_factor;
246 for (j = 0; j < TELETONE_MAX_TONES && map->freqs[j]; j++) {
255 for (i = 0; i < freqlen; i++) {
262 for (c = 1; c < ts->channels; c++) {
263 ts->buffer[ts->samples+1] = ts->buffer[ts->samples];
274 for (c = 0; c < ts->channels; c++) {
275 for (i = 0; i < wait && ts->samples < ts->datalen; i++) {
276 ts->buffer[ts->samples++] = 0;
280 if (ts->debug && ts->debug_stream) {
281 if (map->freqs[0] <= 0) {
282 fprintf(ts->debug_stream,
"wait %d (%dms)\n", wait, wait / (ts->rate / 1000));
284 fprintf(ts->debug_stream,
"Generate: (");
286 for (i = 0; i < TELETONE_MAX_TONES && map->freqs[i]; i++) {
287 fprintf(ts->debug_stream,
"%s%0.2f", i == 0 ?
"" :
"+",map->freqs[i]);
290 fprintf(ts->debug_stream,
291 ") [volume %0.2fdB; samples %d(%dms) x %d channel%s; wait %d(%dms); decay_factor %0.2fdB; decay_step %d(%dms); wrote %d bytes]\n",
294 duration / (ts->rate / 1000),
296 ts->channels == 1 ?
"" :
"s",
298 wait / (ts->rate / 1000),
301 ts->decay_step / (ts->rate / 1000),
305 return ts->samples / ts->channels;
311 size_t len = strlen (s) + 1;
312 void *
new = malloc (len);
318 return (
char *) memcpy (
new, s, len);
323 char *data = NULL, *
cur = NULL, *end = NULL;
338 if (*cur ==
' ' || *cur ==
'\r' || *cur ==
'\n') {
343 if ((end = strchr(cur,
';')) != 0) {
347 if (*(cur + 1) ==
'=') {
350 ts->channels = atoi(cur + 2);
353 ts->rate = atoi(cur + 2);
356 ts->duration = atoi(cur + 2) * (ts->rate / 1000);
360 float vol = (float)atof(cur + 2);
367 ts->decay_step = atoi(cur + 2) * (ts->rate / 1000);
368 ts->decay_direction = -1;
371 ts->decay_step = atoi(cur + 2) * (ts->rate / 1000);
372 ts->decay_direction = 1;
375 ts->decay_factor = (float)atof(cur + 2);
378 ts->wait = atoi(cur + 2) * (ts->rate / 1000);
381 ts->loops = atoi(cur + 2);
386 if ((L = atoi(cur + 2)) > 0) {
395 char *p = NULL, *e = NULL;
398 if (*cur ==
' ' || *cur ==
'\r' || *cur ==
'\n') {
403 ts->tmp_duration = -1;
406 memset(&mymap, 0,
sizeof(mymap));
408 if (*(cur + 1) ==
'(') {
413 if ((e = strchr(p,
')')) != 0) {
417 #if (_MSC_VER == 1600)
422 if ((next = strchr(p,
',')) != 0) {
426 ts->tmp_duration = atoi(p) * (ts->rate / 1000);
429 ts->tmp_wait = atoi(p) * (ts->rate / 1000);
432 mymap.
freqs[i++ - 2] = atof(p);
437 if (i > 2 && *cur ==
'%') {
439 }
else if ((i != 2 || *cur ==
'%')) {
440 if (ts->debug && ts->debug_stream) {
441 fprintf(ts->debug_stream,
"Syntax Error!\n");
450 mapp = &ts->TONES[(int)*cur];
451 }
else if (ts->debug && ts->debug_stream) {
452 fprintf(ts->debug_stream,
"Map [%c] Out Of Range!\n", *cur);
457 if (mapp->
freqs[0]) {
460 ts->handler(ts, mapp);
466 }
else if (ts->debug && ts->debug_stream) {
467 fprintf(ts->debug_stream,
"Ignoring Empty Map [%c]!\n", *cur);
#define TELETONE_API_DATA
static __inline__ int16_t teletone_dds_state_modulate_sample(teletone_dds_state_t *dds, uint32_t pindex)
#define TELETONE_MAX_TONES
An abstraction to store a tone mapping.
static char * my_strdup(const char *s)
teletone_audio_t * buffer
double teletone_process_t
int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map)
Execute a single tone generation instruction.
int teletone_destroy_session(teletone_generation_session_t *ts)
Free the buffer allocated by a tone generation session.
static __inline__ int teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, uint32_t pindex)
#define TELETONE_API(type)
int teletone_run(teletone_generation_session_t *ts, const char *cmd)
Execute a tone generation script and call callbacks after each instruction.
#define TELETONE_VOL_DB_MIN
int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data)
Initilize a tone generation session.
static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level)
teletone_process_t freqs[TELETONE_MAX_TONES]
int teletone_set_tone(teletone_generation_session_t *ts, int index,...)
Assign a set of tones to a tone_session indexed by a paticular index/character.
static int ensure_buffer(teletone_generation_session_t *ts, int need)
switch_byte_t switch_byte_t uint32_t buflen
#define TELETONE_TONE_RANGE
An abstraction to store a tone generation session.
int(* tone_handler)(struct teletone_generation_session *ts, teletone_tone_map_t *map)
int teletone_set_map(teletone_tone_map_t *map,...)
Assign a set of tones to a single tone map.
int16_t TELETONE_SINES[SINE_TABLE_MAX]