Commit 8625b3d0 authored by sagnowski's avatar sagnowski Committed by Fabian Müller
Browse files

Fix memory alignment warning in lib_rend

parent fbfb6355
Loading
Loading
Loading
Loading
+52 −14
Original line number Original line Diff line number Diff line
@@ -3291,31 +3291,72 @@ static ivas_error getConstInputById(
    return IVAS_ERR_OK;
    return IVAS_ERR_OK;
}
}


static void *getInputByIndex( void *inputsArray, const size_t index, const IVAS_REND_AudioConfigType inputType )
{
    switch ( inputType )
    {
        case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED:
            return (input_mc *) inputsArray + index;
        case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS:
            return (input_sba *) inputsArray + index;
        case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED:
            return (input_ism *) inputsArray + index;
        case IVAS_REND_AUDIO_CONFIG_TYPE_MASA:
            return (input_masa *) inputsArray + index;
        default:
            break;
    }

    /* this should be unreachable */
    assert( 0 );
    return NULL;
}

/* Const variant of getInputByIndex. Unfortunately, this duplication is required to keep const-correctness. */
static const void *getConstInputByIndex( const void *inputsArray, const size_t index, const IVAS_REND_AudioConfigType inputType )
{
    switch ( inputType )
    {
        case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED:
            return (const input_mc *) inputsArray + index;
        case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS:
            return (const input_sba *) inputsArray + index;
        case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED:
            return (const input_ism *) inputsArray + index;
        case IVAS_REND_AUDIO_CONFIG_TYPE_MASA:
            return (const input_masa *) inputsArray + index;
        default:
            break;
    }

    /* this should be unreachable */
    assert( 0 );
    return NULL;
}


