furnace/src/engine/engine.h
tildearrow 9a97c38cc6 implement more effects and bugfixes
enough to play time trax intro near flawless
2021-05-15 03:13:21 -05:00

84 lines
1.7 KiB
C++

#ifndef _ENGINE_H
#define _ENGINE_H
#include "song.h"
#include "dispatch.h"
#include "../audio/taAudio.h"
#include "blip_buf.h"
struct DivChannelState {
std::vector<DivDelayedCommand> delayed;
int note, pitch, portaSpeed, portaNote;
int volume, volSpeed;
int vibratoDepth, vibratoRate, vibratoPos;
int tremoloDepth, tremoloRate, tremoloPos;
bool doNote, legato;
DivChannelState():
note(-1),
pitch(0),
portaSpeed(-1),
portaNote(-1),
volume(0x7f00),
volSpeed(0),
vibratoDepth(0),
vibratoRate(0),
vibratoPos(0),
tremoloDepth(0),
tremoloRate(0),
tremoloPos(0),
doNote(false), legato(false) {}
};
class DivEngine {
DivDispatch* dispatch;
TAAudio* output;
TAAudioDesc want, got;
int chans;
bool playing;
bool speedAB;
int ticks, cycles, curRow, curOrder;
int changeOrd, changePos;
DivChannelState chan[17];
short vibTable[60];
blip_buffer_t* bb[2];
short temp[2], prevSample[2];
short* bbOut[2];
void nextOrder();
void nextRow();
void nextTick();
bool perSystemEffect(int ch, unsigned char effect, unsigned char effectVal);
bool perSystemPostEffect(int ch, unsigned char effect, unsigned char effectVal);
void renderSamples();
public:
DivSong song;
void nextBuf(float** in, float** out, int inChans, int outChans, unsigned int size);
// load a .dmf.
bool load(void* f, size_t length);
// save as .dmf.
bool save(FILE* f);
// play
void play();
// initialize the engine.
bool init();
DivEngine():
chans(0),
playing(false),
speedAB(false),
ticks(0),
cycles(0),
curRow(-1),
curOrder(0),
changeOrd(-1),
changePos(0),
temp{0,0},
prevSample{0,0} {}
};
#endif