FreeCalypso > hg > vband-misc
annotate ringing/genring.c @ 12:db5772dac3c3
ringing: generate WAV decodings of FR&EFR ringing signals
for playback testing and subjective quality evaluation
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Apr 2024 19:28:20 +0000 |
parents | b875c8edd54f |
children |
rev | line source |
---|---|
9
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program computes the waveform for the North American precise tone plan |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * ringing signal, specifically the 2 s long ON phase, and writes it into a |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * "robe" PCM16 file. |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <math.h> |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdint.h> |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #define FREQ_LOW (M_PI * 440.0 / 4000.0) |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #define FREQ_HIGH (M_PI * 480.0 / 4000.0) |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #define AMPL_PEAK 2552.329f /* -19 dBm0 */ |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #define TOTAL_SAMPLES 16000 |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 main(argc, argv) |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 char **argv; |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 FILE *outf; |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 float angle_low, angle_high; |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 unsigned nsamp; |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 int sample; |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 unsigned sample_out; |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (argc != 2) { |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 fprintf(stderr, "usage: %s outfile\n", argv[0]); |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 exit(1); |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 outf = fopen(argv[1], "w"); |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 if (!outf) { |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 perror(argv[1]); |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 exit(1); |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 angle_low = 0; |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 angle_high = 0; |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 for (nsamp = 0; nsamp < TOTAL_SAMPLES; nsamp++) { |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 sample = (sinf(angle_low) + sinf(angle_high)) * AMPL_PEAK; |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 sample_out = sample & 0xFFFF; |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 putc(sample_out >> 8, outf); |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 putc(sample_out & 0xFF, outf); |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 angle_low += FREQ_LOW; |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 angle_high += FREQ_HIGH; |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 exit(0); |
b875c8edd54f
ringing: generate North American ringing signal
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |