G4.3 idle-skip + no fixed-tick render: idle CPU ~0, latency 9.8ms
This commit is contained in:
@@ -98,6 +98,8 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
}).detach();
|
||||
|
||||
int activeNotes = 0;
|
||||
bool idle = false;
|
||||
for (;;) {
|
||||
MSG msg;
|
||||
while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) {
|
||||
@@ -105,14 +107,15 @@ int main(int argc, char* argv[]) {
|
||||
DispatchMessageW(&msg);
|
||||
}
|
||||
uint32_t n = ipc->base.midiQueueCount > 64 ? 64 : ipc->base.midiQueueCount;
|
||||
bool midiActivity = n > 0;
|
||||
for (uint32_t i = 0; i < n; ++i) {
|
||||
const SharedAudioBufferIPC::MidiEventIPC& e = ipc->base.midiQueue[i];
|
||||
switch (e.command) {
|
||||
case 0x9:
|
||||
if (e.velocity > 0) inst.noteOn(e.channel, e.pitch, e.velocity / 127.0f, 0);
|
||||
else inst.noteOff(e.channel, e.pitch, 0);
|
||||
if (e.velocity > 0) { inst.noteOn(e.channel, e.pitch, e.velocity / 127.0f, 0); ++activeNotes; }
|
||||
else { inst.noteOff(e.channel, e.pitch, 0); if (activeNotes > 0) --activeNotes; }
|
||||
break;
|
||||
case 0x8: inst.noteOff(e.channel, e.pitch, 0); break;
|
||||
case 0x8: inst.noteOff(e.channel, e.pitch, 0); if (activeNotes > 0) --activeNotes; break;
|
||||
case 0xB: inst.controlChange(e.channel, e.pitch, e.data2); break;
|
||||
case 0xC: inst.programChange(e.channel, e.data2); break;
|
||||
case 0xE: inst.pitchBend(e.channel, e.data2 | (uint32_t(e.data3) << 7)); break;
|
||||
@@ -120,6 +123,15 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
}
|
||||
ipc->base.midiQueueCount = 0;
|
||||
if (midiActivity) idle = false;
|
||||
if (parentPid && !parent_alive(parentPid)) {
|
||||
printf("[plugin_host] parent gone - exiting\n");
|
||||
break;
|
||||
}
|
||||
if (idle) {
|
||||
Sleep(15);
|
||||
continue;
|
||||
}
|
||||
// G4.3 double buffer: render into the slot we are NOT publishing, then
|
||||
// publish. The bridge keeps the last published block, so a slow child
|
||||
// never tears audio (it just repeats the previous block).
|
||||
@@ -127,11 +139,19 @@ int main(int argc, char* argv[]) {
|
||||
inst.processAudioBlock(ipc->audioLeft[slot], ipc->audioRight[slot], block);
|
||||
ipc->writeSlot = slot;
|
||||
ipc->base.bridgeWriteIndex++;
|
||||
if (parentPid && !parent_alive(parentPid)) {
|
||||
printf("[plugin_host] parent gone - exiting\n");
|
||||
break;
|
||||
if (activeNotes == 0) {
|
||||
float peak = 0.0f;
|
||||
for (uint32_t i = 0; i < block; ++i) {
|
||||
float l = ipc->audioLeft[slot][i];
|
||||
if (l < 0.0f) l = -l;
|
||||
float r = ipc->audioRight[slot][i];
|
||||
if (r < 0.0f) r = -r;
|
||||
if (l > peak) peak = l;
|
||||
if (r > peak) peak = r;
|
||||
}
|
||||
if (peak < 0.0005f) idle = true;
|
||||
}
|
||||
Sleep(1);
|
||||
Sleep(0);
|
||||
}
|
||||
inst.closeGUI();
|
||||
#ifdef _WIN32
|
||||
|
||||
Reference in New Issue
Block a user