added a spinlock on the scope
This commit is contained in:
@@ -14,6 +14,9 @@ void ScopeBuffer::push(float sample) {
|
||||
// TODO: needs a mutex to prevent flickering
|
||||
// outputs value from the scope buffer, called by the scope widget
|
||||
void ScopeBuffer::read(std::vector<float>& out) const {
|
||||
|
||||
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();
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
void setWavelength(int32_t wavelength) { wavelength_ = wavelength; }
|
||||
int32_t trigger() { return trigger_; }
|
||||
int32_t wavelength() { return wavelength_; }
|
||||
void spinlock(bool lock) { spinLock_ = lock; };
|
||||
|
||||
// NOTE: there are limits to the wavelengths that the scope can show cleanly due to the size of the audio buffer
|
||||
// at a buffer size of 256 at 44100hz the min visible steady frequency is ~172hz
|
||||
@@ -33,4 +34,6 @@ private:
|
||||
int32_t trigger_ = 0; // units in array indices
|
||||
int32_t wavelength_ = 400;
|
||||
|
||||
bool spinLock_ = false;
|
||||
|
||||
};
|
||||
|
||||
@@ -92,6 +92,9 @@ void Synth::process(float* out, uint32_t nFrames, uint32_t sampleRate) {
|
||||
}
|
||||
}
|
||||
|
||||
// lock the scope from the buffer
|
||||
scope_->spinlock(true);
|
||||
|
||||
for (uint32_t i = 0; i < nFrames; i++) {
|
||||
|
||||
// updates internal buffered parameters for smoothing
|
||||
@@ -133,4 +136,7 @@ void Synth::process(float* out, uint32_t nFrames, uint32_t sampleRate) {
|
||||
}
|
||||
}
|
||||
|
||||
// unlock the scope from the buffer
|
||||
scope_->spinlock(false);
|
||||
|
||||
}
|
||||
@@ -63,6 +63,7 @@ private:
|
||||
// filters
|
||||
Filter filter1_;
|
||||
Filter filter2_;
|
||||
// TODO: I think the filter's state being uninitialized is what's causing popping when a voice starts for the first time
|
||||
|
||||
// paramstore pointer
|
||||
SmoothedParam* params_;
|
||||
|
||||
@@ -24,7 +24,7 @@ void Scope::setScopeBuffer(ScopeBuffer* buffer) {
|
||||
}
|
||||
|
||||
void Scope::paintEvent(QPaintEvent*) {
|
||||
if (!buffer_) return;
|
||||
if(!buffer_) return;
|
||||
|
||||
int32_t wavelength = buffer_->wavelength();
|
||||
int32_t trigger = buffer_->trigger();
|
||||
|
||||
@@ -32,4 +32,5 @@ private:
|
||||
ScopeBuffer* buffer_ = nullptr;
|
||||
std::vector<float> samples_;
|
||||
QTimer timer_;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user