Several fixes.

pull/65/head
Holger Wirtz 3 years ago
parent 0c922276c2
commit 857a73dcf6
  1. 2
      MicroDexed.ino
  2. 15
      audio_timer.cpp
  3. 10
      audio_timer.h

@ -718,7 +718,7 @@ void setup()
#endif #endif
audio_timer.set_bpm(60); audio_timer.set_bpm(60);
audio_timer.function(4, &testfunc); audio_timer.function(8, &testfunc); // 60 bpm with 1/8 pulses
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("<setup end>")); Serial.println(F("<setup end>"));

@ -12,10 +12,10 @@ void AudioTimer::update(void)
tick++; tick++;
if (tick >= float(beat)*float(bpm) + 0.5) if (tick >= _steps)
{ {
if (sequencer_step_function != NULL) if (step_function != NULL)
(*sequencer_step_function)(); (*step_function)();
tick = 0; tick = 0;
} }
} }
@ -30,13 +30,14 @@ void AudioTimer::set_bpm(uint8_t b)
bpm = b; bpm = b;
} }
void AudioTimer::function(uint8_t steps, void(*func)()) void AudioTimer::function(uint8_t stepping, void(*func)())
{ {
steps = stepping;
if (func != NULL) if (func != NULL)
{ {
sequencer_step_function = func; step_function = func;
steps = bpm * steps / 4; _steps = beat * float(bpm) * 4.0 / float(stepping) + 0.5;
} }
else else
sequencer_step_function = NULL; step_function = NULL;
} }

@ -9,19 +9,21 @@ class AudioTimer : public AudioStream
{ {
tick = 0; tick = 0;
bpm = 60; bpm = 60;
sequencer_step_function = NULL; steps = 4;
step_function = NULL;
} }
virtual uint32_t get_tick(void); virtual uint32_t get_tick(void);
virtual void set_bpm(uint8_t b); 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); virtual void update(void);
private: private:
audio_block_t *inputQueueArray[1]; audio_block_t *inputQueueArray[1];
uint8_t bpm; uint8_t bpm;
uint16_t steps; uint8_t steps;
void (*sequencer_step_function)(); uint16_t _steps;
void (*step_function)();
volatile uint32_t tick; volatile uint32_t tick;
const float beat = AUDIO_SAMPLE_RATE_EXACT / float(AUDIO_BLOCK_SAMPLES) / 60.0; const float beat = AUDIO_SAMPLE_RATE_EXACT / float(AUDIO_BLOCK_SAMPLES) / 60.0;
}; };

Loading…
Cancel
Save