furnace/src/engine/platform/dummy.cpp

92 lines
2.1 KiB
C++
Raw Normal View History

#include "dummy.h"
#include "../engine.h"
2021-05-17 05:36:09 +00:00
#include <stdio.h>
#include <math.h>
void DivPlatformDummy::acquire(short* bufL, short* bufR, size_t start, size_t len) {
for (size_t i=start; i<start+len; i++) {
bufL[i]=0;
for (unsigned char j=0; j<chans; j++) {
if (chan[j].active) {
2021-12-18 08:25:42 +00:00
if (!isMuted[j]) bufL[i]+=(((signed short)chan[j].pos)*chan[j].amp*chan[j].vol)>>13;
chan[j].pos+=chan[j].freq;
}
}
}
}
2021-12-18 08:25:42 +00:00
void DivPlatformDummy::muteChannel(int ch, bool mute) {
isMuted[ch]=mute;
}
void DivPlatformDummy::tick() {
2021-06-09 05:10:23 +00:00
for (unsigned char i=0; i<chans; i++) {
2021-12-18 08:25:42 +00:00
chan[i].amp-=3;
if (chan[i].amp<16) chan[i].amp=16;
2021-06-09 06:08:42 +00:00
if (chan[i].freqChanged) {
chan[i].freqChanged=false;
chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch);
2021-06-09 06:08:42 +00:00
}
2021-06-09 05:10:23 +00:00
}
}
int DivPlatformDummy::dispatch(DivCommand c) {
switch (c.cmd) {
case DIV_CMD_NOTE_ON:
2021-12-18 08:25:42 +00:00
chan[c.chan].baseFreq=65.6f*pow(2.0f,((float)c.value/12.0f));
2021-06-09 06:08:42 +00:00
chan[c.chan].freqChanged=true;
chan[c.chan].active=true;
2021-06-09 05:10:23 +00:00
chan[c.chan].amp=64;
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;
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:
2021-12-18 08:25:42 +00:00
chan[c.chan].baseFreq=65.6f*pow(2.0f,((float)c.value/12.0f));
2021-06-09 06:08:42 +00:00
chan[c.chan].freqChanged=true;
break;
case DIV_CMD_GET_VOLMAX:
return 15;
break;
default:
break;
}
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;
}
}
int DivPlatformDummy::init(DivEngine* p, int channels, int sugRate, bool pal) {
parent=p;
2021-12-21 21:02:31 +00:00
skipRegisterWrites=false;
2022-01-08 06:57:37 +00:00
for (int i=0; i<DIV_MAX_CHANS; i++) {
2021-12-18 08:25:42 +00:00
isMuted[i]=false;
}
rate=65536;
chans=channels;
2021-12-11 18:14:38 +00:00
reset();
return channels;
}
void DivPlatformDummy::quit() {
}
DivPlatformDummy::~DivPlatformDummy() {
}