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;
|
|
|
|
int rampSpeed, portaSpeed, portaNote;
|
|
|
|
int volSpeed;
|
|
|
|
int vibratoDepth, vibratoRate;
|
|
|
|
int tremoloDepth, tremoloRate;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DivEngine {
|
|
|
|
DivSong song;
|
|
|
|
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-11 20:08:08 +00:00
|
|
|
std::vector<DivChannelState> chan;
|
|
|
|
|
2021-05-12 08:58:55 +00:00
|
|
|
blip_buffer_t* bb[2];
|
|
|
|
short temp[2], prevSample[2];
|
|
|
|
short* bbOut[2];
|
|
|
|
|
|
|
|
void nextOrder();
|
|
|
|
void nextRow();
|
|
|
|
void nextTick();
|
|
|
|
|
2021-05-11 20:08:08 +00:00
|
|
|
public:
|
2021-05-12 08:58:55 +00:00
|
|
|
void nextBuf(float** in, float** out, int inChans, int outChans, unsigned int size);
|
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
|