Commit 45d6d5a2 authored by David Reid's avatar David Reid

Optimization for stereo sounds in the engine.

In a stereo scenario, the listener will use a channel map of
{SIDE_LEFT, SIDE_RIGHT}, but sounds will default to
{FRONT_LEFT, FRONT_RIGHT}. As a result, channel mapping will be
performed to do the conversion. By instead defaulting stereo sounds
to be consistent with the listener, a passthrough path can be used
instead, improving efficiency.
parent 9bea9fd3
......@@ -72382,6 +72382,7 @@ static ma_result ma_engine_node_get_heap_layout(const ma_engine_node_config* pCo
ma_spatializer_config spatializerConfig;
ma_uint32 channelsIn;
ma_uint32 channelsOut;
ma_channel defaultStereoChannelMap[2] = {MA_CHANNEL_SIDE_LEFT, MA_CHANNEL_SIDE_RIGHT}; /* <-- Consistent with the default channel map of a stereo listener. Means channel conversion can run on a fast path. */
MA_ASSERT(pHeapLayout);
......@@ -72431,6 +72432,10 @@ static ma_result ma_engine_node_get_heap_layout(const ma_engine_node_config* pCo
/* Spatializer. */
spatializerConfig = ma_engine_node_spatializer_config_init(&baseNodeConfig);
if (spatializerConfig.channelsIn == 2) {
spatializerConfig.pChannelMapIn = defaultStereoChannelMap;
}
result = ma_spatializer_get_heap_size(&spatializerConfig, &tempHeapSize);
if (result != MA_SUCCESS) {
return result; /* Failed to retrieve the size of the heap for the spatializer. */
......@@ -72475,6 +72480,7 @@ MA_API ma_result ma_engine_node_init_preallocated(const ma_engine_node_config* p
ma_panner_config pannerConfig;
ma_uint32 channelsIn;
ma_uint32 channelsOut;
ma_channel defaultStereoChannelMap[2] = {MA_CHANNEL_SIDE_LEFT, MA_CHANNEL_SIDE_RIGHT}; /* <-- Consistent with the default channel map of a stereo listener. Means channel conversion can run on a fast path. */
if (pEngineNode == NULL) {
return MA_INVALID_ARGS;
......@@ -72554,6 +72560,10 @@ MA_API ma_result ma_engine_node_init_preallocated(const ma_engine_node_config* p
spatializerConfig = ma_engine_node_spatializer_config_init(&baseNodeConfig);
spatializerConfig.gainSmoothTimeInFrames = pEngineNode->pEngine->gainSmoothTimeInFrames;
if (spatializerConfig.channelsIn == 2) {
spatializerConfig.pChannelMapIn = defaultStereoChannelMap;
}
result = ma_spatializer_init_preallocated(&spatializerConfig, ma_offset_ptr(pHeap, heapLayout.spatializerOffset), &pEngineNode->spatializer);
if (result != MA_SUCCESS) {
goto error2;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment