dsharlet / LiveSPICE

Real time SPICE simulation for audio signals
MIT License
419 stars 61 forks source link

Remove iterations parameter #195

Open dsharlet opened 1 year ago

dsharlet commented 1 year ago

As @Federerer mentioned on #193, the iterations parameter is of questionable utility. I did some experiments and found that performance was actually better with more iterations in some cases. I think this is because the simulation state is closer to converged for the next sample if we don't stop iterating too early.

I also reduced the default oversample parameter from 8 to 2. I read somewhere ages ago (I can't remember where) that simulating audio circuits needed a high oversampling factor to avoid aliasing harmonics in an audible way, and the author recommended 8x. But, I've never once been able to notice a difference with any oversampling factor in terms of audio quality. Maybe this not an issue because our numerical integration is higher quality or something. We're also just doing a box downsample at the end anyways, perhaps this is negating any advantage from oversampling. 2 is what the VST plugin has been doing all along, and I don't think that has caused any issues. Most people are probably using the VST plugin anyways.

Opening this PR for discussion, more testing is probably needed.

Federerer commented 1 year ago

Looks good. Regarding the default oversampling - I think that it would be useful to have a global settings window somewhere, where you can set your defaults (and maybe other advanced simulation settings, like integration method or newton's method delta error value). I find it very annoying that I have to change that every time I start a simulation. Also, there is a possibility to save it per-schematic - creating a json file with the same name as the schematic file with extension like: *.sim.json and reading it when starting simulation with a fallback to defaults.

I've done some audio null tests comparing different oversampling settings and the differences are very minor(mostly on transients in upper harmonics range), in case of iterations, there is a clearly audible clicking/popping when you set it too low. I've also tested changing the relative newton iteration error. Maybe I'll record a quick demo, so you can hear it yourself 😃