From c2e0bfe6325501d03c9a2d2274f810427b93fa31 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Sun, 10 Jun 2018 13:02:51 +0200 Subject: [PATCH] Fixes for summing up notes as integer (instead of float). --- config.h | 6 +++--- dexed.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/config.h b/config.h index c5853bf..89548dd 100644 --- a/config.h +++ b/config.h @@ -22,12 +22,12 @@ */ -#define TEST_MIDI 1 +//#define TEST_MIDI 1 #define TEST_NOTE 40 #define TEST_VEL_MIN 60 #define TEST_VEL_MAX 110 -#define SHOW_DEXED_TIMING 1 +//#define SHOW_DEXED_TIMING 1 #define DEBUG 1 #define SERIAL_SPEED 38400 #define VOLUME 0.1 @@ -48,7 +48,7 @@ #define MASTER_BANK_SELECT 83 // B5 #define USE_TEENSY_DSP 1 -//#define SUM_UP_AS_INT 1 +#define SUM_UP_AS_INT 1 // Use these with the Teensy Audio Shield #define SDCARD_CS_PIN 10 diff --git a/dexed.cpp b/dexed.cpp index 6b5f188..7c9cb95 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -135,6 +135,8 @@ void Dexed::getSamples(uint16_t n_samples, int16_t* buffer) audiobuf.get()[j] = 0; #ifndef SUM_UP_AS_INT sumbuf[j] = 0.0; +#else + buffer[i + j] = 0; #endif } @@ -153,7 +155,7 @@ void Dexed::getSamples(uint16_t n_samples, int16_t* buffer) int32_t clip_val = val < -(1 << 24) ? 0x8000 : val >= (1 << 24) ? 0x7fff : val >> 9; #endif #ifdef SUM_UP_AS_INT - int32_t tmp = buffer[i + j] + clip_val; + int32_t tmp = buffer[i + j] + (clip_val >> 1); if (buffer[i + j] > 0 && clip_val > 0) { if ((tmp < buffer[i + j]) && (tmp < clip_val)) @@ -165,8 +167,9 @@ void Dexed::getSamples(uint16_t n_samples, int16_t* buffer) tmp = 0x7FFF; } buffer[i + j] = tmp; + audiobuf.get()[j] = 0; #else - float f = static_cast(clip_val) / 0x8000; + float f = static_cast(clip_val >> 1) / 0x8000; if (f > 1) f = 1; if (f < -1) f = -1; sumbuf[j] += f;