@mmprod said in How to draw super smooth Waveform?:
Any ideas?
I introduced a simplifyBuffer function that removes redundant points from the buffer based on a SIMPLIFICATION_TOLERANCE
value.
const var dp_analyser = Synth.getDisplayBufferSource("HardcodedMasterFX1"); // or what you neeed
const var rb_analyser = dp_analyser.getDisplayBuffer(0);
const var BUFFER_LENGTH = 512;
const var properties = {
"BufferLength": BUFFER_LENGTH,
"NumChannels": 1
};
rb_analyser.setRingBufferProperties(properties);
const var P1 = Content.getComponent("P1");
const var NUM_WAVEFORMS = 6;
const var waveformBuffers = [];
const var SAMPLE_REDUCTION = 4; // Only process every 4th sample
var time = 0;
for (var i = 0; i < NUM_WAVEFORMS; i++) {
waveformBuffers[i] = rb_analyser.createPath(
P1.getLocalBounds(0),
[0, Math.floor(BUFFER_LENGTH/SAMPLE_REDUCTION), -8.0, 8.0],
0.0
);
}
var bufferIndex = 0;
var offset = 0;
P1.setTimerCallback(function() {
var newPath = rb_analyser.createPath(
this.getLocalBounds(0),
[Math.floor(offset/SAMPLE_REDUCTION),
Math.floor((BUFFER_LENGTH + offset)/SAMPLE_REDUCTION),
-12.0, 12.0],
time * (bufferIndex + 1) * 0.2
);
waveformBuffers[bufferIndex] = newPath;
bufferIndex = (bufferIndex + 1) % NUM_WAVEFORMS;
offset = (offset + 256) % BUFFER_LENGTH;
time += 0.1;
this.repaint();
});
P1.setPaintRoutine(function(g) {
var a = this.getLocalBounds(0);
g.setColour(0xFFB8C043);
for (var i = 0; i < waveformBuffers.length; i++) {
g.drawPath(waveformBuffers[i], a, 1);
}
});
P1.startTimer(20);
Fix this value according your "downsampling":
const var SAMPLE_REDUCTION = 4; // !!!!!!!! Only process every 4th sample
We need to optimize the scope design; this version could be a starting point. You can adjust the SIMPLIFICATION_TOLERANCE
value to control how much the buffer data is simplified, "skipping" redundant points.
That said, I realize this discussion might be going off-topic and potentially not fair to other users. Let me know if it would be better to start a dedicated thread for this topic.