FreeCalypso > hg > freecalypso-reveng
changeset 382:4307b57229d3
miscprog: tone-convert written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 10 Nov 2021 00:04:12 +0000 |
parents | ca75ac283888 |
children | 97a294f69426 |
files | .hgignore miscprog/Makefile miscprog/tone-convert.c |
diffstat | 3 files changed, 51 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Tue Nov 09 18:49:09 2021 +0000 +++ b/.hgignore Wed Nov 10 00:04:12 2021 +0000 @@ -55,6 +55,7 @@ ^miscprog/pircksum2$ ^miscprog/pirimei$ ^miscprog/rfcap-grep$ +^miscprog/tone-convert$ ^mot931c/emu$ ^mot931c/ptydump$
--- a/miscprog/Makefile Tue Nov 09 18:49:09 2021 +0000 +++ b/miscprog/Makefile Wed Nov 10 00:04:12 2021 +0000 @@ -4,7 +4,8 @@ memwrite-grep mokosrec2bin osmo2psi pirbattextr pircalextr pircksum \ pircksum2 rfcap-grep CRYPTO= imeibrute pirimei -PROGS= ${STD} ${CRYPTO} +MATH= tone-convert +PROGS= ${STD} ${CRYPTO} ${MATH} all: ${PROGS} @@ -14,6 +15,9 @@ ${CRYPTO}: ${CC} ${CFLAGS} -o $@ $@.c -lcrypto +${MATH}: + ${CC} ${CFLAGS} -o $@ $@.c -lm + atsc: atsc.c calextract: calextract.c cinitdump: cinitdump.c @@ -31,6 +35,7 @@ pircksum2: pircksum2.c pirimei: pirimei.c rfcap-grep: rfcap-grep.c +tone-convert: tone-convert.c clean: rm -f ${PROGS} *.o *errs *.out
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/miscprog/tone-convert.c Wed Nov 10 00:04:12 2021 +0000 @@ -0,0 +1,44 @@ +/* + * 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); +}