RTS API Documentation  1.10.11
Data Structures | Macros | Typedefs | Functions | Variables
libteletone_generate.h File Reference

Tone Generation Routines. More...

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <math.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <assert.h>
#include <stdarg.h>
#include <libteletone.h>
+ Include dependency graph for libteletone_generate.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  teletone_dds_state
 
struct  teletone_generation_session
 An abstraction to store a tone generation session. More...
 

Macros

#define TELETONE_VOL_DB_MAX   0
 
#define TELETONE_VOL_DB_MIN   -63
 
#define MAX_PHASE_TONES   4
 
#define SINE_TABLE_MAX   128
 
#define SINE_TABLE_LEN   (SINE_TABLE_MAX - 1)
 
#define MAX_PHASE_ACCUMULATOR   0x10000 * 0x10000
 
#define DBM0_MAX_POWER   (3.14f + 3.02f)
 

Typedefs

typedef struct teletone_dds_state teletone_dds_state_t
 
typedef int16_t teletone_audio_t
 
typedef int(* tone_handler) (struct teletone_generation_session *ts, teletone_tone_map_t *map)
 
typedef struct teletone_generation_session teletone_generation_session_t
 

Functions

float powf (float, float)
 
static __inline__ int32_t teletone_dds_phase_rate (teletone_process_t tone, uint32_t rate)
 
static __inline__ int16_t teletone_dds_state_modulate_sample (teletone_dds_state_t *dds, uint32_t pindex)
 
static __inline__ void teletone_dds_state_set_tx_level (teletone_dds_state_t *dds, float tx_level)
 
static __inline__ void teletone_dds_state_reset_accum (teletone_dds_state_t *dds)
 
static __inline__ int teletone_dds_state_set_tone (teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, uint32_t pindex)
 
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. More...
 
int teletone_set_map (teletone_tone_map_t *map,...)
 Assign a set of tones to a single tone map. More...
 
int teletone_init_session (teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data)
 Initilize a tone generation session. More...
 
int teletone_destroy_session (teletone_generation_session_t *ts)
 Free the buffer allocated by a tone generation session. More...
 
int teletone_mux_tones (teletone_generation_session_t *ts, teletone_tone_map_t *map)
 Execute a single tone generation instruction. More...
 
int teletone_run (teletone_generation_session_t *ts, const char *cmd)
 Execute a tone generation script and call callbacks after each instruction. More...
 

Variables

int16_t TELETONE_SINES [SINE_TABLE_MAX]
 

Detailed Description

Tone Generation Routines.

This module is responsible for tone generation specifics

Definition in file libteletone_generate.h.

Macro Definition Documentation

◆ DBM0_MAX_POWER

#define DBM0_MAX_POWER   (3.14f + 3.02f)

Definition at line 147 of file libteletone_generate.h.

Referenced by teletone_dds_state_set_tx_level().

◆ MAX_PHASE_ACCUMULATOR

#define MAX_PHASE_ACCUMULATOR   0x10000 * 0x10000

Definition at line 144 of file libteletone_generate.h.

Referenced by teletone_dds_phase_rate().

◆ MAX_PHASE_TONES

#define MAX_PHASE_TONES   4

◆ SINE_TABLE_LEN

#define SINE_TABLE_LEN   (SINE_TABLE_MAX - 1)

Definition at line 143 of file libteletone_generate.h.

Referenced by teletone_dds_state_modulate_sample().

◆ SINE_TABLE_MAX

#define SINE_TABLE_MAX   128

Definition at line 142 of file libteletone_generate.h.

Referenced by teletone_dds_state_modulate_sample().

◆ TELETONE_VOL_DB_MAX

#define TELETONE_VOL_DB_MAX   0

Definition at line 130 of file libteletone_generate.h.

◆ TELETONE_VOL_DB_MIN

#define TELETONE_VOL_DB_MIN   -63

Definition at line 131 of file libteletone_generate.h.

Referenced by teletone_mux_tones(), and teletone_run().

Typedef Documentation

◆ teletone_audio_t

typedef int16_t teletone_audio_t

Definition at line 208 of file libteletone_generate.h.

◆ teletone_dds_state_t

Definition at line 140 of file libteletone_generate.h.

◆ teletone_generation_session_t

Definition at line 257 of file libteletone_generate.h.

◆ tone_handler

typedef int(* tone_handler) (struct teletone_generation_session *ts, teletone_tone_map_t *map)

