aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2017-04-09 20:20:28 +0200
committerReiner Herrmann <reiner@reiner-h.de>2017-04-09 20:20:28 +0200
commitf018b296625bd8b99aba1ae4bd6bfbb48a49f59b (patch)
treeee1c65d71c9a2f0b81caf0c6b30b6f7daf503ac4
parent7e557bc3f8eb115d352ebd1c6ca356230eb05090 (diff)
Minor output improvement
-rw-r--r--tuner.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/tuner.c b/tuner.c
index 5f81652..74e9820 100644
--- a/tuner.c
+++ b/tuner.c
@@ -88,6 +88,22 @@ static void fft_cleanup()
fftw_free(fft_out);
}
+static void update_output(double freq, char note, int dir)
+{
+ char note_str[] = "---";
+ char freq_str[20] = "---";
+ char peak_str[20] = "---";
+
+ if (freq >= 0) {
+ snprintf(note_str, sizeof(note_str), "%c%c%c", dir<0 ? '>' : ' ', note, dir>0 ? '<' : ' ');
+ snprintf(freq_str, sizeof(freq_str), "%.2f Hz", freq);
+ snprintf(peak_str, sizeof(peak_str), "%.2f Hz", peak_freq);
+ }
+
+ printf("\rNote: %s Frequency: %s, Peak: %s ", note_str, freq_str, peak_str);
+ fflush(stdout);
+}
+
static void find_note(double freq)
{
int i, index = 0, dir = 0;
@@ -117,8 +133,7 @@ static void find_note(double freq)
dir = 0;
}
- printf("\rNote: %c%c%c Frequency: %.2f Hz, Peak: %.2f Hz ", dir<0?'>':' ', note, dir>0?'<':' ', freq, peak_freq);
- fflush(stdout);
+ update_output(freq, note, dir);
}
static void calculate_magnitudes()