The classical Szegö-Verblunsky theorem is referred to by Simon as a “gem” of spectral theory. It relates integrability of the logarithm of the absolutely continuous part of a probability measure on the circle to square summability of the sequence of recurrence coefficients for the orthogonal polynomials determined by the measure. We generalize the underlying theory to several variables and obtain an analogous theorem valid for functions which are almost periodic in the sense of Besicovitch. The results are applied to the onedimensional Schrödinger equation in impedance form to yield a new trace formula valid for piecewise constant impedance, a case where the classical trace formula breaks down.