Pressure dependence of the dielectric and lattice-dynamical properties of GaN and AlN