|
JPL Spatial
Sound spatialization and propagation library
|
This example uses the high-level SpatialManager API in the role of a game engine sound spatializer. It moves a mono source around a listener, updates the spatial simulation, and retrieves quad speaker gains and distance attenuation. A host audio engine would use these values when mixing the source audio.
SpatialManager is an older API that remains under active design review. This example documents its current workflow; it does not render or play audio.
From the JPL Spatial repository root:
Run the resulting executable from an open terminal. A single-config build runs with:
The Visual Studio Release build runs with:
Expected result:
The positions use JPL Spatial's right-handed, Y-up, -Z-forward coordinate convention. The example prints panning gains and distance attenuation separately; combining them is the responsibility of the host mixer.
JPLSPATIAL_SOURCE_DIR is a cache variable, so the example can also be pointed at another checkout:
The expected channel maps can come from user or platform config.
Or you can initialize all supported source and target channel maps.
Note: each panner has a LUT, which can take up to 1 MB of space for channel maps with height channels; therefore, it's best to initialize only what you know will be needed.
This is an optional step, JPL::Spatial::SpatialManager::CreateSource (in step 2) can initialize the required panning objects itself; explicitly creating panners/layouts beforehand moves LUT construction and allocations out of later execution.
After all the updated positions have been sent to Spatial Manager:
This is engine-specific, but the gist of it is to mix-add each source channel to each output channel with corresponding gain from spatializer.
When sound object is destroyed, or no longer relevant, it's generally a good idea to release no longer needed cached data.