fixed
This commit is contained in:
parent
5b9194caae
commit
fef3f69f63
@ -10,24 +10,30 @@
|
|||||||
void sequencerInit() {
|
void sequencerInit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void sequencerExec(void *handle) {
|
#pragma GCC diagnostic push
|
||||||
static uint16_t lengths[e_L_LengthEnd];
|
#pragma GCC diagnostic ignored "-Wswitch"
|
||||||
t_melodies *melodies = (t_melodies*) handle;
|
#pragma GCC diagnostic ignored "-Wreturn-type"
|
||||||
|
static uint16_t calcLength(t_melodies *m, t_noteLength l) {
|
||||||
if (melodies->firstRun) {
|
switch (l) {
|
||||||
melodies->firstRun = false;
|
case e_L_1:
|
||||||
|
return m->quarterLength << 2;
|
||||||
lengths[e_L_1_4] = 60000 / melodies->pace; // duration of a 1/4 tone in ms
|
case e_L_1_2:
|
||||||
lengths[e_L_1_2] = lengths[e_L_1_4] << 1;
|
return m->quarterLength << 1;
|
||||||
lengths[e_L_1] = lengths[e_L_1_4] << 2;
|
case e_L_1_4:
|
||||||
lengths[e_L_1_8] = lengths[e_L_1_4] >> 1;
|
return m->quarterLength;
|
||||||
lengths[e_L_1_16] = lengths[e_L_1_4] >> 2;
|
case e_L_1_8:
|
||||||
lengths[e_L_1_32] = lengths[e_L_1_4] >> 4;
|
return m->quarterLength >> 1;
|
||||||
|
case e_L_1_16:
|
||||||
for (uint8_t i = 0; i < e_L_LengthEnd; i++) {
|
return m->quarterLength >> 2;
|
||||||
lengths[i] /= SEQUENCER_PERIOD;
|
case e_L_1_32:
|
||||||
}
|
return m->quarterLength >> 4;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
|
|
||||||
|
void sequencerExec(void *handle) {
|
||||||
|
t_melodies *melodies = (t_melodies*) handle;
|
||||||
|
|
||||||
for (uint8_t channel = 0; channel < melodies->numOfMelodies; channel++) {
|
for (uint8_t channel = 0; channel < melodies->numOfMelodies; channel++) {
|
||||||
t_melody *melody = &(melodies->melodies[channel]);
|
t_melody *melody = &(melodies->melodies[channel]);
|
||||||
@ -52,7 +58,9 @@ void sequencerExec(void *handle) {
|
|||||||
melody->idx = 0;
|
melody->idx = 0;
|
||||||
}
|
}
|
||||||
psgPlayTone(melody->chip, channel, melody->amplitude, melody->tones[melody->idx].octave, melody->tones[melody->idx].note);
|
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;
|
melody->state = e_HoldTone;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -69,7 +77,7 @@ void sequencerExec(void *handle) {
|
|||||||
break;
|
break;
|
||||||
case e_StaccatoBreak:
|
case e_StaccatoBreak:
|
||||||
psgPlayTone(melody->chip, channel, 0, e_O_Null, e_Pause);
|
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;
|
melody->state = e_HoldStaccatoBreak;
|
||||||
break;
|
break;
|
||||||
case e_HoldStaccatoBreak:
|
case e_HoldStaccatoBreak:
|
||||||
@ -101,7 +109,7 @@ uint16_t sequencerPlayMelodies(t_melodies *melodies) {
|
|||||||
melodies->melodies[i].state = e_Init;
|
melodies->melodies[i].state = e_Init;
|
||||||
}
|
}
|
||||||
melodies->sync = 0;
|
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);
|
melodies->taskId = schAdd(sequencerExec, (void*) melodies, 0, SEQUENCER_PERIOD);
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ typedef struct {
|
|||||||
#define NUM_OF_CHANNELS 3
|
#define NUM_OF_CHANNELS 3
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t taskId;
|
uint8_t taskId;
|
||||||
bool firstRun;
|
uint16_t quarterLength;
|
||||||
uint8_t numOfMelodies;
|
uint8_t numOfMelodies;
|
||||||
uint8_t pace; // quarter notes per minute
|
uint8_t pace; // quarter notes per minute
|
||||||
uint8_t sync;
|
uint8_t sync;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user