Skip to content

Commit

Permalink
Performance improvements (for #67) and minor fixes (#111 and #112)
Browse files Browse the repository at this point in the history
  • Loading branch information
image-et-son committed Feb 27, 2022
1 parent a63d7ce commit 4b524b1
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 170 deletions.
151 changes: 100 additions & 51 deletions common/potmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,86 @@

static const int8_t potBitDepth[POTMUX_POT_COUNT]=
{
/*Mixer*/8, /*Cutoff*/12,/*Resonance*/8,/*FilEnvAmt*/10,/*FilRel*/8,/*FilSus*/10,
/*FilDec*/8,/*FilAtt*/8,/*AmpRel*/8,/*AmpSus*/10,/*AmpDec*/8,/*AmpAtt*/8,
/*Glide*/8,/*BPW*/10,/*MVol*/8,/*MTune*/12,/*PitchWheel*/12,0,0,0,0,0,/*ModWheel*/8,
/*Speed*/12,/*APW*/10,/*PModFilEnv*/10,/*LFOFreq*/10,/*PModOscB*/10,/*LFOAmt*/12,/*FreqB*/12,/*FreqA*/12,/*FreqBFine*/12
};
/*Mixer*/8,
/*Cutoff*/12,
/*Resonance*/8,
/*FilEnvAmt*/10,
/*FilRel*/8,
/*FilSus*/10,
/*FilDec*/8,
/*FilAtt*/8,
/*AmpRel*/8,
/*AmpSus*/10,
/*AmpDec*/8,
/*AmpAtt*/8,
/*Glide*/8,
/*BPW*/10,
/*MVol*/8,
/*MTune*/12,
/*PitchWheel*/12,
0,
0,
0,
0,
0,
/*ModWheel*/8,
/*Speed*/12,
/*APW*/10,
/*PModFilEnv*/10,
/*LFOFreq*/10,
/*PModOscB*/10,
/*LFOAmt*/12,
/*FreqB*/12,
/*FreqA*/12,
/*FreqBFine*/12,

static const p600Pot_t priorityPots[6]=
{
ppPitchWheel, ppMVol, ppFreqA, ppFreqB,
ppModWheel,
ppNone
};

static const p600Pot_t regularPots[23]=
static const int8_t response[POTMUX_POT_COUNT]=
{
ppMixer, ppResonance, ppFilEnvAmt, ppGlide, ppBPW, ppAPW, ppPModFilEnv, ppLFOFreq, ppPModOscB, ppLFOAmt, ppSpeed, ppAmpRel, ppAmpSus, ppAmpDec, ppAmpAtt, ppFilAtt, ppFilDec, ppFilSus, ppFilRel, ppMTune, ppFreqBFine, ppCutoff, ppNone
/*Vol A*/6,
/*Cutoff*/4,
/*Resonance*/3,
/*Fil Env Amt*/6,
/*Filter Release */35,
/*Filter Sustain*/6,
/*Filter Decay*/35,
/*Filter Attack*/35,
/*Amp Release*/35,
/*Amp Sustain*/6,
/*Amp Decay*/35,
/*Amp Attack*/35,
/*Vol B*/6,
/*BPW*/7,
/*Master Vol*/6,
/*Master Tune*/11,
/*Pitch Bender*/3,
0,
0,
0,
0,
0,
/*Mod Wheel*/3,
/*Data Dial*/8,
/*APW*/7,
/*Poly-Mod Env*/8,
/*Poly-Mod OSC B*/3,
/*LFO Frequency*/20,
/*LFO Amount*/6,
/*Frequeny B*/3,
/*Frequeny A*/3,
/*Frequency B Fine*/20,
};


static struct
{
uint32_t potChanged;
uint8_t changeDetect[POTMUX_POT_COUNT];

uint16_t pots[POTMUX_POT_COUNT];
uint8_t potExcited[POTMUX_POT_COUNT];
uint8_t potExcitedCount[POTMUX_POT_COUNT];
uint8_t potcounter[POTMUX_POT_COUNT];
int8_t currentRegularPot;
int8_t lastChanged;
int8_t lastInAction;
Expand All @@ -50,7 +104,7 @@ static void updatePot(int8_t pot)
uint16_t bit;

if (pot<0) return;

BLOCK_INT
{
// successive approximations using DAC and comparator
Expand All @@ -74,7 +128,7 @@ static void updatePot(int8_t pot)

for(i=0;i<=bitDepth;++i)
{
dac_write(estimate);
dac_write(estimate);

// let comparator get correct voltage (don't remove me!)
CYCLE_WAIT(2);
Expand All @@ -96,26 +150,31 @@ static void updatePot(int8_t pot)

io_write(0x0a,0xff);
CYCLE_WAIT(4);

// suppress the bits beyond the measurement accuracy
estimate&=badMask;

// change detector
cdv=estimate>>8;
diff = abs(potmux.changeDetect[pot]-cdv);
if (potmux.lastInAction!=pot && potmux.potExcitedCount[pot]>0) potmux.potExcitedCount[pot]--;
potmux.potExcited[pot]=potmux.potExcitedCount[pot]>0?1:0;
if(diff>CHANGE_DETECT_THRESHOLD || potmux.potExcitedCount[pot]>0)
if (potmux.lastInAction!=pot) potmux.potExcited[pot]=0;
if(diff>CHANGE_DETECT_THRESHOLD || (potmux.potExcited[pot] && pot!=ppPitchWheel))
{
potmux.changeDetect[pot]=cdv;
potmux.potChanged|=(uint32_t)1<<pot;
if(diff>CHANGE_DETECT_THRESHOLD) potmux.potExcitedCount[pot]=10; // keep up excited state for some cycles only if change not too small
potmux.lastChanged=pot; // this is reset in every cycle
potmux.potExcited[pot]=1;
potmux.lastChanged=pot; // this is reset in every cycle, this is used to decide which value to show on the display
potmux.lastInAction=pot; // this stays and is only reset for a change of mode
}

if (estimate>=0xFC00) estimate=badMask; // choose max value above the threshold UINT16_t - CHANGE_DETECT_THRESHOLD
potmux.pots[pot]=estimate;
if (estimate>=0xFC00)
{
potmux.pots[pot]=badMask; // choose max value above the threshold UINT16_t - CHANGE_DETECT_THRESHOLD
}
else
{
potmux.pots[pot]=estimate;
}
}
}

Expand Down Expand Up @@ -148,7 +207,6 @@ void potmux_resetChangedFull(void)
for (i=0;i<POTMUX_POT_COUNT;i++)
{
potmux.potExcited[i]=0;
potmux.potExcitedCount[i]=0;
}
}

Expand All @@ -159,7 +217,6 @@ FORCEINLINE void potmux_resetSpeedPot(void)
potmux.potChanged&=(~(mask<<ppSpeed)); // remove the bit of the speed pot
if (potmux.lastChanged==ppSpeed) potmux.lastChanged=ppNone;
potmux.potExcited[ppSpeed]=0;
potmux.potExcitedCount[ppSpeed]=0;

}

