This commit is contained in:
Wolfgang Hottgenroth 2024-04-10 14:00:12 +02:00
parent 5b9194caae
commit fef3f69f63
2 changed files with 29 additions and 21 deletions

View File

@ -10,25 +10,31 @@
void sequencerInit() {
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch"
#pragma GCC diagnostic ignored "-Wreturn-type"
static uint16_t calcLength(t_melodies *m, t_noteLength l) {
switch (l) {
case e_L_1:
return m->quarterLength << 2;
case e_L_1_2:
return m->quarterLength << 1;
case e_L_1_4:
return m->quarterLength;
case e_L_1_8:
return m->quarterLength >> 1;
case e_L_1_16:
return m->quarterLength >> 2;
case e_L_1_32:
return m->quarterLength >> 4;
}
}
#pragma GCC diagnostic pop
void sequencerExec(void *handle) {
static uint16_t lengths[e_L_LengthEnd];
t_melodies *melodies = (t_melodies*) handle;
if (melodies->firstRun) {
melodies->firstRun = false;
lengths[e_L_1_4] = 60000 / melodies->pace; // duration of a 1/4 tone in ms
lengths[e_L_1_2] = lengths[e_L_1_4] << 1;
lengths[e_L_1] = lengths[e_L_1_4] << 2;
lengths[e_L_1_8] = lengths[e_L_1_4] >> 1;
lengths[e_L_1_16] = lengths[e_L_1_4] >> 2;
lengths[e_L_1_32] = lengths[e_L_1_4] >> 4;
for (uint8_t i = 0; i < e_L_LengthEnd; i++) {
lengths[i] /= SEQUENCER_PERIOD;
}
}
for (uint8_t channel = 0; channel < melodies->numOfMelodies; channel++) {
t_melody *melody = &(melodies->melodies[channel]);
@ -52,7 +58,9 @@ void sequencerExec(void *handle) {
melody->idx = 0;
}
psgPlayTone(melody->chip, channel, melody->amplitude, melody->tones[melody->idx].octave, melody->tones[melody->idx].note);
melody->lengthCnt = (melody->tones[melody->idx].staccato) ? (lengths[melody->tones[melody->idx].length] / 2) : lengths[melody->tones[melody->idx].length];
melody->lengthCnt = (melody->tones[melody->idx].staccato) ?
(calcLength(melodies, melody->tones[melody->idx].length) / 2) :
calcLength(melodies, melody->tones[melody->idx].length);
melody->state = e_HoldTone;
}
break;
@ -69,7 +77,7 @@ void sequencerExec(void *handle) {
break;
case e_StaccatoBreak:
psgPlayTone(melody->chip, channel, 0, e_O_Null, e_Pause);
melody->lengthCnt = lengths[melody->tones[melody->idx].length] / 2;
melody->lengthCnt = calcLength(melodies, melody->tones[melody->idx].length) / 2;
melody->state = e_HoldStaccatoBreak;
break;
case e_HoldStaccatoBreak:
@ -101,7 +109,7 @@ uint16_t sequencerPlayMelodies(t_melodies *melodies) {
melodies->melodies[i].state = e_Init;
}
melodies->sync = 0;
melodies->firstRun = true;
melodies->quarterLength = 60000 / melodies->pace / SEQUENCER_PERIOD; // duration of a 1/4 tone in ms
melodies->taskId = schAdd(sequencerExec, (void*) melodies, 0, SEQUENCER_PERIOD);

View File

@ -53,7 +53,7 @@ typedef struct {
#define NUM_OF_CHANNELS 3
typedef struct {
uint8_t taskId;
bool firstRun;
uint16_t quarterLength;
uint8_t numOfMelodies;
uint8_t pace; // quarter notes per minute
uint8_t sync;