Fixes and simple test code.

pull/4/head
Holger Wirtz 7 years ago
parent 92475f873c
commit c1b5edced8
  1. 17
      MicroDexed.ino
  2. 172
      dexed.cpp
  3. 42
      dexed.h

@ -5,6 +5,7 @@
#define RATE 128
#define TEENSY 1
#define TEST_MIDI
#ifdef TEENSY
#include <Audio.h>
@ -16,8 +17,8 @@
// GUItool: begin automatically generated code
AudioPlayQueue queue1; //xy=811,259
AudioOutputI2S i2s1; //xy=1185,252
AudioConnection patchCord2(queue1, 0, i2s1, 0);
AudioConnection patchCord3(queue1, 0, i2s1, 1);
AudioConnection patchCord1(queue1, 0, i2s1, 0);
AudioConnection patchCord2(queue1, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=830,376
// GUItool: end automatically generated code
#endif
@ -44,8 +45,18 @@ void setup()
// Initialize processor and memory measurements
//AudioProcessorUsageMaxReset();
//AudioMemoryUsageMaxReset();
// initial fill audio buffer
while (queue1.available())
{
queue1.getBuffer();
queue1.playBuffer();
}
#endif
#ifdef TEST_MIDI
dexed->ProcessMidiMessage(0x90, 64, 100);
#endif
}
void loop()
@ -66,7 +77,7 @@ void loop()
#ifdef TEENSY
// play the current buffer
while(!queue1.available());
while (!queue1.available());
queue1.playBuffer();
#endif

