Generalized theory of the photoacoustic effect