From 857a73dcf6e26728146e622bbd9fc99403b43581 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 9 Aug 2021 15:13:49 +0200 Subject: [PATCH] Several fixes. --- MicroDexed.ino | 2 +- audio_timer.cpp | 15 ++++++++------- audio_timer.h | 10 ++++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 2a8ba2b..f1edc73 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -718,7 +718,7 @@ void setup() #endif audio_timer.set_bpm(60); - audio_timer.function(4, &testfunc); + audio_timer.function(8, &testfunc); // 60 bpm with 1/8 pulses #ifdef DEBUG Serial.println(F("")); diff --git a/audio_timer.cpp b/audio_timer.cpp index ef835f7..149158e 100644 --- a/audio_timer.cpp +++ b/audio_timer.cpp @@ -12,10 +12,10 @@ void AudioTimer::update(void) tick++; - if (tick >= float(beat)*float(bpm) + 0.5) + if (tick >= _steps) { - if (sequencer_step_function != NULL) - (*sequencer_step_function)(); + if (step_function != NULL) + (*step_function)(); tick = 0; } } @@ -30,13 +30,14 @@ void AudioTimer::set_bpm(uint8_t b) bpm = b; } -void AudioTimer::function(uint8_t steps, void(*func)()) +void AudioTimer::function(uint8_t stepping, void(*func)()) { + steps = stepping; if (func != NULL) { - sequencer_step_function = func; - steps = bpm * steps / 4; + step_function = func; + _steps = beat * float(bpm) * 4.0 / float(stepping) + 0.5; } else - sequencer_step_function = NULL; + step_function = NULL; } diff --git a/audio_timer.h b/audio_timer.h index 8fecb18..f6ed8ff 100644 --- a/audio_timer.h +++ b/audio_timer.h @@ -9,19 +9,21 @@ class AudioTimer : public AudioStream { tick = 0; bpm = 60; - sequencer_step_function = NULL; + steps = 4; + step_function = NULL; } virtual uint32_t get_tick(void); virtual void set_bpm(uint8_t b); - virtual void function(uint8_t steps, void(*func)()); + virtual void function(uint8_t stepping, void(*func)()); virtual void update(void); private: audio_block_t *inputQueueArray[1]; uint8_t bpm; - uint16_t steps; - void (*sequencer_step_function)(); + uint8_t steps; + uint16_t _steps; + void (*step_function)(); volatile uint32_t tick; const float beat = AUDIO_SAMPLE_RATE_EXACT / float(AUDIO_BLOCK_SAMPLES) / 60.0; };