Replaced looper with IntervalTimer.

pull/4/head
Holger Wirtz 7 years ago
parent b02d227320
commit e325348fc7
  1. 12
      MicroDexed.ino
  2. 15
      dexed.cpp
  3. 2
      dexed.h

@ -13,7 +13,6 @@
#include <TeensyThreads.h> #include <TeensyThreads.h>
#include <QueueArray.h> #include <QueueArray.h>
#include <MIDI.h> #include <MIDI.h>
#include <looper.h>
#include "dexed.h" #include "dexed.h"
#define AUDIO_MEM 32 #define AUDIO_MEM 32
@ -21,7 +20,7 @@
#define SAMPLEAUDIO_BUFFER_SIZE 44100 #define SAMPLEAUDIO_BUFFER_SIZE 44100
#define MIDI_QUEUE_LOCK_TIMEOUT_MS 0 #define MIDI_QUEUE_LOCK_TIMEOUT_MS 0
#define INIT_AUDIO_QUEUE 1 #define INIT_AUDIO_QUEUE 1
#define SHOW_DEXED_TIMING 1 //#define SHOW_DEXED_TIMING 1
#define TEST_MIDI 1 #define TEST_MIDI 1
#define TEST_NOTE1 60 #define TEST_NOTE1 60
@ -46,7 +45,7 @@ MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
Dexed* dexed = new Dexed(SAMPLEAUDIO_BUFFER_SIZE); Dexed* dexed = new Dexed(SAMPLEAUDIO_BUFFER_SIZE);
QueueArray <midi_queue_t> midi_queue; QueueArray <midi_queue_t> midi_queue;
Threads::Mutex midi_queue_lock; Threads::Mutex midi_queue_lock;
looper sched; IntervalTimer sched;
void setup() void setup()
{ {
@ -89,9 +88,7 @@ void setup()
#endif #endif
threads.addThread(midi_thread, 1); threads.addThread(midi_thread, 1);
sched.begin(cpu_and_mem_usage, 1000000);
sched.addJob(cpu_and_mem_usage, 1000);
Serial.println(F("setup end")); Serial.println(F("setup end"));
} }
@ -127,9 +124,8 @@ void loop()
#ifdef SHOW_DEXED_TIMING #ifdef SHOW_DEXED_TIMING
Serial.println(t1, DEC); Serial.println(t1, DEC);
#endif #endif
queue1.playBuffer();
sched.scheduler(); queue1.playBuffer();
} }
void midi_test_thread(void) void midi_test_thread(void)

@ -162,12 +162,11 @@ void Dexed::GetSamples(uint16_t n_samples, int16_t* buffer)
{ {
for (; i < n_samples; i += _N_) { for (; i < n_samples; i += _N_) {
AlignedBuf<int32_t, _N_> audiobuf; AlignedBuf<int32_t, _N_> audiobuf;
int16_t sumbuf[_N_]; float sumbuf[_N_];
for (uint8_t j = 0; j < _N_; ++j) { for (uint8_t j = 0; j < _N_; ++j) {
audiobuf.get()[j] = 0; audiobuf.get()[j] = 0;
//sumbuf[j] = 0.0; sumbuf[j] = 0.0;
sumbuf[j] = 0;
} }
int32_t lfovalue = lfo.getsample(); int32_t lfovalue = lfo.getsample();
@ -180,10 +179,10 @@ void Dexed::GetSamples(uint16_t n_samples, int16_t* buffer)
int32_t val = audiobuf.get()[j]; int32_t val = audiobuf.get()[j];
val = val >> 4; val = val >> 4;
int32_t clip_val = val < -(1 << 24) ? 0x8000 : val >= (1 << 24) ? 0x7fff : val >> 9; int32_t clip_val = val < -(1 << 24) ? 0x8000 : val >= (1 << 24) ? 0x7fff : val >> 9;
float f = static_cast<float>(clip_val >> 1) / static_cast<float>(0x8000); float f = static_cast<float>(clip_val >> 1) / 0x8000;
if (f > 1) f = 1; if (f > 1) f = 1;
if (f < -1) f = -1; if (f < -1) f = -1;
sumbuf[j] += clip_val; sumbuf[j] += f;
audiobuf.get()[j] = 0; audiobuf.get()[j] = 0;
} }
} }
@ -193,12 +192,10 @@ void Dexed::GetSamples(uint16_t n_samples, int16_t* buffer)
for (uint8_t j = 0; j < _N_; ++j) { for (uint8_t j = 0; j < _N_; ++j) {
if (j < jmax) if (j < jmax)
{ {
//buffer[i + j] = static_cast<int16_t>(sumbuf[j]*0x8000); buffer[i + j] = static_cast<int16_t>(sumbuf[j] * 0x8000);
buffer[i + j] = sumbuf[j];
//Serial.println(buffer[i + j], DEC);
} }
else else
extra_buf_[j - jmax] = sumbuf[j]; extra_buf_[j - jmax] = static_cast<int16_t>(sumbuf[j] * 0x8000);
} }
} }
extra_buf_size_ = i - n_samples; extra_buf_size_ = i - n_samples;

@ -92,7 +92,7 @@ class Dexed
EngineOpl* engineOpl; EngineOpl* engineOpl;
float* outbuf_; float* outbuf_;
uint32_t bufsize_; uint32_t bufsize_;
float extra_buf_[_N_]; int16_t extra_buf_[_N_];
uint32_t extra_buf_size_; uint32_t extra_buf_size_;
private: private:

Loading…
Cancel
Save