Severeal fixes - especially the memory violation in the master loop and

the handling of the audio queues.
master
Holger Wirtz 6 years ago
parent 6c14711c6f
commit 617ba419ab
  1. 29
      MicroMDAPiano.ino
  2. 2
      config.h
  3. 50
      mdaEPiano.cpp
  4. 2
      mdaEPiano.h

@ -52,7 +52,7 @@ AudioConnection patchCord6(volume_l, 0, pt8211_1, 1);
#endif
// GUItool: end automatically generated code
mdaEPiano* ep = new mdaEPiano();
mdaEPiano* ep;
bool sd_card_available = false;
uint8_t midi_channel = DEFAULT_MIDI_CHANNEL;
uint32_t xrun = 0;
@ -105,7 +105,6 @@ void setup()
enc1.write(INITIAL_ENC1_VALUE);
#endif
delay(500);
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("https://about.teahub.io/dcoredump/MicroMDAEpiano"));
@ -114,7 +113,8 @@ void setup()
Serial.println(F(" bytes"));
Serial.println();
Serial.println(F("<setup start>"));
delay(1000);
ep = new mdaEPiano();
initial_values_from_eeprom();
@ -135,10 +135,12 @@ void setup()
//sgtl5000_1.dacVolumeRamp();
sgtl5000_1.dacVolumeRampLinear();
sgtl5000_1.unmuteHeadphone();
sgtl5000_1.unmuteLineout();
sgtl5000_1.autoVolumeDisable(); // turn off AGC
sgtl5000_1.volume(1.0, 1.0);
#endif
//set_volume(vol, vol_left, vol_right);
set_volume(vol, vol_left, vol_right);
// start SD card
SPI.setMOSI(SDCARD_MOSI_PIN);
@ -185,8 +187,12 @@ void loop()
int16_t* audio_buffer_l; // pointer to AUDIO_BLOCK_SAMPLES * int16_t
const uint16_t audio_block_time_ms = 1000000 / (SAMPLE_RATE / AUDIO_BLOCK_SAMPLES);
while (42 == 42) // DON'T PANIC!
// Main sound calculation
if (queue_r.available() && queue_l.available())
{
audio_buffer_r = queue_r.getBuffer();
audio_buffer_l = queue_l.getBuffer();
#if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
if (cpu_mem_millis > SHOW_CPU_LOAD_MSEC)
{
@ -207,12 +213,9 @@ void loop()
{
Serial.println(F("E: audio_buffer_l allocation problems!"));
}
if (!queue_r.available() || !queue_l.available())
continue;
elapsedMicros t1;
ep->process(&audio_buffer_l,&audio_buffer_r,AUDIO_BLOCK_SAMPLES);
ep->process(audio_buffer_l, audio_buffer_r, AUDIO_BLOCK_SAMPLES);
uint32_t t2 = t1;
if (t2 > audio_block_time_ms) // everything greater 2.9ms is a buffer underrun!
xrun++;
@ -229,14 +232,17 @@ void loop()
peak++;
}
#ifndef TEENSY_AUDIO_BOARD
for (uint8_t i = 0; i <= AUDIO_BLOCK_SAMPLES; i++)
for (uint8_t i = 0; i < AUDIO_BLOCK_SAMPLES; i++)
{
audio_buffer_r[i] *= vol_r;
audio_buffer_l[i] *= vol_l;
audio_buffer_l[i] *= vol_l;
}
#endif
queue_r.playBuffer();
queue_l.playBuffer();
}
}
void handle_input(void)
{
#ifdef USE_ONBOARD_USB_HOST
@ -743,4 +749,3 @@ void note_off(void)
queue_midi_event(0x80, TEST_NOTE + 60, 0); // 16
}
#endif

@ -32,7 +32,7 @@
#define MIDI_DEVICE Serial1
//#define USE_ONBOARD_USB_HOST 1
#define TEENSY_AUDIO_BOARD 1
#define VOLUME 0.6
#define VOLUME 0.3
#define DEFAULT_MIDI_CHANNEL MIDI_CHANNEL_OMNI
#define AUDIO_MEM 4
#define SAMPLE_RATE 44100

