view mgw/dtmf_init.c @ 199:e6c7ced3c031

mgw: accept zero-length RTP payload as BFI Mainline OsmoBTS now has an option (rtp continuous-streaming) that causes it to emit an RTP packet every 20 ms without gaps, sending a BFI marker in the form of zero-length RTP payload when it has nothing else to send. These codec-independent BFI markers don't indicate TAF, but this provision is a good start. Accept this BFI packet format in themwi-mgw.
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 29 Mar 2023 20:23:43 -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;
}