mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-24 01:04:02 +02:00
ALSA: Reduce the size of a memory allocation.
This commit is contained in:
+12
-5
@@ -28998,18 +28998,17 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
|
|||||||
deviceNameCount = iDeviceName;
|
deviceNameCount = iDeviceName;
|
||||||
|
|
||||||
|
|
||||||
/* Allocate memory for our hardware and software params. We do this with a single allocation. */
|
/* Allocate memory for our hardware and software params. We do this with a single allocation. They are used independently so we can just alias this allocation. */
|
||||||
paramsMemorySize = 0;
|
paramsMemorySize = ma_max(pContextStateALSA->snd_pcm_hw_params_sizeof(), pContextStateALSA->snd_pcm_sw_params_sizeof());
|
||||||
paramsMemorySize += ma_align_64(pContextStateALSA->snd_pcm_hw_params_sizeof());
|
|
||||||
paramsMemorySize += ma_align_64(pContextStateALSA->snd_pcm_sw_params_sizeof());
|
|
||||||
|
|
||||||
pParamsMemory = ma_calloc(paramsMemorySize, ma_context_get_allocation_callbacks(pContext));
|
pParamsMemory = ma_calloc(paramsMemorySize, ma_context_get_allocation_callbacks(pContext));
|
||||||
if (pParamsMemory == NULL) {
|
if (pParamsMemory == NULL) {
|
||||||
return MA_OUT_OF_MEMORY;
|
return MA_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Alias the memory allocation. */
|
||||||
pHWParams = (ma_snd_pcm_hw_params_t*)pParamsMemory;
|
pHWParams = (ma_snd_pcm_hw_params_t*)pParamsMemory;
|
||||||
pSWParams = (ma_snd_pcm_sw_params_t*)ma_offset_ptr(pParamsMemory, ma_align_64(pContextStateALSA->snd_pcm_hw_params_sizeof()));
|
pSWParams = (ma_snd_pcm_sw_params_t*)pParamsMemory;
|
||||||
|
|
||||||
for (iDeviceName = 0; iDeviceName < deviceNameCount; iDeviceName += 1) {
|
for (iDeviceName = 0; iDeviceName < deviceNameCount; iDeviceName += 1) {
|
||||||
const char* pDeviceName = pDeviceNames[iDeviceName];
|
const char* pDeviceName = pDeviceNames[iDeviceName];
|
||||||
@@ -29238,6 +29237,12 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
The hardware parameters memory is aliased with the software parameters memory, so just clear out this pointer
|
||||||
|
for safety and to make it clear that it should not be used from here on out.
|
||||||
|
*/
|
||||||
|
pHWParams = NULL;
|
||||||
|
|
||||||
|
|
||||||
/* Software parameters. */
|
/* Software parameters. */
|
||||||
resultALSA = pContextStateALSA->snd_pcm_sw_params_current(pPCM, pSWParams);
|
resultALSA = pContextStateALSA->snd_pcm_sw_params_current(pPCM, pSWParams);
|
||||||
@@ -29284,6 +29289,8 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pSWParams = NULL;
|
||||||
|
|
||||||
|
|
||||||
/* Grab the internal channel map. For now we're not going to bother trying to change the channel map and instead just do it ourselves. */
|
/* Grab the internal channel map. For now we're not going to bother trying to change the channel map and instead just do it ourselves. */
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user