tetris/sound-driver/sequencer.h

70 lines
1.2 KiB
C
Raw Normal View History

2024-03-26 15:58:45 +01:00
#ifndef _SEQUENCER_H_
#define _SEQUENCER_H_
2024-03-26 16:47:42 +01:00
#include <stdint.h>
2024-03-26 21:05:48 +01:00
#include <stdbool.h>
2024-03-26 15:58:45 +01:00
#include "psg.h"
typedef enum {
2024-03-29 14:11:36 +01:00
e_L_1 = 0,
e_L_1_2 = 1,
e_L_1_4 = 2,
e_L_1_8 = 3,
e_L_1_16 = 4,
e_L_1_32 = 5,
e_L_LengthEnd = 6,
2024-04-10 12:58:30 +02:00
e_L_HoldMark = 252,
e_L_StopMark = 253,
2024-03-29 14:11:36 +01:00
e_L_EndMark = 254,
e_L_SyncMark = 255,
2024-03-26 15:58:45 +01:00
} t_noteLength;
typedef struct {
t_octave octave;
t_note note;
t_noteLength length;
2024-03-26 21:05:48 +01:00
bool legato;
2024-03-26 23:13:59 +01:00
bool staccato;
2024-03-26 15:58:45 +01:00
} t_tone;
2024-03-26 22:12:46 +01:00
typedef enum {
2024-03-26 23:21:24 +01:00
e_Init,
2024-03-26 22:12:46 +01:00
e_PlayTone,
2024-03-29 13:04:05 +01:00
e_Sync,
2024-03-26 22:12:46 +01:00
e_HoldTone,
2024-03-26 23:13:59 +01:00
e_StaccatoBreak,
e_HoldStaccatoBreak,
e_SeparateTone,
2024-04-10 12:58:30 +02:00
e_Hold,
e_Terminate
2024-03-26 22:12:46 +01:00
} t_sequencerState;
2024-03-26 15:58:45 +01:00
typedef struct {
uint16_t idx;
uint16_t lengthCnt;
2024-03-26 22:12:46 +01:00
t_sequencerState state;
2024-03-26 16:47:42 +01:00
const t_tone *tones;
2024-03-26 15:58:45 +01:00
} t_melody;
2024-03-29 14:11:36 +01:00
#define SEQUENCER_PERIOD 4 // ms
#define NUM_OF_CHANNELS 3
typedef struct {
2024-04-17 15:30:45 +02:00
uint8_t slotMask;
2024-04-25 12:12:52 +02:00
uint8_t chip;
2024-05-22 11:55:47 +02:00
uint8_t *p_amplitude;
uint8_t taskId;
2024-04-10 14:00:12 +02:00
uint16_t quarterLength;
2024-04-10 13:43:28 +02:00
uint8_t numOfMelodies;
2024-04-25 12:12:52 +02:00
uint16_t pace; // quarter notes per minute
2024-03-29 13:04:05 +01:00
uint8_t sync;
t_melody melodies[NUM_OF_CHANNELS];
} t_melodies;
2024-03-26 15:58:45 +01:00
void sequencerInit();
2024-04-17 15:30:45 +02:00
void sequencerPlayMelodies(t_melodies *melodies);
2024-04-15 17:10:33 +02:00
void sequencerStopMelodies(t_melodies *melodies);
2024-04-23 12:45:39 +02:00
void sequencerChangePace(t_melodies *melodies);
2024-03-26 15:58:45 +01:00
#endif // _SEQUENCER_H_