PowerNoise: code style fixes and stuff

This commit is contained in:
tildearrow 2024-01-24 14:51:04 -05:00
parent c1ae4a607b
commit a9ca32ae3a
2 changed files with 70 additions and 122 deletions

View file

@ -22,6 +22,7 @@
#include "../../ta-log.h"
#include "furIcons.h"
#include <math.h>
#include "../bsr.h"
#define rWrite(a,v) if (!skipRegisterWrites) {regPool[a]=(v); pwrnoise_write(&pn,(unsigned char)(a),(unsigned char)(v)); if (dumpWrites) {addWrite(a,v);}}
#define cWrite(c,a,v) rWrite((c<<3)|((a)+1),(v))
@ -104,7 +105,7 @@ void DivPlatformPowerNoise::acquire(short** buf, size_t len) {
* EX6 - portion A offset (0-15) - slope only
* EX7 - portion B offset (0-15) - slope only
* EX8 - load LFSR (0-65535) - noise only
**/
*/
void DivPlatformPowerNoise::tick(bool sysTick) {
for (int i=0; i<4; i++) {
@ -114,17 +115,16 @@ void DivPlatformPowerNoise::tick(bool sysTick) {
int val=chan[i].std.ex1.val;
if (chan[i].slope) {
chan[i].slopeA.clip = ((val & 0x20) != 0);
chan[i].slopeB.clip = ((val & 0x10) != 0);
chan[i].slopeA.reset = ((val & 0x08) != 0);
chan[i].slopeB.reset = ((val & 0x04) != 0);
chan[i].slopeA.dir = ((val & 0x02) != 0);
chan[i].slopeB.dir = ((val & 0x01) != 0);
chan[i].slopeA.clip=(val&0x20);
chan[i].slopeB.clip=(val&0x10);
chan[i].slopeA.reset=(val&0x08);
chan[i].slopeB.reset=(val&0x04);
chan[i].slopeA.dir=(val&0x02);
chan[i].slopeB.dir=(val&0x01);
cWrite(i,0x00,slopeCtl(chan[i].active,false,chan[i].slopeA,chan[i].slopeB));
}
else {
chan[i].am = ((val & 0x02) != 0);
chan[i].tapBEnable = ((val & 0x01) != 0);
} else {
chan[i].am=(val&0x02);
chan[i].tapBEnable=(val&0x01);
cWrite(i,0x00,noiseCtl(chan[i].active, chan[i].am, chan[i].tapBEnable));
}
}
@ -190,74 +190,24 @@ void DivPlatformPowerNoise::tick(bool sysTick) {
if (chan[i].freq<0) chan[i].freq=0;
if (chan[i].freq>0x7ffffff) chan[i].freq=0x7ffffff;
chan[i].octave=MAX(bsr(chan[i].freq)-12,0);
if (chan[i].octave>15) chan[i].octave=15;
chan[i].fNum=0xfff-(chan[i].freq>>chan[i].octave);
if (chan[i].freq >= 0x4000000) {
chan[i].octave = 15;
}
else if (chan[i].freq >= 0x2000000) {
chan[i].octave = 14;
}
else if (chan[i].freq >= 0x1000000) {
chan[i].octave = 13;
}
else if (chan[i].freq >= 0x800000) {
chan[i].octave = 12;
}
else if (chan[i].freq >= 0x400000) {
chan[i].octave = 11;
}
else if (chan[i].freq >= 0x200000) {
chan[i].octave = 10;
}
else if (chan[i].freq >= 0x100000) {
chan[i].octave = 9;
}
else if (chan[i].freq >= 0x80000) {
chan[i].octave = 8;
}
else if (chan[i].freq >= 0x40000) {
chan[i].octave = 7;
}
else if (chan[i].freq >= 0x20000) {
chan[i].octave = 6;
}
else if (chan[i].freq >= 0x10000) {
chan[i].octave = 5;
}
else if (chan[i].freq >= 0x8000) {
chan[i].octave = 4;
}
else if (chan[i].freq >= 0x4000) {
chan[i].octave = 3;
}
else if (chan[i].freq >= 0x2000) {
chan[i].octave = 2;
}
else if (chan[i].freq >= 0x1000) {
chan[i].octave = 1;
}
else {
chan[i].octave = 0;
}
chan[i].freq = 0xfff-(chan[i].freq>>chan[i].octave);
cWrite(i,0x01,chan[i].freq&0xff);
cWrite(i,0x02,(chan[i].freq>>8) | (chan[i].octave<<4));
cWrite(i,0x01,chan[i].fNum&0xff);
cWrite(i,0x02,(chan[i].fNum>>8)|(chan[i].octave<<4));
if (chan[i].keyOn) {
if (chan[i].slope) {
cWrite(i,0x00,slopeCtl(true,false,chan[i].slopeA,chan[i].slopeB));
}
else {
} else {
cWrite(i,0x00,noiseCtl(true,chan[i].am,chan[i].tapBEnable));
}
}
if (chan[i].keyOff) {
if (chan[i].slope) {
cWrite(i,0x00,slopeCtl(false,false,chan[i].slopeA,chan[i].slopeB));
}
else {
} else {
cWrite(i,0x00,noiseCtl(false,chan[i].am,chan[i].tapBEnable));
}
}
@ -270,12 +220,15 @@ void DivPlatformPowerNoise::tick(bool sysTick) {
if (chan[i].slope) {
unsigned char counter=pn.s.accum;
regPool[0x18]=counter;
}
else {
} else {
unsigned short lfsr;
if (i == 0) lfsr = pn.n1.lfsr;
else if (i == 1) lfsr = pn.n2.lfsr;
else lfsr = pn.n3.lfsr;
if (i==0) {
lfsr=pn.n1.lfsr;
} else if (i==1) {
lfsr=pn.n2.lfsr;
} else {
lfsr=pn.n3.lfsr;
}
regPool[(i<<3)+0x4]=lfsr&0xff;
regPool[(i<<3)+0x5]=lfsr>>8;
}
@ -286,8 +239,6 @@ int DivPlatformPowerNoise::dispatch(DivCommand c) {
switch (c.cmd) {
case DIV_CMD_NOTE_ON: {
DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_POWERNOISE);
// ??????
if (skipRegisterWrites) break;
if (c.value!=DIV_NOTE_NULL) {
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value);
chan[c.chan].freqChanged=true;
@ -392,8 +343,7 @@ int DivPlatformPowerNoise::dispatch(DivCommand c) {
case DIV_CMD_POWERNOISE_COUNTER_LOAD: {
if (chan[c.chan].slope && c.value==0) {
rWrite(0x18,c.value2&0x7f);
}
else if (!chan[c.chan].slope) {
} else if (!chan[c.chan].slope) {
cWrite(c.chan,0x03+c.value,c.value2);
}
break;
@ -446,18 +396,14 @@ DivChannelModeHints DivPlatformPowerNoise::getModeHints(int ch) {
return ret;
}
DivSamplePos DivPlatformPowerNoise::getSamplePos(int ch) {
return DivSamplePos();
bool DivPlatformPowerNoise::getDCOffRequired() {
return true;
}
DivDispatchOscBuffer* DivPlatformPowerNoise::getOscBuffer(int ch) {
return oscBuf[ch];
}
int DivPlatformPowerNoise::mapVelocity(int ch, float vel) {
return round(15.0*pow(vel,0.22));
}
unsigned char* DivPlatformPowerNoise::getRegisterPool() {
return regPool;
}
@ -471,7 +417,7 @@ void DivPlatformPowerNoise::reset() {
for (int i=0; i<4; i++) {
chan[i]=DivPlatformPowerNoise::Channel();
chan[i].std.setEngine(parent);
chan[i].slope = i == 3;
chan[i].slope=(i==3);
}
pwrnoise_reset(&pn);
@ -482,6 +428,7 @@ void DivPlatformPowerNoise::reset() {
for (int i=0; i<4; i++) {
cWrite(i,0x06,volPan(chan[i].outVol,chan[i].pan));
}
// TODO: set LFSR defaults
addWrite(0xffffffff,0);
}

View file

@ -37,12 +37,14 @@ class DivPlatformPowerNoise: public DivDispatch {
};
struct Channel: public SharedChannel<signed char> {
int fNum;
unsigned char octave, pan, tapA, tapB;
bool slope, am, tapBEnable, keyOn, keyOff;
SlopePortion slopeA, slopeB;
Channel():
SharedChannel<signed char>(15),
fNum(0),
octave(0),
pan(255),
tapA(0),
@ -72,9 +74,8 @@ class DivPlatformPowerNoise: public DivDispatch {
DivMacroInt* getChanMacroInt(int ch);
unsigned short getPan(int chan);
DivChannelModeHints getModeHints(int chan);
DivSamplePos getSamplePos(int ch);
bool getDCOffRequired();
DivDispatchOscBuffer* getOscBuffer(int chan);
int mapVelocity(int ch, float vel);
unsigned char* getRegisterPool();
int getRegisterPoolSize();
void reset();