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
|
|
|
|
2021-05-19 07:05:24 +00:00
|
|
|
enum DivStatusView {
|
|
|
|
DIV_STATUS_NOTHING=0,
|
|
|
|
DIV_STATUS_PATTERN,
|
|
|
|
DIV_STATUS_COMMANDS
|
|
|
|
};
|
|
|
|
|
2021-06-09 08:33:03 +00:00
|
|
|
enum DivAudioEngines {
|
|
|
|
DIV_AUDIO_JACK=0,
|
2021-12-07 08:52:41 +00:00
|
|
|
DIV_AUDIO_SDL,
|
|
|
|
DIV_AUDIO_FILE
|
2021-06-09 08:33:03 +00:00
|
|
|
};
|
|
|
|
|
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-12-05 21:11:12 +00:00
|
|
|
int delayOrder, delayRow;
|
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-28 05:36:25 +00:00
|
|
|
bool doNote, legato, portaStop, keyOn, nowYouCanStop, stopOnOff, arpYield;
|
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-12-05 21:11:12 +00:00
|
|
|
delayOrder(0),
|
|
|
|
delayRow(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-28 05:36:25 +00:00
|
|
|
doNote(false), legato(false), portaStop(false), keyOn(false), nowYouCanStop(true), stopOnOff(false), arpYield(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-12-07 08:52:41 +00:00
|
|
|
bool endOfSong;
|
|
|
|
int ticks, cycles, curRow, curOrder, remainingLoops;
|
2021-05-19 07:05:24 +00:00
|
|
|
int changeOrd, changePos, totalTicks, totalCmds, lastCmds, cmdsPerSecond;
|
|
|
|
DivStatusView view;
|
2021-05-14 08:23:40 +00:00
|
|
|
DivChannelState chan[17];
|
2021-06-09 08:33:03 +00:00
|
|
|
DivAudioEngines audioEngine;
|
2021-05-11 20:08:08 +00:00
|
|
|
|
2021-12-07 08:52:41 +00:00
|
|
|
String outName;
|
|
|
|
|
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-12-06 10:21:42 +00:00
|
|
|
size_t bbInLen;
|
2021-05-16 08:03:23 +00:00
|
|
|
int temp[2], prevSample[2];
|
2021-12-06 10:21:42 +00:00
|
|
|
short* bbIn[2];
|
2021-05-12 08:58:55 +00:00
|
|
|
short* bbOut[2];
|
|
|
|
|
2021-05-19 07:05:24 +00:00
|
|
|
int dispatchCmd(DivCommand c);
|
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();
|
2021-12-07 08:52:41 +00:00
|
|
|
// returns true if end of song.
|
|
|
|
bool 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-27 18:30:37 +00:00
|
|
|
DivWavetable* getWave(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();
|
|
|
|
|
2021-12-07 08:52:41 +00:00
|
|
|
// set remaining loops. -1 means loop forever.
|
|
|
|
void setLoops(int loops);
|
|
|
|
|
2021-06-09 08:33:03 +00:00
|
|
|
// set the audio system.
|
|
|
|
void setAudio(DivAudioEngines which);
|
|
|
|
|
|
|
|
// set the view mode.
|
|
|
|
void setView(DivStatusView which);
|
|
|
|
|
2021-12-07 08:52:41 +00:00
|
|
|
// open audio output file.
|
|
|
|
bool openAudioOut(String filename);
|
|
|
|
|
2021-05-11 20:08:08 +00:00
|
|
|
// initialize the engine.
|
2021-05-12 08:58:55 +00:00
|
|
|
bool init();
|
|
|
|
|
|
|
|
DivEngine():
|
|
|
|
chans(0),
|
|
|
|
playing(false),
|
|
|
|
speedAB(false),
|
2021-12-07 08:52:41 +00:00
|
|
|
endOfSong(false),
|
2021-05-12 08:58:55 +00:00
|
|
|
ticks(0),
|
|
|
|
cycles(0),
|
2021-12-05 21:11:12 +00:00
|
|
|
curRow(0),
|
2021-05-12 08:58:55 +00:00
|
|
|
curOrder(0),
|
2021-12-07 08:52:41 +00:00
|
|
|
remainingLoops(-1),
|
2021-05-12 10:22:01 +00:00
|
|
|
changeOrd(-1),
|
|
|
|
changePos(0),
|
2021-05-19 07:05:24 +00:00
|
|
|
totalTicks(0),
|
|
|
|
totalCmds(0),
|
|
|
|
lastCmds(0),
|
|
|
|
cmdsPerSecond(0),
|
|
|
|
view(DIV_STATUS_PATTERN),
|
2021-06-09 08:33:03 +00:00
|
|
|
audioEngine(DIV_AUDIO_SDL),
|
2021-12-06 10:21:42 +00:00
|
|
|
bbInLen(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
|