# HG changeset patch # User Mychaela Falconia # Date 1636502652 0 # Node ID 4307b57229d3cae827a8d0184e2d0d9425961ead # Parent ca75ac28388852af3e46b38c7086e530a124d2a4 miscprog: tone-convert written, compiles diff -r ca75ac283888 -r 4307b57229d3 .hgignore --- 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$ diff -r ca75ac283888 -r 4307b57229d3 miscprog/Makefile --- 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 diff -r ca75ac283888 -r 4307b57229d3 miscprog/tone-convert.c --- /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 +#include +#include + +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); +}