added a spinlock on the scope
This commit is contained in:
@@ -17,7 +17,7 @@ This synthesizer isn't very good, but it's neat :3
|
||||
responds to note-on/note-off events
|
||||
- [x] Make midi/keyboard control cross-platform. Use case will mostly be
|
||||
Midi -> linux and Keyboard -> windows though
|
||||
- [ ] Create oscillator class where the actual tone generation occurs. Multiple
|
||||
- [x] Create oscillator class where the actual tone generation occurs. Multiple
|
||||
oscillators increase the sound complexity considerably
|
||||
- [x] Create a UI scope to visualize the synthesized composite waveform
|
||||
- [ ] Create wavetables for more complex tone generation. Needs to be selectable from ui
|
||||
@@ -60,7 +60,7 @@ Build. The script will build and install dependencies automatically
|
||||
|
||||
On Windows (MSVC):
|
||||
```PowerShell
|
||||
.\scripts\build.ps1
|
||||
.\scripts\build.ps1 # builds in build/Debug/
|
||||
```
|
||||
|
||||
On Linux (GCC):
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -32,4 +32,5 @@ private:
|
||||
ScopeBuffer* buffer_ = nullptr;
|
||||
std::vector<float> samples_;
|
||||
QTimer timer_;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user