Pitch is actually also derived from mathematical patterns. Notes sound good together (or not) because of the ratios between their frequencies, with simple ratios like 2:3 (or ratios very close to them because our brains aren’t good at discerning extremely close pitches) sounding much better than complicated ratios, particularly if they aren’t rational (i.e. they involve square roots).