diff options
| author | Reiner Herrmann <reiner@reiner-h.de> | 2017-04-04 20:28:20 +0200 |
|---|---|---|
| committer | Reiner Herrmann <reiner@reiner-h.de> | 2017-04-04 20:28:24 +0200 |
| commit | fef5c9fe6c4b1bfa327018367345521995235c4d (patch) | |
| tree | f9ee21aa7d61b78c3d1f27f977ab1df78c5169a8 | |
| parent | eded675ec2b8bb6ba2756a89ef1be1b689edb711 (diff) | |
Dynamically recalculate period from current bpm setting
| -rw-r--r-- | metronome.c | 9 |
1 files changed, 4 insertions, 5 deletions
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); |