Definition at line 210 of file libteletone_generate.h.

Function Documentation

◆ powf()

float powf ( float  ,
float   
)

◆ teletone_dds_phase_rate()

static __inline__ int32_t teletone_dds_phase_rate ( teletone_process_t  tone,
uint32_t  rate 
)
static

Definition at line 151 of file libteletone_generate.h.

References MAX_PHASE_ACCUMULATOR.

Referenced by teletone_dds_state_set_tone().

152 {
153  return (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate);
154 }
#define MAX_PHASE_ACCUMULATOR

◆ teletone_dds_state_modulate_sample()

static __inline__ int16_t teletone_dds_state_modulate_sample ( teletone_dds_state_t dds,
uint32_t  pindex 
)
static

Definition at line 156 of file libteletone_generate.h.

References MAX_PHASE_TONES, teletone_dds_state::phase_accumulator, teletone_dds_state::phase_rate, teletone_dds_state::scale_factor, SINE_TABLE_LEN, SINE_TABLE_MAX, and TELETONE_SINES.

Referenced by teletone_mux_tones().

157 {
158  int32_t bitmask = dds->phase_accumulator, sine_index = (bitmask >>= 23) & SINE_TABLE_LEN;
159  int16_t sample;
160 
161  if (pindex >= MAX_PHASE_TONES) {
162  pindex = 0;
163  }
164 
165  if (bitmask & SINE_TABLE_MAX) {
166  sine_index = SINE_TABLE_LEN - sine_index;
167  }
168 
169  sample = TELETONE_SINES[sine_index];
170 
171  if (bitmask & (SINE_TABLE_MAX * 2)) {
172  sample *= -1;
173  }
174 
175  dds->phase_accumulator += dds->phase_rate[pindex];
176  return (int16_t) (sample * dds->scale_factor >> 15);
177 }
uint32_t phase_rate[MAX_PHASE_TONES]
#define SINE_TABLE_LEN
#define MAX_PHASE_TONES
int16_t TELETONE_SINES[SINE_TABLE_MAX]
#define SINE_TABLE_MAX

◆ teletone_dds_state_reset_accum()

static __inline__ void teletone_dds_state_reset_accum ( teletone_dds_state_t dds)
static

Definition at line 185 of file libteletone_generate.h.

References teletone_dds_state::phase_accumulator.

186 {
187  dds->phase_accumulator = 0;
188 }

◆ teletone_dds_state_set_tone()

static __inline__ int teletone_dds_state_set_tone ( teletone_dds_state_t dds,
teletone_process_t  tone,
uint32_t  rate,
uint32_t  pindex 
)
static

Definition at line 190 of file libteletone_generate.h.

References MAX_PHASE_TONES, teletone_dds_state::phase_rate, and teletone_dds_phase_rate().

Referenced by teletone_mux_tones().

191 {
192  if (pindex < MAX_PHASE_TONES) {
193  dds->phase_rate[pindex] = teletone_dds_phase_rate(tone, rate);
194  return 0;
195  }
196 
197  return -1;
198 }
uint32_t phase_rate[MAX_PHASE_TONES]
static __inline__ int32_t teletone_dds_phase_rate(teletone_process_t tone, uint32_t rate)
#define MAX_PHASE_TONES

◆ teletone_dds_state_set_tx_level()

static __inline__ void teletone_dds_state_set_tx_level ( teletone_dds_state_t dds,
float  tx_level 
)
static

Definition at line 179 of file libteletone_generate.h.

References DBM0_MAX_POWER, powf(), teletone_dds_state::scale_factor, and teletone_dds_state::tx_level.

Referenced by teletone_mux_tones().

180 {
181  dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f));
182  dds->tx_level = tx_level;
183 }
#define DBM0_MAX_POWER
teletone_process_t tx_level
float powf(float, float)

◆ teletone_destroy_session()

int teletone_destroy_session ( teletone_generation_session_t ts)

Free the buffer allocated by a tone generation session.

Parameters
tsthe tone generation session to destroy
Returns
0

Definition at line 177 of file libteletone_generate.c.

References teletone_generation_session::buffer, and teletone_generation_session::samples.

Referenced by inband_dtmf_generate_callback(), main(), setup_ringback(), switch_ivr_gentones(), switch_ivr_originate(), and switch_ivr_wait_for_answer().

178 {
179  if (ts->buffer) {
180  free(ts->buffer);
181  ts->buffer = NULL;
182  ts->samples = 0;
183  }
184  return 0;
185 }

