The subject of this paper is modeling of low-amplitude acoustic fields in enclosures with nonuniform medium and boundary conditions. An efficient calculation method is developed for this class of problems. Boundary conditions, accounting for the boundary-layer losses and movable walls, are applied near solid surfaces. The lossless acoustic wave equation for a nonuniform medium is solved in the bulk of the resonator by a finite-difference method. One application of this model is for designing small thermoacoustic engines. Thermoacoustic processes in the regular-geometry porous medium inserted in resonators can be modeled analytically. A calculation example is presented for a small-scale thermoacoustic engine coupled with an oscillator on a flexing wall of the resonator. The oscillator can be used for extracting mechanical power from the engine. A nonuniform wall deflection may result in a complicated acoustic field in the resonator. This leads to across-the-stack variations of the generated acoustic power and local efficiency of thermoacoustic energy conversion.