furnace/src/engine/platform/dummy.cpp

171 lines
4.3 KiB
C++
Raw Normal View History

2022-02-15 03:12:20 +00:00
/**
* Furnace Tracker - multi-system chiptune tracker
2023-01-20 00:18:40 +00:00
* Copyright (C) 2021-2023 tildearrow and contributors
2022-02-15 03:12:20 +00:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "dummy.h"
#include "../engine.h"
2021-05-17 05:36:09 +00:00
#include <stdio.h>
#include <math.h>
#define CHIP_FREQBASE 2048
2023-01-02 09:53:37 +00:00
void DivPlatformDummy::acquire(short** buf, size_t len) {
int chanOut;
2023-01-02 09:53:37 +00:00
for (size_t i=0; i<len; i++) {
int out=0;
for (unsigned char j=0; j<chans; j++) {
if (chan[j].active) {
if (!isMuted[j]) {
chanOut=(((signed short)chan[j].pos)*chan[j].amp*chan[j].vol)>>12;
2023-06-19 01:00:20 +00:00
oscBuf[j]->data[oscBuf[j]->needle++]=chanOut<<1;
out+=chanOut;
} else {
oscBuf[j]->data[oscBuf[j]->needle++]=0;
}
chan[j].pos+=chan[j].freq;
} else {
oscBuf[j]->data[oscBuf[j]->needle++]=0;
}
}
if (out<-32768) out=-32768;
if (out>32767) out=32767;
2023-01-02 09:53:37 +00:00
buf[0][i]=out;
}
}
2021-12-18 08:25:42 +00:00
void DivPlatformDummy::muteChannel(int ch, bool mute) {
isMuted[ch]=mute;
}
void DivPlatformDummy::tick(bool sysTick) {
2021-06-09 05:10:23 +00:00
for (unsigned char i=0; i<chans; i++) {
if (sysTick) {
chan[i].amp-=7;
if (chan[i].amp<15) chan[i].amp=15;
}
2021-06-09 06:08:42 +00:00
if (chan[i].freqChanged) {
chan[i].freqChanged=false;
2022-12-17 07:07:24 +00:00
chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,0,false,false,0,0,chipClock,CHIP_FREQBASE);
2021-06-09 06:08:42 +00:00
}
2021-06-09 05:10:23 +00:00
}
}
2022-01-27 05:29:16 +00:00
void* DivPlatformDummy::getChanState(int ch) {
return &chan[ch];
}
DivDispatchOscBuffer* DivPlatformDummy::getOscBuffer(int ch) {
return oscBuf[ch];
}
int DivPlatformDummy::dispatch(DivCommand c) {
switch (c.cmd) {
case DIV_CMD_NOTE_ON:
if (c.value!=DIV_NOTE_NULL) {
chan[c.chan].baseFreq=NOTE_FREQUENCY(c.value);
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_NOTE_PORTA: {
int destFreq=NOTE_FREQUENCY(c.value2);
bool return2=false;
if (destFreq>chan[c.chan].baseFreq) {
chan[c.chan].baseFreq+=c.value;
if (chan[c.chan].baseFreq>=destFreq) {
chan[c.chan].baseFreq=destFreq;
return2=true;
}
} else {
chan[c.chan].baseFreq-=c.value;
if (chan[c.chan].baseFreq<=destFreq) {
chan[c.chan].baseFreq=destFreq;
return2=true;
}
}
chan[c.chan].freqChanged=true;
if (return2) return 2;
break;
}
2021-06-09 06:08:42 +00:00
case DIV_CMD_LEGATO:
chan[c.chan].baseFreq=NOTE_FREQUENCY(c.value);
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;
}
void DivPlatformDummy::notifyInsDeletion(void* ins) {
// nothing
}
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, const DivConfig& flags) {
parent=p;
2022-01-17 04:21:27 +00:00
dumpWrites=false;
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;
if (i<channels) {
oscBuf[i]=new DivDispatchOscBuffer;
oscBuf[i]->rate=65536;
}
2021-12-18 08:25:42 +00:00
}
rate=65536;
chipClock=65536;
chans=channels;
2021-12-11 18:14:38 +00:00
reset();
return channels;
}
void DivPlatformDummy::quit() {
for (int i=0; i<chans; i++) {
delete oscBuf[i];
}
}
DivPlatformDummy::~DivPlatformDummy() {
}