From 816c38209cc576f0a1b5c0e32d99c10983b9297a Mon Sep 17 00:00:00 2001 From: Jorj Bauer Date: Sun, 12 Jul 2020 11:08:46 -0400 Subject: [PATCH] debugging --- teensy/teensy-speaker.cpp | 4 ++-- teensy/teensy-speaker.h | 2 +- teensy/teensy.ino | 32 ++++++++++++++++---------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/teensy/teensy-speaker.cpp b/teensy/teensy-speaker.cpp index 940ea7c..2a12593 100644 --- a/teensy/teensy-speaker.cpp +++ b/teensy/teensy-speaker.cpp @@ -83,8 +83,8 @@ void TeensySpeaker::maintainSpeaker() togmutex.unlock(); // Now we can safely update the DAC based on the current toggleState - uint16_t v = (toggleState ? 0xFFF : 0x000); - dac.write((uint8_t) ((v >> 8) & 0xFF), (uint8_t) (v & 0xFF), true); + // uint16_t v = (toggleState ? 0xFFF : 0x000); + // dac.write((uint8_t) ((v >> 8) & 0xFF), (uint8_t) (v & 0xFF), true); } diff --git a/teensy/teensy-speaker.h b/teensy/teensy-speaker.h index f1a16c3..58b83e3 100644 --- a/teensy/teensy-speaker.h +++ b/teensy/teensy-speaker.h @@ -4,7 +4,7 @@ #include "physicalspeaker.h" #include -#define SAMPLERATE 4000 +#define SAMPLERATE 8000 class TeensySpeaker : public PhysicalSpeaker { public: diff --git a/teensy/teensy.ino b/teensy/teensy.ino index c87ac25..12e4e67 100644 --- a/teensy/teensy.ino +++ b/teensy/teensy.ino @@ -164,6 +164,7 @@ void setup() Serial.flush(); threads.setMicroTimer(); // use a 100uS timer instead of a 1mS timer + // threads.setSliceMicros(5); threads.addThread(runDebouncer); } @@ -225,32 +226,31 @@ void biosInterrupt() g_keyboard->maintainKeyboard(); } +uint32_t spk_nextResetMillis = 0; +uint32_t spk_refreshCount = 0; +uint32_t spk_microsAtStart = micros(); +uint32_t spk_microsForNext = 0; void runSpeaker() { - static uint32_t nextResetMillis = 0; - static uint32_t refreshCount = 0; - static uint32_t microsAtStart = micros(); - static uint32_t microsForNext = 0; - if (1) { - if (micros() >= microsForNext) { - refreshCount++; - microsForNext = microsAtStart + ((1000000*refreshCount)/SAMPLERATE); - // ((TeensySpeaker *)g_speaker)->maintainSpeaker(); + if (micros() >= spk_microsForNext) { + spk_refreshCount++; + spk_microsForNext = spk_microsAtStart + ((1000000*spk_refreshCount)/SAMPLERATE); + ((TeensySpeaker *)g_speaker)->maintainSpeaker(); } - if (millis() >= nextResetMillis) { - nextResetMillis = millis() + 1000; + if (millis() >= spk_nextResetMillis) { + spk_nextResetMillis = millis() + 1000; #ifdef DEBUG_TIMING static char buf[25]; - float pct = (100.0 * (float)refreshCount) / (float)SAMPLERATE; - sprintf(buf, "Speaker running at %f%% [%lu]", pct, refreshCount); + float pct = (100.0 * (float)spk_refreshCount) / (float)SAMPLERATE; + sprintf(buf, "Speaker running at %f%% [%lu]", pct, spk_refreshCount); println(buf); #endif - refreshCount = 0; - microsAtStart = micros(); - microsForNext = microsAtStart + ((1000000*refreshCount)/SAMPLERATE); + spk_refreshCount = 0; + spk_microsAtStart = micros(); + spk_microsForNext = spk_microsAtStart + ((1000000*spk_refreshCount)/SAMPLERATE); } }