Expand All @@ -168,39 +225,31 @@ int8_t potmux_isPotZeroCentered(p600Pot_t pot, uint8_t layout)
return pot==ppFilEnvAmt || pot==ppPModFilEnv || pot==ppFreqBFine || pot==ppMTune || pot==ppPitchWheel || (pot==ppMixer && layout==1);
}

inline void potmux_update(uint8_t updateAll, uint8_t potsPerCycle)
inline void potmux_update(uint8_t updateAll)
{
int16_t i, updatable;
updatable=updateAll?22:potsPerCycle;
for(i=0;i<updatable;++i)
{
if (!potmux.potExcited[regularPots[potmux.currentRegularPot]] || updateAll)
updatePot(regularPots[potmux.currentRegularPot]); // done in the next loop
potmux.currentRegularPot++;
if (regularPots[potmux.currentRegularPot]==ppNone) potmux.currentRegularPot=0;
}

p600Pot_t pp=regularPots[0];
i=0;
while (pp!=ppNone) // this cycle once through the pots in prio 2
{
if (potmux.potExcited[pp]) updatePot(pp);
i++;
pp=regularPots[i];
}
int16_t i;

i=0;
pp=priorityPots[0];
while (pp!=ppNone) // this cycle once through the pots in prio 1
for(i=0;i<POTMUX_POT_COUNT;++i)
{
updatePot(pp);
i++;
pp=priorityPots[i];
if (response[i]!=0)
{
if (potmux.potcounter[i]==0 || potmux.potExcited[i] || updateAll)
{
updatePot(i);
}
}
potmux.potcounter[i]=(potmux.potcounter[i]+1)%(2*response[i]);
}
}

void potmux_init(void)
{
memset(&potmux,0,sizeof(potmux));
potmux.lastChanged=ppNone;
potmux_resetChangedFull();
uint8_t i;

for (i=0;i<POTMUX_POT_COUNT;++i)
{
potmux.potcounter[i]=i; // distribute the pots as evenly as possible
}
}
2 changes: 1 addition & 1 deletion common/potmux.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void potmux_resetSpeedPot(void);

