uint16_t tempo;
uint16_t newtempo; // changed by the interrupt then updated to the current tempo?
uint16_t xtempo; // stored tempo in eeprom
volatile uint32_t tempo_x0;
volatile uint8_t cshfl = 1; // shuffled clock or not?
volatile uint8_t cshfl_i = 0;
volatile uint32_t tempo_xA;
volatile uint32_t tempo_xB;
const uint8_t shfl_idx2level[21] =
{
/* top secret values here */
};
const uint16_t cshfl_coeffs1[11] =
{
/* top secret values here */
};
const uint16_t cshfl_coeffs2[11] =
{
/* top secret values here */
};
volatile uint8_t zshfl_lvl = 0xFF;
#define Z_TEMPO_ONE 4294967295000000
void change_tempo(uint16_t set_tempo)
{
if (set_tempo > MAX_TEMPO)
{
set_tempo = MAX_TEMPO;
}
if (set_tempo < MIN_TEMPO)
{
set_tempo = MIN_TEMPO;
}
if (tempo != set_tempo)
{
// don't send serial messages from here
z_send_tempo = 1;
}
else
{
// tempo hasn't changed
if (cshfl)
{
const uint8_t lvl = (shfl_idx2level[shuffle_idx] & 0x7F);
if (lvl != zshfl_lvl)
{
zshfl_lvl = lvl;
}
else { return; }
}
else { return; }
}
newtempo = tempo = set_tempo;
if (cshfl)
{
// multiply tempo by (100 * 10000)
const uint32_t txx = (uint32_t)(set_tempo) * 1000000;
tempo_xA = txx/cshfl_coeffs1[zshfl_lvl];
tempo_xA = Z_TEMPO_ONE / (tempo_coeff/tempo_xA);
tempo_xB = txx/cshfl_coeffs2[zshfl_lvl];
tempo_xB = (uint64_t)(Z_TEMPO_ONE) / (tempo_coeff/tempo_xB);
}
else
{
// multiply tempo by 100
const uint32_t txx = (uint32_t)(set_tempo) * 100;
tempo_x0 = (uint64_t)(Z_TEMPO_ONE) / (tempo_coeff/txx);
}
}