Commit 35ce972b authored by David Reid's avatar David Reid

Make sure heap layouts are aligned properly.

parent ebaa74d6
...@@ -2378,6 +2378,9 @@ MA_API float ma_delay_node_get_decay(const ma_delay_node* pDelayNode); ...@@ -2378,6 +2378,9 @@ MA_API float ma_delay_node_get_decay(const ma_delay_node* pDelayNode);
#if defined(MA_IMPLEMENTATION) || defined(MINIAUDIO_IMPLEMENTATION) #if defined(MA_IMPLEMENTATION) || defined(MINIAUDIO_IMPLEMENTATION)
#define ma_align(x, a) ((x + (a-1)) & ~(a-1))
#define ma_align_64(x) ma_align(x, 8)
MA_API ma_result ma_paged_audio_buffer_data_init(ma_format format, ma_uint32 channels, ma_paged_audio_buffer_data* pData) MA_API ma_result ma_paged_audio_buffer_data_init(ma_format format, ma_uint32 channels, ma_paged_audio_buffer_data* pData)
{ {
if (pData == NULL) { if (pData == NULL) {
...@@ -2825,6 +2828,9 @@ static ma_result ma_gainer_get_heap_layout(const ma_gainer_config* pConfig, ma_g ...@@ -2825,6 +2828,9 @@ static ma_result ma_gainer_get_heap_layout(const ma_gainer_config* pConfig, ma_g
pHeapLayout->newGainsOffset = pHeapLayout->sizeInBytes; pHeapLayout->newGainsOffset = pHeapLayout->sizeInBytes;
pHeapLayout->sizeInBytes += sizeof(float) * pConfig->channels; pHeapLayout->sizeInBytes += sizeof(float) * pConfig->channels;
/* Alignment. */
pHeapLayout->sizeInBytes = ma_align_64(pHeapLayout->sizeInBytes);
return MA_SUCCESS; return MA_SUCCESS;
} }
...@@ -4306,7 +4312,7 @@ static ma_result ma_node_get_heap_layout(const ma_node_config* pConfig, ma_node_ ...@@ -4306,7 +4312,7 @@ static ma_result ma_node_get_heap_layout(const ma_node_config* pConfig, ma_node_
/* Input buses. */ /* Input buses. */
if (inputBusCount > MA_MAX_NODE_LOCAL_BUS_COUNT) { if (inputBusCount > MA_MAX_NODE_LOCAL_BUS_COUNT) {
pHeapLayout->inputBusOffset = pHeapLayout->sizeInBytes; pHeapLayout->inputBusOffset = pHeapLayout->sizeInBytes;
pHeapLayout->sizeInBytes += sizeof(ma_node_input_bus) * inputBusCount; pHeapLayout->sizeInBytes += ma_align_64(sizeof(ma_node_input_bus) * inputBusCount);
} else { } else {
pHeapLayout->inputBusOffset = MA_SIZE_MAX; /* MA_SIZE_MAX indicates that no heap allocation is required for the input bus. */ pHeapLayout->inputBusOffset = MA_SIZE_MAX; /* MA_SIZE_MAX indicates that no heap allocation is required for the input bus. */
} }
...@@ -4314,7 +4320,7 @@ static ma_result ma_node_get_heap_layout(const ma_node_config* pConfig, ma_node_ ...@@ -4314,7 +4320,7 @@ static ma_result ma_node_get_heap_layout(const ma_node_config* pConfig, ma_node_
/* Output buses. */ /* Output buses. */
if (outputBusCount > MA_MAX_NODE_LOCAL_BUS_COUNT) { if (outputBusCount > MA_MAX_NODE_LOCAL_BUS_COUNT) {
pHeapLayout->outputBusOffset = pHeapLayout->sizeInBytes; pHeapLayout->outputBusOffset = pHeapLayout->sizeInBytes;
pHeapLayout->sizeInBytes += sizeof(ma_node_output_bus) * outputBusCount; pHeapLayout->sizeInBytes += ma_align_64(sizeof(ma_node_output_bus) * outputBusCount);
} else { } else {
pHeapLayout->outputBusOffset = MA_SIZE_MAX; pHeapLayout->outputBusOffset = MA_SIZE_MAX;
} }
...@@ -4354,7 +4360,7 @@ static ma_result ma_node_get_heap_layout(const ma_node_config* pConfig, ma_node_ ...@@ -4354,7 +4360,7 @@ static ma_result ma_node_get_heap_layout(const ma_node_config* pConfig, ma_node_
} }
pHeapLayout->cachedDataOffset = pHeapLayout->sizeInBytes; pHeapLayout->cachedDataOffset = pHeapLayout->sizeInBytes;
pHeapLayout->sizeInBytes += cachedDataSizeInBytes; pHeapLayout->sizeInBytes += ma_align_64(cachedDataSizeInBytes);
} }
...@@ -10991,7 +10997,7 @@ static ma_result ma_spatializer_listener_get_heap_layout(const ma_spatializer_li ...@@ -10991,7 +10997,7 @@ static ma_result ma_spatializer_listener_get_heap_layout(const ma_spatializer_li
/* Channel map. We always need this, even for passthroughs. */ /* Channel map. We always need this, even for passthroughs. */
pHeapLayout->channelMapOutOffset = pHeapLayout->sizeInBytes; pHeapLayout->channelMapOutOffset = pHeapLayout->sizeInBytes;
pHeapLayout->sizeInBytes += sizeof(*pConfig->pChannelMapOut) * pConfig->channelsOut; pHeapLayout->sizeInBytes += ma_align_64(sizeof(*pConfig->pChannelMapOut) * pConfig->channelsOut);
return MA_SUCCESS; return MA_SUCCESS;
} }
...@@ -11306,12 +11312,12 @@ static ma_result ma_spatializer_get_heap_layout(const ma_spatializer_config* pCo ...@@ -11306,12 +11312,12 @@ static ma_result ma_spatializer_get_heap_layout(const ma_spatializer_config* pCo
pHeapLayout->channelMapInOffset = MA_SIZE_MAX; /* <-- MA_SIZE_MAX indicates no allocation necessary. */ pHeapLayout->channelMapInOffset = MA_SIZE_MAX; /* <-- MA_SIZE_MAX indicates no allocation necessary. */
if (pConfig->pChannelMapIn != NULL) { if (pConfig->pChannelMapIn != NULL) {
pHeapLayout->channelMapInOffset = pHeapLayout->sizeInBytes; pHeapLayout->channelMapInOffset = pHeapLayout->sizeInBytes;
pHeapLayout->sizeInBytes += sizeof(*pConfig->pChannelMapIn) * pConfig->channelsIn; pHeapLayout->sizeInBytes += ma_align_64(sizeof(*pConfig->pChannelMapIn) * pConfig->channelsIn);
} }
/* New channel gains for output. */ /* New channel gains for output. */
pHeapLayout->newChannelGainsOffset = pHeapLayout->sizeInBytes; pHeapLayout->newChannelGainsOffset = pHeapLayout->sizeInBytes;
pHeapLayout->sizeInBytes += sizeof(float) * pConfig->channelsOut; pHeapLayout->sizeInBytes += ma_align_64(sizeof(float) * pConfig->channelsOut);
/* Gainer. */ /* Gainer. */
{ {
...@@ -11326,7 +11332,7 @@ static ma_result ma_spatializer_get_heap_layout(const ma_spatializer_config* pCo ...@@ -11326,7 +11332,7 @@ static ma_result ma_spatializer_get_heap_layout(const ma_spatializer_config* pCo
} }
pHeapLayout->gainerOffset = pHeapLayout->sizeInBytes; pHeapLayout->gainerOffset = pHeapLayout->sizeInBytes;
pHeapLayout->sizeInBytes += gainerHeapSizeInBytes; pHeapLayout->sizeInBytes += ma_align_64(gainerHeapSizeInBytes);
} }
return MA_SUCCESS; return MA_SUCCESS;
...@@ -12582,7 +12588,7 @@ static ma_result ma_engine_node_get_heap_layout(const ma_engine_node_config* pCo ...@@ -12582,7 +12588,7 @@ static ma_result ma_engine_node_get_heap_layout(const ma_engine_node_config* pCo
} }
pHeapLayout->baseNodeOffset = pHeapLayout->sizeInBytes; pHeapLayout->baseNodeOffset = pHeapLayout->sizeInBytes;
pHeapLayout->sizeInBytes += tempHeapSize; pHeapLayout->sizeInBytes += ma_align_64(tempHeapSize);
/* Spatializer. */ /* Spatializer. */
...@@ -12594,7 +12600,7 @@ static ma_result ma_engine_node_get_heap_layout(const ma_engine_node_config* pCo ...@@ -12594,7 +12600,7 @@ static ma_result ma_engine_node_get_heap_layout(const ma_engine_node_config* pCo
} }
pHeapLayout->spatializerOffset = pHeapLayout->sizeInBytes; pHeapLayout->spatializerOffset = pHeapLayout->sizeInBytes;
pHeapLayout->sizeInBytes += tempHeapSize; pHeapLayout->sizeInBytes += ma_align_64(tempHeapSize);
return MA_SUCCESS; return MA_SUCCESS;
......
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