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

@@ -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

View File

@@ -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<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);
for (size_t i = 0; i < out.size(); i++) {
size_t idx = (w + trigger_ + i * wavelength_ / out.size()) % buffer_.size();

View File

@@ -6,12 +6,10 @@
#include <fstream>
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<uint32_t>(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;
}

View File

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