void potmux_init(void);

void potmux_update(uint8_t updateAll, uint8_t potsPerCycle);
void potmux_update(uint8_t updateAll);
uint8_t comparePotVal(p600Pot_t pot, uint16_t potValue, uint16_t compareValue);

int8_t potmux_isPotZeroCentered(p600Pot_t pot, uint8_t layout);
Expand Down
21 changes: 11 additions & 10 deletions common/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ static void resetPickUps(void)
{
uint8_t cnt;
for (cnt=0;cnt<cpCount;++cnt) currentPreset.contParamPotStatus[cnt]=0;
currentPreset.switchStatus=0;
}

static LOWERCODESIZE int8_t storageLoad(uint16_t pageIdx, uint8_t pageCount)
Expand Down Expand Up @@ -215,10 +214,10 @@ LOWERCODESIZE int8_t settings_load(void)
settings.midiReceiveChannel=-1; // default is 'OMNI'
settings.voiceMask=0x3f; // default is: all on
settings.midiSendChannel=0; // deault is: 1
settings.syncMode=smInternal; // default ist internal clock
settings.syncMode=smInternal; // default is internal clock
settings.vcfLimit=0; // default is: no limit on the VCF
settings.midiMode=0; // normal mode
settings.panelLayout=0; // normal mode
settings.panelLayout=0; // GliGli layout

if (storage.version<1)
return 1;
Expand Down Expand Up @@ -353,6 +352,7 @@ LOWERCODESIZE int8_t preset_loadCurrent(uint16_t number, uint8_t loadFromBuffer)
{
uint8_t i;
int8_t readVar;
int16_t readVarLong;

BLOCK_INT
{
Expand All @@ -367,9 +367,6 @@ LOWERCODESIZE int8_t preset_loadCurrent(uint16_t number, uint8_t loadFromBuffer)
}
else
{

resetPickUps();

// check the storage MAGIC
storage.bufPtr=storage.buffer;

Expand All @@ -379,6 +376,7 @@ LOWERCODESIZE int8_t preset_loadCurrent(uint16_t number, uint8_t loadFromBuffer)
return 0;
}
storage.version=storageRead8();
resetPickUps();
}

// compatibility with previous versions require the ""Pulse Width Sync Bug""
Expand Down Expand Up @@ -482,7 +480,10 @@ LOWERCODESIZE int8_t preset_loadCurrent(uint16_t number, uint8_t loadFromBuffer)
// v7

for (i=0; i<TUNER_NOTE_COUNT; i++)
currentPreset.perNoteTuning[i]=storageRead16();
{
readVarLong=storageRead16();
if (number!=MANUAL_PRESET_PAGE || loadFromBuffer) currentPreset.perNoteTuning[i]=readVarLong; // always reset equal tempered tuning for manual mode: keep defaults
}

if (storage.version<8)
{
Expand Down Expand Up @@ -671,9 +672,8 @@ LOWERCODESIZE void preset_loadDefault(int8_t makeSound)
currentPreset.continuousParameters[cpAmpSus]=UINT16_MAX;
currentPreset.continuousParameters[cpAmpVelocity]=HALF_RANGE;
currentPreset.continuousParameters[cpVibFreq]=HALF_RANGE;
if (settings.panelLayout==1) currentPreset.continuousParameters[cpDrive]=HALF_RANGE;
if (settings.panelLayout==0) currentPreset.continuousParameters[cpMixVolA]=UINT16_MAX;
//currentPreset.continuousParameters[cpDrive]=HALF_RANGE; // this is internal parameter for SCI panel layout
//currentPreset.continuousParameters[cpVolA]=UINT16_MAX;

currentPreset.steppedParameters[spBenderSemitones]=5;
currentPreset.steppedParameters[spBenderTarget]=modAB;
Expand Down Expand Up @@ -703,9 +703,10 @@ LOWERCODESIZE void settings_loadDefault(void)
memset(&settings,0,sizeof(settings));

settings.benderMiddle=HALF_RANGE;
settings.midiReceiveChannel=-1;
settings.midiReceiveChannel=-1; // OMNI
settings.voiceMask=0x3f;
settings.seqArpClock=HALF_RANGE;
settings.panelLayout=0; // GliGli layout

tuner_init(); // use theoretical tuning
}
Expand Down
Loading

0 comments on commit 4b524b1

Please sign in to comment.