Initial MKI table engine

pull/1/head
asb2m10 9 years ago
parent d1d506fc61
commit ce3db6b2b1
  1. BIN
      Builds/MacOSX/Dexed.xcodeproj/project.xcworkspace/xcuserdata/asb2m10.xcuserdatad/UserInterfaceState.xcuserstate
  2. 14
      Source/CartManager.cpp
  3. 3
      Source/CartManager.h
  4. 269
      Source/EngineMkI.cpp
  5. 15
      Source/EngineMkI.h
  6. 14
      Source/EngineOpl.cpp
  7. 2
      Source/EngineOpl.h
  8. 14
      Source/PluginData.cpp
  9. 26
      Source/PluginParam.cpp
  10. 2
      Source/PluginProcessor.cpp
  11. 46
      Source/msfa/controllers.h
  12. 2
      Source/msfa/dx7note.cc
  13. 3
      Source/msfa/fm_core.cc
  14. 3
      Source/msfa/fm_core.h

@ -91,7 +91,9 @@ CartManager::CartManager(DexedAudioProcessorEditor *editor) : Component("CartMan
cartBrowserList = new DirectoryContentsList(syxFileFilter, *timeSliceThread); cartBrowserList = new DirectoryContentsList(syxFileFilter, *timeSliceThread);
cartBrowserList->setDirectory(cartDir, true, true); cartBrowserList->setDirectory(cartDir, true, true);
cartBrowser = new FileTreeDrop(*cartBrowserList); cartBrowser = new FileTreeDrop(*cartBrowserList);
cartBrowser->addKeyListener(this);
addAndMakeVisible(cartBrowser); addAndMakeVisible(cartBrowser);
cartBrowser->setBounds(23, 18, 590, 384); cartBrowser->setBounds(23, 18, 590, 384);
cartBrowser->setDragAndDropDescription("Sysex Browser"); cartBrowser->setDragAndDropDescription("Sysex Browser");
cartBrowser->addListener(this); cartBrowser->addListener(this);
@ -334,6 +336,18 @@ void CartManager::initialFocus() {
cartBrowser->grabKeyboardFocus(); cartBrowser->grabKeyboardFocus();
} }
bool CartManager::keyPressed(const KeyPress& key, Component* originatingComponent) {
if ( key.getKeyCode() == 13 ) {
File file = cartBrowser->getSelectedFile();
if ( file.isDirectory() )
return true;
mainWindow->loadCart(file);
activeCart->setCartridge(mainWindow->processor->currentCart);
return true;
}
return false;
}
void CartManager::showSysexConfigMsg() { void CartManager::showSysexConfigMsg() {
AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "Warning", "The DX7 midi interface is not configured correctly.\n\n" AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "Warning", "The DX7 midi interface is not configured correctly.\n\n"
"These buttons are used to 'ask' the DX7 to send the current program/cartridge.\n\n" "These buttons are used to 'ask' the DX7 to send the current program/cartridge.\n\n"

@ -27,7 +27,7 @@
#include "PluginData.h" #include "PluginData.h"
class CartManager : public Component, public ButtonListener, public DragAndDropContainer, public FileBrowserListener class CartManager : public Component, public ButtonListener, public DragAndDropContainer, public FileBrowserListener
, public ProgramListBoxListener { , public ProgramListBoxListener, public KeyListener {
ScopedPointer<TextButton> newButton; ScopedPointer<TextButton> newButton;
ScopedPointer<TextButton> loadButton; ScopedPointer<TextButton> loadButton;
ScopedPointer<TextButton> saveButton; ScopedPointer<TextButton> saveButton;
@ -68,6 +68,7 @@ public:
virtual void programSelected(ProgramListBox *source, int pos) override; virtual void programSelected(ProgramListBox *source, int pos) override;
virtual void programRightClicked(ProgramListBox *source, int pos) override; virtual void programRightClicked(ProgramListBox *source, int pos) override;
virtual void programDragged(ProgramListBox *destListBox, int dest, char *packedPgm) override; virtual void programDragged(ProgramListBox *destListBox, int dest, char *packedPgm) override;
virtual bool keyPressed(const KeyPress& key, Component* originatingComponent) override;
void initialFocus(); void initialFocus();
}; };

@ -23,127 +23,134 @@
#include "msfa/sin.h" #include "msfa/sin.h"
#include "msfa/exp2.h" #include "msfa/exp2.h"
const FmAlgorithm EngineMkI::algo2[32] = { static const uint16_t MKI_BITDEPTH = 8;
{ { 0xc1, 0x11, 0x11, 0x14, 0x01, 0x14 } }, // 1 static const uint16_t MKI_TABLESIZE = 1<<MKI_BITDEPTH;
{ { 0x01, 0x11, 0x11, 0x14, 0xc1, 0x14 } }, // 2 static const uint16_t MKI_TABLEFILTER = MKI_TABLESIZE-1;
{ { 0xc1, 0x11, 0x14, 0x01, 0x11, 0x14 } }, // 3 static const uint16_t NEGATIVE_BIT = 0x8000;
{ { 0xc4, 0x00, 0x00, 0x01, 0x11, 0x14 } }, // 4 ** EXCEPTION VIA CODE
{ { 0xc1, 0x14, 0x01, 0x14, 0x01, 0x14 } }, // 5 #ifdef _WIN32
{ { 0xc4, 0x00, 0x01, 0x14, 0x01, 0x14 } }, // 6 ** EXCEPTION VIA CODE __declspec(align(16)) int zeros[N] = {0};
{ { 0xc1, 0x11, 0x05, 0x14, 0x01, 0x14 } }, // 7 #else
{ { 0x01, 0x11, 0xc5, 0x14, 0x01, 0x14 } }, // 8 const int32_t __attribute__ ((aligned(16))) zeros[N] = {0};
{ { 0x01, 0x11, 0x05, 0x14, 0xc1, 0x14 } }, // 9 #endif
{ { 0x01, 0x05, 0x14, 0xc1, 0x11, 0x14 } }, // 10
{ { 0xc1, 0x05, 0x14, 0x01, 0x11, 0x14 } }, // 11 static uint16_t sinLogTable[MKI_TABLESIZE];
{ { 0x01, 0x05, 0x05, 0x14, 0xc1, 0x14 } }, // 12 static uint16_t sinExpTable[MKI_TABLESIZE];
{ { 0xc1, 0x05, 0x05, 0x14, 0x01, 0x14 } }, // 13
{ { 0xc1, 0x05, 0x11, 0x14, 0x01, 0x14 } }, // 14 EngineMkI::EngineMkI() {
{ { 0x01, 0x05, 0x11, 0x14, 0xc1, 0x14 } }, // 15 float bitReso = MKI_TABLESIZE;
{ { 0xc1, 0x11, 0x02, 0x25, 0x05, 0x14 } }, // 16
{ { 0x01, 0x11, 0x02, 0x25, 0xc5, 0x14 } }, // 17 for(int i=0;i<MKI_TABLESIZE;i++) {
{ { 0x01, 0x11, 0x11, 0xc5, 0x05, 0x14 } }, // 18 float x1 = sin(((0.5+i)/bitReso) * M_PI/2.0);
{ { 0xc1, 0x14, 0x14, 0x01, 0x11, 0x14 } }, // 19 sinLogTable[i] = round(-bitReso * log2(x1));
{ { 0x01, 0x05, 0x14, 0xc1, 0x14, 0x14 } }, // 20 }
{ { 0x01, 0x14, 0x14, 0xc1, 0x14, 0x14 } }, // 21
{ { 0xc1, 0x14, 0x14, 0x14, 0x01, 0x14 } }, // 22 bitReso = MKI_TABLESIZE;
{ { 0xc1, 0x14, 0x14, 0x01, 0x14, 0x04 } }, // 23 for(int i=0;i<MKI_TABLESIZE;i++) {
{ { 0xc1, 0x14, 0x14, 0x14, 0x04, 0x04 } }, // 24 float x1 = (pow(2, float(i)/bitReso)-1)*1024;
{ { 0xc1, 0x14, 0x14, 0x04, 0x04, 0x04 } }, // 25 sinExpTable[i] = round(x1);
{ { 0xc1, 0x05, 0x14, 0x01, 0x14, 0x04 } }, // 26 }
{ { 0x01, 0x05, 0x14, 0xc1, 0x14, 0x04 } }, // 27 }
{ { 0x04, 0xc1, 0x11, 0x14, 0x01, 0x14 } }, // 28
{ { 0xc1, 0x14, 0x01, 0x14, 0x04, 0x04 } }, // 29 static inline uint16_t sinLog(uint16_t phi) {
{ { 0x04, 0xc1, 0x11, 0x14, 0x04, 0x04 } }, // 30 const uint16_t index = (phi & MKI_TABLEFILTER);
{ { 0xc1, 0x14, 0x04, 0x04, 0x04, 0x04 } }, // 31
{ { 0xc4, 0x04, 0x04, 0x04, 0x04, 0x04 } }, // 32 switch( ( phi & (MKI_TABLESIZE*3) ) ) {
}; case 0x0000:
// rising quarter wave Shape A
return sinLogTable[index];
case MKI_TABLESIZE:
// falling quarter wave Shape B
return sinLogTable[index ^ MKI_TABLEFILTER];
case (MKI_TABLESIZE*2):
// rising quarter wave -ve Shape C
return sinLogTable[index] | NEGATIVE_BIT;
default:
// falling quarter wave -ve Shape D
return sinLogTable[index ^ MKI_TABLEFILTER] | NEGATIVE_BIT;
}
}
inline int32_t mkiSin(int32_t phase, uint16_t env) {
const uint16_t shift = 22 - MKI_BITDEPTH;
uint16_t expVal = sinLog(phase >> shift) + (env << 3);
const bool isSigned = expVal & NEGATIVE_BIT;
expVal &= ~NEGATIVE_BIT;
// expVal: 0..2137+511*8 = 0..6225
// result: 0..1018+1024
uint16_t result = 0x0400 + sinExpTable[( expVal & MKI_TABLEFILTER ) ^ MKI_TABLEFILTER];
result <<= 1;
result >>= ( expVal >> 8 ); // exp
uint32_t ret;
if( isSigned ) {
// -1 for one's complement
ret = -result - 1;
} else {
ret = result;
}
return ret << shift;
}
void EngineMkI::compute(int32_t *output, const int32_t *input, void EngineMkI::compute(int32_t *output, const int32_t *input,
int32_t phase0, int32_t freq, int32_t phase0, int32_t freq,
int32_t gain1, int32_t gain2, bool add, const Controllers *controllers) { int32_t gain1, int32_t gain2, bool add) {
int32_t dgain = (gain2 - gain1 + (N >> 1)) >> LG_N; int32_t dgain = (gain2 - gain1 + (N >> 1)) >> LG_N;
int32_t gain = gain1; int32_t gain = gain1;
int32_t phase = phase0; int32_t phase = phase0;
if (add) { const int32_t *adder = add ? output : zeros;
for (int i = 0; i < N; i++) {
gain += dgain;
int32_t y = Sin::lookup(phase + input[i]);
int32_t y1 = ((int64_t)y * (int64_t)gain) >> 24;
output[i] += y1;
phase += freq;
}
} else {
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
gain += dgain; gain += dgain;
int32_t y = Sin::lookup(phase + input[i]); int32_t y = mkiSin((phase+input[i]), gain);
int32_t y1 = ((int64_t)y * (int64_t)gain) >> 24; output[i] = y + adder[i];
output[i] = y1;
phase += freq; phase += freq;
} }
}
} }
void EngineMkI::compute_pure(int32_t *output, int32_t phase0, int32_t freq, void EngineMkI::compute_pure(int32_t *output, int32_t phase0, int32_t freq,
int32_t gain1, int32_t gain2, bool add, const Controllers *controllers) { int32_t gain1, int32_t gain2, bool add) {
int32_t dgain = (gain2 - gain1 + (N >> 1)) >> LG_N; int32_t dgain = (gain2 - gain1 + (N >> 1)) >> LG_N;
int32_t gain = gain1; int32_t gain = gain1;
int32_t phase = phase0; int32_t phase = phase0;
if (add) { const int32_t *adder = add ? output : zeros;
for (int i = 0; i < N; i++) {
gain += dgain;
int32_t y = Sin::lookup(phase);
int32_t y1 = ((int64_t)y * (int64_t)gain) >> 24;
output[i] += y1;
phase += freq;
}
} else {
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
gain += dgain; gain += dgain;
int32_t y = Sin::lookup(phase); int32_t y = mkiSin(phase , gain);
int32_t y1 = ((int64_t)y * (int64_t)gain) >> 24; output[i] = y + adder[i];
output[i] = y1;
phase += freq; phase += freq;
} }
} }
}
void EngineMkI::compute_fb(int32_t *output, int32_t phase0, int32_t freq, void EngineMkI::compute_fb(int32_t *output, int32_t phase0, int32_t freq,
int32_t gain1, int32_t gain2, int32_t gain1, int32_t gain2,
int32_t *fb_buf, int fb_shift, bool add, const Controllers *controllers) { int32_t *fb_buf, int fb_shift, bool add) {
int32_t dgain = (gain2 - gain1 + (N >> 1)) >> LG_N; int32_t dgain = (gain2 - gain1 + (N >> 1)) >> LG_N;
int32_t gain = gain1; int32_t gain = gain1;
int32_t phase = phase0; int32_t phase = phase0;
const int32_t *adder = add ? output : zeros;
int32_t y0 = fb_buf[0]; int32_t y0 = fb_buf[0];
int32_t y = fb_buf[1]; int32_t y = fb_buf[1];
if (add) {
for (int i = 0; i < N; i++) {
gain += dgain;
int32_t scaled_fb = (y0 + y) >> (fb_shift + 1);
y0 = y;
y = Sin::lookup(phase + scaled_fb);
y = ((int64_t)y * (int64_t)gain) >> 24;
output[i] += y;
phase += freq;
}
} else {
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
gain += dgain; gain += dgain;
int32_t scaled_fb = (y0 + y) >> (fb_shift + 1); int32_t scaled_fb = (y0 + y) >> (fb_shift + 1);
y0 = y; y0 = y;
y = Sin::lookup(phase + scaled_fb); y = mkiSin((phase+scaled_fb), gain);
y = ((int64_t)y * (int64_t)gain) >> 24; output[i] = y + adder[i];
output[i] = y;
phase += freq; phase += freq;
} }
}
fb_buf[0] = y0; fb_buf[0] = y0;
fb_buf[1] = y; fb_buf[1] = y;
} }
// exclusively used for ALGO 6 with feedback // exclusively used for ALGO 6 with feedback
void EngineMkI::compute_fb2(int32_t *output, FmOpParams *parms, int32_t gain01, int32_t gain02, int32_t *fb_buf, int fb_shift, const Controllers *cont) { void EngineMkI::compute_fb2(int32_t *output, FmOpParams *parms, int32_t gain01, int32_t gain02, int32_t *fb_buf, int fb_shift) {
int32_t dgain[2]; int32_t dgain[2];
int32_t gain[2]; int32_t gain[2];
int32_t phase[2]; int32_t phase[2];
@ -181,8 +188,43 @@ void EngineMkI::compute_fb2(int32_t *output, FmOpParams *parms, int32_t gain01,
fb_buf[1] = y; fb_buf[1] = y;
} }
const FmAlgorithm EngineMkI::algo2[32] = {
{ { 0xc1, 0x11, 0x11, 0x14, 0x01, 0x14 } }, // 1
{ { 0x01, 0x11, 0x11, 0x14, 0xc1, 0x14 } }, // 2
{ { 0xc1, 0x11, 0x14, 0x01, 0x11, 0x14 } }, // 3
{ { 0xc4, 0x00, 0x00, 0x01, 0x11, 0x14 } }, // 4 ** EXCEPTION VIA CODE
{ { 0xc1, 0x14, 0x01, 0x14, 0x01, 0x14 } }, // 5
{ { 0xc4, 0x00, 0x01, 0x14, 0x01, 0x14 } }, // 6 ** EXCEPTION VIA CODE
{ { 0xc1, 0x11, 0x05, 0x14, 0x01, 0x14 } }, // 7
{ { 0x01, 0x11, 0xc5, 0x14, 0x01, 0x14 } }, // 8
{ { 0x01, 0x11, 0x05, 0x14, 0xc1, 0x14 } }, // 9
{ { 0x01, 0x05, 0x14, 0xc1, 0x11, 0x14 } }, // 10
{ { 0xc1, 0x05, 0x14, 0x01, 0x11, 0x14 } }, // 11
{ { 0x01, 0x05, 0x05, 0x14, 0xc1, 0x14 } }, // 12
{ { 0xc1, 0x05, 0x05, 0x14, 0x01, 0x14 } }, // 13
{ { 0xc1, 0x05, 0x11, 0x14, 0x01, 0x14 } }, // 14
{ { 0x01, 0x05, 0x11, 0x14, 0xc1, 0x14 } }, // 15
{ { 0xc1, 0x11, 0x02, 0x25, 0x05, 0x14 } }, // 16
{ { 0x01, 0x11, 0x02, 0x25, 0xc5, 0x14 } }, // 17
{ { 0x01, 0x11, 0x11, 0xc5, 0x05, 0x14 } }, // 18
{ { 0xc1, 0x14, 0x14, 0x01, 0x11, 0x14 } }, // 19
{ { 0x01, 0x05, 0x14, 0xc1, 0x14, 0x14 } }, // 20
{ { 0x01, 0x14, 0x14, 0xc1, 0x14, 0x14 } }, // 21
{ { 0xc1, 0x14, 0x14, 0x14, 0x01, 0x14 } }, // 22
{ { 0xc1, 0x14, 0x14, 0x01, 0x14, 0x04 } }, // 23
{ { 0xc1, 0x14, 0x14, 0x14, 0x04, 0x04 } }, // 24
{ { 0xc1, 0x14, 0x14, 0x04, 0x04, 0x04 } }, // 25
{ { 0xc1, 0x05, 0x14, 0x01, 0x14, 0x04 } }, // 26
{ { 0x01, 0x05, 0x14, 0xc1, 0x14, 0x04 } }, // 27
{ { 0x04, 0xc1, 0x11, 0x14, 0x01, 0x14 } }, // 28
{ { 0xc1, 0x14, 0x01, 0x14, 0x04, 0x04 } }, // 29
{ { 0x04, 0xc1, 0x11, 0x14, 0x04, 0x04 } }, // 30
{ { 0xc1, 0x14, 0x04, 0x04, 0x04, 0x04 } }, // 31
{ { 0xc4, 0x04, 0x04, 0x04, 0x04, 0x04 } }, // 32
};
// exclusively used for ALGO 4 with feedback // exclusively used for ALGO 4 with feedback
void EngineMkI::compute_fb3(int32_t *output, FmOpParams *parms, int32_t gain01, int32_t gain02, int32_t *fb_buf, int fb_shift, const Controllers *cont) { void EngineMkI::compute_fb3(int32_t *output, FmOpParams *parms, int32_t gain01, int32_t gain02, int32_t *fb_buf, int fb_shift) {
int32_t dgain[3]; int32_t dgain[3];
int32_t gain[3]; int32_t gain[3];
int32_t phase[3]; int32_t phase[3];
@ -230,10 +272,54 @@ void EngineMkI::compute_fb3(int32_t *output, FmOpParams *parms, int32_t gain01,
fb_buf[1] = y; fb_buf[1] = y;
} }
void EngineMkI::render(int32_t *output, FmOpParams *params, int algorithm, void EngineMkI::render(int32_t *output, FmOpParams *params, int algorithm,
int32_t *fb_buf, int feedback_shift, const Controllers *controllers) { int32_t *fb_buf, int feedback_shift) {
const int kLevelThresh = 1120; const int kLevelThresh = 507; // really ????
const FmAlgorithm alg = algorithms[algorithm];
bool has_contents[3] = { true, false, false };
for (int op = 0; op < 6; op++) {
int flags = alg.ops[op];
bool add = (flags & OUT_BUS_ADD) != 0;
FmOpParams &param = params[op];
int inbus = (flags >> 4) & 3;
int outbus = flags & 3;
int32_t *outptr = (outbus == 0) ? output : buf_[outbus - 1].get();
int32_t gain1 = param.gain_out == 0 ? 511 : param.gain_out;
int32_t gain2 = 512-(param.level_in >> 19);
param.gain_out = gain2;
if (gain1 <= kLevelThresh || gain2 <= kLevelThresh) {
if (!has_contents[outbus]) {
add = false;
}
if (inbus == 0 || !has_contents[inbus]) {
// todo: more than one op in a feedback loop
if ((flags & 0xc0) == 0xc0 && feedback_shift < 16) {
// cout << op << " fb " << inbus << outbus << add << endl;
compute_fb(outptr, param.phase, param.freq,
gain1, gain2,
fb_buf, feedback_shift, add);
} else {
// cout << op << " pure " << inbus << outbus << add << endl;
compute_pure(outptr, param.phase, param.freq,
gain1, gain2, add);
}
} else {
// cout << op << " normal " << inbus << outbus << " " << param.freq << add << endl;
compute(outptr, buf_[inbus - 1].get(),
param.phase, param.freq, gain1, gain2, add);
}
has_contents[outbus] = true;
} else if (!add) {
has_contents[outbus] = false;
}
param.phase += param.freq << LG_N;
}
}
/*
void EngineMkI::render(int32_t *output, FmOpParams *params, int algorithm, int32_t *fb_buf, int feedback_shift) {
const int kLevelThresh = 507;
const FmAlgorithm alg = algo2[algorithm]; const FmAlgorithm alg = algo2[algorithm];
bool has_contents[3] = { true, false, false }; bool has_contents[3] = { true, false, false };
@ -244,8 +330,8 @@ void EngineMkI::render(int32_t *output, FmOpParams *params, int algorithm,
int inbus = (flags >> 4) & 3; int inbus = (flags >> 4) & 3;
int outbus = flags & 3; int outbus = flags & 3;
int32_t *outptr = (outbus == 0) ? output : buf_[outbus - 1].get(); int32_t *outptr = (outbus == 0) ? output : buf_[outbus - 1].get();
int32_t gain1 = param.gain_out; int32_t gain1 = param.gain_out == 0 ? 511 : param.gain_out;
int32_t gain2 = Exp2::lookup(param.level_in - (14 * (1 << 24))); int32_t gain2 = 512-(param.level_in >> 19);
param.gain_out = gain2; param.gain_out = gain2;
if (gain1 >= kLevelThresh || gain2 >= kLevelThresh) { if (gain1 >= kLevelThresh || gain2 >= kLevelThresh) {
@ -261,13 +347,13 @@ void EngineMkI::render(int32_t *output, FmOpParams *params, int algorithm,
switch ( algorithm ) { switch ( algorithm ) {
// two operator feedback, process exception for ALGO 6 // two operator feedback, process exception for ALGO 6
case 5 : case 5 :
compute_fb2(outptr, params, gain1, gain2, fb_buf, feedback_shift, controllers); //compute_fb2(outptr, params, gain1, gain2, fb_buf, feedback_shift, controllers);
params[1].phase += params[1].freq << LG_N; // yuk, hack, we already processed op-5 params[1].phase += params[1].freq << LG_N; // yuk, hack, we already processed op-5
op++; // ignore next operator; op++; // ignore next operator;
break; break;
// three operator feedback, process exception for ALGO 4 // three operator feedback, process exception for ALGO 4
case 3 : case 3 :
compute_fb3(outptr, params, gain1, gain2, fb_buf, feedback_shift, controllers); //compute_fb3(outptr, params, gain1, gain2, fb_buf, feedback_shift, controllers);
params[1].phase += params[1].freq << LG_N; // hack, we already processed op-5 - op-4 params[1].phase += params[1].freq << LG_N; // hack, we already processed op-5 - op-4
params[2].phase += params[2].freq << LG_N; // yuk yuk params[2].phase += params[2].freq << LG_N; // yuk yuk
op += 2; // ignore the 2 other operators op += 2; // ignore the 2 other operators
@ -275,18 +361,17 @@ void EngineMkI::render(int32_t *output, FmOpParams *params, int algorithm,
default: default:
// one operator feedback, normal proces // one operator feedback, normal proces
//cout << "\t" << op << " fb " << inbus << outbus << add << endl; //cout << "\t" << op << " fb " << inbus << outbus << add << endl;
compute_fb(outptr, param.phase, param.freq,gain1, gain2, fb_buf, feedback_shift, add, controllers); compute_fb(outptr, param.phase, param.freq,gain1, gain2, fb_buf, feedback_shift, add);
break; break;
} }
} else { } else {
// cout << op << " pure " << inbus << outbus << add << endl; // cout << op << " pure " << inbus << outbus << add << endl;
compute_pure(outptr, param.phase, param.freq, gain1, gain2, add, controllers); compute_pure(outptr, param.phase, param.freq, gain1, gain2, add);
} }
} else { } else {
// cout << op << " normal " << inbus << outbus << " " << param.freq << add << endl; // cout << op << " normal " << inbus << outbus << " " << param.freq << add << endl;
compute(outptr, buf_[inbus - 1].get(), compute(outptr, buf_[inbus - 1].get(), param.phase, param.freq, gain1, gain2, add);
param.phase, param.freq, gain1, gain2, add, controllers);
} }
has_contents[outbus] = true; has_contents[outbus] = true;
@ -297,4 +382,4 @@ void EngineMkI::render(int32_t *output, FmOpParams *params, int algorithm,
param.phase += param.freq << LG_N; param.phase += param.freq << LG_N;
} }
} }
*/

@ -29,21 +29,22 @@ class EngineMkI : public FmCore {
//refacter this when it is working //refacter this when it is working
const static FmAlgorithm algo2[32]; const static FmAlgorithm algo2[32];
public: public:
virtual void render(int32_t *output, FmOpParams *params, int algorithm, EngineMkI();
int32_t *fb_buf, int feedback_shift, const Controllers *controllers);
void render(int32_t *output, FmOpParams *params, int algorithm, int32_t *fb_buf, int feedback_shift) override;
void compute(int32_t *output, const int32_t *input, int32_t phase0, int32_t freq, int32_t gain1, int32_t gain2, void compute(int32_t *output, const int32_t *input, int32_t phase0, int32_t freq, int32_t gain1, int32_t gain2,
bool add, const Controllers *controllers); bool add);
void compute_pure(int32_t *output, int32_t phase0, int32_t freq, int32_t gain1, int32_t gain2, void compute_pure(int32_t *output, int32_t phase0, int32_t freq, int32_t gain1, int32_t gain2,
bool add, const Controllers *controllers); bool add);
void compute_fb(int32_t *output, int32_t phase0, int32_t freq, int32_t gain1, int32_t gain2, void compute_fb(int32_t *output, int32_t phase0, int32_t freq, int32_t gain1, int32_t gain2,
int32_t *fb_buf, int fb_gain, bool add, const Controllers *controllers); int32_t *fb_buf, int fb_gain, bool add);
void compute_fb2(int32_t *output, FmOpParams *params, int32_t gain01, int32_t gain02, int32_t *fb_buf, int fb_shift, const Controllers *controllers); void compute_fb2(int32_t *output, FmOpParams *params, int32_t gain01, int32_t gain02, int32_t *fb_buf, int fb_shift);
void compute_fb3(int32_t *output, FmOpParams *params, int32_t gain01, int32_t gain02, int32_t *fb_buf, int fb_shift, const Controllers *controllers); void compute_fb3(int32_t *output, FmOpParams *params, int32_t gain01, int32_t gain02, int32_t *fb_buf, int fb_shift);
}; };

@ -169,7 +169,7 @@ void EngineOpl::compute_fb(int32_t *output, int32_t phase0, int32_t freq,
void EngineOpl::render(int32_t *output, FmOpParams *params, int algorithm, void EngineOpl::render(int32_t *output, FmOpParams *params, int algorithm,
int32_t *fb_buf, int feedback_shift, const Controllers *controllers) { int32_t *fb_buf, int feedback_shift) {
const int kLevelThresh = 507; // really ???? const int kLevelThresh = 507; // really ????
const FmAlgorithm alg = algorithms[algorithm]; const FmAlgorithm alg = algorithms[algorithm];
bool has_contents[3] = { true, false, false }; bool has_contents[3] = { true, false, false };
@ -212,3 +212,15 @@ void EngineOpl::render(int32_t *output, FmOpParams *params, int algorithm,
param.phase += param.freq << LG_N; param.phase += param.freq << LG_N;
} }
} }

@ -31,7 +31,7 @@
class EngineOpl : public FmCore { class EngineOpl : public FmCore {
public: public:
virtual void render(int32_t *output, FmOpParams *params, int algorithm, virtual void render(int32_t *output, FmOpParams *params, int algorithm,
int32_t *fb_buf, int feedback_shift, const Controllers *controllers); int32_t *fb_buf, int feedback_shift) override;
void compute(int32_t *output, const int32_t *input, int32_t phase0, int32_t freq, int32_t gain1, int32_t gain2, bool add); void compute(int32_t *output, const int32_t *input, int32_t phase0, int32_t freq, int32_t gain1, int32_t gain2, bool add);
void compute_pure(int32_t *output, int32_t phase0, int32_t freq, int32_t gain1, int32_t gain2, bool add); void compute_pure(int32_t *output, int32_t phase0, int32_t freq, int32_t gain1, int32_t gain2, bool add);
void compute_fb(int32_t *output, int32_t phase0, int32_t freq, void compute_fb(int32_t *output, int32_t phase0, int32_t freq,

@ -286,6 +286,15 @@ void DexedAudioProcessor::getStateInformation(MemoryBlock& destData) {
dexedState.setAttribute("monoMode", monoMode); dexedState.setAttribute("monoMode", monoMode);
dexedState.setAttribute("engineType", (int) engineType); dexedState.setAttribute("engineType", (int) engineType);
char mod_cfg[15];
controllers.wheel.setConfig(mod_cfg);
dexedState.setAttribute("wheelMod", mod_cfg);
controllers.foot.setConfig(mod_cfg);
dexedState.setAttribute("footMod", mod_cfg);
controllers.breath.setConfig(mod_cfg);
dexedState.setAttribute("breathMod", mod_cfg);
controllers.at.setConfig(mod_cfg);
dexedState.setAttribute("aftertouchMod", mod_cfg);
if ( activeFileCartridge.exists() ) if ( activeFileCartridge.exists() )
dexedState.setAttribute("activeFileCartridge", activeFileCartridge.getFullPathName()); dexedState.setAttribute("activeFileCartridge", activeFileCartridge.getFullPathName());
@ -315,6 +324,11 @@ void DexedAudioProcessor::setStateInformation(const void* source, int sizeInByte
fx.uiGain = root->getDoubleAttribute("gain"); fx.uiGain = root->getDoubleAttribute("gain");
currentProgram = root->getIntAttribute("currentProgram"); currentProgram = root->getIntAttribute("currentProgram");
controllers.wheel.parseConfig(root->getStringAttribute("wheelMod").toRawUTF8());
controllers.foot.parseConfig(root->getStringAttribute("footMod").toRawUTF8());
controllers.breath.parseConfig(root->getStringAttribute("breathMod").toRawUTF8());
controllers.at.parseConfig(root->getStringAttribute("aftertouchMod").toRawUTF8());
setEngineType(root->getIntAttribute("engineType", 0)); setEngineType(root->getIntAttribute("engineType", 0));
monoMode = root->getIntAttribute("monoMode", 0); monoMode = root->getIntAttribute("monoMode", 0);

@ -584,6 +584,22 @@ void DexedAudioProcessor::loadPreference() {
if ( prop.containsKey( String("showKeyboard") ) ) { if ( prop.containsKey( String("showKeyboard") ) ) {
showKeyboard = prop.getIntValue( String("showKeyboard") ); showKeyboard = prop.getIntValue( String("showKeyboard") );
} }
if ( prop.containsKey( String("wheelMod") ) ) {
controllers.wheel.parseConfig(prop.getValue(String("wheelMod")).toRawUTF8());
}
if ( prop.containsKey( String("footMod") ) ) {
controllers.foot.parseConfig(prop.getValue(String("footMod")).toRawUTF8());
}
if ( prop.containsKey( String("breathMod") ) ) {
controllers.breath.parseConfig(prop.getValue(String("breathMod")).toRawUTF8());
}
if ( prop.containsKey( String("aftertouchMod") ) ) {
controllers.at.parseConfig(prop.getValue(String("aftertouchMod")).toRawUTF8());
}
} }
void DexedAudioProcessor::savePreference() { void DexedAudioProcessor::savePreference() {
@ -601,6 +617,16 @@ void DexedAudioProcessor::savePreference() {
prop.setValue(String("showKeyboard"), showKeyboard); prop.setValue(String("showKeyboard"), showKeyboard);
char mod_cfg[15];
controllers.wheel.setConfig(mod_cfg);
prop.setValue(String("wheelMod"), mod_cfg);
controllers.foot.setConfig(mod_cfg);
prop.setValue(String("footMod"), mod_cfg);
controllers.breath.setConfig(mod_cfg);
prop.setValue(String("breathMod"), mod_cfg);
controllers.at.setConfig(mod_cfg);
prop.setValue(String("aftertouchMod"), mod_cfg);
//prop.setValue(String("engineResolution"), engineResolution); //prop.setValue(String("engineResolution"), engineResolution);
prop.save(); prop.save();

@ -194,7 +194,7 @@ void DexedAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& mi
voices[note].dx7_note->compute(audiobuf.get(), lfovalue, lfodelay, &controllers); voices[note].dx7_note->compute(audiobuf.get(), lfovalue, lfodelay, &controllers);
for (int j=0; j < N; ++j) { for (int j=0; j < N; ++j) {
int32_t val = audiobuf.get()[j]; //& 0xFFFFF000); int32_t val = audiobuf.get()[j];
val = val >> 4; val = val >> 4;
int clip_val = val < -(1 << 24) ? 0x8000 : val >= (1 << 24) ? 0x7fff : val >> 9; int clip_val = val < -(1 << 24) ? 0x8000 : val >= (1 << 24) ? 0x7fff : val >> 9;

@ -19,6 +19,7 @@
#include "synth.h" #include "synth.h"
#include "../Dexed.h" #include "../Dexed.h"
#include <stdio.h>
// State of MIDI controllers // State of MIDI controllers
const int kControllerPitch = 128; const int kControllerPitch = 128;
@ -32,32 +33,34 @@ struct FmMod {
bool pitch = false; bool pitch = false;
bool amp = false; bool amp = false;
bool eg = false; bool eg = false;
void parseConfig(const char *cfg) {
int r = 0, p = 0, a = 0, e = 0;
sscanf(cfg, "%d %d %d %d", &r, &p, &a, &e);
range = r < 0 && r > 127 ? 0 : r;
pitch = p != 0;
amp = a != 0;
eg = e != 0;
}
void setConfig(char *cfg) {
snprintf(cfg, 13, "%d %d %d %d", range, pitch, amp, eg);
}
}; };
class Controllers { class Controllers {
void applyMod(int cc, FmMod &mod) { void applyMod(int cc, FmMod &mod) {
float range = 0.01 * mod.range; float range = 0.01 * mod.range;
if ( mod.amp ) {
int total = cc * range;
if ( amp_mod + total > 127 )
amp_mod = 127;
else
amp_mod += total;
}
if ( mod.pitch ) {
int total = cc * range; int total = cc * range;
if ( pitch_mod + total > 127 ) if ( mod.amp )
pitch_mod = 127; amp_mod = max(amp_mod, total);
else
pitch_mod += total; if ( mod.pitch )
} pitch_mod = max(pitch_mod, total);
if ( mod.eg ) {
int total = cc * range; if ( mod.eg )
if ( eg_mod + total > 127 ) eg_mod = max(eg_mod, total);
eg_mod = 127;
else
eg_mod += total;
}
} }
public: public:
@ -87,6 +90,9 @@ public:
applyMod(foot_cc, foot); applyMod(foot_cc, foot);
applyMod(aftertouch_cc, at); applyMod(aftertouch_cc, at);
if ( ! ((wheel.eg || foot.eg) || (breath.eg || at.eg)) )
eg_mod = 127;
TRACE("amp_mod %d pitch_mod %d", amp_mod, pitch_mod); TRACE("amp_mod %d pitch_mod %d", amp_mod, pitch_mod);
} }

@ -225,7 +225,7 @@ void Dx7Note::compute(int32_t *buf, int32_t lfo_val, int32_t lfo_delay, const Co
} }
params_[op].level_in = level; params_[op].level_in = level;
} }
ctrls->core->render(buf, params_, algorithm_, fb_buf_, fb_shift_, ctrls); ctrls->core->render(buf, params_, algorithm_, fb_buf_, fb_shift_);
} }
void Dx7Note::keyup() { void Dx7Note::keyup() {

@ -90,8 +90,7 @@ void FmCore::dump() {
#endif #endif
} }
void FmCore::render(int32_t *output, FmOpParams *params, int algorithm, void FmCore::render(int32_t *output, FmOpParams *params, int algorithm, int32_t *fb_buf, int feedback_shift) {
int32_t *fb_buf, int feedback_shift, const Controllers *controller) {
const int kLevelThresh = 1120; const int kLevelThresh = 1120;
const FmAlgorithm alg = algorithms[algorithm]; const FmAlgorithm alg = algorithms[algorithm];
bool has_contents[3] = { true, false, false }; bool has_contents[3] = { true, false, false };

@ -48,8 +48,7 @@ class FmCore {
public: public:
virtual ~FmCore() {}; virtual ~FmCore() {};
static void dump(); static void dump();
virtual void render(int32_t *output, FmOpParams *params, int algorithm, virtual void render(int32_t *output, FmOpParams *params, int algorithm, int32_t *fb_buf, int32_t feedback_gain);
int32_t *fb_buf, int32_t feedback_gain, const Controllers *controller);
protected: protected:
AlignedBuf<int32_t, N>buf_[2]; AlignedBuf<int32_t, N>buf_[2];
const static FmAlgorithm algorithms[32]; const static FmAlgorithm algorithms[32];

Loading…
Cancel
Save