Compare commits

..

2 Commits

Author SHA1 Message Date
Holger Wirtz 1dec1a1308 . 6 years ago
Holger Wirtz d8b7045057 Simple and stupid chorus... work, but is not nice. 6 years ago
  1. 47
      Encoder4.h
  2. 86
      LiquidCrystalPlus_I2C.h
  3. 102
      MicroMDAEPiano.ino
  4. 18
      UI.cpp
  5. 10
      UI.h
  6. 12
      config.h
  7. 3
      mdaEPiano.cpp

@ -0,0 +1,47 @@
/*
MicroMDAEPiano
MicroMDAEPiano is a port of the MDA-EPiano sound engine
(https://sourceforge.net/projects/mda-vst/) for the Teensy-3.5/3.6 with audio shield.
(c)2019 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 <Encoder.h>
#ifndef ENCODER4_H_INCLUDED
#define ENCODER4_H_INCLUDED
class Encoder4 : public Encoder
{
public:
using Encoder::Encoder;
int32_t read()
{
return (Encoder::read() / 4);
}
void write(int32_t p)
{
Encoder::write(p * 4);
}
};
#endif

@ -0,0 +1,86 @@
/*
MicroMDAEPiano
MicroMDAEPiano is a port of the MDA-EPiano sound engine
(https://sourceforge.net/projects/mda-vst/) for the Teensy-3.5/3.6 with audio shield.
(c)2019 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
*/
#ifndef LIQUIDCRYSTALPLUS_I2C_H_INCLUDED
#define LIQUIDCRYSTALPLUS_I2C_H_INCLUDED
#include <LiquidCrystal_I2C.h> // https://www.arduinolibraries.info/libraries/liquid-crystal-i2-c
#define STRING_BUF_SIZE 21
class LiquidCrystalPlus_I2C : public LiquidCrystal_I2C
{
public:
using LiquidCrystal_I2C::LiquidCrystal_I2C;
void show(uint8_t y, uint8_t x, uint8_t fs, char *str)
{
_show(y, x, fs, str, false, false);
}
void show(uint8_t y, uint8_t x, uint8_t fs, long num)
{
char _buf10[STRING_BUF_SIZE];
_show(y, x, fs, itoa(num, _buf10, 10), true, true);
}
private:
void _show(uint8_t pos_y, uint8_t pos_x, uint8_t field_size, char *str, bool justify_right, bool fill_zero)
{
{
char tmp[STRING_BUF_SIZE];
char *s = tmp;
uint8_t l = strlen(str);
memset(tmp, 0, sizeof(tmp));
if (fill_zero == true)
memset(tmp, '0', field_size);
else
memset(tmp, 0x20, field_size - 1); // blank
if (l > field_size)
l = field_size;
if (justify_right == true)
s += field_size - l;
strncpy(s, str, l);
setCursor(pos_x, pos_y);
print(tmp);
#ifdef DEBUG
Serial.print(pos_y, DEC);
Serial.print(F("/"));
Serial.print(pos_x, DEC);
Serial.print(F(": ["));
Serial.print(tmp);
Serial.println(F("]"));
#endif
}
}
};
#endif

