annotate mgw/dtmf_init.c @ 240:c7a3ba56c636

themwi-short-dial: fix bug in printf arguments
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 15:37:59 -0800
parents 815e4c59162e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
126
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * The code in this module executes once upon themwi-mgw startup;
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * it initializes the arrays of linear PCM samples for DTMF output.
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 *
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * The amplitudes of the two sine waves comprising each DTMF tone
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * are also defined here.
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 */
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <math.h>
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdint.h>
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdlib.h>
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "dtmf_defs.h"
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "int_defs.h"
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #define DTMF_AMPL_LOW_TONE 5000
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #define DTMF_AMPL_HIGH_TONE 6000
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern struct dtmf_desc dtmf_table[];
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 static void
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 init_one_dtmf(desc)
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 struct dtmf_desc *desc;
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 {
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 float angle_low, angle_high;
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 unsigned n;
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 int16_t *samp;
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 angle_low = 0;
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 angle_high = 0;
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 samp = desc->samples;
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 for (n = 0; n < DTMF_MAX_FRAMES * SAMPLES_PER_FRAME; n++) {
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 *samp++ = sinf(angle_low) * DTMF_AMPL_LOW_TONE +
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 sinf(angle_high) * DTMF_AMPL_HIGH_TONE;
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 angle_low += desc->freq_low;
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 angle_high += desc->freq_high;
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 dtmf_init_sample_arrays()
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 {
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 struct dtmf_desc *desc;
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 for (desc = dtmf_table; desc->digit; desc++) {
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 desc->samples =
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 malloc(DTMF_MAX_FRAMES * SAMPLES_PER_FRAME * sizeof(int16_t));
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (!desc->samples) {
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 perror("malloc for DTMF samples");
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 exit(1);
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 init_one_dtmf(desc);
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return 0;
815e4c59162e mgw DTMF: tone definitions and sample array generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }