Sound moves in waves.
Say “Sound X” is what you’re trying to cancel.
Sound waves have two important characteristics when it comes to this: the amplitude and the phase.
(There’s more that goes into this, but think the “strength” and the “timing” of a given sound wave, respectively)
If you get “Sound Y” that has the same amplitude but opposite phase of “Sound X”, Sound Y will interfere with Sound X to form a new wave altogether, and effectively cancel both Sound Y and Sound X out.
Latest Answers