Acoustic resonances leading to high unsteady pressure levels may occur in flow past cavities. The resonance involves a coupling between the downstream-propagating instability wave on the shear layer spanning the open face of the cavity, and acoustic waves propagating within and external to the cavity. These elements of the disturbance field are coupled by the scattering processes that occur at the upstream and downstream ends of the cavity. We develop a theoretical prediction method that combines propagation models in the central region of the cavity with scattering models for the end regions. In our analyses of the scattering processes at the cavity ends, the square-corner geometry is treated exactly, by a method employing the Wiener-Hopf technique. The shear layer is approximated as a vortex sheet in the edge scattering analyses, but finite shear-layer thickness is accounted for in analyzing the propagation of the waves along the length of the cavity. The global analysis leads to a prediction for the resonant frequencies which has a form similar to the Rossiter formula, but contains no empirical constants. In addition to prediction of the frequency, our theory also determines the temporal growth or decay rate of each mode. Finally, our theory also predicts the influence of secondary feedback loops involving other components of the unsteady field. The theoretical predictions are validated by comparison with experimental data.