@ -1,22 +1,22 @@
/**
*
* Copyright (c) 2016-2017 Holger Wirtz <dcoredump@googlemail.com>
*
* 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 3 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
*
*/
Copyright (c) 2016-2017 Holger Wirtz <dcoredump@googlemail.com>
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 3 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 "dexed.h"
#include "EngineMkI.h"
@ -39,7 +39,7 @@ Dexed::Dexed(double num_samples)
Tanh::init();
Sin::init();
_rate=num_samples;
_rate = num_samples;
Freqlut::init(_rate);
Lfo::init(_rate);
@ -47,18 +47,18 @@ Dexed::Dexed(double num_samples)
Env::init_sr(_rate);
//fx.init(_rate);
engineMkI=new EngineMkI;
engineOpl=new EngineOpl;
engineMsfa=new FmCore;
engineMkI = new EngineMkI;
engineOpl = new EngineOpl;
engineMsfa = new FmCore;
for(i=0; i<MAX_ACTIVE_NOTES; i++) {
for (i = 0; i < MAX_ACTIVE_NOTES; i++) {
voices[i].dx7_note = new Dx7Note;
voices[i].keydown = false;
voices[i].sustained = false;
voices[i].live = false;
}
max_notes=16;
max_notes = 16;
currentNote = 0;
controllers.values_[kControllerPitch] = 0x2000;
controllers.values_[kControllerPitchRange] = 0;
@ -67,10 +67,10 @@ Dexed::Dexed(double num_samples)
controllers.foot_cc = 0;
controllers.breath_cc = 0;
controllers.aftertouch_cc = 0;
controllers.masterTune=0;
controllers.opSwitch=0x3f; // enable all operators
controllers.masterTune = 0;
controllers.opSwitch = 0x3f; // enable all operators
lfo.reset(data+137);
lfo.reset(data + 137);
setMonoMode(false);
@ -97,11 +97,11 @@ Dexed::~Dexed()
voices[note].live = false;
}
if(engineMsfa)
if (engineMsfa)
delete(engineMkI);
if(engineOpl)
if (engineOpl)
delete(engineMkI);
if(engineMkI)
if (engineMkI)
delete(engineMkI);
}
@ -118,8 +118,8 @@ void Dexed::deactivate(void)
}
/*
void Dexed::set_params(void)
{
void Dexed::set_params(void)
{
_param_change_counter=0;
bool polymono=bool(*p(p_polymono));
@ -334,11 +334,11 @@ void Dexed::set_params(void)
panic();
controllers.refresh();
}
}
}
*/
/*void Dexed::run (uint8_t* midi_data)
{
{
static int16_t buffer;
ProcessMidiMessage(midi_data);
@ -347,18 +347,18 @@ void Dexed::set_params(void)
GetSamples(&buffer);
//fx.process(&buffer,_rate);
}*/
}*/
void Dexed::GetSamples(int16_t* buffer)
{
uint32_t i=0;
uint32_t i = 0;
if(refreshVoice) {
for(i=0;i < max_notes;i++) {
if (refreshVoice) {
for (i = 0; i < max_notes; i++) {
if ( voices[i].live )
voices[i].dx7_note->update(data, voices[i].midi_note, voices[i].velocity);
}
lfo.reset(data+137);
lfo.reset(data + 137);
refreshVoice = false;
}
@ -378,15 +378,15 @@ void Dexed::GetSamples(int16_t* buffer)
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 (uint32_t j = 0; j < _N_; ++j) {
int32_t val = audiobuf.get()[j];
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;
if(f>1) f=1;
if(f<-1) f=-1;
sumbuf[j]+=f;
audiobuf.get()[j]=0;
float f = static_cast<float>(clip_val >> 1) / 0x8000;
if (f > 1) f = 1;
if (f < -1) f = -1;
sumbuf[j] += f;
audiobuf.get()[j] = 0;
}
}
}
@ -395,59 +395,59 @@ void Dexed::GetSamples(int16_t* buffer)
buffer[i + j] = sumbuf[j];
}
if(++_k_rate_counter%32 && !monoMode)
if (++_k_rate_counter % 32 && !monoMode)
{
uint8_t op_carrier=controllers.core->get_carrier_operators(data[134]); // look for carriers
uint8_t op_carrier = controllers.core->get_carrier_operators(data[134]); // look for carriers
for(i=0;i < max_notes;i++)
for (i = 0; i < max_notes; i++)
{
if(voices[i].live==true)
if (voices[i].live == true)
{
uint8_t op_amp=0;
uint8_t op_carrier_num=0;
uint8_t op_amp = 0;
uint8_t op_carrier_num = 0;
voices[i].dx7_note->peekVoiceStatus(voiceStatus);
for(uint8_t op=0;op<6;op++)
for (uint8_t op = 0; op < 6; op++)
{
uint8_t op_bit=pow(2,op);
uint8_t op_bit = pow(2, op);
if((op_carrier&op_bit)>0)
if ((op_carrier & op_bit) > 0)
{
// this voice is a carrier!
op_carrier_num++;
if(voiceStatus.amp[op]<=1069 && voiceStatus.ampStep[op]==4) // this voice produces no audio output
if (voiceStatus.amp[op] <= 1069 && voiceStatus.ampStep[op] == 4) // this voice produces no audio output
op_amp++;
}
}
if(op_amp==op_carrier_num)
if (op_amp == op_carrier_num)
{
// all carrier-operators are silent -> disable the voice
voices[i].live=false;
voices[i].sustained=false;
voices[i].keydown=false;
voices[i].live = false;
voices[i].sustained = false;
voices[i].keydown = false;
}
}
}
}
}
bool Dexed::ProcessMidiMessage(uint8_t cmd,uint8_t data1,uint8_t data2)
bool Dexed::ProcessMidiMessage(uint8_t cmd, uint8_t data1, uint8_t data2)
{
switch(cmd & 0xf0) {
switch (cmd & 0xf0) {
case 0x80 :
// TRACE("MIDI keyup event: %d",buf[1]);
keyup(data1);
return(false);
return (false);
break;
case 0x90 :
// TRACE("MIDI keydown event: %d %d",buf[1],buf[2]);
keydown(data1, data2);
return(false);
return (false);
break;
case 0xb0 : {
switch(data1) {
switch (data1) {
case 1:
// TRACE("MIDI modwheel event: %d %d",ctrl,value);
controllers.modwheel_cc = data2;
@ -478,20 +478,20 @@ bool Dexed::ProcessMidiMessage(uint8_t cmd,uint8_t data1,uint8_t data2)
case 120:
// TRACE("MIDI all-sound-off: %d %d",ctrl,value);
panic();
return(true);
return (true);
break;
case 123:
// TRACE("MIDI all-notes-off: %d %d",ctrl,value);
notes_off();
return(true);
return (true);
break;
}
break;
}
// case 0xc0 :
// setCurrentProgram(data1);
// break;
// case 0xc0 :
// setCurrentProgram(data1);
// break;
// channel aftertouch
case 0xd0 :
@ -507,7 +507,7 @@ bool Dexed::ProcessMidiMessage(uint8_t cmd,uint8_t data1,uint8_t data2)
break;
}
return(false);
return (false);
}
void Dexed::keydown(uint8_t pitch, uint8_t velo) {
@ -519,9 +519,9 @@ void Dexed::keydown(uint8_t pitch, uint8_t velo) {
pitch += data[144] - 24;
uint8_t note = currentNote;
uint8_t keydown_counter=0;
uint8_t keydown_counter = 0;
for (uint8_t i=0; i<max_notes; i++) {
for (uint8_t i = 0; i < max_notes; i++) {
if (!voices[note].keydown) {
currentNote = (note + 1) % max_notes;
voices[note].midi_note = pitch;
@ -539,10 +539,10 @@ void Dexed::keydown(uint8_t pitch, uint8_t velo) {
note = (note + 1) % max_notes;
}
if(keydown_counter==0)
if (keydown_counter == 0)
lfo.keydown();
if ( monoMode ) {
for(uint8_t i=0; i<max_notes; i++) {
for (uint8_t i = 0; i < max_notes; i++) {
if ( voices[i].live ) {
// all keys are up, only transfer signal
if ( ! voices[i].keydown ) {
@ -567,7 +567,7 @@ void Dexed::keyup(uint8_t pitch) {
pitch += data[144] - 24;
uint8_t note;
for (note=0; note<max_notes; ++note) {
for (note = 0; note < max_notes; ++note) {
if ( voices[note].midi_note == pitch && voices[note].keydown ) {
voices[note].keydown = false;
break;
@ -582,7 +582,7 @@ void Dexed::keyup(uint8_t pitch) {
if ( monoMode ) {
int8_t highNote = -1;
int8_t target = 0;
for (int8_t i=0; i<max_notes;i++) {
for (int8_t i = 0; i < max_notes; i++) {
if ( voices[i].keydown && voices[i].midi_note > highNote ) {
target = i;
highNote = voices[i].midi_note;
@ -604,7 +604,7 @@ void Dexed::keyup(uint8_t pitch) {
}
/*void Dexed::onParam(uint8_t param_num,float param_val)
{
{
int32_t tune;
if(param_val!=data_float[param_num])
@ -668,7 +668,7 @@ void Dexed::keyup(uint8_t pitch) {
break;
}
}
}
}
*/
uint8_t Dexed::getEngineType() {
@ -676,7 +676,7 @@ uint8_t Dexed::getEngineType() {
}
void Dexed::setEngineType(uint8_t tp) {
if(engineType==tp && controllers.core!=NULL)
if (engineType == tp && controllers.core != NULL)
return;
switch (tp) {
@ -688,7 +688,7 @@ void Dexed::setEngineType(uint8_t tp) {
break;
default:
controllers.core = engineMsfa;
tp=DEXED_ENGINE_MODERN;
tp = DEXED_ENGINE_MODERN;
break;
}
engineType = tp;
@ -701,16 +701,16 @@ bool Dexed::isMonoMode(void) {
}
void Dexed::setMonoMode(bool mode) {
if(monoMode==mode)
if (monoMode == mode)
return;
monoMode = mode;
}
void Dexed::panic(void) {
for(uint8_t i=0;i<MAX_ACTIVE_NOTES;i++)
for (uint8_t i = 0; i < MAX_ACTIVE_NOTES; i++)
{
if(voices[i].live == true) {
if (voices[i].live == true) {
voices[i].keydown = false;
voices[i].live = false;
voices[i].sustained = false;
@ -722,9 +722,9 @@ void Dexed::panic(void) {
}
void Dexed::notes_off(void) {
for(uint8_t i=0;i<MAX_ACTIVE_NOTES;i++) {
if(voices[i].live==true&&voices[i].keydown==true) {
voices[i].keydown=false;
for (uint8_t i = 0; i < MAX_ACTIVE_NOTES; i++) {
if (voices[i].live == true && voices[i].keydown == true) {
voices[i].keydown = false;
}
}
}

@ -1,22 +1,22 @@
/**
*
* Copyright (c) 2013-2015 Pascal Gauthier.
*
* 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 3 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
*
*/
Copyright (c) 2013-2015 Pascal Gauthier.
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 3 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
*/
#ifndef DEXED_H_INCLUDED
#define DEXED_H_INCLUDED
@ -83,7 +83,7 @@ class Dexed
void setMonoMode(bool mode);
void set_params(void);
void GetSamples(int16_t* buffer);
bool ProcessMidiMessage(uint8_t cmd,uint8_t data1,uint8_t data2);
bool ProcessMidiMessage(uint8_t cmd, uint8_t data1, uint8_t data2);
Controllers controllers;
VoiceStatus voiceStatus;
@ -96,7 +96,7 @@ class Dexed
void notes_off(void);
static const uint8_t MAX_ACTIVE_NOTES = 32;
uint8_t max_notes=MAX_ACTIVE_NOTES;
uint8_t max_notes = MAX_ACTIVE_NOTES;
ProcessorVoice voices[MAX_ACTIVE_NOTES];
uint8_t currentNote;
bool sustain;
@ -117,7 +117,7 @@ class Dexed
uint16_t _rate;
uint8_t _k_rate_counter;
uint8_t _param_change_counter;
uint8_t data[173]={
uint8_t data[173] = {
95, 29, 20, 50, 99, 95, 00, 00, 41, 00, 19, 00, 00, 03, 00, 06, 79, 00, 01, 00, 14,
95, 20, 20, 50, 99, 95, 00, 00, 00, 00, 00, 00, 00, 03, 00, 00, 99, 00, 01, 00, 00,
95, 29, 20, 50, 99, 95, 00, 00, 00, 00, 00, 00, 00, 03, 00, 06, 89, 00, 01, 00, 07,

Loading…
Cancel
Save