annotate miscprog/tone-convert.c @ 382:4307b57229d3

miscprog: tone-convert written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 10 Nov 2021 00:04:12 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
382
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This command line utility converts a Calypso DSP tone specification from
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * frequency in Hz and amplitude in dBfs into the 16-bit tone control word
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * that would go into the DSP for the keybeep or tones audio task.
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 *
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * The conversion is done in exactly the same way how RiViera Audio Service
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * does it, allowing the possibility of reconstructing Audio Service API
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 * input values from DSP tone control words captured in L1 traces.
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 */
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <math.h>
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdio.h>
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <stdlib.h>
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 main(argc, argv)
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char **argv;
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 int freq_hz, ampl_dbfs;
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 double frequency_index, frequency_beep;
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 double amplitude_beep, amplitude, amplitude_index;
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 unsigned output;
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (argc != 3) {
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 fprintf(stderr, "usage: %s freq ampl\n", argv[0]);
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 exit(1);
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 freq_hz = atoi(argv[1]);
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 ampl_dbfs = atoi(argv[2]);
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 /* code from RiViera Audio Service */
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 /* frequency computation */
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 frequency_beep = (double) freq_hz;
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 frequency_index = (256 * cos(6.283185*(frequency_beep/8000)));
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 /* amplitude computation */
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 amplitude_beep = (double) ampl_dbfs;
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 amplitude = exp((amplitude_beep*0.115129)+(5.544625));
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 amplitude_index = amplitude * sin(6.283185*(frequency_beep/8000));
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 /* output word */
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 output = (unsigned)((((unsigned)(frequency_index))<<8) |
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 ((unsigned)(amplitude_index)));
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 printf("0x%04X\n", output);
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 exit(0);
4307b57229d3 miscprog: tone-convert written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }