Finding or for a realistic model star is a complicated problem. The calculations become somewhat simpler if we can assume a relation like throughout the star. If has a positive imaginary part, then the star is unstable against radial perturbations. Without presenting a full stability analysis, let us do a simple calculation to illuminate the nature of the problem. Ray paths for various p-modes.
Dotted circles shows the turning point.
The sun behaves like a resonant cavity because acoustic waves are bounded on top by the surface, and on the bottom by refraction. Rays bend towards the surface because c increases with temperature, i.e., with depth. The angle at which the wave reflects determines how far it will penetrate. The shallower the angle, the shallower the penetration. Because the different modes penetrate to different depths, their frequencies are determined by conditions in different parts of the Sun.