◆ teletone_init_session()

int teletone_init_session ( teletone_generation_session_t ts,
int  buflen,
tone_handler  handler,
void *  user_data 
)

Initilize a tone generation session.

Parameters
tsthe tone generation session to initilize
buflenthe size of the buffer(in samples) to dynamically allocate
handlera callback function to execute when a tone generation instruction is complete
user_dataoptional user data to send
Returns
0

Definition at line 134 of file libteletone_generate.c.

References teletone_generation_session::buffer, buflen, teletone_generation_session::channels, teletone_generation_session::datalen, teletone_generation_session::decay_factor, teletone_generation_session::decay_step, teletone_generation_session::duration, teletone_generation_session::dynamic, teletone_generation_session::handler, memset(), teletone_generation_session::rate, teletone_set_tone(), teletone_generation_session::tmp_duration, teletone_generation_session::tmp_wait, teletone_generation_session::user_data, teletone_generation_session::volume, and teletone_generation_session::wait.

Referenced by inband_dtmf_generate_callback(), main(), setup_ringback(), switch_ivr_gentones(), and switch_ivr_wait_for_answer().

135 {
136  memset(ts, 0, sizeof(*ts));
137  ts->rate = 8000;
138  ts->channels = 1;
139  ts->duration = 2000;
140  ts->wait = 500;
141  ts->tmp_duration = -1;
142  ts->tmp_wait = -1;
143  ts->handler = handler;
144  ts->user_data = user_data;
145  ts->volume = -7;
146  ts->decay_step = 0;
147  ts->decay_factor = 1;
148  if (buflen) {
149  if ((ts->buffer = calloc(buflen, sizeof(teletone_audio_t))) == 0) {
150  return -1;
151  }
152  ts->datalen = buflen;
153  } else {
154  ts->dynamic = 1024;
155  }
156  /* Add Standard DTMF Tones */
157  teletone_set_tone(ts, '1', 697.0, 1209.0, 0.0);
158  teletone_set_tone(ts, '2', 697.0, 1336.0, 0.0);
159  teletone_set_tone(ts, '3', 697.0, 1477.0, 0.0);
160  teletone_set_tone(ts, 'A', 697.0, 1633.0, 0.0);
161  teletone_set_tone(ts, '4', 770.0, 1209.0, 0.0);
162  teletone_set_tone(ts, '5', 770.0, 1336.0, 0.0);
163  teletone_set_tone(ts, '6', 770.0, 1477.0, 0.0);
164  teletone_set_tone(ts, 'B', 770.0, 1633.0, 0.0);
165  teletone_set_tone(ts, '7', 859.0, 1209.0, 0.0);
166  teletone_set_tone(ts, '8', 859.0, 1336.0, 0.0);
167  teletone_set_tone(ts, '9', 859.0, 1477.0, 0.0);
168  teletone_set_tone(ts, 'C', 859.0, 1633.0, 0.0);
169  teletone_set_tone(ts, '*', 941.0, 1209.0, 0.0);
170  teletone_set_tone(ts, '0', 941.0, 1336.0, 0.0);
171  teletone_set_tone(ts, '#', 941.0, 1477.0, 0.0);
172  teletone_set_tone(ts, 'D', 941.0, 1633.0, 0.0);
173 
174  return 0;
175 }
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.
switch_byte_t switch_byte_t uint32_t buflen
int16_t teletone_audio_t
memset(buf, 0, buflen)

◆ teletone_mux_tones()

int teletone_mux_tones ( teletone_generation_session_t ts,
teletone_tone_map_t map 
)

Execute a single tone generation instruction.

Parameters
tsthe tone generation session to consult for parameters
mapthe tone mapping to use for the frequencies
Returns
0

Definition at line 206 of file libteletone_generate.c.

References teletone_generation_session::buffer, teletone_generation_session::channels, teletone_generation_session::datalen, teletone_generation_session::debug, teletone_generation_session::debug_stream, teletone_generation_session::decay_direction, teletone_generation_session::decay_factor, teletone_generation_session::decay_step, teletone_generation_session::duration, teletone_generation_session::dynamic, ensure_buffer(), teletone_tone_map_t::freqs, memset(), teletone_generation_session::rate, teletone_generation_session::samples, teletone_dds_state_modulate_sample(), teletone_dds_state_set_tone(), teletone_dds_state_set_tx_level(), TELETONE_MAX_TONES, TELETONE_VOL_DB_MIN, teletone_generation_session::tmp_duration, teletone_generation_session::tmp_wait, teletone_generation_session::volume, and teletone_generation_session::wait.

