From 8e838c61e6a0bb131049a7638e49716990c0a4ba Mon Sep 17 00:00:00 2001 From: Blitblank Date: Sat, 18 Apr 2026 12:25:20 -0500 Subject: [PATCH] bugfix: loading more than 4 wavetables --- src/main.cpp | 3 +++ src/synth/ScopeBuffer.cpp | 4 ---- src/synth/WavetableController.cpp | 16 +++++++--------- src/synth/WavetableController.h | 1 + 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7d68bee..ea71058 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,9 @@ int main(int argc, char *argv[]) { MainWindow window; // entry point goes to MainWindow::MainWindow() window.show(); + + // TODO: logging + // i made a good debug filtering setup in ouros so could probably improt that into this project int status = app.exec(); // app execution; blocks until window close diff --git a/src/synth/ScopeBuffer.cpp b/src/synth/ScopeBuffer.cpp index 4c6682e..256bad0 100644 --- a/src/synth/ScopeBuffer.cpp +++ b/src/synth/ScopeBuffer.cpp @@ -11,13 +11,9 @@ void ScopeBuffer::push(float sample) { buffer_[w % buffer_.size()] = sample; } -// TODO: needs a mutex/spinlock to prevent flickering // outputs value from the scope buffer, called by the scope widget void ScopeBuffer::read(std::vector& out) const { - // yeah this didn't work, maybe it needs to be atomic or something - //while(!spinLock_) { int x = 1 + 1; } - size_t w = writeIndex_.load(std::memory_order_relaxed); for (size_t i = 0; i < out.size(); i++) { size_t idx = (w + trigger_ + i * wavelength_ / out.size()) % buffer_.size(); diff --git a/src/synth/WavetableController.cpp b/src/synth/WavetableController.cpp index 196eabf..2438bc6 100644 --- a/src/synth/WavetableController.cpp +++ b/src/synth/WavetableController.cpp @@ -6,12 +6,10 @@ #include WavetableController::WavetableController() { - // load from files - + + // load from files init(); - //std::cout << "wavetable init" << std::endl; - } void WavetableController::init() { @@ -23,11 +21,11 @@ void WavetableController::init() { wavetableFiles.push_back(entry.path()); } } - uint32_t wavetableCount = wavetableFiles.size(); - wavetables_.resize(wavetableCount); + wavetableCount_ = wavetableFiles.size(); + wavetables_.resize(wavetableCount_); // load the wavetable files - for(int i = 0; i < wavetableCount; i++) { + for(int i = 0; i < wavetableCount_; i++) { std::cout << "loading wavetable file [" << i << "]: " << wavetableFiles[i] << std::endl; std::ifstream inputFile(wavetableFiles[i], std::ios::in | std::ios::binary); if(!inputFile) std::cout << "error opening file" << std::endl; @@ -56,8 +54,8 @@ float WavetableController::sample(uint8_t wavetableIndex, float phase) { uint32_t index = static_cast(round(scaledPhase)); if(index >= SYNTH_WAVETABLE_SIZE) index = SYNTH_WAVETABLE_SIZE - 1; - if(wavetableIndex >= 4) { - wavetableIndex = 3; + if(wavetableIndex >= wavetableCount_) { + wavetableIndex = wavetableCount_ - 1; } else if(wavetableIndex < 0) { wavetableIndex = 0; } diff --git a/src/synth/WavetableController.h b/src/synth/WavetableController.h index 49207fc..1618425 100644 --- a/src/synth/WavetableController.h +++ b/src/synth/WavetableController.h @@ -30,6 +30,7 @@ public: private: std::vector wavetables_; + uint32_t wavetableCount_; const std::filesystem::path wavetablesRoot_ = "./config/wavetables";