Gravity waves generated by potential-vorticity anomalies in shear flows