Optimized the calculation funtion for the sound and got some CPU cycles more for sound

calculation. This fixes also the too low output volume.
pull/32/head
Holger Wirtz 5 years ago
parent 8b25e15925
commit b2e20804ca
  1. 3
      MicroDexed.ino
  2. 39
      dexed.cpp

@ -258,12 +258,11 @@ void setup()
pinMode(U8X8_CS_PIN, OUTPUT); pinMode(U8X8_CS_PIN, OUTPUT);
#endif #endif
delay(320); // necessary, because before no serial output is done :(
#ifdef ENABLE_LCD_UI #ifdef ENABLE_LCD_UI
setup_ui(); setup_ui();
#else #else
#ifdef DEBUG #ifdef DEBUG
delay(320); // necessary, because before no serial output is done :(
Serial.println(F("NO LCD DISPLAY ENABLED!")); Serial.println(F("NO LCD DISPLAY ENABLED!"));
#endif #endif
#endif #endif

@ -111,7 +111,8 @@ void Dexed::deactivate(void)
void Dexed::getSamples(uint16_t n_samples, int16_t* buffer) void Dexed::getSamples(uint16_t n_samples, int16_t* buffer)
{ {
uint16_t i; uint16_t i,j;
uint8_t note;
float sumbuf[n_samples]; float sumbuf[n_samples];
if (refreshVoice) if (refreshVoice)
@ -121,7 +122,6 @@ void Dexed::getSamples(uint16_t n_samples, int16_t* buffer)
if ( voices[i].live ) if ( voices[i].live )
voices[i].dx7_note->update(data, voices[i].midi_note, voices[i].velocity, voices[i].porta); voices[i].dx7_note->update(data, voices[i].midi_note, voices[i].velocity, voices[i].porta);
} }
lfo.reset(data + 137); lfo.reset(data + 137);
refreshVoice = false; refreshVoice = false;
} }
@ -139,37 +139,15 @@ void Dexed::getSamples(uint16_t n_samples, int16_t* buffer)
int32_t lfovalue = lfo.getsample(); int32_t lfovalue = lfo.getsample();
int32_t lfodelay = lfo.getdelay(); int32_t lfodelay = lfo.getdelay();
for (uint8_t note = 0; note < max_notes; note++) for (note = 0; note < max_notes; note++)
{ {
if (voices[note].live) if (voices[note].live)
{ {
voices[note].dx7_note->compute(audiobuf.get(), lfovalue, lfodelay, &controllers); voices[note].dx7_note->compute(audiobuf.get(), lfovalue, lfodelay, &controllers);
for (uint8_t j = 0; j < _N_; ++j) for (j = 0; j < _N_; ++j)
{ {
int32_t val = audiobuf.get()[j]; sumbuf[i + j] += static_cast<float>(signed_saturate_rshift(audiobuf.get()[j] >> 4, 24, 9)) / 0x8000;
val = val >> 4;
#ifdef USE_TEENSY_DSP
int32_t clip_val = signed_saturate_rshift(val, 24, 9);
#else
int32_t clip_val = val < -(1 << 24) ? 0x8000 : val >= (1 << 24) ? 0x7fff : val >> 9;
#endif
float f = static_cast<float>(clip_val >> REDUCE_LOUDNESS) / 0x7fff;
#if defined(REDUCE_LOUDNESS_FACTOR)
f *= REDUCE_LOUDNESS_FACTOR;
#endif
if (f > 1.0)
{
f = 1.0;
overload++;
}
else if (f < -1.0)
{
f = -1.0;
overload++;
}
sumbuf[i + j] += f;
audiobuf.get()[j] = 0; audiobuf.get()[j] = 0;
} }
} }
@ -178,16 +156,9 @@ void Dexed::getSamples(uint16_t n_samples, int16_t* buffer)
#ifdef USE_FX #ifdef USE_FX
fx.process(sumbuf, n_samples); fx.process(sumbuf, n_samples);
// #else
// arm_scale_f32(sumbuf, fx.getGain(), sumbuf, n_samples);
#endif #endif
//#ifdef USE_TEENSY_DSP
arm_float_to_q15(sumbuf, buffer, AUDIO_BLOCK_SAMPLES); arm_float_to_q15(sumbuf, buffer, AUDIO_BLOCK_SAMPLES);
//#else
//for (i = 0; i < n_samples; ++i)
//buffer[i] = static_cast<int16_t>(sumbuf[i] * 0x7fff);
//#endif
} }
void Dexed::keydown(int16_t pitch, uint8_t velo) { void Dexed::keydown(int16_t pitch, uint8_t velo) {

Loading…
Cancel
Save