From fef5c9fe6c4b1bfa327018367345521995235c4d Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Tue, 4 Apr 2017 20:28:20 +0200 Subject: Dynamically recalculate period from current bpm setting --- metronome.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'metronome.c') diff --git a/metronome.c b/metronome.c index ad981b9..0c5202a 100644 --- a/metronome.c +++ b/metronome.c @@ -202,19 +202,18 @@ static void play_tone(snd_pcm_t *pcm_handle, char tone) } } -static int play(snd_pcm_t *pcm_handle, const char *pattern, int bpm) +static int play(snd_pcm_t *pcm_handle, const char *pattern) { int i = 0; - double period_us; struct timespec cur_t, old_t = {}; - period_us = 1000000 * 60.0 / bpm; - /* fill buffer with silence */ snd_pcm_prepare(pcm_handle); play_tone(pcm_handle, 's'); while(1) { + double period_us = 1000000 * 60.0 / bpm; + if (input_available()) { char c; read(STDIN_FILENO, &c, 1); @@ -298,7 +297,7 @@ int main(int argc, char *argv[]) instructions(); prepare_tones(); - play(pcm_handle, pattern, bpm); + play(pcm_handle, pattern); printf("\n"); snd_pcm_close(pcm_handle); -- cgit v1.2.3