fix QuickLevel artifacting

master
zetaPRIME 2022-03-20 06:29:56 -04:00
parent dd6c9009a7
commit 33916acc65
2 changed files with 12 additions and 20 deletions

2
notes
View File

@ -40,8 +40,6 @@ TODO {
}
}
fix weird blips with QuickLevel
normalize pulse waves from 2x03
revert-to-saved menu action

View File

@ -38,10 +38,7 @@ void QuickLevel::init() {
auto out = addPort(Port::Output, Port::Audio, 0);
out->passthroughTo = in;
lv[0][0] = 0;
lv[0][1] = 0;
lv[1][0] = 0;
lv[1][1] = 0;
lv = { };
}
void QuickLevel::reset() {
@ -54,10 +51,7 @@ void QuickLevel::release() {
buf.clear();
buf.setCapacity(0);
lv[0][0] = 0;
lv[0][1] = 0;
lv[1][0] = 0;
lv[1][1] = 0;
lv = { };
if (obj) QMetaObject::invokeMethod(obj->scene(), "update", Qt::QueuedConnection);
}
@ -68,9 +62,10 @@ void QuickLevel::process() {
in->pull();
size_t ts = audioEngine->curTickSize();
decltype(lv) clv; // compute on local copy to avoid artifacting on draw thread
for (size_t c = 0; c < 2; c++) {
lv[c][0] = std::numeric_limits<double>::max();
lv[c][1] = std::numeric_limits<double>::min();
clv[c][0] = std::numeric_limits<double>::max();
clv[c][1] = std::numeric_limits<double>::min();
}
// push entire tick; we don't need to clear anything as the buffer's maximum size is exactly how much we want
@ -80,12 +75,14 @@ void QuickLevel::process() {
auto fst = buf.firstIndex(), lst = buf.lastIndex();
for (int i = fst; i <= lst; i++) {
auto f = buf.at(i);
lv[0][0] = std::min(lv[0][0], f.l);
lv[0][1] = std::max(lv[0][1], f.l);
lv[1][0] = std::min(lv[1][0], f.r);
lv[1][1] = std::max(lv[1][1], f.r);
clv[0][0] = std::min(clv[0][0], f.l);
clv[0][1] = std::max(clv[0][1], f.l);
clv[1][0] = std::min(clv[1][0], f.r);
clv[1][1] = std::max(clv[1][1], f.r);
}
lv = clv;
if (obj) QMetaObject::invokeMethod(obj, [obj = obj] {
obj->scene()->update(obj->sceneBoundingRect());
}, Qt::QueuedConnection);
@ -93,10 +90,7 @@ void QuickLevel::process() {
// clear levels on port disconnect
void QuickLevel::onPortDisconnected(Data::Port::Type, Data::Port::DataType, uint8_t, std::weak_ptr<Data::Port>) {
lv[0][0] = 0;
lv[0][1] = 0;
lv[1][0] = 0;
lv[1][1] = 0;
lv = { };
if (obj) QMetaObject::invokeMethod(obj->scene(), "update", Qt::QueuedConnection);
}