Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e49af486 authored by Andy Hung's avatar Andy Hung Committed by Gerrit Code Review
Browse files

Merge "libeffects: Introduced on the fly allocation of memories in LVM module"

parents 75c2179c 6d7fe7fd
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ cc_library_static {
        "Bundle/src/LVM_Control.cpp",
        "SpectrumAnalyzer/src/LVPSA_Control.cpp",
        "SpectrumAnalyzer/src/LVPSA_Init.cpp",
        "SpectrumAnalyzer/src/LVPSA_Memory.cpp",
        "SpectrumAnalyzer/src/LVPSA_Process.cpp",
        "SpectrumAnalyzer/src/LVPSA_QPD_Init.cpp",
        "SpectrumAnalyzer/src/LVPSA_QPD_Process.cpp",
+17 −83
Original line number Diff line number Diff line
@@ -69,9 +69,6 @@
/*                                                                                      */
/****************************************************************************************/

/* Memory table*/
#define LVDBE_NR_MEMORY_REGIONS        4                            /* Number of memory regions */

/* Bass Enhancement effect level */
#define LVDBE_EFFECT_03DB            3                              /* Effect defines for backwards compatibility */
#define LVDBE_EFFECT_06DB            6
@@ -112,25 +109,12 @@ typedef enum
    LVDBE_VOLUME_MAX = LVM_MAXINT_32
} LVDBE_Volume_en;

/* Memory Types */
typedef enum
{
    LVDBE_PERSISTENT      = 0,
    LVDBE_PERSISTENT_DATA = 1,
    LVDBE_PERSISTENT_COEF = 2,
    LVDBE_SCRATCH         = 3,
    LVDBE_MEMORY_MAX      = LVM_MAXINT_32

} LVDBE_MemoryTypes_en;

/* Function return status */
typedef enum
{
    LVDBE_SUCCESS        = 0,                        /* Successful return from a routine */
    LVDBE_ALIGNMENTERROR = 1,                        /* Memory alignment error */
    LVDBE_NULLADDRESS    = 2,                        /* NULL allocation address */
    LVDBE_TOOMANYSAMPLES = 3,                        /* Maximum block size exceeded */
    LVDBE_SIZEERROR      = 4,                        /* Incorrect structure size */
    LVDBE_NULLADDRESS    = 1,                        /* NULL allocation address */
    LVDBE_TOOMANYSAMPLES = 2,                        /* Maximum block size exceeded */
    LVDBE_STATUS_MAX     = LVM_MAXINT_32
} LVDBE_ReturnStatus_en;

@@ -213,21 +197,6 @@ typedef enum
/*                                                                                      */
/****************************************************************************************/

/* Memory region definition */
typedef struct
{
    LVM_UINT32                Size;                        /* Region size in bytes */
    LVM_UINT16                Alignment;                  /* Region alignment in bytes */
    LVDBE_MemoryTypes_en      Type;                       /* Region type */
    void                      *pBaseAddress;              /* Pointer to the region base address */
} LVDBE_MemoryRegion_t;

/* Memory table containing the region definitions */
typedef struct
{
    LVDBE_MemoryRegion_t    Region[LVDBE_NR_MEMORY_REGIONS];  /* One definition for each region */
} LVDBE_MemTab_t;

