FreeCalypso > hg > freecalypso-reveng
view miscprog/tone-convert.c @ 404:ceb71478414d
tfo: find-is-hdr program written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Mar 2023 18:16:22 +0000 |
parents | 4307b57229d3 |
children |
line wrap: on
line source
/* * This command line utility converts a Calypso DSP tone specification from * frequency in Hz and amplitude in dBfs into the 16-bit tone control word * that would go into the DSP for the keybeep or tones audio task. * * The conversion is done in exactly the same way how RiViera Audio Service * does it, allowing the possibility of reconstructing Audio Service API * input values from DSP tone control words captured in L1 traces. */ #include <math.h> #include <stdio.h> #include <stdlib.h> main(argc, argv) char **argv; { int freq_hz, ampl_dbfs; double frequency_index, frequency_beep; double amplitude_beep, amplitude, amplitude_index; unsigned output; if (argc != 3) { fprintf(stderr, "usage: %s freq ampl\n", argv[0]); exit(1); } freq_hz = atoi(argv[1]); ampl_dbfs = atoi(argv[2]); /* code from RiViera Audio Service */ /* frequency computation */ frequency_beep = (double) freq_hz; frequency_index = (256 * cos(6.283185*(frequency_beep/8000))); /* amplitude computation */ amplitude_beep = (double) ampl_dbfs; amplitude = exp((amplitude_beep*0.115129)+(5.544625)); amplitude_index = amplitude * sin(6.283185*(frequency_beep/8000)); /* output word */ output = (unsigned)((((unsigned)(frequency_index))<<8) | ((unsigned)(amplitude_index))); printf("0x%04X\n", output); exit(0); }