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