We prove that the Shimizu $L$-function of a real quadratic field is obtained from a (Lorentzian) spectral triple on a noncommutative torus with real multiplication, as an adiabatic limit of the Dirac operator on a 3-dimensional solvmanifold. The Dirac operator on this 3-dimensional geometry gives, via the Connes–Landi isospectral deformations, a spectral triple for the noncommutative tori obtained by deforming the fiber tori to noncommutative spaces. The 3-dimensional solvmanifold is the homotopy quotient in the sense of Baum–Connes of the noncommutative space obtained as the crossed product of the noncommutative torus by the action of the units of the real quadratic field. This noncommutative space is identified with the twisted group $C^*$-algebra of the fundamental group of the 3-manifold. The twisting can be interpreted as the cocycle arising from a magnetic field, as in the theory of the quantum Hall effect. We prove a twisted index theorem that computes the range of the trace on the $K$-theory of this noncommutative space and gives an estimate on the gaps in the spectrum of the associated Harper operator.