bugfix: loading more than 4 wavetables

This commit is contained in:
2026-04-18 12:25:20 -05:00
parent 5c9a37b8d4
commit 8e838c61e6
4 changed files with 11 additions and 13 deletions

View File

@@ -15,6 +15,9 @@ int main(int argc, char *argv[]) {
MainWindow window; // entry point goes to MainWindow::MainWindow() MainWindow window; // entry point goes to MainWindow::MainWindow()
window.show(); 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 int status = app.exec(); // app execution; blocks until window close
return status; return status;

View File

@@ -11,13 +11,9 @@ void ScopeBuffer::push(float sample) {
buffer_[w % buffer_.size()] = 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 // outputs value from the scope buffer, called by the scope widget
void ScopeBuffer::read(std::vector<float>& out) const { void ScopeBuffer::read(std::vector<float>& 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); size_t w = writeIndex_.load(std::memory_order_relaxed);
for (size_t i = 0; i < out.size(); i++) { for (size_t i = 0; i < out.size(); i++) {
size_t idx = (w + trigger_ + i * wavelength_ / out.size()) % buffer_.size(); size_t idx = (w + trigger_ + i * wavelength_ / out.size()) % buffer_.size();

View File

@@ -6,12 +6,10 @@
#include <fstream> #include <fstream>
WavetableController::WavetableController() { WavetableController::WavetableController() {
// load from files // load from files
init(); init();
//std::cout << "wavetable init" << std::endl;
} }
void WavetableController::init() { void WavetableController::init() {
@@ -23,11 +21,11 @@ void WavetableController::init() {
wavetableFiles.push_back(entry.path()); wavetableFiles.push_back(entry.path());
} }
} }
uint32_t wavetableCount = wavetableFiles.size(); wavetableCount_ = wavetableFiles.size();
wavetables_.resize(wavetableCount); wavetables_.resize(wavetableCount_);
// load the wavetable files // 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::cout << "loading wavetable file [" << i << "]: " << wavetableFiles[i] << std::endl;
std::ifstream inputFile(wavetableFiles[i], std::ios::in | std::ios::binary); std::ifstream inputFile(wavetableFiles[i], std::ios::in | std::ios::binary);
if(!inputFile) std::cout << "error opening file" << std::endl; 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<uint32_t>(round(scaledPhase)); uint32_t index = static_cast<uint32_t>(round(scaledPhase));
if(index >= SYNTH_WAVETABLE_SIZE) index = SYNTH_WAVETABLE_SIZE - 1; if(index >= SYNTH_WAVETABLE_SIZE) index = SYNTH_WAVETABLE_SIZE - 1;
if(wavetableIndex >= 4) { if(wavetableIndex >= wavetableCount_) {
wavetableIndex = 3; wavetableIndex = wavetableCount_ - 1;
} else if(wavetableIndex < 0) { } else if(wavetableIndex < 0) {
wavetableIndex = 0; wavetableIndex = 0;
} }

View File

@@ -30,6 +30,7 @@ public:
private: private:
std::vector<Wavetable> wavetables_; std::vector<Wavetable> wavetables_;
uint32_t wavetableCount_;
const std::filesystem::path wavetablesRoot_ = "./config/wavetables"; const std::filesystem::path wavetablesRoot_ = "./config/wavetables";