Added config.h

Some more fixes for porting to Teensy.
chorus
Holger Wirtz 6 years ago
parent ed76eaeece
commit e8f37a99be
  1. 19
      MicroMDAPiano.ino
  2. 78
      config.h
  3. 108
      mdaEPiano.cpp
  4. 10
      mdaEPiano.h
  5. 4
      mdaEPianoData.h
  6. 97
      midinotes.h

@ -1,9 +1,22 @@
void setup() {
// put your setup code here, to run once:
#include "mdaEPianoData.h"
void setup() {
Serial.begin(38400);
delay(500);
Serial.println("START");
Serial.println(sizeof(epianoData),DEC);
uint32_t i;
for(i=0;i<sizeof(epianoData)/sizeof(uint16_t); i++)
{
Serial.print(i,DEC);
Serial.print(F(" "));
Serial.println(epianoData[i], DEC);
}
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("LOOP");
delay(10000);
}

@ -0,0 +1,78 @@
/*
MicroMDAEpiano
MicroMDAEpiano is a port of the MDAEpiano sound engine
(http://mda.smartelectronix.com/synths.htm) for the Teensy-3.5/3.6 with audio
shield.
(c)2018 H. Wirtz <wirtz@parasitstudio.de>
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 "midinotes.h"
// ATTENTION! For better latency you have to redefine AUDIO_BLOCK_SAMPLES from
// 128 to 64 in <ARDUINO-IDE-DIR>/cores/teensy3/AudioStream.h
// Initial values
#define USE_ONBOARD_USB_HOST 1
#define TEENSY_AUDIO_BOARD 1
#define VOLUME 0.6
#define DEFAULT_MIDI_CHANNEL MIDI_CHANNEL_OMNI
#define AUDIO_MEM 2
#define SAMPLE_RATE 44100
#if !defined(__MK66FX1M0__) // check for Teensy-3.6
#define MAX_NOTES 11 // No?
#undef USE_ONBOARD_USB_HOST
#else
#define MAX_NOTES 16 // Yes
#endif
// Debug output
#define SERIAL_SPEED 38400
#define DEBUG 1
#define SHOW_MIDI_EVENT 1
#define SHOW_XRUN 1
#define SHOW_CPU_LOAD_MSEC 5000
// Use these with the Teensy Audio Shield
//#define SDCARD_CS_PIN 10
//#define SDCARD_MOSI_PIN 7
//#define SDCARD_SCK_PIN 14
// Use these with the Teensy 3.5 & 3.6 SD card
#define SDCARD_CS_PIN BUILTIN_SDCARD
#define SDCARD_MOSI_PIN 11 // not actually used
#define SDCARD_SCK_PIN 13 // not actually used
// Encoder with button
#define ENC1_PIN_A 14
#define ENC1_PIN_B 15
#define BUT1_PIN 16
#define INITIAL_ENC1_VALUE 0
// EEPROM address
#define EEPROM_OFFSET 0
#define EEPROM_DATA_LENGTH 5
#define EEPROM_CRC32_ADDR EEPROM.length()-sizeof(uint32_t)
#define EEPROM_BANK_ADDR 0
#define EEPROM_VOICE_ADDR 1
#define EEPROM_MASTER_VOLUME_ADDR 2
#define EEPROM_VOLUME_RIGHT_ADDR 3
#define EEPROM_VOLUME_LEFT_ADDR 4

@ -4,12 +4,12 @@
#include <stdio.h>
#include <math.h>
AudioEffect *createEffectInstance(audioMasterCallback audioMaster)
{
return new mdaEPiano(audioMaster);
}
// AudioEffect *createEffectInstance(audioMasterCallback audioMaster)
//{
// return new mdaEPiano(audioMaster);
//}
mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) : AudioEffectX(audioMaster, NPROGS, NPARAMS)
mdaEPiano::mdaEPiano() // mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) : AudioEffectX(audioMaster, NPROGS, NPARAMS)
{
Fs = 44100.0f; iFs = 1.0f/Fs; //just in case...
@ -17,7 +17,7 @@ mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) : AudioEffectX(audioMaster
if(programs)
{
//fill patches...
VstInt32 i=0;
int32_t i=0;
fillpatch(i++, "Default", 0.500f, 0.500f, 0.500f, 0.500f, 0.500f, 0.650f, 0.250f, 0.500f, 0.50f, 0.500f, 0.146f, 0.000f);
fillpatch(i++, "Bright", 0.500f, 0.500f, 1.000f, 0.800f, 0.500f, 0.650f, 0.250f, 0.500f, 0.50f, 0.500f, 0.146f, 0.500f);
fillpatch(i++, "Mellow", 0.500f, 0.500f, 0.000f, 0.000f, 0.500f, 0.650f, 0.250f, 0.500f, 0.50f, 0.500f, 0.246f, 0.000f);
@ -29,6 +29,7 @@ mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) : AudioEffectX(audioMaster
setProgram(0);
}
/*
if(audioMaster)
{
setNumInputs(0);
@ -37,8 +38,8 @@ mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) : AudioEffectX(audioMaster
isSynth();
setUniqueID('MDAe'); ///
}
waves = epianoData;
*/
waves = (short*)epianoData;
//Waveform data and keymapping
kgrp[ 0].root = 36; kgrp[ 0].high = 39; //C1
@ -88,10 +89,10 @@ mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) : AudioEffectX(audioMaster
kgrp[32].pos = 414487; kgrp[32].end = 422408; kgrp[32].loop = 2169;
//extra xfade looping...
for(VstInt32 k=0; k<28; k++)
for(int32_t k=0; k<28; k++)
{
VstInt32 p0 = kgrp[k].end;
VstInt32 p1 = kgrp[k].end - kgrp[k].loop;
int32_t p0 = kgrp[k].end;
int32_t p1 = kgrp[k].end - kgrp[k].loop;
float xf = 1.0f;
float dxf = -0.02f;
@ -106,7 +107,7 @@ mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) : AudioEffectX(audioMaster
}
//initialise...
for(VstInt32 v=0; v<NVOICES; v++)
for(int32_t v=0; v<NVOICES; v++)
{
voice[v].env = 0.0f;
voice[v].dec = 0.99f; //all notes off
@ -121,13 +122,13 @@ mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) : AudioEffectX(audioMaster
guiUpdate = 0;
update();
suspend();
// suspend();
}
void mdaEPiano::update() //parameter change
{
float * param = programs[curProgram].param;
size = (VstInt32)(12.0f * param[2] - 6.0f);
size = (int32_t)(12.0f * param[2] - 6.0f);
treb = 4.0f * param[3] * param[3] - 1.0f; //treble gain
if(param[3] > 0.5f) tfrq = 14000.0f; else tfrq = 5000.0f; //treble freq
@ -142,7 +143,7 @@ void mdaEPiano::update() //parameter change
if(param[6] < 0.25f) velsens -= 0.75f - 3.0f * param[6];
width = 0.03f * param[7];
poly = 1 + (VstInt32)(31.9f * param[8]);
poly = 1 + (int32_t)(31.9f * param[8]);
fine = param[9] - 0.5f;
random = 0.077f * param[10] * param[10];
stretch = 0.0f; //0.000434f * (param[11] - 0.5f); parameter re-used for overdrive!
@ -152,11 +153,12 @@ void mdaEPiano::update() //parameter change
void mdaEPiano::resume()
{
Fs = getSampleRate();
//Fs = getSampleRate();
Fs=44100;
iFs = 1.0f / Fs;
dlfo = 6.283f * iFs * (float)exp(6.22f * programs[curProgram].param[5] - 2.61f); //lfo rate
DECLARE_VST_DEPRECATED (wantEvents) ();
//DECLARE_VST_DEPRECATED (wantEvents) ();
}
@ -166,14 +168,14 @@ mdaEPiano::~mdaEPiano () //destroy any buffers...
}
void mdaEPiano::setProgram(VstInt32 program)
void mdaEPiano::setProgram(int32_t program)
{
curProgram = program;
update();
}
void mdaEPiano::setParameter(VstInt32 index, float value)
void mdaEPiano::setParameter(int32_t index, float value)
{
programs[curProgram].param[index] = value;
update();
@ -184,7 +186,7 @@ void mdaEPiano::setParameter(VstInt32 index, float value)
}
void mdaEPiano::fillpatch(VstInt32 p, char *name, float p0, float p1, float p2, float p3, float p4,
void mdaEPiano::fillpatch(int32_t p, char *name, float p0, float p1, float p2, float p3, float p4,
float p5, float p6, float p7, float p8, float p9, float p10,float p11)
{
strcpy(programs[p].name, name);
@ -196,17 +198,17 @@ void mdaEPiano::fillpatch(VstInt32 p, char *name, float p0, float p1, float p2,
programs[p].param[10]= p10; programs[p].param[11] = p11;
}
float mdaEPiano::getParameter(VstInt32 index) { return programs[curProgram].param[index]; }
/*
float mdaEPiano::getParameter(int32_t index) { return programs[curProgram].param[index]; }
void mdaEPiano::setProgramName(char *name) { strcpy(programs[curProgram].name, name); }
void mdaEPiano::getProgramName(char *name) { strcpy(name, programs[curProgram].name); }
void mdaEPiano::setBlockSize(VstInt32 blockSize) { AudioEffectX::setBlockSize(blockSize); }
void mdaEPiano::setBlockSize(int32_t blockSize) { AudioEffectX::setBlockSize(blockSize); }
bool mdaEPiano::getEffectName(char* name) { strcpy(name, "ePiano"); return true; }
bool mdaEPiano::getVendorString(char* text) { strcpy(text, "mda"); return true; }
bool mdaEPiano::getProductString(char* text) { strcpy(text, "mda ePiano"); return true; }
bool mdaEPiano::getOutputProperties(VstInt32 index, VstPinProperties* properties)
bool mdaEPiano::getOutputProperties(int32_t index, VstPinProperties* properties)
{
if(index<NOUTS)
{
@ -220,7 +222,7 @@ bool mdaEPiano::getOutputProperties(VstInt32 index, VstPinProperties* properties
}
bool mdaEPiano::getProgramNameIndexed(VstInt32 category, VstInt32 index, char* text)
bool mdaEPiano::getProgramNameIndexed(int32_t category, int32_t index, char* text)
{
if ((unsigned int)index < NPROGS)
{
@ -231,7 +233,7 @@ bool mdaEPiano::getProgramNameIndexed(VstInt32 category, VstInt32 index, char* t
}
bool mdaEPiano::copyProgram(VstInt32 destination)
bool mdaEPiano::copyProgram(int32_t destination)
{
if(destination<NPROGS)
{
@ -242,7 +244,7 @@ bool mdaEPiano::copyProgram(VstInt32 destination)
}
VstInt32 mdaEPiano::canDo(char* text)
int32_t mdaEPiano::canDo(char* text)
{
if(strcmp(text, "receiveVstEvents") == 0) return 1;
if(strcmp(text, "receiveVstMidiEvent") == 0) return 1;
@ -250,7 +252,7 @@ VstInt32 mdaEPiano::canDo(char* text)
}
void mdaEPiano::getParameterName(VstInt32 index, char *label)
void mdaEPiano::getParameterName(int32_t index, char *label)
{
switch (index)
{
@ -273,7 +275,7 @@ void mdaEPiano::getParameterName(VstInt32 index, char *label)
}
void mdaEPiano::getParameterDisplay(VstInt32 index, char *text)
void mdaEPiano::getParameterDisplay(int32_t index, char *text)
{
char string[16];
float * param = programs[curProgram].param;
@ -301,7 +303,7 @@ void mdaEPiano::getParameterDisplay(VstInt32 index, char *text)
}
void mdaEPiano::getParameterLabel(VstInt32 index, char *label)
void mdaEPiano::getParameterLabel(int32_t index, char *label)
{
switch(index)
{
@ -314,22 +316,22 @@ void mdaEPiano::getParameterLabel(VstInt32 index, char *label)
}
void mdaEPiano::guiGetDisplay(VstInt32 index, char *label)
void mdaEPiano::guiGetDisplay(int32_t index, char *label)
{
getParameterName(index, label);
strcat(label, " = ");
getParameterDisplay(index, label + strlen(label));
getParameterLabel(index, label + strlen(label));
}
*/
void mdaEPiano::process(float **inputs, float **outputs, VstInt32 sampleFrames)
void mdaEPiano::process(float **inputs, float **outputs, int32_t sampleFrames)
{
float* out0 = outputs[0];
float* out1 = outputs[1];
VstInt32 event=0, frame=0, frames, v;
int32_t event=0, frame=0, frames, v;
float x, l, r, od=overdrive;
VstInt32 i;
int32_t i;
while(frame<sampleFrames)
{
@ -379,8 +381,8 @@ void mdaEPiano::process(float **inputs, float **outputs, VstInt32 sampleFrames)
{
if(activevoices == 0 && programs[curProgram].param[4] > 0.5f)
{ lfo0 = -0.7071f; lfo1 = 0.7071f; } //reset LFO phase - good idea?
VstInt32 note = notes[event++];
VstInt32 vel = notes[event++];
int32_t note = notes[event++];
int32_t vel = notes[event++];
noteOn(note, vel);
}
}
@ -392,13 +394,13 @@ void mdaEPiano::process(float **inputs, float **outputs, VstInt32 sampleFrames)
}
void mdaEPiano::processReplacing(float **inputs, float **outputs, VstInt32 sampleFrames)
void mdaEPiano::processReplacing(float **inputs, float **outputs, int32_t sampleFrames)
{
float* out0 = outputs[0];
float* out1 = outputs[1];
VstInt32 event=0, frame=0, frames, v;
int32_t event=0, frame=0, frames, v;
float x, l, r, od=overdrive;
VstInt32 i;
int32_t i;
while(frame<sampleFrames)
{
@ -452,8 +454,8 @@ void mdaEPiano::processReplacing(float **inputs, float **outputs, VstInt32 sampl
{
if(activevoices == 0 && programs[curProgram].param[4] > 0.5f)
{ lfo0 = -0.7071f; lfo1 = 0.7071f; } //reset LFO phase - good idea?
VstInt32 note = notes[event++];
VstInt32 vel = notes[event++];
int32_t note = notes[event++];
int32_t vel = notes[event++];
noteOn(note, vel);
}
}
@ -465,11 +467,11 @@ void mdaEPiano::processReplacing(float **inputs, float **outputs, VstInt32 sampl
}
void mdaEPiano::noteOn(VstInt32 note, VstInt32 velocity)
void mdaEPiano::noteOn(int32_t note, int32_t velocity)
{
float * param = programs[curProgram].param;
float l=99.0f;
VstInt32 v, vl=0, k, s;
int32_t v, vl=0, k, s;
if(velocity > 0)
{
@ -492,13 +494,13 @@ void mdaEPiano::noteOn(VstInt32 note, VstInt32 velocity)
if(note > 60) l += stretch * (float)k; //stretch
s = size;
//if(velocity > 40) s += (VstInt32)(sizevel * (float)(velocity - 40)); - no velocity to hardness in ePiano
//if(velocity > 40) s += (int32_t)(sizevel * (float)(velocity - 40)); - no velocity to hardness in ePiano
k = 0;
while(note > (kgrp[k].high + s)) k += 3; //find keygroup
l += (float)(note - kgrp[k].root); //pitch
l = 32000.0f * iFs * (float)exp(0.05776226505 * l);
voice[vl].delta = (VstInt32)(65536.0f * l);
voice[vl].delta = (int32_t)(65536.0f * l);
voice[vl].frac = 0;
if(velocity > 48) k++; //mid velocity sample
@ -540,12 +542,13 @@ void mdaEPiano::noteOn(VstInt32 note, VstInt32 velocity)
}
VstInt32 mdaEPiano::processEvents(VstEvents* ev)
int32_t mdaEPiano::processEvents()
{
float * param = programs[curProgram].param;
VstInt32 npos=0;
for (VstInt32 i=0; i<ev->numEvents; i++)
int32_t npos=0;
/*
for (int32_t i=0; i<ev->numEvents; i++)
{
if((ev->events[i])->type != kVstMidiType) continue;
VstMidiEvent* event = (VstMidiEvent*)ev->events[i];
@ -596,7 +599,7 @@ VstInt32 mdaEPiano::processEvents(VstEvents* ev)
default: //all notes off
if(midiData[1]>0x7A)
{
for(VstInt32 v=0; v<NVOICES; v++) voice[v].dec=0.99f;
for(int32_t v=0; v<NVOICES; v++) voice[v].dec=0.99f;
sustain = 0;
muff = 160.0f;
}
@ -615,6 +618,7 @@ VstInt32 mdaEPiano::processEvents(VstEvents* ev)
event++; //?
}
notes[npos] = EVENTS_DONE;
*/
return 1;
}

@ -53,15 +53,15 @@ struct KGRP //keygroup
int32_t loop;
};
class mdaEPiano : public AudioEffectX
class mdaEPiano //: public AudioEffectX
{
public:
mdaEPiano(audioMasterCallback audioMaster);
mdaEPiano(); // mdaEPiano(audioMasterCallback audioMaster);
~mdaEPiano();
virtual void process(float **inputs, float **outputs, int32_t sampleframes);
virtual void processReplacing(float **inputs, float **outputs, int32_t sampleframes);
virtual int32_t processEvents(VstEvents* events);
virtual int32_t processEvents(); // virtual int32_t processEvents(VstEvents* events);
virtual void setProgram(int32_t program);
virtual void setProgramName(char *name);
@ -74,7 +74,7 @@ public:
virtual void setBlockSize(int32_t blockSize);
virtual void resume();
virtual bool getOutputProperties (int32_t index, VstPinProperties* properties);
virtual bool getOutputProperties (int32_t index); // virtual bool getOutputProperties (int32_t index, VstPinProperties* properties);
virtual bool getProgramNameIndexed (int32_t category, int32_t index, char* text);
virtual bool copyProgram (int32_t destination);
virtual bool getEffectName (char* name);
@ -112,6 +112,8 @@ private:
float treb, tfrq, tl, tr;
float tune, fine, random, stretch, overdrive;
float muff, muffvel, sizevel, velsens, volume, modwhl;
uint8_t curProgram;
};
#endif

@ -1,4 +1,6 @@
short epianoData[] = {
#include <Arduino.h>
const int16_t epianoData[] PROGMEM = {
-7,-23,-28,-16,-30,-17,-28,-16,-31,-15,-34,-12,-35,-6,-42,4,-58,44,-227,-1690,
-1412,-1295,-1059,-908,-685,-518,-308,-152,31,182,368,531,731,948,1195,1439,1694,1950,2228,2487,
2742,2988,3225,3428,3624,3790,3969,4108,4253,4382,4495,4591,4647,4689,4737,4794,4846,4920,5003,5077,

@ -0,0 +1,97 @@
/*************************************************
* MIDI note values
*************************************************/
#ifndef _MIDINOTES_H
#define _MIDINOTES_H
#define MIDI_A0 21
#define MIDI_AIS0 22
#define MIDI_B0 23
#define MIDI_C1 24
#define MIDI_CIS1 25
#define MIDI_D1 26
#define MIDI_DIS1 27
#define MIDI_E1 28
#define MIDI_F1 29
#define MIDI_FIS1 30
#define MIDI_G1 31
#define MIDI_GIS1 32
#define MIDI_A1 33
#define MIDI_AIS1 34
#define MIDI_B1 35
#define MIDI_C2 36
#define MIDI_CIS2 37
#define MIDI_D2 38
#define MIDI_DIS2 39
#define MIDI_E2 40
#define MIDI_F2 41
#define MIDI_FIS2 42
#define MIDI_G2 43
#define MIDI_GIS2 44
#define MIDI_A2 45
#define MIDI_AIS2 46
#define MIDI_B2 47
#define MIDI_C3 48
#define MIDI_CIS3 49
#define MIDI_D3 50
#define MIDI_DIS3 51
#define MIDI_E3 52
#define MIDI_F3 53
#define MIDI_FIS3 54
#define MIDI_G3 55
#define MIDI_GIS3 56
#define MIDI_A3 57
#define MIDI_AIS3 58
#define MIDI_B3 59
#define MIDI_C4 60
#define MIDI_CIS4 61
#define MIDI_D4 62
#define MIDI_DIS4 63
#define MIDI_E4 64
#define MIDI_F4 65
#define MIDI_FIS4 66
#define MIDI_G4 67
#define MIDI_GIS4 68
#define MIDI_A4 69
#define MIDI_AIS4 70
#define MIDI_B4 71
#define MIDI_C5 72
#define MIDI_CIS5 73
#define MIDI_D5 74
#define MIDI_DIS5 75
#define MIDI_E5 76
#define MIDI_F5 77
#define MIDI_FIS5 78
#define MIDI_G5 79
#define MIDI_GIS5 80
#define MIDI_A5 81
#define MIDI_AIS5 82
#define MIDI_B5 83
#define MIDI_C6 84
#define MIDI_CIS6 85
#define MIDI_D6 86
#define MIDI_DIS6 87
#define MIDI_E6 88
#define MIDI_F6 89
#define MIDI_FIS6 90
#define MIDI_G6 91
#define MIDI_GIS6 92
#define MIDI_A6 93
#define MIDI_AIS6 94
#define MIDI_B6 95
#define MIDI_C7 96
#define MIDI_CIS7 97
#define MIDI_D7 98
#define MIDI_DIS7 99
#define MIDI_E7 100
#define MIDI_F7 101
#define MIDI_FIS7 102
#define MIDI_G7 103
#define MIDI_GIS7 104
#define MIDI_A7 105
#define MIDI_AIS7 106
#define MIDI_B7 107
#define MIDI_C8 108
#endif
Loading…
Cancel
Save