The sound simulation is not done through X-Plane but through a commercial product called Simphonics.  It is a sound simulation software that is used in commercial Level D flight simulators.  The software takes input from the host simulation with data for things like airspeed, engine N1, engine N2 and manipulates individual wave files and mixes them together to create an accurate sound reproduction.  In addition to engine sound, it simulates other things such as cabin air, aural warning, aerodynamic wind effects (air impact, air impact from flaps spoilers), landing gear, and brake noises as well as weather effects.

Let’s take for an example how the sound of the engine is generated.  Wave files were derived for each individual physical element of the engine.  Things like RPM or air impact are used to drive the volume and frequency of each individual wave file.  When they are all played together the accurately simulate the sound of the engine.  This method is used so that the engine sound is always accurate no matter what the flight condition is or what mechanical element, such as a N1 rotor seizure, is accurate to the real airplane.

Wave files used to derive the engine sound
Visual programming interface for Simphonics
Simulator speaker layout