sequencer
This commit is contained in:
@ -11,7 +11,7 @@ CFLAGS+= -g3 -ggdb -gdwarf-2
|
|||||||
|
|
||||||
LDFLAGS=-mmcu=$(MCU) -L $(TOOLCHAIN_PREFIX)/include
|
LDFLAGS=-mmcu=$(MCU) -L $(TOOLCHAIN_PREFIX)/include
|
||||||
|
|
||||||
$(ARTIFACT).elf: main.o scheduler.o notes.o psg.o
|
$(ARTIFACT).elf: main.o scheduler.o psg.o sequencer.o
|
||||||
$(CC) -o $@ $(LDFLAGS) $^
|
$(CC) -o $@ $(LDFLAGS) $^
|
||||||
$(OBJDUMP) -D $(ARTIFACT).elf > $(ARTIFACT).txt
|
$(OBJDUMP) -D $(ARTIFACT).elf > $(ARTIFACT).txt
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "psg.h"
|
#include "psg.h"
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
|
#include "sequencer.h"
|
||||||
|
|
||||||
void __attribute__ ((interrupt (USCIAB0RX_VECTOR))) receive() {
|
void __attribute__ ((interrupt (USCIAB0RX_VECTOR))) receive() {
|
||||||
if (UC0IFG & UCB0RXIFG) {
|
if (UC0IFG & UCB0RXIFG) {
|
||||||
@ -40,6 +41,7 @@ int main() {
|
|||||||
schInit();
|
schInit();
|
||||||
|
|
||||||
psgInit();
|
psgInit();
|
||||||
|
sequencerInit();
|
||||||
|
|
||||||
__enable_interrupt();
|
__enable_interrupt();
|
||||||
|
|
||||||
|
0
sound-driver/melody.c
Normal file
0
sound-driver/melody.c
Normal file
8
sound-driver/melody.h
Normal file
8
sound-driver/melody.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef _MELODY_H_
|
||||||
|
#define _MELODY_H_
|
||||||
|
|
||||||
|
|
||||||
|
void melodyInit();
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _MELODY_H_
|
@ -28,14 +28,6 @@ typedef enum {
|
|||||||
e_H
|
e_H
|
||||||
} t_note;
|
} t_note;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
e_L_1 = 80,
|
|
||||||
e_L_1_2 = 40,
|
|
||||||
e_L_1_4 = 20,
|
|
||||||
e_L_1_8 = 10,
|
|
||||||
e_L_1_16 = 5
|
|
||||||
} t_noteLength;
|
|
||||||
|
|
||||||
|
|
||||||
void psgInit();
|
void psgInit();
|
||||||
void psgPlayTone(uint8_t channel, t_octave octave, t_note note);
|
void psgPlayTone(uint8_t channel, t_octave octave, t_note note);
|
||||||
|
31
sound-driver/sequencer.c
Normal file
31
sound-driver/sequencer.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "sequencer.h"
|
||||||
|
#include "scheduler.h"
|
||||||
|
#include "psg.h"
|
||||||
|
|
||||||
|
|
||||||
|
void sequencerInit() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void sequencerExec(void *handle) {
|
||||||
|
t_melody *melody = (t_melody*) handle;
|
||||||
|
|
||||||
|
if (melody->lengthCnt == 0) {
|
||||||
|
if (melody->tones[melody->idx].octave == e_O_EndMark) {
|
||||||
|
melody->idx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
psgPlayTone(channel, melody->tones[melody->idx].octave, melody->tones[idx].note);
|
||||||
|
|
||||||
|
melody->lengthCnt = melody->tones[melody->idx].length;
|
||||||
|
}
|
||||||
|
|
||||||
|
melody->lengthCnt -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t sequencerPlayMelody(t_melody *melody) {
|
||||||
|
melody->idx = 0;
|
||||||
|
melody->lengthCnt = 0;
|
||||||
|
schAdd(sequencerExec, (void*) melody, 0, 25);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
33
sound-driver/sequencer.h
Normal file
33
sound-driver/sequencer.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef _SEQUENCER_H_
|
||||||
|
#define _SEQUENCER_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include "psg.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
e_L_EndMark = 0,
|
||||||
|
e_L_1 = 80,
|
||||||
|
e_L_1_2 = 40,
|
||||||
|
e_L_1_4 = 20,
|
||||||
|
e_L_1_8 = 10,
|
||||||
|
e_L_1_16 = 5
|
||||||
|
} t_noteLength;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
t_octave octave;
|
||||||
|
t_note note;
|
||||||
|
t_noteLength length;
|
||||||
|
} t_tone;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t idx;
|
||||||
|
uint8_t lengthCnt;
|
||||||
|
uint8_t channel;
|
||||||
|
t_tone *tones;
|
||||||
|
} t_melody;
|
||||||
|
|
||||||
|
void sequencerInit();
|
||||||
|
uint8_t sequencerPlayMelody(t_melody *melody);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _SEQUENCER_H_
|
Reference in New Issue
Block a user