comparison mgw/dtmf_init.c @ 126:815e4c59162e

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