FreeCalypso > hg > themwi-system-sw
view mgw/dtmf_init.c @ 217:9f6a148ceb25
tcpserv-dump: brown paper bag
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 24 Jul 2023 22:33:01 -0800 |
parents | 815e4c59162e |
children |
line wrap: on
line source
/* * The code in this module executes once upon themwi-mgw startup; * it initializes the arrays of linear PCM samples for DTMF output. * * The amplitudes of the two sine waves comprising each DTMF tone * are also defined here. */ #include <math.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include "dtmf_defs.h" #include "int_defs.h" #define DTMF_AMPL_LOW_TONE 5000 #define DTMF_AMPL_HIGH_TONE 6000 extern struct dtmf_desc dtmf_table[]; static void init_one_dtmf(desc) struct dtmf_desc *desc; { float angle_low, angle_high; unsigned n; int16_t *samp; angle_low = 0; angle_high = 0; samp = desc->samples; for (n = 0; n < DTMF_MAX_FRAMES * SAMPLES_PER_FRAME; n++) { *samp++ = sinf(angle_low) * DTMF_AMPL_LOW_TONE + sinf(angle_high) * DTMF_AMPL_HIGH_TONE; angle_low += desc->freq_low; angle_high += desc->freq_high; } } dtmf_init_sample_arrays() { struct dtmf_desc *desc; for (desc = dtmf_table; desc->digit; desc++) { desc->samples = malloc(DTMF_MAX_FRAMES * SAMPLES_PER_FRAME * sizeof(int16_t)); if (!desc->samples) { perror("malloc for DTMF samples"); exit(1); } init_one_dtmf(desc); } return 0; }