changeset 9:b875c8edd54f

ringing: generate North American ringing signal
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Apr 2024 19:05:18 +0000
parents d5bcfb378049
children 466a46387b6b
files .hgignore ringing/Makefile ringing/genring.c
diffstat 3 files changed, 72 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sun Apr 07 07:20:46 2024 +0000
+++ b/.hgignore	Sun Apr 07 19:05:18 2024 +0000
@@ -8,3 +8,6 @@
 
 ^dmw/gen-dmw-bin$
 ^dmw/dmw-[au]law\.
+
+^ringing/genring$
+^ringing/ringing\.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ringing/Makefile	Sun Apr 07 19:05:18 2024 +0000
@@ -0,0 +1,21 @@
+CC=	gcc
+CFLAGS=	-O2
+PROG=	genring
+FILES=	ringing.robe ringing.ul ringing.al
+
+all:	${PROG} ${FILES}
+
+${PROG}:	${PROG}.c
+	${CC} ${CFLAGS} -o $@ $@.c -lm
+
+ringing.robe:	${PROG}
+	./${PROG} $@
+
+ringing.ul:	ringing.robe
+	pcm16-to-ulaw ringing.robe $@
+
+ringing.al:	ringing.robe
+	pcm16-to-alaw ringing.robe $@
+
+clean:
+	rm -f *.o ${PROG} *.robe *.ul *.al
--- /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);
+}