@ -28,22 +28,25 @@
#include <MIDI.h> #include <MIDI.h>
#include <EEPROM.h> #include <EEPROM.h>
#include <limits.h> #include <limits.h>
#include <BALibrary.h>
#include <BAEffects.h>
#include "mdaEPiano.h" #include "mdaEPiano.h"
#ifdef USE_XFADE_DATA #ifdef USE_XFADE_DATA
#include "mdaEPianoDataXfade.h" #include "mdaEPianoDataXfade.h"
#else #else
#include "mdaEPianoData.h" #include "mdaEPianoData.h"
#endif #endif
#if defined(MIDI_DEVICE_USB) #ifdef MIDI_DEVICE_USB
#include <midi_UsbTransport.h> #include <midi_UsbTransport.h>
#endif #endif
#ifdef MIDI_DEVICE_USB_HOST #ifdef MIDI_DEVICE_USB_HOST
#include <USBHost_t36.h> #include <USBHost_t36.h>
#endif #endif
#include <Bounce.h>
#include "Encoder4.h"
#include "LiquidCrystalPlus_I2C.h"
#include "UI.h"
#include <BALibrary.h> // had rename libraries/BALibrary/src/peripherals/BAPhysicalControls.cpp
#include <BAEffects.h>
using namespace BALibrary;
using namespace BAEffects; using namespace BAEffects;
//************************************************************************************************* //*************************************************************************************************
@ -55,48 +58,42 @@ AudioPlayQueue queue_r;
AudioPlayQueue queue_l; AudioPlayQueue queue_l;
AudioAnalyzePeak peak_r; AudioAnalyzePeak peak_r;
AudioAnalyzePeak peak_l; AudioAnalyzePeak peak_l;
AudioEffectAnalogChorus analogChorus_r;
AudioEffectAnalogChorus analogChorus_l;
AudioEffectFreeverb freeverb_r; AudioEffectFreeverb freeverb_r;
AudioEffectFreeverb freeverb_l; AudioEffectFreeverb freeverb_l;
AudioMixer4 mixer_r; AudioMixer4 reverb_mixer_r;
AudioMixer4 mixer_l; AudioMixer4 reverb_mixer_l;
AudioEffectSimpleChorus chorus_r(20.0);
AudioEffectSimpleChorus chorus_l(20.0);
//BAEffects::AudioEffectAnalogDelay chorus_r(200.0);
//BAEffects::AudioEffectAnalogDelay chorus_l(200.0);
AudioConnection patchCord0(queue_r, peak_r); AudioConnection patchCord0(queue_r, peak_r);
AudioConnection patchCord1(queue_l, peak_l); AudioConnection patchCord1(queue_l, peak_l);
AudioConnection patchCord2(queue_r, analogChorus_r); AudioConnection patchCord2(queue_r, chorus_r);
AudioConnection patchCord3(queue_l, analogChorus_l); AudioConnection patchCord3(queue_l, chorus_l);
AudioConnection patchCord4(analogChorus_r, freeverb_r); AudioConnection patchCord4(chorus_r, freeverb_r);
AudioConnection patchCord5(analogChorus_l, freeverb_l); AudioConnection patchCord5(chorus_l, freeverb_l);
AudioConnection patchCord6(queue_r, 0, mixer_r, 0); AudioConnection patchCord6(chorus_r, 0, reverb_mixer_r, 0);
AudioConnection patchCord7(queue_l, 0, mixer_l, 0); AudioConnection patchCord7(chorus_l, 0, reverb_mixer_l, 0);
AudioConnection patchCord8(freeverb_r, 0, mixer_r, 1); AudioConnection patchCord8(freeverb_r, 0, reverb_mixer_r, 1);
AudioConnection patchCord9(freeverb_l, 0, mixer_l, 1); AudioConnection patchCord9(freeverb_l, 0, reverb_mixer_l, 1);
#ifdef TEENSY_AUDIO_BOARD #ifdef TEENSY_AUDIO_BOARD
AudioOutputI2S i2s1; AudioOutputI2S i2s1;
AudioConnection patchCord110(mixer_r, 0, i2s1, 0); AudioConnection patchCord10(reverb_mixer_r, 0, i2s1, 0);
AudioConnection patchCord111(mixer_l, 0, i2s1, 1); AudioConnection patchCord11(reverb_mixer_l, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; AudioControlSGTL5000 sgtl5000_1;
#elif defined(TGA_BOARD)
BAAudioControlWM8731 codecControl;
AudioOutputI2S i2sOut;
AudioAmplifier volume_r;
AudioAmplifier volume_l;
AudioConnection patchCord10(mixer_r, volume_r);
AudioConnection patchCord11(mixer_l, volume_l);
AudioConnection patchCord12(volume_r, 0, i2sOut, 1);
AudioConnection patchCord13(volume_l, 0, i2sOut, 0);
#else #else
AudioOutputPT8211 pt8211_1; AudioOutputPT8211 pt8211_1;
AudioAmplifier volume_r; AudioAmplifier volume_r;
AudioAmplifier volume_l; AudioAmplifier volume_l;
AudioConnection patchCord10(mixer_r, volume_r); AudioConnection patchCord10(reverb_mixer_r, volume_r);
AudioConnection patchCord11(mixer_l, volume_l); AudioConnection patchCord11(reverb_mixer_l, volume_l);
AudioConnection patchCord12(volume_r, 0, pt8211_1, 1); AudioConnection patchCord12(volume_r, 0, pt8211_1, 1);
AudioConnection patchCord13(volume_l, 0, pt8211_1, 0); AudioConnection patchCord13(volume_l, 0, pt8211_1, 0);
#endif #endif
// Objects // Objects
mdaEPiano* ep; mdaEPiano* ep;
BALibrary::LowFrequencyOscillatorVector<float> chorus_lfo;
#ifdef MIDI_DEVICE_DIN #ifdef MIDI_DEVICE_DIN
MIDI_CREATE_INSTANCE(HardwareSerial, MIDI_DEVICE_DIN, midi_serial); MIDI_CREATE_INSTANCE(HardwareSerial, MIDI_DEVICE_DIN, midi_serial);
@ -118,7 +115,7 @@ uint32_t xrun = 0;
uint32_t overload = 0; uint32_t overload = 0;
uint32_t peak = 0; uint32_t peak = 0;
uint16_t render_time_max = 0; uint16_t render_time_max = 0;
float vol = XVOLUME; float vol = _VOLUME;
float vol_right = 1.0; float vol_right = 1.0;
float vol_left = 1.0; float vol_left = 1.0;
elapsedMicros fill_audio_buffer; elapsedMicros fill_audio_buffer;
@ -160,7 +157,6 @@ void setup()
but[0].update(); but[0].update();
but[1].update(); but[1].update();
*/ */
// Debug output // Debug output
Serial.println(F("MicroMDAEPiano based on https://sourceforge.net/projects/mda-vst")); Serial.println(F("MicroMDAEPiano based on https://sourceforge.net/projects/mda-vst"));
Serial.println(F("(c)2018 H. Wirtz <wirtz@parasitstudio.de>")); Serial.println(F("(c)2018 H. Wirtz <wirtz@parasitstudio.de>"));
@ -196,14 +192,6 @@ void setup()
#endif #endif
// start audio card // start audio card
AudioNoInterrupts();
#ifdef TGA_BOARD
codecControl.disable();
delay(100);
codecControl.enable();
delay(100);
#endif
AudioMemory(AUDIO_MEM); AudioMemory(AUDIO_MEM);
#ifdef TEENSY_AUDIO_BOARD #ifdef TEENSY_AUDIO_BOARD
@ -231,6 +219,7 @@ void setup()
Serial.print(1000000 / (SAMPLE_RATE / AUDIO_BLOCK_SAMPLES)); Serial.print(1000000 / (SAMPLE_RATE / AUDIO_BLOCK_SAMPLES));
Serial.println(F("ms)")); Serial.println(F("ms)"));
// Epiano
ep->setParameter(DECAY, 0.5); ep->setParameter(DECAY, 0.5);
ep->setParameter(RELEASE, 0.5); ep->setParameter(RELEASE, 0.5);
ep->setParameter(HARDNESS, 0.7); ep->setParameter(HARDNESS, 0.7);
@ -240,28 +229,27 @@ void setup()
ep->setParameter(STEREO, 0.7); ep->setParameter(STEREO, 0.7);
ep->setParameter(OVERDRIVE, 0.3); ep->setParameter(OVERDRIVE, 0.3);
// Reverb
freeverb_r.roomsize(0.2); freeverb_r.roomsize(0.2);
freeverb_l.roomsize(0.2); freeverb_l.roomsize(0.2);
freeverb_r.damping(0.5); freeverb_r.damping(0.5);
freeverb_l.damping(0.5); freeverb_l.damping(0.5);
reverb_mixer_r.gain(0, 1.0);
analogChorus_r.enable(); reverb_mixer_l.gain(0, 1.0);
analogChorus_r.bypass(true); reverb_mixer_r.gain(1, 0.0);
analogChorus_r.rate(0.2f); reverb_mixer_l.gain(1, 0.0);
analogChorus_r.mix(0.5f);
analogChorus_r.depth(0.4f); // Chorus
analogChorus_l.enable(); chorus_r.enable();
analogChorus_l.bypass(true); chorus_r.bypass(false);
analogChorus_l.rate(0.2f); chorus_r.frequency(1.0f);
analogChorus_l.mix(0.5f); chorus_r.mix(0.5f);
analogChorus_l.depth(0.4f); chorus_r.intensity(0.5f);
chorus_l.enable();
mixer_r.gain(0, 0.7); chorus_r.bypass(false);
mixer_l.gain(0, 0.7); chorus_l.frequency(1.0f);
mixer_r.gain(1, 0.3); chorus_l.mix(0.5f);
mixer_l.gain(1, 0.3); chorus_l.intensity(0.5f);
AudioInterrupts();
Serial.println(F("<setup end>")); Serial.println(F("<setup end>"));

@ -24,12 +24,18 @@
#include "config.h" #include "config.h"
#include "UI.h" #include "UI.h"
/*
UI::UI() UI::UI()
{ {
LiquidCrystalPlus_I2C lcd(LCD_I2C_ADDRESS, LCD_CHARS, LCD_LINES); lcd=new LiquidCrystalPlus_I2C(LCD_I2C_ADDRESS, LCD_CHARS, LCD_LINES);
enc[] = {Encoder4(ENC_L_PIN_A, ENC_L_PIN_B), Encoder4(ENC_R_PIN_A, ENC_R_PIN_B)}; enc[0] = new Encoder4(ENC_L_PIN_A, ENC_L_PIN_B);
enc_val[] = {INITIAL_ENC_L_VALUE, INITIAL_ENC_R_VALUE}; enc[1] = new Encoder4(ENC_R_PIN_A, ENC_R_PIN_B);
but[] = {Bounce(BUT_L_PIN, BUT_DEBOUNCE_MS), Bounce(BUT_R_PIN, BUT_DEBOUNCE_MS)}; enc_val[0] = INITIAL_ENC_L_VALUE;
enc_val[1] = INITIAL_ENC_R_VALUE;
but[0] = new Bounce(BUT_L_PIN, BUT_DEBOUNCE_MS);
but[1] = new Bounce(BUT_R_PIN, BUT_DEBOUNCE_MS);
}
UI::~UI()
{
;
} }
*/

10
UI.h

@ -24,7 +24,6 @@
#ifndef UI_H_INCLUDED #ifndef UI_H_INCLUDED
#define UI_H_INCLUDED #define UI_H_INCLUDED
/*
#include "config.h" #include "config.h"
#include "LiquidCrystalPlus_I2C.h" #include "LiquidCrystalPlus_I2C.h"
#include <Bounce.h> #include <Bounce.h>
@ -37,10 +36,9 @@ class UI
~UI(); ~UI();
private: private:
LiquidCrystalPlus_I2C lcd; LiquidCrystalPlus_I2C* lcd;
Encoder4 enc[2]; Encoder4* enc[2];
int32_t enc_val[2]; int32_t enc_val[2];
Bounce but[2]; Bounce* but[2];
} };
*/
#endif #endif

@ -26,6 +26,13 @@
#include "midinotes.h" #include "midinotes.h"
#define DELAY_R_MS 10.0
#define DELAY_L_MS 10.0
#define DELAY_R_INTENSITY 0.5
#define DELAY_L_INTENSITY 0.5
#define DELAY_FRQ 1.0
#define DELAY_VOLUME 0.5
// ATTENTION! For better latency you have to redefine AUDIO_BLOCK_SAMPLES from // ATTENTION! For better latency you have to redefine AUDIO_BLOCK_SAMPLES from
// 128 to 64 in <ARDUINO-IDE-DIR>/cores/teensy3/AudioStream.h // 128 to 64 in <ARDUINO-IDE-DIR>/cores/teensy3/AudioStream.h
@ -40,7 +47,6 @@
// AUDIO // AUDIO
//#define TEENSY_AUDIO_BOARD 1 //#define TEENSY_AUDIO_BOARD 1
#define TGA_BOARD
//************************************************************************************************* //*************************************************************************************************
//* MIDI SETTINGS //* MIDI SETTINGS
@ -53,10 +59,10 @@
//* AUDIO SETTINGS //* AUDIO SETTINGS
//************************************************************************************************* //*************************************************************************************************
#define XVOLUME 0.8 #define _VOLUME 0.8
#define AUDIO_MEM 128 #define AUDIO_MEM 128
#define SAMPLE_RATE 44100 #define SAMPLE_RATE 44100
#define REDUCE_LOUDNESS 0 #define REDUCE_LOUDNESS 1
#define USE_XFADE_DATA 1 #define USE_XFADE_DATA 1
//************************************************************************************************* //*************************************************************************************************

@ -228,9 +228,6 @@ void mdaEPiano::process(int16_t* outputs_r, int16_t* outputs_l)
l += l * lmod * lfo1; l += l * lmod * lfo1;
r += r * rmod * lfo1; //worth making all these local variables? r += r * rmod * lfo1; //worth making all these local variables?
r*=0.5;
l*=0.5;
if (r > 1.0) if (r > 1.0)
r = 1.0; r = 1.0;
else if (r < -1.0) else if (r < -1.0)

Loading…
Cancel
Save