Address external review: generator tests, class param docs, nits

- Add deterministic generator-level tests: BitReduceTests (level snapping +
  1-bit floor), SampleRateDecimateTests (sample-and-hold groups), and
  ReverseDelayTests (silent-then-flat-replay). Asserts are output-gain
  independent.
- Add class-level `- Parameters:` doc blocks to BitReduce, SampleRateDecimate,
  and ReverseDelay (dual-location param docs).
- BitReduce: clamp the shift amount directly and note shift-safety; clarify
  mid-tread wording.
- ReverseDelay: comment the unreachable baseAddress guard.

Suite 247.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-27 21:46:23 -07:00
parent 7ceb93e411
commit 077a8ad9f0
7 changed files with 2849 additions and 2 deletions
@@ -13,7 +13,11 @@ private let bitReduceZeroBlock: [Double] = makeSampleBuffer()
/// quantisation noise of the "bit" half of a lo-fi / bitcrusher effect.
///
/// `bits` is read at control rate (once per block) and clamped to `[1, 16]`. Each sample is
/// rounded to the nearest step of size `2^(1-bits)` over the `[-1, 1]` range. Output is mono.
/// rounded to the nearest of `2^bits` levels over the `[-1, 1]` range (mid-tread). Output is mono.
///
/// - Parameters:
/// - input: Audio-rate signal to quantise.
/// - bits: Bit depth — quantises to `2^bits` levels. Control rate; clamped to `[1, 16]`.
public final class BitReduce: GeneratorBase, AudioGenerator {
/// Resolved input signal.
@@ -55,7 +59,8 @@ public final class BitReduce: GeneratorBase, AudioGenerator {
let bits: Double = min(max(_bits.floatValue(graph: graph), minimumBits), maximumBits)
// Number of quantisation levels = 2^bits, via an integer shift (avoids importing `pow`).
let bitsInt: Int = Int(bits.rounded())
// Clamp the shift amount directly too: `1 << bitsInt` is only safe while bits ∈ [1, 16].
let bitsInt: Int = min(max(Int(bits.rounded()), 1), 16)
let levels: Double = Double(1 << bitsInt)
// Step between adjacent levels over [-1, 1], and its reciprocal for the round.
let step: Double = 2.0 / levels