NesLinearCounter
StructSource: AudioTypes.h
Description
NES APU linear counter state for the TRIANGLE channel.
The linear counter is a quarter-frame clocked 7-bit countdown shared with the TRIANGLE channel. A write to $4008 sets the reload value (lower 7 bits) and the reload flag. On the next quarter-clock:
- if
reloadFlagis set, the counter is loaded fromreloadValue; - else if the counter is > 0, it is decremented;
- if the shared
controlflag (i.e.NesLengthCounter::halt) is clear, the reload flag is also cleared.
The shared halt flag is read through the lengthCounter pointer, which is bound in AudioChannel::reset(). This avoids duplicating the flag and keeps $4008's control bit and $400B's halt bit behaviour in lockstep with the canonical NES semantics.
When the linear counter is enabled (linearEnabled == true) and the counter is 0, the TRIANGLE sequencer is gated per-sample (output 0, phase frozen) but the voice is NOT disabled. Re-loading via a $4008 write resumes the voice without needing a fresh play event.
Default OFF: linearEnabled == false on construction, so the counter does not tick and the canonical track PCM is unchanged. Hito 2 M5.
Source: https://www.nesdev.org/wiki/APU_Linear_Counter
Properties
| Name | Type | Description |
|---|---|---|
linearEnabled | bool | Per-voice opt-in. False = counter does not tick; bypasses the gate. |
reloadFlag | bool | Set by $4008 write; cleared on quarter-clock if the shared halt/control flag is 0. |
reloadValue | uint8_t | 7-bit reload value (high bits ignored). |
counter | uint8_t | Current value, decremented at quarter-clock rate (240 Hz NTSC mode 0). |
lengthCounter | NesLengthCounter* | Bound in AudioChannel::reset() to share the halt/control flag with the length counter. |
