* PM_K-1 Stage 3 : summing node (selected input + click)
*
* An inverting summing amp mixes STAGE1_OUT (line/instrument) and CLICK_OUT (DAC).
* Each source feeds the op-amp's inverting input through its own 10k resistor; the
* feedback holds that node at a "virtual ground" (~0V). Because BOTH sources see 0V
* there, neither can load or pull on the other -- they sum with no interaction.
*   Vout = -(Rf/Ri1)*V1 - (Rf/Ri2)*V2 ;  with Rf=Ri=10k -> Vout = -(V1+V2).
*
* We confirm: each input alone = 0 dB (gain -1), both together = +6 dB (they add),
* and each input's gain is unchanged by the other (isolation).
* Run:  ngspice -b ../eda/sim/stage3_sum.cir

.title Stage3 inverting summer

Vinp inp 0 AC 1        ; selected input (STAGE1_OUT)
Vclk clk 0 AC 1        ; filtered click (CLICK_OUT)
Ri1 inp vm 10k
Ri2 clk vm 10k
Rf  vm  out 10k
Eop out 0 0 vm 1e6     ; +in = gnd, -in = vm  -> inverting; feedback makes vm a virtual ground

.ac dec 10 100 20k
.control
* both sources active -> they sum
run
meas ac g_both find vdb(out) at=1k
echo "  both        = $&g_both dB   (+6 dB over each-alone = the two sum)"
* input alone (click muted)
alter @Vclk[acmag]=0
run
meas ac g_in find vdb(out) at=1k
echo "  input alone = $&g_in dB    (gain -1, i.e. 0 dB)"
* click alone (input muted)
alter @Vinp[acmag]=0
alter @Vclk[acmag]=1
run
meas ac g_clk find vdb(out) at=1k
echo "  click alone = $&g_clk dB    (gain -1; unchanged by the input = virtual-ground isolation)"
.endc
.end
