view ringing/genring.c @ 24:c52fb8080faf

pcmu2efr: emit all 320 computed frames
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 12 May 2024 04:28:49 +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);
}