Referenced by teletone_dtmf_generate_handler(), and teletone_handler().

207 {
208  /*teletone_process_t period = (1.0 / ts->rate) / ts->channels;*/
209  int i;
210  int freqlen = 0;
212  //int decay = 0;
213  int duration;
214  int wait = 0;
215  int32_t sample;
216  int32_t dc = 0;
217  float vol = ts->volume;
218 
219  ts->samples = 0;
220  memset(tones, 0, sizeof(tones[0]) * TELETONE_MAX_TONES);
221  duration = (ts->tmp_duration > -1) ? ts->tmp_duration : ts->duration;
222  wait = (ts->tmp_wait > -1) ? ts->tmp_wait : ts->wait;
223 
224  if (map->freqs[0] > 0) {
225  for (freqlen = 0; freqlen < TELETONE_MAX_TONES && map->freqs[freqlen]; freqlen++) {
226  teletone_dds_state_set_tone(&tones[freqlen], map->freqs[freqlen], ts->rate, 0);
227  teletone_dds_state_set_tx_level(&tones[freqlen], vol);
228  }
229 
230  if (ts->dynamic) {
231  if (ensure_buffer(ts, duration * ts->channels)) {
232  return -1;
233  }
234  }
235 
236  for (ts->samples = 0; ts->samples < ts->datalen && ts->samples < duration; ts->samples++) {
237  if (ts->decay_direction && ++dc >= ts->decay_step) {
238  float nvol = vol + ts->decay_direction * ts->decay_factor;
239  int j;
240 
241  if (nvol <= TELETONE_VOL_DB_MAX && nvol >= TELETONE_VOL_DB_MIN) {
242  vol = nvol;
243  for (j = 0; j < TELETONE_MAX_TONES && map->freqs[j]; j++) {
244  teletone_dds_state_set_tx_level(&tones[j], vol);
245  }
246  dc = 0;
247  }
248  }
249 
250  sample = 128;
251 
252  for (i = 0; i < freqlen; i++) {
253  int32_t s = teletone_dds_state_modulate_sample(&tones[i], 0);
254  sample += s;
255  }
256  if (freqlen) {
257  sample /= freqlen;
258  }
259  ts->buffer[ts->samples] = (teletone_audio_t)sample;
260  }
261  }
262 
263  if (ts->dynamic) {
264  if (ensure_buffer(ts, wait * ts->channels)) {
265  return -1;
266  }
267  }
268 
269  for (i = 0; i < wait && ts->samples < ts->datalen; i++) {
270  ts->buffer[ts->samples++] = 0;
271  }
272 
273  if (ts->debug && ts->debug_stream) {
274  if (map->freqs[0] <= 0) {
275  fprintf(ts->debug_stream, "wait %d (%dms)\n", wait, wait / (ts->rate / 1000));
276  } else {
277  fprintf(ts->debug_stream, "Generate: (");
278 
279  for (i = 0; i < TELETONE_MAX_TONES && map->freqs[i]; i++) {
280  fprintf(ts->debug_stream, "%s%0.2f", i == 0 ? "" : "+",map->freqs[i]);
281  }
282 
283  fprintf(ts->debug_stream,
284  ") [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",
285  ts->volume,
286  duration,
287  duration / (ts->rate / 1000),
288  ts->channels,
289  ts->channels == 1 ? "" : "s",
290  wait,
291  wait / (ts->rate / 1000),
292  ts->decay_factor,
293  ts->decay_step,
294  ts->decay_step / (ts->rate / 1000),
295  ts->samples * 2);
296  }
297  }
298  return ts->samples;
299 }
static __inline__ int16_t teletone_dds_state_modulate_sample(teletone_dds_state_t *dds, uint32_t pindex)
#define TELETONE_MAX_TONES
Definition: libteletone.h:81
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_VOL_DB_MIN
static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level)
teletone_process_t freqs[TELETONE_MAX_TONES]
Definition: libteletone.h:95
static int ensure_buffer(teletone_generation_session_t *ts, int need)
int16_t teletone_audio_t
memset(buf, 0, buflen)

◆ teletone_run()

int teletone_run ( teletone_generation_session_t ts,
const char *  cmd 
)

Execute a tone generation script and call callbacks after each instruction.

