A soundwave is coming, you intake it with a microphone and attempt producing its inversion in real time in speakers, to cancel it.
As I have written, it may not work properly with impactive noise - it can do the opposite, because the impactive sound is cleaner. Or, it may be calibrated for impactive noise - so there exist earmuffs that recognize shooting sounds at their inception, to reduce these selectively.
As an aside, since your ears are not ringing / recovering from a very loud sound, and the amplifier turns back on very quickly, you can hear the reverberations, echos, and sympathetic resonances. It's quite cool.