@ -90,23 +90,27 @@ mdaEPiano::mdaEPiano() // mdaEPiano::mdaEPiano(audioMasterCallback audioMaster)
kgrp[31].pos = 406046; kgrp[31].end = 414486; kgrp[31].loop = 2306; //ghost
kgrp[32].pos = 414487; kgrp[32].end = 422408; kgrp[32].loop = 2169;
//extra xfade looping...
for (int32_t k = 0; k < 28; k++)
{
int32_t p0 = kgrp[k].end;
int32_t p1 = kgrp[k].end - kgrp[k].loop;
/*
//extra xfade looping...
for (int32_t k = 0; k < 28; k++)
{
int32_t p0 = kgrp[k].end;
int32_t p1 = kgrp[k].end - kgrp[k].loop;
float xf = 1.0f;
float dxf = -0.02f;
float xf = 1.0f;
float dxf = -0.02f;
while (xf > 0.0f)
{
waves[p0] = (short)((1.0f - xf) * (float)waves[p0] + xf * (float)waves[p1]);
p0--;
p1--;
xf += dxf;
}
}
Serial.println("3");
while (xf > 0.0f)
{
waves[p0] = (short)((1.0f - xf) * (float)waves[p0] + xf * (float)waves[p1]);
p0--;
p1--;
xf += dxf;
}
}*/
//initialise...
for (int32_t v = 0; v < NVOICES; v++)
@ -329,10 +333,8 @@ float mdaEPiano::getParameter(int32_t index) {
}
*/
void mdaEPiano::process(int16_t **outputs_r, int16_t **outputs_l, int32_t sampleFrames)
void mdaEPiano::process(int16_t *outputs_r, int16_t *outputs_l, int32_t sampleFrames)
{
int16_t* out_l = outputs_r[0];
int16_t* out_r = outputs_l[0];
int32_t event = 0, frame = 0, frames, v;
float x, l, r, od = overdrive;
int32_t i;
@ -355,10 +357,12 @@ void mdaEPiano::process(int16_t **outputs_r, int16_t **outputs_l, int32_t sample
V->pos += V->frac >> 16;
V->frac &= 0xFFFF;
if (V->pos > V->end) V->pos -= V->loop;
i = waves[V->pos];
i = (i << 7) + (V->frac >> 9) * (waves[V->pos + 1] - i) + 0x40400000;
//i = waves[V->pos];
//i = (i << 7) + (V->frac >> 9) * (waves[V->pos + 1] - i) + 0x40400000; //not working on intel mac !?!
//x = V->env * (*(float *)&i - 3.0f); //fast int->float
x = V->env * (float(i) - 3.0f);
//x = V->env * (float)i / 32768.0f;
i = waves[V->pos] + ((V->frac * (waves[V->pos + 1] - waves[V->pos])) >> 16);
x = V->env * (float)i / 32768.0f;
V->env = V->env * V->dec; //envelope
@ -382,8 +386,8 @@ void mdaEPiano::process(int16_t **outputs_r, int16_t **outputs_l, int32_t sample
l += l * lmod * lfo1;
r += r * rmod * lfo1; //worth making all these local variables?
*out_r++ = static_cast<int16_t>(l * 0x8000);
*out_l++ = static_cast<int16_t>(r * 0x8000);
outputs_r[sampleFrames - frames] = static_cast<int16_t>(r * 0x8000);
outputs_l[sampleFrames - frames] = static_cast<int16_t>(l * 0x8000);
}
if (frame < sampleFrames)

@ -60,7 +60,7 @@ public:
mdaEPiano(); // mdaEPiano(audioMasterCallback audioMaster);
~mdaEPiano();
virtual void process(int16_t **outputs_r, int16_t **outputs_l, int32_t sampleFrames);
virtual void process(int16_t *outputs_r, int16_t *outputs_l, int32_t sampleFrames);
virtual bool processMidiMessage(uint8_t type, uint8_t data1, uint8_t data2);
virtual void setProgram(int32_t program);
//virtual void setProgramName(char *name);

Loading…
Cancel
Save