diff --git a/core/bank.h b/core/bank.h index d7f76b5..4014dd9 100644 --- a/core/bank.h +++ b/core/bank.h @@ -80,7 +80,8 @@ struct Bank { } // Highest index that is playable right now. Returns -1 when nothing is ready yet, which the - // audio thread answers with ramped silence rather than with dry signal. + // audio thread answers with ramped silence rather than with dry signal — unless the bank is + // empty (count 0), where nothing will ever be ready and the input passes through dry. int highestReady() const { int highest = -1; diff --git a/core/crossfadeengine.cpp b/core/crossfadeengine.cpp index 1e0fe0d..7fbb184 100644 --- a/core/crossfadeengine.cpp +++ b/core/crossfadeengine.cpp @@ -310,11 +310,19 @@ void CrossfadeEngine::processNative(NAM_SAMPLE **in, NAM_SAMPLE **out, int numFr const int highest = mBank ? mBank->highestReady() : -1; mHaveReady = highest >= 0; if (!mHaveReady) { - // Ramp to silence, never to dry signal: dry would be the wrong level and would jump the - // moment a model landed. + // Two different states arrive here. With no capture assigned at all — no bank, or the + // empty bank a Clear publishes — nothing is ever going to land, so the input passes + // through dry, as the parent plug-in does with no model loaded. That is what lets an + // instance be used for its cabinet alone. With a capture assigned but not yet built, + // ramp to silence instead: dry would be the wrong level and would jump the moment the + // model landed. Either way the dry gate is ramped, so neither change clicks. + const bool assigned = mBank && mBank->count > 0; + const double dryTarget = assigned ? 0.0 : 1.0; for (int i = 0; i < numFrames; ++i) { mReadyMix = std::max(0.0, mReadyMix - mReadyStep); - dst[i] = src[i] * mReadyMix; + mDryMix = dryTarget > mDryMix ? std::min(dryTarget, mDryMix + mReadyStep) + : std::max(dryTarget, mDryMix - mReadyStep); + dst[i] = src[i] * mDryMix; } return; } @@ -532,6 +540,17 @@ void CrossfadeEngine::processNative(NAM_SAMPLE **in, NAM_SAMPLE **out, int numFr chunkOut[i] *= mReadyMix; } + // A capture landed while dry signal was still sounding — a bank whose first entry was + // already built by the time it was polled. Fade the dry signal out underneath the ready + // gate rather than cutting it. chunkIn is still intact here: the engine is never handed + // the same buffer for input and output. Zero in steady state, so this costs nothing then. + if (mDryMix > 0.0) { + for (int i = 0; i < n; ++i) { + mDryMix = std::max(0.0, mDryMix - mReadyStep); + chunkOut[i] += chunkIn[i] * mDryMix; + } + } + // --- advance the position ------------------------------------------------------------- pos = mPos; if (std::fabs(delta) <= step * n) { diff --git a/core/crossfadeengine.h b/core/crossfadeengine.h index 4f67aa1..e4dc4cc 100644 --- a/core/crossfadeengine.h +++ b/core/crossfadeengine.h @@ -83,19 +83,22 @@ class CrossfadeEngine : public NativeBlockProcessor } // Normalized index of the capture that is actually sounding — the nearer branch, not the knob. double activeIndexNorm() const; - // True once at least one entry is playable. Until then the engine outputs ramped silence, not - // dry signal: passing the input through and then dropping a model on top of it would jump in - // level the instant the first entry landed. + // True once at least one entry is playable. Until then an engine with a capture assigned + // outputs ramped silence, not dry signal: passing the input through and then dropping a model + // on top of it would jump in level the instant the first entry landed. An engine with NO + // capture assigned passes its input through dry instead, as the parent plug-in does with no + // model loaded; that is not "playable" in this sense, because no model is running. bool playable() const { return mReadyMix > 0.0 || mHaveReady; } - // True once this engine has actually put a sample into the output. Distinct from playable(): - // the rack uses it to tell "nothing is being heard yet" from "something is", because adopting - // a channel outright is only free while nothing is audible. + // True once this engine has actually put a sample into the output: a model's, or the dry + // pass-through of an engine with nothing assigned. Distinct from playable(): the rack uses it + // to tell "nothing is being heard yet" from "something is", because adopting a channel + // outright is only free while nothing is audible, and dry signal is audible. bool sounding() const { - return mReadyMix > 0.0; + return mReadyMix > 0.0 || mDryMix > 0.0; } // True when the ready gate is fully open, so this engine's output is its models' output and // not a ramp of it. The channel fade must not start before this: a fade into a signal that is @@ -188,7 +191,10 @@ class CrossfadeEngine : public NativeBlockProcessor double mSlewStep = 0.0; // position units per sample while following the knob double mReadyMix = 0.0; // ramped 0 .. 1 gate over "a playable entry exists" - double mReadyStep = 1.0; + // Ramped 0 .. 1 gate over "no capture is assigned, so pass the input through". Starts closed, + // so a restored project that is still building never lets a dry blip through first. + double mDryMix = 0.0; + double mReadyStep = 1.0; // shared by both gates bool mHaveReady = false; int mOutputMode = 0; diff --git a/core/tools/rations_ircheck.cpp b/core/tools/rations_ircheck.cpp index 2ad0734..e243c02 100644 --- a/core/tools/rations_ircheck.cpp +++ b/core/tools/rations_ircheck.cpp @@ -352,8 +352,8 @@ int main(int argc, char **argv) } // The cabinet stage is what this tool measures, but it measures it through the whole chain, so - // the channels still have to be sounding something: with no captures loaded the rack outputs - // ramped silence and every blend measurement would be taken on nothing. + // the channels still have to be sounding an amp: with no captures loaded the rack passes the + // DI through dry and every blend measurement would be taken on that instead. opt.captures = RationsTools::captureRoot(opt.captures); if (opt.captures.empty()) { RationsTools::printCaptureUsage("rations_ircheck"); @@ -519,6 +519,56 @@ int main(int argc, char **argv) ++failures; } + // --- the cabinet on its own, with no capture loaded anywhere --------------------------------- + // The parent plug-in passes its input through when no model is loaded, so one instance can be + // a cabinet and nothing else in a chain of other plug-ins. That only works if a channel with + // no capture assigned passes its input through dry instead of gating to silence: the IR then + // convolves the DI rather than nothing. Every channel is cleared the way the settings page + // clears one, and the clear is given time to reach the audio thread, which polls for it. + { + printf("== no capture loaded\n"); + bool cleared = true; + for (int c = 0; c < Rations::kChannelCount; ++c) + cleared = + RationsTools::sendCaptureLoad(hostContext, component, c, "", false) && cleared; + cleared = sendIr(hostContext, component, 0, "") && cleared; + cleared = sendIr(hostContext, component, 1, "") && cleared; + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + renderer.run(0.0); // settle the dry gate's ramp before measuring + + const std::vector dry = renderer.run(0.0); + const double inRms = rms(renderer.signal, renderer.flushSamples); + const double dryRms = rms(dry, 0); + // Not bit-exact: the tone stack is still in, at its defaults. It is close to flat there, + // so a few dB is the margin against "the amp gated to silence" (hundreds of dB), not a + // claim about the tone stack. + const bool passes = cleared && std::fabs(toDb(dryRms) - toDb(inRms)) < 3.0; + printf(" %s nothing loaded passes the input through (in %+.2f dB, out %+.2f dB)\n", + passes ? "ok " : "FAIL", toDb(inRms), toDb(dryRms)); + if (!passes) + ++failures; + + const std::string &ir = opt.pairs.front().first; + const bool loaded = sendIr(hostContext, component, 0, ir); + renderer.run(0.0); + const std::vector cab = renderer.run(0.0); + const double cabRms = rms(cab, 0); + // Audible, and the cabinet's sound rather than the dry signal's: an IR is a filter, so it + // must change the samples. + const bool sounds = loaded && toDb(cabRms) > -60.0 && !identical(cab, dry); + printf(" %s %s alone, no capture: %s (out %+.2f dB)\n", sounds ? "ok " : "FAIL", + baseName(ir), + !loaded ? "THE PLUG-IN REFUSED THE IR" + : toDb(cabRms) <= -60.0 ? "SILENT" + : identical(cab, dry) ? "THE IR DID NOT CHANGE THE AUDIO" + : "the cabinet sounds", + toDb(cabRms)); + if (!sounds) + ++failures; + sendIr(hostContext, component, 0, ""); + printf("\n"); + } + processor->setProcessing(false); component->setActive(false); @@ -526,6 +576,7 @@ int main(int argc, char **argv) printf("FAILED - %d check%s did not hold\n", failures, failures == 1 ? "" : "s"); return 1; } - printf("PASSED - the second slot is invisible to a one-IR user, and the blend is level\n"); + printf("PASSED - the second slot is invisible to a one-IR user, the blend is level, and the " + "cabinet works with no capture loaded\n"); return 0; } diff --git a/core/tools/toolcaptures.h b/core/tools/toolcaptures.h index ee446e3..fa77c52 100644 --- a/core/tools/toolcaptures.h +++ b/core/tools/toolcaptures.h @@ -83,8 +83,9 @@ inline bool sendCaptureLoad(Steinberg::Vst::HostApplication &host, } // All four channels from one root, each from its own subdirectory. A channel whose directory is -// missing is not an error here: ModelBank warns and that channel outputs ramped silence, which is -// the behaviour a tool asserting on a partial bank set wants to see rather than be spared. +// missing is not an error here: ModelBank warns and that channel stays empty, passing its input +// through dry, which is the behaviour a tool asserting on a partial bank set wants to see rather +// than be spared. // Publish a Slim setting the way the settings overlay does: an IMessage on the message thread, // never the parameter queue, because applying it rebuilds every capture in every loaded bank. // The caller has to WAIT afterwards - a rebuilt bank is republished before any entry is ready, so diff --git a/products/rack/src/rationsprocessor.cpp b/products/rack/src/rationsprocessor.cpp index 6248cb3..46ecdc7 100644 --- a/products/rack/src/rationsprocessor.cpp +++ b/products/rack/src/rationsprocessor.cpp @@ -114,9 +114,11 @@ tresult PLUGIN_API RationsProcessor::initialize(FUnknown *context) // Nothing is loaded here, and that is the change this build is about. The plug-in used to ship // four banks inside its own bundle and request all four at this point; it ships none now, so a // fresh instance comes up with four empty channels and the settings page asking for them. Empty - // is a state the rack already handles correctly - it answers with ramped silence, never with - // dry signal, which would jump in level the instant a model landed - so there is nothing to add - // here beyond not doing it. + // is a state the rack already handles: a channel with no capture assigned passes its input + // through dry, as the parent plug-in does with no model loaded, so an instance can be used for + // its cabinet alone. Only a capture that is assigned but still building answers with ramped + // silence, because dry signal there would jump in level the instant the model landed. So there + // is nothing to add here beyond not loading anything. // // The four workers still exist and still start now. What makes the build breadth-first is one // worker per channel, and that is a property of the rack rather than of when the loads arrive: diff --git a/products/rack/src/rationsprocessor.h b/products/rack/src/rationsprocessor.h index f067f09..3673f08 100644 --- a/products/rack/src/rationsprocessor.h +++ b/products/rack/src/rationsprocessor.h @@ -113,7 +113,8 @@ class RationsProcessor : public Steinberg::Vst::AudioEffect void sendMidiTable(); // message thread only void allocateBuffers(); // message thread only // Load one channel's bank from a folder (isDirectory) or a single file. An empty path clears - // the channel, which the rack answers with ramped silence. Message thread only — file I/O. + // the channel, which the rack answers by passing its input through dry. Message thread only — + // file I/O. void loadCaptureSource(int channel, const std::string &path, bool isDirectory); // Publish the output section to the rack. Safe from EITHER thread - it is nothing but atomic // stores - which it has to be, because a radio click on the settings page arrives as a host diff --git a/products/rack/tools/rations_midicheck.cpp b/products/rack/tools/rations_midicheck.cpp index 631abec..9a65678 100644 --- a/products/rack/tools/rations_midicheck.cpp +++ b/products/rack/tools/rations_midicheck.cpp @@ -576,8 +576,8 @@ int main(int argc, char **argv) // A learned footswitch has to reach the channel that is actually SOUNDING, not merely the // parameter, and this tool asserts exactly that — so the four channels have to have something - // to sound. With nothing loaded every channel is ramped silence and the assertion would pass - // against four identical nothings. + // to sound. With nothing loaded every channel passes the same dry input through and the + // assertion would pass against four identical signals. opt.captures = RationsTools::captureRoot(opt.captures); if (opt.captures.empty()) { RationsTools::printCaptureUsage("rations_midicheck"); diff --git a/products/rations/CMakeLists.txt b/products/rations/CMakeLists.txt index aed0b42..f5aee8b 100644 --- a/products/rations/CMakeLists.txt +++ b/products/rations/CMakeLists.txt @@ -546,8 +546,8 @@ endforeach() # person's amps, and made every build of it depend on files that are deliberately # not in this repository. Both are gone. The four banks are now whatever folder or # file the user picks on the settings page, remembered by absolute path in the -# state blob, and an instance with nothing loaded outputs ramped silence rather -# than failing to exist. +# state blob, and an instance with nothing loaded passes its input through dry +# rather than failing to exist. # # The offline proofs still need captures to run against, and take a --captures # argument (or $RATIONS_TEST_CAPTURES) rather than reading them out of a bundle. diff --git a/products/rations/scripts/ir-gate.sh b/products/rations/scripts/ir-gate.sh index e5bd9ba..5eb51d6 100755 --- a/products/rations/scripts/ir-gate.sh +++ b/products/rations/scripts/ir-gate.sh @@ -26,9 +26,9 @@ root="${RATIONS_IR_DIR:-$HOME/Impulse-Responses}" build="${RATIONS_BUILD_DIR:-$(cd "$(dirname "$0")/../../.." && pwd)/build}" bundle="$build/VST3/Release/NAMp-rations.vst3" tool="$build/rations_ircheck" -# The cabinet stage is measured through the whole chain, so the channels have to be sounding -# something: with no captures loaded the rack outputs ramped silence and every blend measurement -# would be taken on nothing. The plug-in ships no captures, so this has to say where they are. +# The cabinet stage is measured through the whole chain, so the channels have to be sounding an +# amp: with no captures loaded the rack passes the DI through dry and every blend measurement would +# be taken on that instead. The plug-in ships no captures, so this has to say where they are. captures="${RATIONS_TEST_CAPTURES:-$(cd "$(dirname "$0")/.." && pwd)/captures}" V="$root/Celestion Vintage 30 - 2002 Mesa Boogie Traditional 4x12 - SM57" diff --git a/products/rations/src/rationsprocessor.cpp b/products/rations/src/rationsprocessor.cpp index a220697..35061c6 100644 --- a/products/rations/src/rationsprocessor.cpp +++ b/products/rations/src/rationsprocessor.cpp @@ -120,9 +120,11 @@ tresult PLUGIN_API RationsProcessor::initialize(FUnknown *context) // Nothing is loaded here, and that is the change this build is about. The plug-in used to ship // four banks inside its own bundle and request all four at this point; it ships none now, so a // fresh instance comes up with four empty channels and the settings page asking for them. Empty - // is a state the rack already handles correctly - it answers with ramped silence, never with - // dry signal, which would jump in level the instant a model landed - so there is nothing to add - // here beyond not doing it. + // is a state the rack already handles: a channel with no capture assigned passes its input + // through dry, as the parent plug-in does with no model loaded, so an instance can be used for + // its cabinet alone. Only a capture that is assigned but still building answers with ramped + // silence, because dry signal there would jump in level the instant the model landed. So there + // is nothing to add here beyond not loading anything. // // The four workers still exist and still start now. What makes the build breadth-first is one // worker per channel, and that is a property of the rack rather than of when the loads arrive: diff --git a/products/rations/src/rationsprocessor.h b/products/rations/src/rationsprocessor.h index 9ac0153..2557ca7 100644 --- a/products/rations/src/rationsprocessor.h +++ b/products/rations/src/rationsprocessor.h @@ -108,7 +108,8 @@ class RationsProcessor : public Steinberg::Vst::AudioEffect void sendMidiTable(); // message thread only void allocateBuffers(); // message thread only // Load one channel's bank from a folder (isDirectory) or a single file. An empty path clears - // the channel, which the rack answers with ramped silence. Message thread only — file I/O. + // the channel, which the rack answers by passing its input through dry. Message thread only — + // file I/O. void loadCaptureSource(int channel, const std::string &path, bool isDirectory); // Publish the output section to the rack. Safe from EITHER thread - it is nothing but atomic // stores - which it has to be, because a radio click on the settings page arrives as a host diff --git a/products/rations/tools/rations_lv2check.cpp b/products/rations/tools/rations_lv2check.cpp index f6cb701..4494508 100644 --- a/products/rations/tools/rations_lv2check.cpp +++ b/products/rations/tools/rations_lv2check.cpp @@ -1094,8 +1094,9 @@ void checkInstantiate(LilvWorld *world, const LilvPlugin *plugin) seqOut->atom.size = static_cast(atomOut.size() - sizeof(LV2_Atom)); lilv_instance_run(instance, kBlock); } - // Nothing is loaded, so the amp is at its ramped-silence gate and the output must be silent — - // which is also the check that run() wrote the buffers at all rather than leaving them alone. + // Nothing is loaded, so the amp passes its input through, and the input is silence: the output + // must be silent too — which is also the check that run() wrote the buffers at all rather than + // leaving them alone. bool silent = true; for (uint32_t i = 0; i < kBlock; ++i) silent = silent && audioOutL[i] == 0.0f && audioOutR[i] == 0.0f; @@ -1113,12 +1114,17 @@ void checkInstantiate(LilvWorld *world, const LilvPlugin *plugin) // of the instance. Four banks that could not be switched between, a dial that could not sweep // its bank, and no control on the panel that did anything. // - // Bypass is the one that needs no captures. With nothing loaded the amp is at its - // ramped-silence gate, so bypass OUT is silence and bypass IN is the dry input — a difference - // no default can produce, reached only by the host writing a port. + // Bypass is the one that needs no captures. With nothing loaded the amp passes its input + // through, as the parent plug-in does, so on its own bypass would make no difference to hear. + // Output gain is what separates them: it trims the wet path and nothing else, so with it at + // its -40 dB floor bypass OUT is the input a hundred times down and bypass IN is the input + // itself — a difference no default can produce, reached only by the host writing two ports. const int bypassPort = static_cast(kPortControlFirst); // kBypassId is the first control check(controlPortParam(0) == kBypassId, "the first control port is no longer Bypass; this " "check names it by position"); + const int outputGainPort = static_cast(kPortControlFirst) + 2; + check(controlPortParam(2) == kOutputGainId, "the third control port is no longer Output gain; " + "this check names it by position"); const auto runSine = [&](int blocks, double &rms) { double sum = 0.0; int counted = 0; @@ -1142,9 +1148,21 @@ void checkInstantiate(LilvWorld *world, const LilvPlugin *plugin) rms = counted > 0 ? std::sqrt(sum / counted) : 0.0; }; + // First the thing a cabinet-only instance depends on: nothing loaded, bypass off, every + // control at its default, and the input comes out. Not bit-exact, because the tone stack is + // in at its defaults; within a few dB of the 0.177 input is the difference from a gate that + // shut (silence) or a stage that never ran. + double rmsPassThrough = 0.0; + gPortValues[bypassPort] = 0.0f; + runSine(64, rmsPassThrough); + checkf(rmsPassThrough > 0.177 * 0.7 && rmsPassThrough < 0.177 * 1.4, + "with nothing loaded the input did not pass through (output rms %.6f against an input " + "rms of about 0.177): an instance used only for its cabinet would be silent", + rmsPassThrough); + double rmsBypassOut = 0.0; double rmsBypassIn = 0.0; - gPortValues[bypassPort] = 0.0f; + gPortValues[outputGainPort] = static_cast(controlSpec(2).min); runSine(64, rmsBypassOut); gPortValues[bypassPort] = 1.0f; runSine(64, rmsBypassIn); @@ -1155,7 +1173,9 @@ void checkInstantiate(LilvWorld *world, const LilvPlugin *plugin) "(output rms %.6f against an input rms of about 0.177): the host's control ports are " "not reaching the plug-in at all", rmsBypassIn); - checkf(rmsBypassIn > rmsBypassOut * 100.0 + 1e-6, + // -40 dB is a factor of 100; 20 leaves room for the tone stack without letting a bypass that + // did nothing (a factor of 1) through. + checkf(rmsBypassIn > rmsBypassOut * 20.0 + 1e-6, "the bypass control port made no difference (out %.6f, in %.6f)", rmsBypassOut, rmsBypassIn); // And back again, so what is being measured is the port and not a one-way latch. @@ -1164,6 +1184,7 @@ void checkInstantiate(LilvWorld *world, const LilvPlugin *plugin) checkf(rmsAgain < rmsBypassIn * 0.5, "bypass could be switched on and not off again (on %.6f, off again %.6f)", rmsBypassIn, rmsAgain); + gPortValues[outputGainPort] = static_cast(controlSpec(2).def); // The state round trip. A fresh instance with nothing loaded still has a full blob — the // shared controls, the trims, the pedalboard, the output section — so this exercises the same diff --git a/products/rations/tools/rations_midicheck.cpp b/products/rations/tools/rations_midicheck.cpp index c88441d..9b229b1 100644 --- a/products/rations/tools/rations_midicheck.cpp +++ b/products/rations/tools/rations_midicheck.cpp @@ -576,8 +576,8 @@ int main(int argc, char **argv) // A learned footswitch has to reach the channel that is actually SOUNDING, not merely the // parameter, and this tool asserts exactly that — so the four channels have to have something - // to sound. With nothing loaded every channel is ramped silence and the assertion would pass - // against four identical nothings. + // to sound. With nothing loaded every channel passes the same dry input through and the + // assertion would pass against four identical signals. opt.captures = RationsTools::captureRoot(opt.captures); if (opt.captures.empty()) { RationsTools::printCaptureUsage("rations_midicheck");