diff 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
line wrap: on
line diff
--- /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);
+}