2021-05-12 08:58:55 +00:00
|
|
|
#include "dummy.h"
|
2021-05-17 05:36:09 +00:00
|
|
|
#include <stdio.h>
|
2021-05-12 10:22:01 +00:00
|
|
|
#include <math.h>
|
2021-05-12 08:58:55 +00:00
|
|
|
|
2021-12-06 21:51:18 +00:00
|
|
|
void DivPlatformDummy::acquire(short* bufL, short* bufR, size_t start, size_t len) {
|
2021-12-06 10:21:42 +00:00
|
|
|
for (size_t i=start; i<start+len; i++) {
|
2021-12-06 21:51:18 +00:00
|
|
|
bufL[i]=0;
|
2021-12-06 10:21:42 +00:00
|
|
|
for (unsigned char j=0; j<chans; j++) {
|
|
|
|
if (chan[j].active) {
|
2021-12-06 21:51:18 +00:00
|
|
|
bufL[i]+=((chan[j].pos>=0x8000)?chan[j].vol:-chan[j].vol)*chan[j].amp;
|
2021-12-06 10:21:42 +00:00
|
|
|
chan[j].pos+=chan[j].freq;
|
|
|
|
}
|
2021-05-12 10:22:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformDummy::tick() {
|
2021-06-09 05:10:23 +00:00
|
|
|
for (unsigned char i=0; i<chans; i++) {
|
|
|
|
chan[i].amp--;
|
|
|
|
if (chan[i].amp<0) chan[i].amp=0;
|
2021-06-09 06:08:42 +00:00
|
|
|
|
|
|
|
if (chan[i].freqChanged) {
|
|
|
|
chan[i].freqChanged=false;
|
|
|
|
chan[i].freq=(chan[i].baseFreq*(ONE_SEMITONE+chan[i].pitch))/ONE_SEMITONE;
|
|
|
|
}
|
2021-06-09 05:10:23 +00:00
|
|
|
}
|
2021-05-12 08:58:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int DivPlatformDummy::dispatch(DivCommand c) {
|
2021-05-12 10:22:01 +00:00
|
|
|
switch (c.cmd) {
|
|
|
|
case DIV_CMD_NOTE_ON:
|
2021-06-09 06:08:42 +00:00
|
|
|
chan[c.chan].baseFreq=16.4f*pow(2.0f,((float)c.value/12.0f));
|
|
|
|
chan[c.chan].freqChanged=true;
|
2021-05-12 10:22:01 +00:00
|
|
|
chan[c.chan].active=true;
|
2021-06-09 05:10:23 +00:00
|
|
|
chan[c.chan].amp=64;
|
2021-05-12 10:22:01 +00:00
|
|
|
break;
|
|
|
|
case DIV_CMD_NOTE_OFF:
|
|
|
|
chan[c.chan].active=false;
|
|
|
|
break;
|
2021-05-12 22:19:18 +00:00
|
|
|
case DIV_CMD_VOLUME:
|
|
|
|
chan[c.chan].vol=c.value;
|
2021-06-09 05:10:23 +00:00
|
|
|
if (chan[c.chan].vol>15) chan[c.chan].vol=15;
|
2021-05-12 22:19:18 +00:00
|
|
|
break;
|
2021-05-17 08:06:45 +00:00
|
|
|
case DIV_CMD_GET_VOLUME:
|
|
|
|
return chan[c.chan].vol;
|
|
|
|
break;
|
2021-06-09 06:08:42 +00:00
|
|
|
case DIV_CMD_PITCH:
|
|
|
|
chan[c.chan].pitch=c.value;
|
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_LEGATO:
|
|
|
|
chan[c.chan].baseFreq=16.4f*pow(2.0f,((float)c.value/12.0f));
|
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
break;
|
2021-05-17 20:06:11 +00:00
|
|
|
case DIV_CMD_GET_VOLMAX:
|
|
|
|
return 15;
|
|
|
|
break;
|
2021-05-12 10:22:01 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-05-12 08:58:55 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-12-11 18:14:38 +00:00
|
|
|
void DivPlatformDummy::reset() {
|
|
|
|
for (int i=0; i<chans; i++) {
|
|
|
|
chan[i]=DivPlatformDummy::Channel();
|
|
|
|
chan[i].vol=0x0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-08 06:56:40 +00:00
|
|
|
int DivPlatformDummy::init(DivEngine* p, int channels, int sugRate, bool pal) {
|
2021-05-12 08:58:55 +00:00
|
|
|
parent=p;
|
2021-05-12 10:22:01 +00:00
|
|
|
rate=65536;
|
|
|
|
chans=channels;
|
2021-12-11 18:14:38 +00:00
|
|
|
reset();
|
2021-05-12 08:58:55 +00:00
|
|
|
return channels;
|
2021-05-12 10:22:01 +00:00
|
|
|
}
|