From c38473f5f9ff847d768e028fb7759f8b0a1b4088 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 22 Aug 2025 00:25:26 -0400 Subject: usr: notes: Add dynamic frequency addend Signed-off-by: Ian Moffett --- usr.bin/notes/notes.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'usr.bin/notes') diff --git a/usr.bin/notes/notes.c b/usr.bin/notes/notes.c index e6aeed5..9db8b60 100644 --- a/usr.bin/notes/notes.c +++ b/usr.bin/notes/notes.c @@ -36,6 +36,8 @@ #define BEEP_MSEC 100 #define key_step(KEY) ('9' - ((KEY))) +static uint8_t freq_addend = 0; + static uint16_t freqtab[] = { [ key_step('0') ] = 950, [ key_step('9') ] = 900, @@ -70,13 +72,15 @@ static inline void play_notekey(char key) { uint8_t step = key_step(key); + uint16_t freq; /* Should not happen */ if (step >= NELEM(freqtab)) { step = key_step('0'); } - beep(freqtab[step]); + freq = freqtab[step] + freq_addend; + beep(freq); } static void @@ -92,6 +96,16 @@ play_loop(void) case 'q': running = false; break; + case 'i': + /* NOTE: Overflow purposefully allowed here */ + ++freq_addend; + printf("%d ", freq_addend); + break; + case 'd': + /* NOTE: Underflow purposefully allowed here */ + --freq_addend; + printf("%d ", freq_addend); + break; default: if (!isdigit(c)) { break; @@ -100,6 +114,8 @@ play_loop(void) play_notekey(c); } } + + printf("\ncya!\n"); } int @@ -110,6 +126,7 @@ main(int argc, char **argv) return -1; } + printf("bleep bloop time! - [i]nc/[d]ec\n"); play_loop(); close(beep_fd); } -- cgit v1.2.3