Parameters
tsthe tone generation session to execute on
cmdthe script to execute
Returns
0

Definition at line 314 of file libteletone_generate.c.

References teletone_generation_session::channels, cur, teletone_generation_session::debug, teletone_generation_session::debug_stream, teletone_generation_session::decay_direction, teletone_generation_session::decay_factor, teletone_generation_session::decay_step, teletone_generation_session::duration, teletone_tone_map_t::freqs, teletone_generation_session::handler, teletone_generation_session::loops, teletone_generation_session::LOOPS, memset(), my_strdup(), teletone_generation_session::rate, TELETONE_MAX_TONES, TELETONE_TONE_RANGE, TELETONE_VOL_DB_MIN, teletone_generation_session::tmp_duration, teletone_generation_session::tmp_wait, teletone_generation_session::TONES, teletone_generation_session::volume, and teletone_generation_session::wait.

Referenced by inband_dtmf_generate_callback(), main(), setup_ringback(), switch_ivr_gentones(), and switch_ivr_wait_for_answer().

315 {
316  char *data = NULL, *cur = NULL, *end = NULL;
317  int LOOPING = 0;
318 
319  if (!cmd) {
320  return -1;
321  }
322 
323  do {
324  if (!(data = my_strdup(cmd))) {
325  return -1;
326  }
327 
328  cur = data;
329 
330  while (*cur) {
331  if (*cur == ' ' || *cur == '\r' || *cur == '\n') {
332  cur++;
333  continue;
334  }
335 
336  if ((end = strchr(cur, ';')) != 0) {
337  *end++ = '\0';
338  }
339 
340  if (*(cur + 1) == '=') {
341  switch(*cur) {
342  case 'c':
343  ts->channels = atoi(cur + 2);
344  break;
345  case 'r':
346  ts->rate = atoi(cur + 2);
347  break;
348  case 'd':
349  ts->duration = atoi(cur + 2) * (ts->rate / 1000);
350  break;
351  case 'v':
352  {
353  float vol = (float)atof(cur + 2);
354  if (vol <= TELETONE_VOL_DB_MAX && vol >= TELETONE_VOL_DB_MIN) {
355  ts->volume = vol;
356  }
357  }
358  break;
359  case '>':
360  ts->decay_step = atoi(cur + 2) * (ts->rate / 1000);
361  ts->decay_direction = -1;
362  break;
363  case '<':
364  ts->decay_step = atoi(cur + 2) * (ts->rate / 1000);
365  ts->decay_direction = 1;
366  break;
367  case '+':
368  ts->decay_factor = (float)atof(cur + 2);
369  break;
370  case 'w':
371  ts->wait = atoi(cur + 2) * (ts->rate / 1000);
372  break;
373  case 'l':
374  ts->loops = atoi(cur + 2);
375  break;
376  case 'L':
377  if (!LOOPING) {
378  int L;
379  if ((L = atoi(cur + 2)) > 0) {
380  ts->LOOPS = L;
381  LOOPING++;
382  }
383  }
384  break;
385  }
386  } else {
387  while (*cur) {
388  char *p = NULL, *e = NULL;
389  teletone_tone_map_t mymap, *mapp = NULL;
390 
391  if (*cur == ' ' || *cur == '\r' || *cur == '\n') {
392  cur++;
393  continue;
394  }
395 
396  ts->tmp_duration = -1;
397  ts->tmp_wait = -1;
398 
399  memset(&mymap, 0, sizeof(mymap));
400 
401  if (*(cur + 1) == '(') {
402  p = cur + 2;
403  if (*cur) {
404  char *next;
405  int i = 0;
406  if ((e = strchr(p, ')')) != 0) {
407  *e++ = '\0';
408  }
409  do {
410 #if (_MSC_VER == 1600)
411  if (!p) {
412  break;
413  }
414 #endif
415  if ((next = strchr(p, ',')) != 0) {
416  *next++ = '\0';
417  }
418  if (i == 0) {
419  ts->tmp_duration = atoi(p) * (ts->rate / 1000);
420  i++;
421  } else if (i == 1) {
422  ts->tmp_wait = atoi(p) * (ts->rate / 1000);
423  i++;
424  } else {
425  mymap.freqs[i++ - 2] = atof(p);
426  }
427  p = next;
428 
429  } while (next && (i-2) < TELETONE_MAX_TONES);
430  if (i > 2 && *cur == '%') {
431  mapp = &mymap;
432  } else if ((i != 2 || *cur == '%')) {
433  if (ts->debug && ts->debug_stream) {
434  fprintf(ts->debug_stream, "Syntax Error!\n");
435  }
436  goto bottom;
437  }
438  }
439  }
440 
441  if (*cur && !mapp) {
442  if (*cur > 0 && *cur < TELETONE_TONE_RANGE) {
443  mapp = &ts->TONES[(int)*cur];
444  } else if (ts->debug && ts->debug_stream) {
445  fprintf(ts->debug_stream, "Map [%c] Out Of Range!\n", *cur);
446  }
447  }
448 
449  if (mapp) {
450  if (mapp->freqs[0]) {
451  if (ts->handler) {
452  do {
453  ts->handler(ts, mapp);
454  if (ts->loops > 0) {
455  ts->loops--;
456  }
457  } while (ts->loops);
458  }
459  } else if (ts->debug && ts->debug_stream) {
460  fprintf(ts->debug_stream, "Ignoring Empty Map [%c]!\n", *cur);
461  }
462  }
463 
464  if (e) {
465  cur = e;
466  } else {
467  cur++;
468  }
469  }
470  }
471 
472  if (end) {
473  cur = end;
474  } else if (*cur){
475  cur++;
476  }
477  }
478  bottom:
479  free(data);
480  data = NULL;
481 
482  if (ts->LOOPS > 0) {
483  ts->LOOPS--;
484  }
485 
486  } while (ts->LOOPS);
487 
488  return 0;
489 }
#define TELETONE_MAX_TONES
Definition: libteletone.h:81
An abstraction to store a tone mapping.
Definition: libteletone.h:93
static char * my_strdup(const char *s)
pack cur
teletone_tone_map_t TONES[TELETONE_TONE_RANGE]
#define TELETONE_VOL_DB_MIN
teletone_process_t freqs[TELETONE_MAX_TONES]
Definition: libteletone.h:95
#define TELETONE_TONE_RANGE
Definition: libteletone.h:82
memset(buf, 0, buflen)

