|
|
|
#include <Audio.h>
|
|
|
|
#include "config.h"
|
|
|
|
#include "audio_timer.h"
|
|
|
|
|
|
|
|
void AudioTimer::update(void)
|
|
|
|
{
|
|
|
|
audio_block_t *in;
|
|
|
|
|
|
|
|
in = receiveReadOnly(0);
|
|
|
|
if (in)
|
|
|
|
release(in);
|
|
|
|
|
|
|
|
tick++;
|
|
|
|
|
|
|
|
if (tick >= _steps)
|
|
|
|
{
|
|
|
|
if (step_function != NULL)
|
|
|
|
(*step_function)();
|
|
|
|
tick = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t AudioTimer::get_tick(void)
|
|
|
|
{
|
|
|
|
return (tick);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioTimer::set_bpm(uint8_t b)
|
|
|
|
{
|
|
|
|
bpm = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioTimer::function(uint8_t stepping, void(*func)())
|
|
|
|
{
|
|
|
|
steps = stepping;
|
|
|
|
if (func != NULL)
|
|
|
|
{
|
|
|
|
step_function = func;
|
|
|
|
_steps = beat * float(bpm) * 4.0 / float(stepping) + 0.5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
step_function = NULL;
|
|
|
|
}
|