|
|
|
@ -18,6 +18,7 @@ |
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include "synth.h" |
|
|
|
|
#include "dexed.h" |
|
|
|
|
#include "EngineMkI.h" |
|
|
|
|
#include "EngineOpl.h" |
|
|
|
@ -26,12 +27,11 @@ |
|
|
|
|
#include "sin.h" |
|
|
|
|
#include "freqlut.h" |
|
|
|
|
#include "controllers.h" |
|
|
|
|
//#include "PluginFx.h"
|
|
|
|
|
#include "trace.h" |
|
|
|
|
#include <unistd.h> |
|
|
|
|
#include <limits.h> |
|
|
|
|
#include <math.h> |
|
|
|
|
|
|
|
|
|
Dexed::Dexed(uint16_t num_samples) |
|
|
|
|
Dexed::Dexed(uint8_t rate) |
|
|
|
|
{ |
|
|
|
|
uint8_t i; |
|
|
|
|
|
|
|
|
@ -39,18 +39,31 @@ Dexed::Dexed(uint16_t num_samples) |
|
|
|
|
Tanh::init(); |
|
|
|
|
Sin::init(); |
|
|
|
|
|
|
|
|
|
_rate = num_samples; |
|
|
|
|
|
|
|
|
|
Freqlut::init(_rate); |
|
|
|
|
Lfo::init(_rate); |
|
|
|
|
PitchEnv::init(_rate); |
|
|
|
|
Env::init_sr(_rate); |
|
|
|
|
//fx.init(_rate);
|
|
|
|
|
Freqlut::init(rate); |
|
|
|
|
Lfo::init(rate); |
|
|
|
|
PitchEnv::init(rate); |
|
|
|
|
Env::init_sr(rate); |
|
|
|
|
|
|
|
|
|
engineMkI = new EngineMkI; |
|
|
|
|
engineOpl = new EngineOpl; |
|
|
|
|
engineMsfa = new FmCore; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if(!(engineMkI=new (std::nothrow) EngineMkI)) |
|
|
|
|
TRACE("Cannot not create engine EngineMkI"); |
|
|
|
|
if(!(engineOpl=new (std::nothrow) EngineOpl)) |
|
|
|
|
{ |
|
|
|
|
delete(engineMkI); |
|
|
|
|
TRACE("Cannot not create engine EngineOpl"); |
|
|
|
|
} |
|
|
|
|
if(!(engineMsfa=new (std::nothrow) FmCore)) |
|
|
|
|
{ |
|
|
|
|
delete(engineMkI); |
|
|
|
|
delete(engineOpl); |
|
|
|
|
TRACE("Cannot create engine FmCore"); |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_ACTIVE_NOTES; i++) { |
|
|
|
|
voices[i].dx7_note = new Dx7Note; |
|
|
|
|
voices[i].keydown = false; |
|
|
|
@ -58,6 +71,11 @@ Dexed::Dexed(uint16_t num_samples) |
|
|
|
|
voices[i].live = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* for(i=0;i<sizeof(data);++i)
|
|
|
|
|
{ |
|
|
|
|
data_float[i]=static_cast<float>(data[i]); |
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
max_notes = 16; |
|
|
|
|
currentNote = 0; |
|
|
|
|
controllers.values_[kControllerPitch] = 0x2000; |
|
|
|
@ -69,6 +87,11 @@ Dexed::Dexed(uint16_t num_samples) |
|
|
|
|
controllers.aftertouch_cc = 0; |
|
|
|
|
controllers.masterTune = 0; |
|
|
|
|
controllers.opSwitch = 0x3f; // enable all operators
|
|
|
|
|
//controllers.opSwitch=0x00;
|
|
|
|
|
|
|
|
|
|
bufsize_ = 256; |
|
|
|
|
|
|
|
|
|
outbuf_ = new float[bufsize_]; |
|
|
|
|
|
|
|
|
|
lfo.reset(data + 137); |
|
|
|
|
|
|
|
|
@ -76,32 +99,24 @@ Dexed::Dexed(uint16_t num_samples) |
|
|
|
|
|
|
|
|
|
sustain = false; |
|
|
|
|
|
|
|
|
|
extra_buf_size_ = 0; |
|
|
|
|
|
|
|
|
|
memset(&voiceStatus, 0, sizeof(VoiceStatus)); |
|
|
|
|
|
|
|
|
|
setEngineType(DEXED_ENGINE_MARKI); |
|
|
|
|
setEngineType(DEXED_ENGINE_MODERN); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Dexed::~Dexed() |
|
|
|
|
{ |
|
|
|
|
delete [] outbuf_; |
|
|
|
|
|
|
|
|
|
currentNote = -1; |
|
|
|
|
|
|
|
|
|
for (uint8_t note = 0; note < MAX_ACTIVE_NOTES; ++note) |
|
|
|
|
{ |
|
|
|
|
if ( voices[note].dx7_note != NULL ) |
|
|
|
|
{ |
|
|
|
|
delete voices[note].dx7_note; |
|
|
|
|
voices[note].dx7_note = NULL; |
|
|
|
|
} |
|
|
|
|
voices[note].keydown = false; |
|
|
|
|
voices[note].sustained = false; |
|
|
|
|
voices[note].live = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (engineMsfa) |
|
|
|
|
delete(engineMkI); |
|
|
|
|
if (engineOpl) |
|
|
|
|
delete(engineMkI); |
|
|
|
|
if (engineMkI) |
|
|
|
|
delete(engineMsfa); |
|
|
|
|
delete(engineOpl); |
|
|
|
|
delete(engineMkI); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -114,12 +129,12 @@ void Dexed::activate(void) |
|
|
|
|
|
|
|
|
|
void Dexed::deactivate(void) |
|
|
|
|
{ |
|
|
|
|
; // Nothing to do - please reboot ;-)
|
|
|
|
|
; // nothing to do...
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Dexed::GetSamples(uint32_t n_samples, int16_t* buffer) |
|
|
|
|
void Dexed::GetSamples(uint16_t n_samples, int16_t* buffer) |
|
|
|
|
{ |
|
|
|
|
uint32_t i; |
|
|
|
|
uint16_t i; |
|
|
|
|
|
|
|
|
|
if (refreshVoice) { |
|
|
|
|
for (i = 0; i < max_notes; i++) { |
|
|
|
@ -130,42 +145,65 @@ void Dexed::GetSamples(uint32_t n_samples, int16_t* buffer) |
|
|
|
|
refreshVoice = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_samples; i += _N_) { |
|
|
|
|
// flush first events
|
|
|
|
|
for (i = 0; i < n_samples && i < extra_buf_size_; i++) { |
|
|
|
|
buffer[i] = extra_buf_[i]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// remaining buffer is still to be processed
|
|
|
|
|
if (extra_buf_size_ > n_samples) { |
|
|
|
|
for (uint16_t j = 0; j < extra_buf_size_ - n_samples; j++) { |
|
|
|
|
extra_buf_[j] = extra_buf_[j + n_samples]; |
|
|
|
|
} |
|
|
|
|
extra_buf_size_ -= n_samples; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
for (; i < n_samples; i += _N_) { |
|
|
|
|
AlignedBuf<int32_t, _N_> audiobuf; |
|
|
|
|
float sumbuf[_N_]; |
|
|
|
|
int16_t sumbuf[_N_]; |
|
|
|
|
|
|
|
|
|
for (uint32_t j = 0; j < _N_; ++j) { |
|
|
|
|
for (uint8_t j = 0; j < _N_; ++j) { |
|
|
|
|
audiobuf.get()[j] = 0; |
|
|
|
|
sumbuf[j] = 0.0; |
|
|
|
|
//sumbuf[j] = 0.0;
|
|
|
|
|
sumbuf[j] = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int32_t lfovalue = lfo.getsample(); |
|
|
|
|
int32_t lfodelay = lfo.getdelay(); |
|
|
|
|
|
|
|
|
|
for (uint8_t note = 0; note < max_notes; ++note) { |
|
|
|
|
|
|
|
|
|
if (voices[note].live) { |
|
|
|
|
voices[note].dx7_note->compute(audiobuf.get(), lfovalue, lfodelay, &controllers); |
|
|
|
|
|
|
|
|
|
for (uint32_t j = 0; j < _N_; ++j) { |
|
|
|
|
|
|
|
|
|
for (uint8_t j = 0; j < _N_; ++j) { |
|
|
|
|
int32_t val = audiobuf.get()[j]; |
|
|
|
|
val = val >> 4; |
|
|
|
|
//val = val >> 4;
|
|
|
|
|
int32_t clip_val = val < -(1 << 24) ? 0x8000 : val >= (1 << 24) ? 0x7fff : val >> 9; |
|
|
|
|
float f = static_cast<float>(clip_val >> 1) / 0x8000; |
|
|
|
|
/* float f = static_cast<float>(clip_val >> 1) / static_cast<float>(0x8000);
|
|
|
|
|
if (f > 1) f = 1; |
|
|
|
|
if (f < -1) f = -1; |
|
|
|
|
sumbuf[j] += f; |
|
|
|
|
sumbuf[j] += f;*/ |
|
|
|
|
sumbuf[j] += clip_val; |
|
|
|
|
audiobuf.get()[j] = 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (uint32_t j = 0; j < _N_; ++j) { |
|
|
|
|
buffer[j + (i * _N_)] = sumbuf[j]; |
|
|
|
|
|
|
|
|
|
uint16_t jmax = n_samples - i; |
|
|
|
|
for (uint8_t j = 0; j < _N_; ++j) { |
|
|
|
|
if (j < jmax) |
|
|
|
|
{ |
|
|
|
|
//buffer[i + j] = static_cast<int16_t>(sumbuf[j]*0x8000);
|
|
|
|
|
buffer[i + j] = sumbuf[j]; |
|
|
|
|
Serial.println(buffer[i + j], DEC); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
extra_buf_[j - jmax] = sumbuf[j]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
extra_buf_size_ = i - n_samples; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// mark unused voice as not live
|
|
|
|
|
if (++_k_rate_counter % 32 && !monoMode) |
|
|
|
|
{ |
|
|
|
|
uint8_t op_carrier = controllers.core->get_carrier_operators(data[134]); // look for carriers
|
|
|
|
@ -188,6 +226,8 @@ void Dexed::GetSamples(uint32_t n_samples, int16_t* buffer) |
|
|
|
|
// this voice is a carrier!
|
|
|
|
|
op_carrier_num++; |
|
|
|
|
|
|
|
|
|
//TRACE("Voice[%2d] OP [%d] amp=%ld,amp_step=%d,pitch_step=%d",i,op,voiceStatus.amp[op],voiceStatus.ampStep[op],voiceStatus.pitchStep);
|
|
|
|
|
|
|
|
|
|
if (voiceStatus.amp[op] <= 1069 && voiceStatus.ampStep[op] == 4) // this voice produces no audio output
|
|
|
|
|
op_amp++; |
|
|
|
|
} |
|
|
|
@ -198,8 +238,10 @@ void Dexed::GetSamples(uint32_t n_samples, int16_t* buffer) |
|
|
|
|
voices[i].live = false; |
|
|
|
|
voices[i].sustained = false; |
|
|
|
|
voices[i].keydown = false; |
|
|
|
|
TRACE("Shutted down Voice[%2d]", i); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// TRACE("Voice[%2d] live=%d keydown=%d",i,voices[i].live,voices[i].keydown);
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -208,34 +250,38 @@ bool Dexed::ProcessMidiMessage(uint8_t cmd, uint8_t data1, uint8_t data2) |
|
|
|
|
{ |
|
|
|
|
switch (cmd & 0xf0) { |
|
|
|
|
case 0x80 : |
|
|
|
|
// TRACE("MIDI keyup event: %d",buf[1]);
|
|
|
|
|
//TRACE("MIDI keyup event: %d", data1);
|
|
|
|
|
keyup(data1); |
|
|
|
|
return (false); |
|
|
|
|
break; |
|
|
|
|
case 0x90 : |
|
|
|
|
//TRACE("MIDI keydown event: %d %d", data1, data2);
|
|
|
|
|
keydown(data1, data2); |
|
|
|
|
return (false); |
|
|
|
|
break; |
|
|
|
|
case 0xb0 : { |
|
|
|
|
switch (data1) { |
|
|
|
|
uint8_t ctrl = data1; |
|
|
|
|
uint8_t value = data2; |
|
|
|
|
|
|
|
|
|
switch (ctrl) { |
|
|
|
|
case 1: |
|
|
|
|
//TRACE("MIDI modwheel event: %d %d", ctrl, value);
|
|
|
|
|
controllers.modwheel_cc = data2; |
|
|
|
|
controllers.modwheel_cc = value; |
|
|
|
|
controllers.refresh(); |
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
//TRACE("MIDI breath event: %d %d", ctrl, value);
|
|
|
|
|
controllers.breath_cc = data2; |
|
|
|
|
controllers.breath_cc = value; |
|
|
|
|
controllers.refresh(); |
|
|
|
|
break; |
|
|
|
|
case 4: |
|
|
|
|
//TRACE("MIDI footsw event: %d %d", ctrl, value);
|
|
|
|
|
controllers.foot_cc = data2; |
|
|
|
|
controllers.foot_cc = value; |
|
|
|
|
controllers.refresh(); |
|
|
|
|
break; |
|
|
|
|
case 64: |
|
|
|
|
//TRACE("MIDI sustain event: %d %d", ctrl, value);
|
|
|
|
|
sustain = data2 > 63; |
|
|
|
|
sustain = value > 63; |
|
|
|
|
if (!sustain) { |
|
|
|
|
for (uint8_t note = 0; note < max_notes; note++) { |
|
|
|
|
if (voices[note].sustained && !voices[note].keydown) { |
|
|
|
@ -265,22 +311,28 @@ bool Dexed::ProcessMidiMessage(uint8_t cmd, uint8_t data1, uint8_t data2) |
|
|
|
|
|
|
|
|
|
// channel aftertouch
|
|
|
|
|
case 0xd0 : |
|
|
|
|
//TRACE("MIDI aftertouch 0xd0 event: %d %d", data1);
|
|
|
|
|
controllers.aftertouch_cc = data1; |
|
|
|
|
controllers.refresh(); |
|
|
|
|
break; |
|
|
|
|
// pitchbend
|
|
|
|
|
case 0xe0 : |
|
|
|
|
//TRACE("MIDI pitchbend 0xe0 event: %d %d", data1, data2);
|
|
|
|
|
controllers.values_[kControllerPitch] = data1 | (data2 << 7); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
//TRACE("MIDI event unknown: cmd=%d, val1=%d, val2=%d", cmd, data1, data2);
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TRACE("Bye"); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Dexed::keydown(uint8_t pitch, uint8_t velo) { |
|
|
|
|
TRACE("Hi"); |
|
|
|
|
TRACE("pitch=%d, velo=%d\n", pitch, velo); |
|
|
|
|
if ( velo == 0 ) { |
|
|
|
|
keyup(pitch); |
|
|
|
|
return; |
|
|
|
@ -331,9 +383,13 @@ void Dexed::keydown(uint8_t pitch, uint8_t velo) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
voices[note].live = true; |
|
|
|
|
TRACE("Bye"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Dexed::keyup(uint8_t pitch) { |
|
|
|
|
TRACE("Hi"); |
|
|
|
|
TRACE("pitch=%d\n", pitch); |
|
|
|
|
|
|
|
|
|
pitch += data[144] - 24; |
|
|
|
|
|
|
|
|
|
uint8_t note; |
|
|
|
@ -346,6 +402,7 @@ void Dexed::keyup(uint8_t pitch) { |
|
|
|
|
|
|
|
|
|
// note not found ?
|
|
|
|
|
if ( note >= max_notes ) { |
|
|
|
|
TRACE("note-off not found???"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -359,7 +416,7 @@ void Dexed::keyup(uint8_t pitch) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( highNote != -1 ) { |
|
|
|
|
if ( highNote != -1 && voices[note].live ) { |
|
|
|
|
voices[note].live = false; |
|
|
|
|
voices[target].live = true; |
|
|
|
|
voices[target].dx7_note->transferState(*voices[note].dx7_note); |
|
|
|
@ -371,14 +428,21 @@ void Dexed::keyup(uint8_t pitch) { |
|
|
|
|
} else { |
|
|
|
|
voices[note].dx7_note->keyup(); |
|
|
|
|
} |
|
|
|
|
TRACE("Bye"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*void Dexed::onParam(uint8_t param_num,float param_val)
|
|
|
|
|
/*
|
|
|
|
|
void Dexed::onParam(uint8_t param_num, float param_val) |
|
|
|
|
{ |
|
|
|
|
int32_t tune; |
|
|
|
|
|
|
|
|
|
if (param_val != data_float[param_num]) |
|
|
|
|
{ |
|
|
|
|
TRACE("Parameter %d change from %f to %f", param_num, data_float[param_num], param_val); |
|
|
|
|
#ifdef DEBUG |
|
|
|
|
uint8_t tmp = data[param_num]; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
_param_change_counter++; |
|
|
|
|
|
|
|
|
|
if (param_num == 144 || param_num == 134 || param_num == 172) |
|
|
|
@ -397,29 +461,44 @@ void Dexed::keyup(uint8_t pitch) { |
|
|
|
|
controllers.values_[kControllerPitchStep] = data[param_num]; |
|
|
|
|
break; |
|
|
|
|
case 157: |
|
|
|
|
// TRACE("wheel.setRange(%d)",data[param_num]);
|
|
|
|
|
controllers.wheel.setRange(data[param_num]); |
|
|
|
|
controllers.wheel.setTarget(data[param_num + 1]); |
|
|
|
|
controllers.refresh(); |
|
|
|
|
break; |
|
|
|
|
case 158: |
|
|
|
|
controllers.wheel.setRange(data[param_num - 1]); |
|
|
|
|
controllers.wheel.setTarget(data[param_num]); |
|
|
|
|
controllers.refresh(); |
|
|
|
|
break; |
|
|
|
|
case 159: |
|
|
|
|
controllers.foot.setRange(data[param_num]); |
|
|
|
|
controllers.foot.setTarget(data[param_num + 1]); |
|
|
|
|
controllers.refresh(); |
|
|
|
|
break; |
|
|
|
|
case 160: |
|
|
|
|
controllers.foot.setRange(data[param_num - 1]); |
|
|
|
|
controllers.foot.setTarget(data[param_num]); |
|
|
|
|
controllers.refresh(); |
|
|
|
|
break; |
|
|
|
|
case 161: |
|
|
|
|
controllers.breath.setRange(data[param_num]); |
|
|
|
|
controllers.breath.setTarget(data[param_num + 1]); |
|
|
|
|
controllers.refresh(); |
|
|
|
|
break; |
|
|
|
|
case 162: |
|
|
|
|
controllers.breath.setRange(data[param_num - 1]); |
|
|
|
|
controllers.breath.setTarget(data[param_num]); |
|
|
|
|
controllers.refresh(); |
|
|
|
|
break; |
|
|
|
|
case 163: |
|
|
|
|
controllers.at.setRange(data[param_num]); |
|
|
|
|
controllers.at.setTarget(data[param_num + 1]); |
|
|
|
|
controllers.refresh(); |
|
|
|
|
break; |
|
|
|
|
case 164: |
|
|
|
|
controllers.at.setRange(data[param_num - 1]); |
|
|
|
|
controllers.at.setTarget(data[param_num]); |
|
|
|
|
controllers.refresh(); |
|
|
|
|
break; |
|
|
|
|
case 165: |
|
|
|
|
tune = param_val * 0x4000; |
|
|
|
@ -437,6 +516,8 @@ void Dexed::keyup(uint8_t pitch) { |
|
|
|
|
max_notes = data[param_num]; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TRACE("Done: Parameter %d changed from %d to %d", param_num, tmp, data[param_num]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
@ -446,17 +527,22 @@ uint8_t Dexed::getEngineType() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Dexed::setEngineType(uint8_t tp) { |
|
|
|
|
TRACE("settings engine %d", tp); |
|
|
|
|
|
|
|
|
|
if (engineType == tp && controllers.core != NULL) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
switch (tp) { |
|
|
|
|
case DEXED_ENGINE_MARKI: |
|
|
|
|
TRACE("DEXED_ENGINE_MARKI:%d", DEXED_ENGINE_MARKI); |
|
|
|
|
controllers.core = engineMkI; |
|
|
|
|
break; |
|
|
|
|
case DEXED_ENGINE_OPL: |
|
|
|
|
TRACE("DEXED_ENGINE_OPL:%d", DEXED_ENGINE_OPL); |
|
|
|
|
controllers.core = engineOpl; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
TRACE("DEXED_ENGINE_MODERN:%d", DEXED_ENGINE_MODERN); |
|
|
|
|
controllers.core = engineMsfa; |
|
|
|
|
tp = DEXED_ENGINE_MODERN; |
|
|
|
|
break; |
|
|
|
@ -499,9 +585,10 @@ void Dexed::notes_off(void) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
void Dexed::set_params(void) |
|
|
|
|
{ |
|
|
|
|
/* //TRACE("Hi");
|
|
|
|
|
|
|
|
|
|
_param_change_counter=0; |
|
|
|
|
|
|
|
|
|
bool polymono=bool(*p(p_polymono)); |
|
|
|
@ -716,6 +803,9 @@ void Dexed::notes_off(void) { |
|
|
|
|
panic(); |
|
|
|
|
controllers.refresh(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//TRACE("Bye");
|
|
|
|
|
*/ |
|
|
|
|
; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|