2021-05-12 08:58:55 +00:00
|
|
|
#ifndef _ENGINE_H
|
|
|
|
#define _ENGINE_H
|
2021-05-11 20:08:08 +00:00
|
|
|
#include "song.h"
|
|
|
|
#include "dispatch.h"
|
|
|
|
#include "../audio/taAudio.h"
|
2021-05-12 08:58:55 +00:00
|
|
|
#include "blip_buf.h"
|
2021-05-11 20:08:08 +00:00
|
|
|
|
|
|
|
struct DivChannelState {
|
|
|
|
std::vector<DivDelayedCommand> delayed;
|
2021-05-14 08:23:40 +00:00
|
|
|
int note, pitch, portaSpeed, portaNote;
|
2021-05-17 20:06:11 +00:00
|
|
|
int volume, volSpeed, cut, rowDelay, volMax;
|
2021-05-18 08:02:47 +00:00
|
|
|
int vibratoDepth, vibratoRate, vibratoPos, vibratoDir, vibratoFine;
|
2021-05-14 19:16:48 +00:00
|
|
|
int tremoloDepth, tremoloRate, tremoloPos;
|
2021-05-18 07:53:59 +00:00
|
|
|
unsigned char arp, arpStage, arpTicks;
|
2021-05-15 08:13:21 +00:00
|
|
|
bool doNote, legato;
|
2021-05-14 08:23:40 +00:00
|
|
|
|
|
|
|
DivChannelState():
|
|
|
|
note(-1),
|
|
|
|
pitch(0),
|
|
|
|
portaSpeed(-1),
|
|
|
|
portaNote(-1),
|
|
|
|
volume(0x7f00),
|
|
|
|
volSpeed(0),
|
2021-05-16 08:03:23 +00:00
|
|
|
cut(-1),
|
|
|
|
rowDelay(0),
|
2021-05-14 08:23:40 +00:00
|
|
|
vibratoDepth(0),
|
|
|
|
vibratoRate(0),
|
2021-05-14 19:16:48 +00:00
|
|
|
vibratoPos(0),
|
2021-05-18 07:29:17 +00:00
|
|
|
vibratoDir(0),
|
2021-05-18 08:02:47 +00:00
|
|
|
vibratoFine(15),
|
2021-05-14 08:23:40 +00:00
|
|
|
tremoloDepth(0),
|
2021-05-14 19:16:48 +00:00
|
|
|
tremoloRate(0),
|
|
|
|
tremoloPos(0),
|
2021-05-16 08:03:23 +00:00
|
|
|
arp(0),
|
|
|
|
arpStage(-1),
|
2021-05-18 07:53:59 +00:00
|
|
|
arpTicks(1),
|
2021-05-15 08:13:21 +00:00
|
|
|
doNote(false), legato(false) {}
|
2021-05-11 20:08:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DivEngine {
|
|
|
|
DivDispatch* dispatch;
|
|
|
|
TAAudio* output;
|
|
|
|
TAAudioDesc want, got;
|
|
|
|
int chans;
|
|
|
|
bool playing;
|
|
|
|
bool speedAB;
|
2021-05-12 08:58:55 +00:00
|
|
|
int ticks, cycles, curRow, curOrder;
|
2021-05-12 10:22:01 +00:00
|
|
|
int changeOrd, changePos;
|
2021-05-14 08:23:40 +00:00
|
|
|
DivChannelState chan[17];
|
2021-05-11 20:08:08 +00:00
|
|
|
|
2021-05-16 08:03:23 +00:00
|
|
|
short vibTable[64];
|
2021-05-14 19:16:48 +00:00
|
|
|
|
2021-05-12 08:58:55 +00:00
|
|
|
blip_buffer_t* bb[2];
|
2021-05-16 08:03:23 +00:00
|
|
|
int temp[2], prevSample[2];
|
2021-05-12 08:58:55 +00:00
|
|
|
short* bbOut[2];
|
|
|
|
|
2021-05-16 08:03:23 +00:00
|
|
|
void processRow(int i, bool afterDelay);
|
2021-05-12 08:58:55 +00:00
|
|
|
void nextOrder();
|
|
|
|
void nextRow();
|
|
|
|
void nextTick();
|
2021-05-13 07:39:26 +00:00
|
|
|
bool perSystemEffect(int ch, unsigned char effect, unsigned char effectVal);
|
2021-05-15 08:13:21 +00:00
|
|
|
bool perSystemPostEffect(int ch, unsigned char effect, unsigned char effectVal);
|
2021-05-13 07:39:26 +00:00
|
|
|
void renderSamples();
|
2021-05-12 08:58:55 +00:00
|
|
|
|
2021-05-11 20:08:08 +00:00
|
|
|
public:
|
2021-05-12 22:19:18 +00:00
|
|
|
DivSong song;
|
2021-05-12 08:58:55 +00:00
|
|
|
void nextBuf(float** in, float** out, int inChans, int outChans, unsigned int size);
|
2021-05-17 01:49:54 +00:00
|
|
|
DivInstrument* getIns(int index);
|
2021-05-11 20:08:08 +00:00
|
|
|
// load a .dmf.
|
|
|
|
bool load(void* f, size_t length);
|
|
|
|
// save as .dmf.
|
|
|
|
bool save(FILE* f);
|
|
|
|
|
|
|
|
// play
|
|
|
|
void play();
|
|
|
|
|
|
|
|
// initialize the engine.
|
2021-05-12 08:58:55 +00:00
|
|
|
bool init();
|
|
|
|
|
|
|
|
DivEngine():
|
|
|
|
chans(0),
|
|
|
|
playing(false),
|
|
|
|
speedAB(false),
|
|
|
|
ticks(0),
|
|
|
|
cycles(0),
|
|
|
|
curRow(-1),
|
|
|
|
curOrder(0),
|
2021-05-12 10:22:01 +00:00
|
|
|
changeOrd(-1),
|
|
|
|
changePos(0),
|
2021-05-12 08:58:55 +00:00
|
|
|
temp{0,0},
|
|
|
|
prevSample{0,0} {}
|
2021-05-11 20:08:08 +00:00
|
|
|
};
|
2021-05-12 10:22:01 +00:00
|
|
|
#endif
|