mirror of
https://github.com/got-feedBack/feedBack-desktop.git
synced 2026-09-11 00:54:10 +00:00
* fix(audio): prefer same-backend duplex routing * fix(audio): centre mono input; limit duplex to same-endpoint devices Two issues found while testing the USB-guitar-cable path on Windows: 1. Centre a mono input. SourceChain::processBlock fell into the pass-through branch for a 1-channel input, filling only min(inputChannels, outputChannels) = 1 output channel and zeroing the rest, so a mono USB guitar cable played out of the left speaker only. A single-channel input is now broadcast across every output channel. 2. Only attempt the combined (duplex) device when input and output are the SAME physical endpoint. Two different endpoints of the same backend (USB cable in + separate speakers out) are independent hardware clocks; routing them through one duplex device was unstable across the app lifecycle (no audio until an explicit Apply, then distortion / dropouts / silent-in-song on navigation). Different endpoints now use the split path, whose ring bridges the two clocks. Same-endpoint duplex (one interface for in and out) keeps the low-latency win. Low latency for the two-device case is a follow-up that needs the device-lifecycle work (startup restore + reconfigure on navigation). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JEoFeTPSnz4NpwwCG52hnu * fix(audio): probe same-endpoint duplex the same way apply routes it Startup auto-apply (renderer init) fail-closes on probeDeviceOptionsDual's `compatible` verdict, but the probe still measured a COMBINED duplex device for any same-backend pair while setAudioDevices now opens split for different endpoints. That mismatch made the startup probe describe a config that isn't the one applied — surfacing as "no audio until I press Apply" for a USB cable + separate speakers. Gate the probe's duplex path on the same sameEndpointIntent (same type AND same device) the apply path uses, so a two-device pair is probed via the split path it will actually run on. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JEoFeTPSnz4NpwwCG52hnu * fix(audio): never feed chain processors blocks larger than prepared size WASAPI shared mode can deliver oversized blocks right after a device start. The NAM core pre-allocates its conv ring/output buffers to the Reset() maxBufferSize and only asserts (release no-op) on larger blocks; one oversized block corrupts the conv ring state and garbles all subsequent audio until the next Reset() — the 'first start heavily distorted until tone reset / engine restart' bug. - NAMProcessor::processBlock: process in slices of at most the prepared block size. - SignalChain::process: slice oversized device blocks into prepared-size chunks before any slot (VST/NAM/IR) sees them. See docs/audio-distortion-first-start-investigation.md. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(audio): close stale-format race when processors are added mid-reconfigure addProcessor/replaceProcessor prepare the incoming processor off the audio lock on N-API worker threads. A concurrent device reconfigure's SignalChain::prepare() can't see that processor (not slotted yet), so a slot could go live prepared at a stale sample rate / block size and stay wrong until the next device restart — heard as pitch-shifted/garbled monitoring when a chain loads while the device is being (re)opened (widest window: WASAPI exclusive mode's slower open). Re-check the chain's current format under the lock at insert/swap time and re-prepare if it moved; log the transition to stderr so tester logs show when the race fired. prepare() now publishes the format under the lock so the check can't tear. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(effects): align executor plan schema with rebranded capability layer The rebrand left a three-way schema split: rig_builder sent the old 'slopsmith.audio_effects.chain_plan.v1', the renderer capability layer validated against the new 'feedBack.…' id (rejecting every plan), and this executor still expected the old one. Result: every song chain load fell back to legacy clearChain+loadPreset — a full multi-VST rebuild per currentSong poll cycle, heard as continuous distortion during playback (tester logs: 4-6 rebuilds/session, slot IDs into the 90s). Executor now uses the rebranded id and accepts the legacy one as an alias (matching the capability layer's new alias), so neither side of the handoff can break on old plugin bundles. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(audio): guard input callback against double registration Tester main-process log showed two consecutive 'startAudio: duplex=0' lines: a transient audioDeviceStopped() (WASAPI exclusive opens fire one mid-start) cleared audioRunning while the input callback stayed attached, so the second startAudio() re-added it. JUCE then dispatched the input callback twice per block: DSP ran twice and each block was pushed into the split ring twice — every sample played twice (half speed, one octave down, garbled). stopAudio()'s single removeAudioCallback left the duplicate registration alive, wedging the engine (restart no longer helped) and keeping the exclusive-mode device open even after app close. Mirror the existing outputCallbackRegistered guard for the input side. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore(audio): diagnostic instrumentation for tester repro builds Main-process stderr logging on every open lead, RT paths rate-limited (first-25 per anomaly + ~5s heartbeats per callback clock): - primary callback re-entrancy (duplicate registration detector) - oversized blocks on primary/output callbacks, SignalChain slicing, NAM chunking (pre-fix corruption trigger visibility) - ring fill + under/overflow counters (split-mode pacing) - device lifecycle: aboutToStart/stopped on both managers with sr/bs and callback-registration flags; startAudio guard-skip; stopAudio state - SourceChain.prepare format trace (stale-rate lead) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore(audio): drop diagnostic heartbeats, keep anomaly detectors The 5s ring/format heartbeats served the distortion hunt and are noise now. Keep the cheap anomaly-only diagnostics (callback re-entrancy, oversized-block detectors, chain slicing/chunking, stale-format re-prepare, device lifecycle) — they log only on misbehavior and stay relevant for the exclusive-mode playback work. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs: keep investigation notes out of the PR (local working notes) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore(audio): gate lifecycle [diag] logs behind SLOPSMITH_SANDBOX_DEBUG Review follow-up (#86): the six lifecycle diagnostics (stopAudio, audioDeviceAboutToStart/Stopped, audioOutputAboutToStart/Stopped, SourceChain::prepare) printed unconditionally while the PR body claimed they were verbose-gated. Gate them behind the existing slopsmith_vst_trace::isEnabled() runtime flag (SLOPSMITH_SANDBOX_DEBUG — already flipped by the app's debug-logging switch, so tester debug runs still capture them). The RT-path anomaly detectors (primary re-entry, oversized-block) keep their firstN/anomaly bounds unchanged, as reviewed. VSTTrace.h now defines NOMINMAX/WIN32_LEAN_AND_MEAN before windows.h so including it from engine TUs doesn't clobber std::min. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: ChrisBeWithYou <chris@rifflarr.local> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
174 lines
6.4 KiB
C++
174 lines
6.4 KiB
C++
// Diagnostic logger for VST3 host ↔ plugin handshake.
|
|
//
|
|
// Defined in a header so it's reachable from both the addon
|
|
// (NodeAddon.cpp, VSTHost.cpp) and the vendored JUCE VST3 host context
|
|
// (juce_VST3PluginFormatImpl.h). Writes every call to a file + stderr
|
|
// with immediate flush so a process abort (e.g. `__fastfail` from a
|
|
// crashy plugin) doesn't lose the last few lines.
|
|
//
|
|
// Compiled into all builds, but no-op at runtime unless
|
|
// SLOPSMITH_SANDBOX_DEBUG is set to any non-empty value other than "0"
|
|
// when the addon loads. The first call caches the env var, so flipping
|
|
// it mid-process has no effect.
|
|
|
|
#pragma once
|
|
|
|
#include <cstdio>
|
|
#include <cstdarg>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <ctime>
|
|
#include <mutex>
|
|
|
|
#if defined(_WIN32)
|
|
// Keep windows.h from defining min/max macros that clobber std::min /
|
|
// std::max in any TU that includes this header (NOMINMAX only helps if
|
|
// nothing else included windows.h first — WIN32_LEAN_AND_MEAN keeps the
|
|
// surface small either way).
|
|
#ifndef NOMINMAX
|
|
#define NOMINMAX
|
|
#endif
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#endif
|
|
#include <windows.h>
|
|
#else
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
namespace slopsmith_vst_trace {
|
|
|
|
// Gate on SLOPSMITH_SANDBOX_DEBUG=1 so release builds don't litter %TEMP%
|
|
// with the trace file or burn stderr cycles on every host callback.
|
|
inline bool isEnabled()
|
|
{
|
|
static const bool v = [] {
|
|
const char* s = std::getenv("SLOPSMITH_SANDBOX_DEBUG");
|
|
return s && *s && std::strcmp(s, "0") != 0;
|
|
}();
|
|
return v;
|
|
}
|
|
|
|
inline std::FILE* logFile()
|
|
{
|
|
static std::FILE* f = []() -> std::FILE* {
|
|
if (!isEnabled()) return nullptr;
|
|
char path[1024] = {0};
|
|
#if defined(_WIN32)
|
|
// Prefer %TEMP%; fall back to %USERPROFILE% (per-PID log path in
|
|
// src/vst-host/main.cpp does the same — non-elevated users can't
|
|
// write to C:\ root, and "trace gated on env var but silently
|
|
// creates no file" is the worst-of-both-worlds failure mode).
|
|
DWORD n = GetEnvironmentVariableA("TEMP", path, sizeof(path));
|
|
if (n == 0 || n >= sizeof(path)) {
|
|
n = GetEnvironmentVariableA("USERPROFILE", path, sizeof(path));
|
|
}
|
|
if (n > 0 && n < sizeof(path)) {
|
|
// Per-PID suffix: this header is compiled into both the addon
|
|
// and the sandbox host, so concurrent runs would otherwise
|
|
// interleave traces in one file and make sandbox debugging
|
|
// (host A spawning host B) hard to correlate. Mirrors the
|
|
// per-PID naming the sandbox-host log already uses.
|
|
char suffix[64]{};
|
|
const int suffixLen = std::snprintf(
|
|
suffix, sizeof(suffix), "\\slopsmith-vst-trace-%lu.log",
|
|
(unsigned long)GetCurrentProcessId());
|
|
if (suffixLen > 0
|
|
&& (size_t)n + (size_t)suffixLen < sizeof(path))
|
|
{
|
|
std::strncat(path, suffix, sizeof(path) - n - 1);
|
|
}
|
|
}
|
|
// If both env vars failed, leave `path` empty — writing to the
|
|
// drive root requires admin on a default Windows install and the
|
|
// sandbox host's per-PID log made the same decision. fopen(nullptr-
|
|
// equivalent path) returns NULL, which the rest of the code handles
|
|
// cleanly.
|
|
#else
|
|
// Per-PID suffix mirrors the Windows branch: same rationale (header
|
|
// compiled into addon + sandbox host → concurrent runs interleave
|
|
// the same file) plus /tmp is world-writable on POSIX, which makes
|
|
// a stable filename a symlink-attack / log-poisoning vector. The
|
|
// per-PID name closes both.
|
|
std::snprintf(path, sizeof(path), "/tmp/slopsmith-vst-trace-%ld.log",
|
|
(long)getpid());
|
|
#endif
|
|
// Truncate ("w") rather than append ("a"): per-PID naming guarantees
|
|
// single-writer-per-file, but Windows reuses PIDs across reboots
|
|
// (and Linux can too under PID-namespace cycling), so an old trace
|
|
// from a previous run on the same PID would otherwise accumulate
|
|
// confusing context. Matches the sandbox-host log policy in
|
|
// src/vst-host/main.cpp.
|
|
std::FILE* fp = path[0] ? std::fopen(path, "w") : nullptr;
|
|
if (fp) {
|
|
std::fprintf(fp, "\n========== slopsmith-vst-trace opened (pid=%lu) ==========\n",
|
|
(unsigned long)
|
|
#if defined(_WIN32)
|
|
GetCurrentProcessId()
|
|
#else
|
|
(unsigned long) getpid()
|
|
#endif
|
|
);
|
|
std::fflush(fp);
|
|
}
|
|
return fp;
|
|
}();
|
|
return f;
|
|
}
|
|
|
|
inline std::mutex& logMutex()
|
|
{
|
|
static std::mutex m;
|
|
return m;
|
|
}
|
|
|
|
inline void writef(const char* fmt, ...)
|
|
{
|
|
if (!isEnabled()) return;
|
|
std::lock_guard<std::mutex> lock(logMutex());
|
|
|
|
char buf[2048];
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
std::vsnprintf(buf, sizeof(buf), fmt, ap);
|
|
va_end(ap);
|
|
|
|
auto* fp = logFile();
|
|
if (fp) {
|
|
std::fputs(buf, fp);
|
|
std::fputc('\n', fp);
|
|
std::fflush(fp);
|
|
}
|
|
std::fputs("[vst-trace] ", stderr);
|
|
std::fputs(buf, stderr);
|
|
std::fputc('\n', stderr);
|
|
std::fflush(stderr);
|
|
}
|
|
|
|
// Format 16 hex bytes of a TUID. The Steinberg TUID type is `char[16]`.
|
|
// Rotates through a 4-slot ring of thread-local buffers so multiple tuidHex
|
|
// arguments in a single VST_TRACE call don't clobber each other before the
|
|
// formatter consumes them.
|
|
inline const char* tuidHex(const void* tuid)
|
|
{
|
|
static thread_local char ring[4][40];
|
|
static thread_local unsigned idx = 0;
|
|
char* out = ring[idx++ & 3u];
|
|
const unsigned char* b = static_cast<const unsigned char*>(tuid);
|
|
std::snprintf(out, sizeof(ring[0]),
|
|
"%02x%02x%02x%02x-%02x%02x%02x%02x-%02x%02x%02x%02x-%02x%02x%02x%02x",
|
|
b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
|
|
b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15]);
|
|
return out;
|
|
}
|
|
|
|
} // namespace slopsmith_vst_trace
|
|
|
|
// Check the enabled flag at the call site so disabled builds don't pay for
|
|
// formatting arg evaluation (e.g. `tuidHex(...)`, `cmd.toRawUTF8()`).
|
|
#define VST_TRACE(...) \
|
|
do { \
|
|
if (::slopsmith_vst_trace::isEnabled()) \
|
|
::slopsmith_vst_trace::writef(__VA_ARGS__); \
|
|
} while (0)
|