/* Parameter structure */
typedef struct
{
@@ -259,75 +228,40 @@ typedef struct

/****************************************************************************************/
/*                                                                                      */
/* FUNCTION:                 LVDBE_Memory                                               */
/* FUNCTION:                 LVDBE_Init                                                 */
/*                                                                                      */
/* DESCRIPTION:                                                                         */
/*    This function is used for memory allocation and free. It can be called in         */
/*    two ways:                                                                         */
/*                                                                                      */
/*        hInstance = NULL                Returns the memory requirements               */
/*        hInstance = Instance handle        Returns the memory requirements and        */
/*                                        allocated base addresses for the instance     */
/*                                                                                      */
/*    When this function is called for memory allocation (hInstance=NULL) the memory    */
/*  base address pointers are NULL on return.                                           */
/*                                                                                      */
/*    When the function is called for free (hInstance = Instance Handle) the memory     */
/*  table returns the allocated memory and base addresses used during initialisation.   */
/*    Create and initialisation function for the Bass Enhancement module                */
/*                                                                                      */
/* PARAMETERS:                                                                          */
/*  hInstance                Instance Handle                                            */
/*  pMemoryTable             Pointer to an empty memory definition table                */
/*    pCapabilities            Pointer to the default capabilites                       */
/*  phInstance               Pointer to instance handle                                 */
/*  pCapabilities            Pointer to the initialisation capabilities                 */
/*  pScratch                 Pointer to the bundle scratch buffer                       */
/*                                                                                      */
/* RETURNS:                                                                             */
/*  LVDBE_SUCCESS            Succeeded                                                  */
/*  LVDBE_SUCCESS            Initialisation succeeded                                   */
/*  LVDBE_NULLADDRESS        One or more memory has a NULL pointer - malloc failure     */
/*                                                                                      */
/* NOTES:                                                                               */
/*    1.    This function may be interrupted by the LVDBE_Process function              */
/*  1.    This function must not be interrupted by the LVDBE_Process function           */
/*                                                                                      */
/****************************************************************************************/

LVDBE_ReturnStatus_en LVDBE_Memory(LVDBE_Handle_t           hInstance,
                                   LVDBE_MemTab_t           *pMemoryTable,
                                   LVDBE_Capabilities_t     *pCapabilities);
LVDBE_ReturnStatus_en LVDBE_Init(LVDBE_Handle_t           *phInstance,
                                 LVDBE_Capabilities_t     *pCapabilities,
                                 void                     *pScratch);

/****************************************************************************************/
/*                                                                                      */
/* FUNCTION:                 LVDBE_Init                                                 */
/* FUNCTION:                 LVDBE_DeInit                                               */
/*                                                                                      */
/* DESCRIPTION:                                                                         */
/*    Create and initialisation function for the Bass Enhancement module                */
/*                                                                                      */
/*    This function can be used to create an algorithm instance by calling with         */
/*    hInstance set to NULL. In this case the algorithm returns the new instance        */
/*    handle.                                                                           */
/*                                                                                      */
/*    This function can be used to force a full re-initialisation of the algorithm      */
/*    by calling with hInstance = Instance Handle. In this case the memory table        */
/*    should be correct for the instance, this can be ensured by calling the function   */
/*    LVDBE_Memory before calling this function.                                        */
/*    Free the memories created during LVDBE_Init including instance handle             */
/*                                                                                      */
/* PARAMETERS:                                                                          */
/*  hInstance                  Instance handle                                          */
/*  pMemoryTable             Pointer to the memory definition table                     */
/*  pCapabilities            Pointer to the initialisation capabilities                 */
/*                                                                                      */
/* RETURNS:                                                                             */
/*  LVDBE_SUCCESS                Initialisation succeeded                               */
/*  LVDBE_ALIGNMENTERROR        Instance or scratch memory on incorrect alignment       */
/*    LVDBE_NULLADDRESS            One or more memory has a NULL pointer                */
/*                                                                                      */
/* NOTES:                                                                               */
/*  1.     The instance handle is the pointer to the base address of the first memory   */
/*        region.                                                                       */
/*    2.    This function must not be interrupted by the LVDBE_Process function         */
/*  phInstance               Pointer to instance handle                                 */
/*                                                                                      */
/****************************************************************************************/

LVDBE_ReturnStatus_en LVDBE_Init(LVDBE_Handle_t             *phInstance,
                                   LVDBE_MemTab_t           *pMemoryTable,
                                   LVDBE_Capabilities_t     *pCapabilities);
void LVDBE_DeInit(LVDBE_Handle_t         *phInstance);

/****************************************************************************************/
/*                                                                                      */
+58 −139
Original line number Diff line number Diff line
@@ -20,176 +20,60 @@
/*    Includes                                                                          */
/*                                                                                      */
/****************************************************************************************/
#include <stdlib.h>

#include "LVDBE.h"
#include "LVDBE_Private.h"

/****************************************************************************************/
/*                                                                                      */
/* FUNCTION:                 LVDBE_Memory                                               */
/*                                                                                      */
/* DESCRIPTION:                                                                         */
/*    This function is used for memory allocation and free. It can be called in         */
/*    two ways:                                                                         */
/*                                                                                      */
/*        hInstance = NULL                Returns the memory requirements               */
/*        hInstance = Instance handle        Returns the memory requirements and        */
/*                                        allocated base addresses for the instance     */
/*                                                                                      */
/*    When this function is called for memory allocation (hInstance=NULL) the memory    */
/*  base address pointers are NULL on return.                                           */
/*                                                                                      */
/*    When the function is called for free (hInstance = Instance Handle) the memory     */
/*  table returns the allocated memory and base addresses used during initialisation.   */
/*                                                                                      */
/* PARAMETERS:                                                                          */
/*  hInstance                Instance Handle                                            */
/*  pMemoryTable             Pointer to an empty memory definition table                */
/*    pCapabilities           Pointer to the instance capabilities                      */
/*                                                                                      */
/* RETURNS:                                                                             */
/*  LVDBE_SUCCESS            Succeeded                                                  */
/*                                                                                      */
/* NOTES:                                                                               */
/*    1.    This function may be interrupted by the LVDBE_Process function              */
/*                                                                                      */
/****************************************************************************************/

LVDBE_ReturnStatus_en LVDBE_Memory(LVDBE_Handle_t            hInstance,
                                   LVDBE_MemTab_t            *pMemoryTable,
                                   LVDBE_Capabilities_t      *pCapabilities)
{

    LVM_UINT32          ScratchSize;
    LVDBE_Instance_t    *pInstance = (LVDBE_Instance_t *)hInstance;

    /*
     * Fill in the memory table
     */
    if (hInstance == LVM_NULL)
    {
        /*
         * Instance memory
         */
        pMemoryTable->Region[LVDBE_MEMREGION_INSTANCE].Size         = sizeof(LVDBE_Instance_t);
        pMemoryTable->Region[LVDBE_MEMREGION_INSTANCE].Alignment    = LVDBE_INSTANCE_ALIGN;
        pMemoryTable->Region[LVDBE_MEMREGION_INSTANCE].Type         = LVDBE_PERSISTENT;
        pMemoryTable->Region[LVDBE_MEMREGION_INSTANCE].pBaseAddress = LVM_NULL;

        /*
         * Data memory
         */
        pMemoryTable->Region[LVDBE_MEMREGION_PERSISTENT_DATA].Size   = sizeof(LVDBE_Data_FLOAT_t);
        pMemoryTable->Region[LVDBE_MEMREGION_PERSISTENT_DATA].Alignment    = LVDBE_PERSISTENT_DATA_ALIGN;
        pMemoryTable->Region[LVDBE_MEMREGION_PERSISTENT_DATA].Type         = LVDBE_PERSISTENT_DATA;
        pMemoryTable->Region[LVDBE_MEMREGION_PERSISTENT_DATA].pBaseAddress = LVM_NULL;

        /*
         * Coef memory
         */
        pMemoryTable->Region[LVDBE_MEMREGION_PERSISTENT_COEF].Size   = sizeof(LVDBE_Coef_FLOAT_t);
        pMemoryTable->Region[LVDBE_MEMREGION_PERSISTENT_COEF].Alignment    = LVDBE_PERSISTENT_COEF_ALIGN;
        pMemoryTable->Region[LVDBE_MEMREGION_PERSISTENT_COEF].Type         = LVDBE_PERSISTENT_COEF;
        pMemoryTable->Region[LVDBE_MEMREGION_PERSISTENT_COEF].pBaseAddress = LVM_NULL;

        /*
         * Scratch memory
         */
        ScratchSize = (LVM_UINT32)(LVDBE_SCRATCHBUFFERS_INPLACE*sizeof(LVM_FLOAT) * \
                                        pCapabilities->MaxBlockSize);
        pMemoryTable->Region[LVDBE_MEMREGION_SCRATCH].Size         = ScratchSize;
        pMemoryTable->Region[LVDBE_MEMREGION_SCRATCH].Alignment    = LVDBE_SCRATCH_ALIGN;
        pMemoryTable->Region[LVDBE_MEMREGION_SCRATCH].Type         = LVDBE_SCRATCH;
        pMemoryTable->Region[LVDBE_MEMREGION_SCRATCH].pBaseAddress = LVM_NULL;
    }
    else
    {
        /* Read back memory allocation table */
        *pMemoryTable = pInstance->MemoryTable;
    }

    return(LVDBE_SUCCESS);
}

/****************************************************************************************/
/*                                                                                      */
/* FUNCTION:                 LVDBE_Init                                                 */
/*                                                                                      */
/* DESCRIPTION:                                                                         */
/*    Create and initialisation function for the Dynamic Bass Enhancement module        */
/*                                                                                      */
/*    This function can be used to create an algorithm instance by calling with         */
/*    hInstance set to NULL. In this case the algorithm returns the new instance        */
/*    handle.                                                                           */
/*                                                                                      */
/*    This function can be used to force a full re-initialisation of the algorithm      */
/*    by calling with hInstance = Instance Handle. In this case the memory table        */
/*    should be correct for the instance, this can be ensured by calling the function   */
/*    DBE_Memory before calling this function.                                          */
/*    Create and initialisation function for the Bass Enhancement module                */
/*                                                                                      */
/* PARAMETERS:                                                                          */
/*  hInstance                  Instance handle                                          */
/*  pMemoryTable             Pointer to the memory definition table                     */
/*  pCapabilities              Pointer to the instance capabilities                     */
/*  phInstance               Pointer to instance handle                                 */
/*  pCapabilities            Pointer to the initialisation capabilities                 */
/*  pScratch                 Pointer to the bundle scratch buffer                       */
/*                                                                                      */
/* RETURNS:                                                                             */
/*  LVDBE_SUCCESS            Initialisation succeeded                                   */
/*  LVDBE_ALIGNMENTERROR    Instance or scratch memory on incorrect alignment           */
/*    LVDBE_NULLADDRESS        Instance or scratch memory has a NULL pointer            */
/*  LVDBE_NULLADDRESS        One or more memory has a NULL pointer - malloc failure     */
/*                                                                                      */
/* NOTES:                                                                               */
/*  1.     The instance handle is the pointer to the base address of the first memory   */
/*        region.                                                                       */
/*    2.    This function must not be interrupted by the LVDBE_Process function         */
/*  1.    This function must not be interrupted by the LVDBE_Process function           */
/*                                                                                      */
/****************************************************************************************/

LVDBE_ReturnStatus_en LVDBE_Init(LVDBE_Handle_t       *phInstance,
                                   LVDBE_MemTab_t       *pMemoryTable,
                                   LVDBE_Capabilities_t *pCapabilities)
                                 LVDBE_Capabilities_t *pCapabilities,
                                 void                 *pScratch)
{

    LVDBE_Instance_t      *pInstance;
    LVMixer3_1St_FLOAT_st *pMixer_Instance;
    LVMixer3_2St_FLOAT_st *pBypassMixer_Instance;
    LVM_FLOAT             MixGain;
    LVM_INT16             i;

    /*
     * Set the instance handle if not already initialised
     * Create the instance handle if not already initialised
     */
    if (*phInstance == LVM_NULL)
    {
        *phInstance = (LVDBE_Handle_t)pMemoryTable->Region[LVDBE_MEMREGION_INSTANCE].pBaseAddress;
        *phInstance = calloc(1, sizeof(*pInstance));
    }
    pInstance =(LVDBE_Instance_t  *)*phInstance;

    /*
     * Check the memory table for NULL pointers and incorrectly aligned data
     */
    for (i=0; i<LVDBE_NR_MEMORY_REGIONS; i++)
    {
        if (pMemoryTable->Region[i].Size!=0)
        {
            if (pMemoryTable->Region[i].pBaseAddress==LVM_NULL)
    if (*phInstance == LVM_NULL)
    {
                return(LVDBE_NULLADDRESS);
            }
            if (((uintptr_t)pMemoryTable->Region[i].pBaseAddress % pMemoryTable->Region[i].Alignment)!=0){
                return(LVDBE_ALIGNMENTERROR);
            }
        }
        return LVDBE_NULLADDRESS;
    }
    pInstance =(LVDBE_Instance_t  *)*phInstance;

    /*
     * Save the memory table in the instance structure
     */
    pInstance->Capabilities = *pCapabilities;

    /*
     * Save the memory table in the instance structure
     */
    pInstance->MemoryTable = *pMemoryTable;
    pInstance->pScratch = pScratch;

    /*
     * Set the default instance parameters
@@ -204,12 +88,18 @@ LVDBE_ReturnStatus_en LVDBE_Init(LVDBE_Handle_t *phInstance,
    pInstance->Params.VolumedB          =    0;

    /*
     * Set pointer to data and coef memory
     * Create pointer to data and coef memory
     */
    pInstance->pData =
         (LVDBE_Data_FLOAT_t *)pMemoryTable->Region[LVDBE_MEMREGION_PERSISTENT_DATA].pBaseAddress;
    pInstance->pCoef =
         (LVDBE_Coef_FLOAT_t *)pMemoryTable->Region[LVDBE_MEMREGION_PERSISTENT_COEF].pBaseAddress;
    pInstance->pData = (LVDBE_Data_FLOAT_t *)calloc(1, sizeof(*(pInstance->pData)));
    if (pInstance->pData == NULL)
    {
        return LVDBE_NULLADDRESS;
    }
    pInstance->pCoef = (LVDBE_Coef_FLOAT_t *)calloc(1, sizeof(*(pInstance->pCoef)));
    if (pInstance->pCoef == NULL)
    {
        return LVDBE_NULLADDRESS;
    }

    /*
     * Initialise the filters
@@ -278,3 +168,32 @@ LVDBE_ReturnStatus_en LVDBE_Init(LVDBE_Handle_t *phInstance,

    return(LVDBE_SUCCESS);
}

/****************************************************************************************/
/*                                                                                      */
/* FUNCTION:                 LVDBE_DeInit                                               */
/*                                                                                      */
/* DESCRIPTION:                                                                         */
/*    Free the memories created during LVDBE_Init including instance handle             */
/*                                                                                      */
/* PARAMETERS:                                                                          */
/*  phInstance               Pointer to instance handle                                 */
/*                                                                                      */
/****************************************************************************************/
void LVDBE_DeInit(LVDBE_Handle_t *phInstance)
{
    LVDBE_Instance_t *pInstance = (LVDBE_Instance_t *)*phInstance;
    if (pInstance == LVM_NULL) {
        return;
    }
    if (pInstance->pData != LVM_NULL) {
        free(pInstance->pData);
        pInstance->pData = LVM_NULL;
    }
    if (pInstance->pCoef != LVM_NULL) {
        free(pInstance->pCoef);
        pInstance->pCoef = LVM_NULL;
    }
    free(pInstance);
    *phInstance = LVM_NULL;
}
+1 −15
Original line number Diff line number Diff line
@@ -47,20 +47,6 @@
/* General */
#define    LVDBE_INVALID            0xFFFF        /* Invalid init parameter */

/* Memory */
#define LVDBE_MEMREGION_INSTANCE         0       /* Offset to the instance memory region */
#define LVDBE_MEMREGION_PERSISTENT_DATA  1       /* Offset to persistent data memory region */
#define LVDBE_MEMREGION_PERSISTENT_COEF  2       /* Offset to persistent coefficient region */
#define LVDBE_MEMREGION_SCRATCH          3       /* Offset to data scratch memory region */

#define LVDBE_INSTANCE_ALIGN             4       /* 32-bit alignment for structures */
#define LVDBE_PERSISTENT_DATA_ALIGN      4       /* 32-bit alignment for data */
#define LVDBE_PERSISTENT_COEF_ALIGN      4       /* 32-bit alignment for coef */
#define LVDBE_SCRATCH_ALIGN              4       /* 32-bit alignment for long data */

/* Number of buffers required for inplace processing */
#define LVDBE_SCRATCHBUFFERS_INPLACE     (LVM_MAX_CHANNELS * 3)

#define LVDBE_MIXER_TC                   5       /* Mixer time  */
#define LVDBE_BYPASS_MIXER_TC            100     /* Bypass mixer time */

@@ -96,13 +82,13 @@ typedef struct
typedef struct
{
    /* Public parameters */
    LVDBE_MemTab_t                MemoryTable;        /* Instance memory allocation table */
    LVDBE_Params_t                Params;             /* Instance parameters */
    LVDBE_Capabilities_t        Capabilities;         /* Instance capabilities */

    /* Data and coefficient pointers */
    LVDBE_Data_FLOAT_t                *pData;                /* Instance data */
    LVDBE_Coef_FLOAT_t                *pCoef;                /* Instance coefficients */
    void                        *pScratch;             /* scratch pointer */
} LVDBE_Instance_t;

/****************************************************************************************/
+1 −2

File changed.

Preview size limit exceeded, changes collapsed.

Loading