The speed of sound is determined by the medium's properties, specifically its bulk modulus (a measure of stiffness) and density. The formula for the speed of sound is approximately $v = \sqrt{B/\rho}$ for liquids and solids, where B is the bulk modulus and $\rho$ is the density. Solids generally have much higher bulk moduli than liquids and gases, leading to higher sound speeds, even though they might also have higher densities. Among solids, stiffer materials tend to have higher sound speeds.