From e325348fc78e6ec60e1b31df26f42b6157db3fb0 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Tue, 15 May 2018 11:33:00 +0200 Subject: [PATCH] Replaced looper with IntervalTimer. --- MicroDexed.ino | 12 ++++-------- dexed.cpp | 15 ++++++--------- dexed.h | 2 +- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index d49607b..c0b0069 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -13,7 +13,6 @@ #include #include #include -#include #include "dexed.h" #define AUDIO_MEM 32 @@ -21,7 +20,7 @@ #define SAMPLEAUDIO_BUFFER_SIZE 44100 #define MIDI_QUEUE_LOCK_TIMEOUT_MS 0 #define INIT_AUDIO_QUEUE 1 -#define SHOW_DEXED_TIMING 1 +//#define SHOW_DEXED_TIMING 1 #define TEST_MIDI 1 #define TEST_NOTE1 60 @@ -46,7 +45,7 @@ MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI); Dexed* dexed = new Dexed(SAMPLEAUDIO_BUFFER_SIZE); QueueArray midi_queue; Threads::Mutex midi_queue_lock; -looper sched; +IntervalTimer sched; void setup() { @@ -89,9 +88,7 @@ void setup() #endif threads.addThread(midi_thread, 1); - - sched.addJob(cpu_and_mem_usage, 1000); - + sched.begin(cpu_and_mem_usage, 1000000); Serial.println(F("setup end")); } @@ -127,9 +124,8 @@ void loop() #ifdef SHOW_DEXED_TIMING Serial.println(t1, DEC); #endif - queue1.playBuffer(); - sched.scheduler(); + queue1.playBuffer(); } void midi_test_thread(void) diff --git a/dexed.cpp b/dexed.cpp index 7535757..63ceb5c 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -162,12 +162,11 @@ void Dexed::GetSamples(uint16_t n_samples, int16_t* buffer) { for (; i < n_samples; i += _N_) { AlignedBuf audiobuf; - int16_t sumbuf[_N_]; + float sumbuf[_N_]; for (uint8_t j = 0; j < _N_; ++j) { audiobuf.get()[j] = 0; - //sumbuf[j] = 0.0; - sumbuf[j] = 0; + sumbuf[j] = 0.0; } 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]; val = val >> 4; int32_t clip_val = val < -(1 << 24) ? 0x8000 : val >= (1 << 24) ? 0x7fff : val >> 9; - float f = static_cast(clip_val >> 1) / static_cast(0x8000); + float f = static_cast(clip_val >> 1) / 0x8000; if (f > 1) f = 1; if (f < -1) f = -1; - sumbuf[j] += clip_val; + sumbuf[j] += f; 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) { if (j < jmax) { - //buffer[i + j] = static_cast(sumbuf[j]*0x8000); - buffer[i + j] = sumbuf[j]; - //Serial.println(buffer[i + j], DEC); + buffer[i + j] = static_cast(sumbuf[j] * 0x8000); } else - extra_buf_[j - jmax] = sumbuf[j]; + extra_buf_[j - jmax] = static_cast(sumbuf[j] * 0x8000); } } extra_buf_size_ = i - n_samples; diff --git a/dexed.h b/dexed.h index 4d04a85..392fc80 100644 --- a/dexed.h +++ b/dexed.h @@ -92,7 +92,7 @@ class Dexed EngineOpl* engineOpl; float* outbuf_; uint32_t bufsize_; - float extra_buf_[_N_]; + int16_t extra_buf_[_N_]; uint32_t extra_buf_size_; private: