view ringing/genring.c @ 36:e4c6fc4e30f4

dhf: generate binary form of FR1 DHF
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 14 May 2024 04:26:18 +0000
parents b875c8edd54f
children
line wrap: on
line source

/*
 * This program computes the waveform for the North American precise tone plan
 * ringing signal, specifically the 2 s long ON phase, and writes it into a
 * "robe" PCM16 file.
 */

#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

#define	FREQ_LOW	(M_PI * 440.0 / 4000.0)
#define	FREQ_HIGH	(M_PI * 480.0 / 4000.0)

#define	AMPL_PEAK	2552.329f	/* -19 dBm0 */

#define	TOTAL_SAMPLES	16000

main(argc, argv)
	char **argv;
{
	FILE *outf;
	float angle_low, angle_high;
	unsigned nsamp;
	int sample;
	unsigned sample_out;

	if (argc != 2) {
		fprintf(stderr, "usage: %s outfile\n", argv[0]);
		exit(1);
	}
	outf = fopen(argv[1], "w");
	if (!outf) {
		perror(argv[1]);
		exit(1);
	}
	angle_low = 0;
	angle_high = 0;
	for (nsamp = 0; nsamp < TOTAL_SAMPLES; nsamp++) {
		sample = (sinf(angle_low) + sinf(angle_high)) * AMPL_PEAK;
		sample_out = sample & 0xFFFF;
		putc(sample_out >> 8, outf);
		putc(sample_out & 0xFF, outf);
		angle_low += FREQ_LOW;
		angle_high += FREQ_HIGH;
	}
	exit(0);
}