static ivas_error findFreeInputSlot(
static ivas_error findFreeInputSlot(
    const void *inputs,
    const void *inputs,
    const int32_t inputStructSize,
    const IVAS_REND_AudioConfigType inputType,
    const int32_t maxInputs,
    const int32_t maxInputs,
    int32_t *inputIndex )
    int32_t *inputIndex )
{
{
    /* Using a void pointer and a separately provided size is a hack for this function
    /* Using a void pointer and a separately provided type is a hack for this function
       to be reusable for arrays of any input type (input_ism, input_mc, input_sba, input_masa).
       to be reusable for arrays of any input type (input_ism, input_mc, input_sba, input_masa).
        Assumptions:
        Assumptions:
            - input_base is always the first member in the input struct
            - input_base is always the first member in the input struct
            - provided size is correct
            - memory alignments of original input type and input_base are the same
    */
    */


    int32_t i;
    int32_t i;
    bool canAddInput;
    bool canAddInput;
    const uint8_t *pByte;
    const input_base *pInputBase;
    const input_base *pInputBase;


    canAddInput = false;
    canAddInput = false;


    /* Find first unused input in array */
    /* Find first unused input in array */
    for ( i = 0, pByte = inputs; i < maxInputs; ++i, pByte += inputStructSize )
    for ( i = 0; i < maxInputs; ++i )
    {
    {
        pInputBase = (const input_base *) pByte;
        pInputBase = (const input_base *) getConstInputByIndex( inputs, i, inputType );


        if ( pInputBase->inConfig == IVAS_AUDIO_CONFIG_INVALID )
        if ( pInputBase->inConfig == IVAS_AUDIO_CONFIG_INVALID )
        {
        {
@@ -3457,7 +3498,7 @@ ivas_error IVAS_REND_AddInput(
    ivas_error error;
    ivas_error error;
    int32_t maxNumInputsOfType;
    int32_t maxNumInputsOfType;
    void *inputsArray;
    void *inputsArray;
    int32_t inputStructSize;
    IVAS_REND_AudioConfigType inputType;
    ivas_error ( *activateInput )( void *, AUDIO_CONFIG, IVAS_REND_InputId, RENDER_CONFIG_DATA *, hrtf_handles * );
    ivas_error ( *activateInput )( void *, AUDIO_CONFIG, IVAS_REND_InputId, RENDER_CONFIG_DATA *, hrtf_handles * );
    int32_t inputIndex;
    int32_t inputIndex;


@@ -3478,30 +3519,27 @@ ivas_error IVAS_REND_AddInput(
        }
        }
    }
    }


    switch ( getAudioConfigType( inConfig ) )
    inputType = getAudioConfigType( inConfig );
    switch ( inputType )
    {
    {
        case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED:
        case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED:
            maxNumInputsOfType = RENDERER_MAX_ISM_INPUTS;
            maxNumInputsOfType = RENDERER_MAX_ISM_INPUTS;
            inputsArray = hIvasRend->inputsIsm;
            inputsArray = hIvasRend->inputsIsm;
            inputStructSize = sizeof( *hIvasRend->inputsIsm );
            activateInput = setRendInputActiveIsm;
            activateInput = setRendInputActiveIsm;
            break;
            break;
        case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED:
        case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED:
            maxNumInputsOfType = RENDERER_MAX_MC_INPUTS;
            maxNumInputsOfType = RENDERER_MAX_MC_INPUTS;
            inputsArray = hIvasRend->inputsMc;
            inputsArray = hIvasRend->inputsMc;
            inputStructSize = sizeof( *hIvasRend->inputsMc );
            activateInput = setRendInputActiveMc;
            activateInput = setRendInputActiveMc;
            break;
            break;
        case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS:
        case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS:
            maxNumInputsOfType = RENDERER_MAX_SBA_INPUTS;
            maxNumInputsOfType = RENDERER_MAX_SBA_INPUTS;
            inputsArray = hIvasRend->inputsSba;
            inputsArray = hIvasRend->inputsSba;
            inputStructSize = sizeof( *hIvasRend->inputsSba );
            activateInput = setRendInputActiveSba;
            activateInput = setRendInputActiveSba;
            break;
            break;
        case IVAS_REND_AUDIO_CONFIG_TYPE_MASA:
        case IVAS_REND_AUDIO_CONFIG_TYPE_MASA:
            maxNumInputsOfType = RENDERER_MAX_MASA_INPUTS;
            maxNumInputsOfType = RENDERER_MAX_MASA_INPUTS;
            inputsArray = hIvasRend->inputsMasa;
            inputsArray = hIvasRend->inputsMasa;
            inputStructSize = sizeof( *hIvasRend->inputsMasa );
            activateInput = setRendInputActiveMasa;
            activateInput = setRendInputActiveMasa;
            break;
            break;
        default:
        default:
@@ -3509,13 +3547,13 @@ ivas_error IVAS_REND_AddInput(
    }
    }


    /* Find first free input in array corresponding to input type */
    /* Find first free input in array corresponding to input type */
    if ( ( error = findFreeInputSlot( inputsArray, inputStructSize, maxNumInputsOfType, &inputIndex ) ) != IVAS_ERR_OK )
    if ( ( error = findFreeInputSlot( inputsArray, inputType, maxNumInputsOfType, &inputIndex ) ) != IVAS_ERR_OK )
    {
    {
        return error;
        return error;
    }
    }


    *inputId = makeInputId( inConfig, inputIndex );
    *inputId = makeInputId( inConfig, inputIndex );
    if ( ( error = activateInput( (uint8_t *) inputsArray + inputStructSize * inputIndex, inConfig, *inputId, hIvasRend->hRendererConfig, &hIvasRend->hHrtfs ) ) != IVAS_ERR_OK )
    if ( ( error = activateInput( getInputByIndex( inputsArray, inputIndex, inputType ), inConfig, *inputId, hIvasRend->hRendererConfig, &hIvasRend->hHrtfs ) ) != IVAS_ERR_OK )
    {
    {
        return error;
        return error;
    }
    }