That is a great question!!
The teeth chatter and lips smack, which make the noise.
This is an instinctual behavior cats do when hunting prey. They make this noise commonly when they deliver a fatal bite to the neck of prey. The noise is pure excitement when hunting.
When you see a cat sitting in window making this noise, is made from frustration of not being able to get the prey he sees. You'll notice a cat doing this if outside but the prey is too far out of reach as well.