parent
e8772102b1
commit
09ff0cb755
@ -0,0 +1,39 @@ |
||||
#include <Audio.h> |
||||
#include "config.h" |
||||
#include "sequencer_timer.h" |
||||
|
||||
void AudioSequencerTimer::update(void) |
||||
{ |
||||
audio_block_t *in; |
||||
|
||||
in = receiveReadOnly(0); |
||||
if (in) |
||||
release(in); |
||||
|
||||
tick++; |
||||
|
||||
if (tick >= float(beat)*float(bpm) + 0.5) |
||||
{ |
||||
if (sequencer_step_function != NULL) |
||||
(*sequencer_step_function)(); |
||||
tick = 0; |
||||
} |
||||
} |
||||
|
||||
uint32_t AudioSequencerTimer::get_tick(void) |
||||
{ |
||||
return (tick); |
||||
} |
||||
|
||||
void AudioSequencerTimer::set_bpm(uint8_t b) |
||||
{ |
||||
bpm = b; |
||||
} |
||||
|
||||
void AudioSequencerTimer::step_function(void(*func)()) |
||||
{ |
||||
if (func != NULL) |
||||
sequencer_step_function = func; |
||||
else |
||||
sequencer_step_function = NULL; |
||||
} |
@ -0,0 +1,27 @@ |
||||
#ifndef _SEQUENCER_TIMER_H_ |
||||
#define _SEQUENCER_TIMER_H_ |
||||
|
||||
class AudioSequencerTimer : public AudioStream |
||||
{ |
||||
public: |
||||
AudioSequencerTimer(void): |
||||
AudioStream(1, inputQueueArray) |
||||
{ |
||||
tick = 0; |
||||
bpm = 60; |
||||
sequencer_step_function = NULL; |
||||
} |
||||
|
||||
virtual uint32_t get_tick(void); |
||||
virtual void set_bpm(uint8_t b); |
||||
virtual void step_function(void(*func)()); |
||||
virtual void update(void); |
||||
|
||||
private: |
||||
audio_block_t *inputQueueArray[1]; |
||||
uint8_t bpm; |
||||
void (*sequencer_step_function)(); |
||||
volatile uint32_t tick; |
||||
const float beat = AUDIO_SAMPLE_RATE_EXACT / float(AUDIO_BLOCK_SAMPLES) / 60.0; |
||||
}; |
||||
#endif |
Loading…
Reference in new issue