◆ teletone_set_map()

int teletone_set_map ( teletone_tone_map_t map,
  ... 
)

Assign a set of tones to a single tone map.

Parameters
mapthe map to assign the tones to
...up to TELETONE_MAX_TONES frequencies terminated by 0.0
Returns
0

Definition at line 118 of file libteletone_generate.c.

References teletone_tone_map_t::freqs, and TELETONE_MAX_TONES.

119 {
120  va_list ap;
121  int i = 0;
122  teletone_process_t x = 0;
123 
124  va_start(ap, map);
125  while (i < TELETONE_MAX_TONES && (x = va_arg(ap, teletone_process_t))) {
126  map->freqs[i++] = x;
127  }
128  va_end(ap);
129 
130  return (i > TELETONE_MAX_TONES) ? -1 : 0;
131 
132 }
#define TELETONE_MAX_TONES
Definition: libteletone.h:81
double teletone_process_t
Definition: libteletone.h:84
teletone_process_t freqs[TELETONE_MAX_TONES]
Definition: libteletone.h:95

◆ teletone_set_tone()

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.

Parameters
tsthe tone generation session
indexthe index to map the tone to
...up to TELETONE_MAX_TONES frequencies terminated by 0.0
Returns
0

Definition at line 102 of file libteletone_generate.c.

References teletone_tone_map_t::freqs, index, TELETONE_MAX_TONES, and teletone_generation_session::TONES.

Referenced by teletone_init_session().

103 {
104  va_list ap;
105  int i = 0;
106  teletone_process_t x = 0;
107 
108  va_start(ap, index);
109  while (i < TELETONE_MAX_TONES && (x = va_arg(ap, teletone_process_t))) {
110  ts->TONES[index].freqs[i++] = x;
111  }
112  va_end(ap);
113 
114  return (i > TELETONE_MAX_TONES) ? -1 : 0;
115 
116 }
#define TELETONE_MAX_TONES
Definition: libteletone.h:81
double teletone_process_t
Definition: libteletone.h:84
teletone_tone_map_t TONES[TELETONE_TONE_RANGE]
teletone_process_t freqs[TELETONE_MAX_TONES]
Definition: libteletone.h:95
int index
Definition: switch_cJSON.h:160

Variable Documentation

◆ TELETONE_SINES

int16_t TELETONE_SINES[SINE_TABLE_MAX]

Definition at line 82 of file libteletone_generate.c.

Referenced by teletone_dds_state_modulate_sample().