Simplified audio calculation function.

Small fixes.
pull/4/head
Holger Wirtz 6 years ago
parent ba27df8a81
commit 7cbb2608ec
  1. 4
      MicroDexed.ino
  2. 119
      dexed.cpp
  3. 2
      dexed.h
  4. 6
      synth.h

@ -21,7 +21,7 @@
//#define SHOW_DEXED_TIMING 1
#define SHOW_XRUN 1
#define SHOW_CPU_LOAD_MSEC 5000
#define MAX_NOTES 10
#define MAX_NOTES 11
#define TEST_MIDI 1
#define TEST_NOTE 40
#define TEST_VEL 60
@ -76,7 +76,7 @@ void setup()
dexed->activate();
dexed->setMaxNotes(MAX_NOTES);
#ifdef TEST_MIDI
queue_midi_event(0x90, TEST_NOTE, TEST_VEL); // 1

@ -71,11 +71,6 @@ Dexed::Dexed(int rate)
voices[i].live = false;
}
/* for(i=0;i<sizeof(data);++i)
{
data_float[i]=static_cast<float>(data[i]);
}*/
max_notes = 16;
currentNote = 0;
controllers.values_[kControllerPitch] = 0x2000;
@ -95,11 +90,11 @@ Dexed::Dexed(int rate)
sustain = false;
extra_buf_size_ = 0;
memset(&voiceStatus, 0, sizeof(VoiceStatus));
setEngineType(DEXED_ENGINE_MODERN);
//setEngineType(DEXED_ENGINE_MARKI);
//setEngineType(DEXED_ENGINE_OPL);
}
Dexed::~Dexed()
@ -140,100 +135,38 @@ void Dexed::GetSamples(uint16_t n_samples, int16_t* buffer)
refreshVoice = false;
}
// flush first events
for (i = 0; i < n_samples && i < extra_buf_size_; i++) {
buffer[i] = extra_buf_[i];
}
for (i = 0; i < n_samples; i += _N_) {
AlignedBuf<int32_t, _N_> audiobuf;
float sumbuf[_N_];
// remaining buffer is still to be processed
if (extra_buf_size_ > n_samples) {
for (uint16_t j = 0; j < extra_buf_size_ - n_samples; j++) {
extra_buf_[j] = extra_buf_[j + n_samples];
for (uint8_t j = 0; j < _N_; ++j) {
audiobuf.get()[j] = 0;
sumbuf[j] = 0.0;
}
extra_buf_size_ -= n_samples;
}
else
{
for (; i < n_samples; i += _N_) {
AlignedBuf<int32_t, _N_> audiobuf;
float sumbuf[_N_];
for (uint8_t j = 0; j < _N_; ++j) {
audiobuf.get()[j] = 0;
sumbuf[j] = 0.0;
}
int32_t lfovalue = lfo.getsample();
int32_t lfodelay = lfo.getdelay();
for (uint8_t note = 0; note < max_notes; ++note) {
if (voices[note].live) {
voices[note].dx7_note->compute(audiobuf.get(), lfovalue, lfodelay, &controllers);
for (uint8_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;
}
int32_t lfovalue = lfo.getsample();
int32_t lfodelay = lfo.getdelay();
for (uint8_t note = 0; note < max_notes; ++note) {
if (voices[note].live) {
voices[note].dx7_note->compute(audiobuf.get(), lfovalue, lfodelay, &controllers);
for (uint8_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;
}
}
}
uint16_t jmax = n_samples - i;
for (uint8_t j = 0; j < _N_; ++j) {
if (j < jmax)
{
buffer[i + j] = static_cast<int16_t>(sumbuf[j] * 0x8000);
}
else
extra_buf_[j - jmax] = static_cast<int16_t>(sumbuf[j] * 0x8000);
}
for (uint8_t j = 0; j < _N_; ++j) {
buffer[i + j] = static_cast<int16_t>(sumbuf[j] * 0x8000);
}
extra_buf_size_ = i - n_samples;
}
/* if (++_k_rate_counter == 0 && !monoMode)
{
uint8_t op_carrier = controllers.core->get_carrier_operators(data[134]); // look for carriers
for (i = 0; i < max_notes; i++)
{
if (voices[i].live == true)
{
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++)
{
uint8_t op_bit = static_cast<uint8_t>(pow(2, op));
if ((op_carrier & op_bit) > 0)
{
// this voice is a carrier!
op_carrier_num++;
//TRACE("Voice[%2d] OP [%d] amp=%ld,amp_step=%d,pitch_step=%d",i,op,voiceStatus.amp[op],voiceStatus.ampStep[op],voiceStatus.pitchStep);
if (voiceStatus.amp[op] <= 1069 && voiceStatus.ampStep[op] == 4) // this voice produces no audio output
op_amp++;
}
}
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;
TRACE("Shutted down Voice[%2d]", i);
}
}
}
} */
}
bool Dexed::ProcessMidiMessage(uint8_t type, uint8_t data1, uint8_t data2)

@ -90,8 +90,6 @@ class Dexed
FmCore* engineMsfa;
EngineMkI* engineMkI;
EngineOpl* engineOpl;
int16_t extra_buf_[_N_];
uint32_t extra_buf_size_;
private:
uint8_t _k_rate_counter;

@ -17,8 +17,8 @@
#ifndef __SYNTH_H
#define __SYNTH_H
#include <Arduino.h>
#define SUPER_PRECISE
//#include <Arduino.h>
//#define SUPER_PRECISE
// This IS not be present on MSVC.
// See http://stackoverflow.com/questions/126279/c99-stdint-h-header-and-ms-visual-studio
@ -50,7 +50,6 @@ typedef __int16 SInt16;
#define SynthMemoryBarrier()
#endif
/*
template<typename T>
inline static T min(const T& a, const T& b) {
return a < b ? a : b;
@ -60,7 +59,6 @@ template<typename T>
inline static T max(const T& a, const T& b) {
return a > b ? a : b;
}
*/
#define QER(n,b) ( ((float)n)/(1<<b) )

Loading…
Cancel
Save