FreeCalypso > hg > vband-misc
comparison 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 |
comparison
equal
deleted
inserted
replaced
8:d5bcfb378049 | 9:b875c8edd54f |
---|---|
1 /* | |
2 * This program computes the waveform for the North American precise tone plan | |
3 * ringing signal, specifically the 2 s long ON phase, and writes it into a | |
4 * "robe" PCM16 file. | |
5 */ | |
6 | |
7 #include <math.h> | |
8 #include <stdio.h> | |
9 #include <stdint.h> | |
10 #include <stdlib.h> | |
11 | |
12 #define FREQ_LOW (M_PI * 440.0 / 4000.0) | |
13 #define FREQ_HIGH (M_PI * 480.0 / 4000.0) | |
14 | |
15 #define AMPL_PEAK 2552.329f /* -19 dBm0 */ | |
16 | |
17 #define TOTAL_SAMPLES 16000 | |
18 | |
19 main(argc, argv) | |
20 char **argv; | |
21 { | |
22 FILE *outf; | |
23 float angle_low, angle_high; | |
24 unsigned nsamp; | |
25 int sample; | |
26 unsigned sample_out; | |
27 | |
28 if (argc != 2) { | |
29 fprintf(stderr, "usage: %s outfile\n", argv[0]); | |
30 exit(1); | |
31 } | |
32 outf = fopen(argv[1], "w"); | |
33 if (!outf) { | |
34 perror(argv[1]); | |
35 exit(1); | |
36 } | |
37 angle_low = 0; | |
38 angle_high = 0; | |
39 for (nsamp = 0; nsamp < TOTAL_SAMPLES; nsamp++) { | |
40 sample = (sinf(angle_low) + sinf(angle_high)) * AMPL_PEAK; | |
41 sample_out = sample & 0xFFFF; | |
42 putc(sample_out >> 8, outf); | |
43 putc(sample_out & 0xFF, outf); | |
44 angle_low += FREQ_LOW; | |
45 angle_high += FREQ_HIGH; | |
46 } | |
47 exit(0); | |
48 } |