diff ringing/genring.c @ 9:b875c8edd54f

ringing: generate North American ringing signal
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Apr 2024 19:05:18 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ringing/genring.c	Sun Apr 07 19:05:18 2024 +0000
@@ -0,0 +1,48 @@
+/*
+ * 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);
+}