Ray did this some time ago. So it's prior art. As is the ceiling fan jitter discovery.
I had no idea about your work and 'discovered' it independently so i'll see you both in court
More seriously, if this was patent-able, ESS would've done it. Seems to be 'just' a math algorithm so maybe patent a device/chip that implements it. Anyway, if anyone can figure out a practical algorithm/device, I'll donate to your kickstarter/etc.
Some previous work (with code examples):
Those tools mostly do generate HD. But if you can generate HD, you will surely learn a few things about de-generating it. This is your chance
@pkane to grab back all the HD that you put out in the universe
I also remember reading a paper some years ago which claimed that HD-cancellation is the reason why SET amps sound so good/clean: i.e. the big HD spikes of a SET amp play a cancellation game with the ~same as big HD spikes of a speaker. Far fetched hypothesis and IIRC there were no practical examples/measurements but the math looked alright (for a non audio expert like me). Might be able to google it.
The computation seems daunting but the theory says it's possible, at least to some (usable) extent. The H2 and H3 would be easiest/fastest to remove but those are exactly the ones that you don't want to remove. And the H5+ ones that you really want out, would be much harder/complex (a point for a diff discussion/thread I guess).
I'd say the anti-HD DSP filter should be somewhat similar to a RoomCorrection filter. Just based on the measured HD of dac/amp/speaker (instead of room measurements). Or it may be more similar to noise-cancelling tech. In any case, you'll need to apply the anti-HD-filter during playback. Not sure which would be better: before or after the RC filter.
Good luck!