1 /* 2 * Copyright (C) 2004-2010 NXP Software 3 * Copyright (C) 2010 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #ifndef _LVPSA_PRIVATE_H_ 19 #define _LVPSA_PRIVATE_H_ 20 21 #include <audio_utils/BiquadFilter.h> 22 #include "LVPSA.h" 23 #include "BIQUAD.h" 24 #include "LVPSA_QPD.h" 25 #include "LVM_Macros.h" 26 27 /********************************************************************************** 28 CONSTANT DEFINITIONS 29 ***********************************************************************************/ 30 31 #define LVPSA_NR_SUPPORTED_RATE 13 /* From 8000Hz to 192000Hz*/ 32 #define LVPSA_NR_SUPPORTED_SPEED \ 33 3 /* LOW, MEDIUM, HIGH */ 34 35 #define LVPSA_MAXBUFFERDURATION \ 36 4000 /* Maximum length in ms of the levels buffer */ 37 #define LVPSA_MAXINPUTBLOCKSIZE \ 38 5000 /* Maximum length in mono samples of the block to process */ 39 #define LVPSA_NBANDSMIN 1 /* Minimum number of frequency band */ 40 #define LVPSA_NBANDSMAX 30 /* Maximum number of frequency band */ 41 #define LVPSA_MAXCENTERFREQ \ 42 20000 /* Maximum possible center frequency */ 43 #define LVPSA_MINPOSTGAIN \ 44 (-15) /* Minimum possible post gain */ 45 #define LVPSA_MAXPOSTGAIN 15 /* Maximum possible post gain */ 46 #define LVPSA_MINQFACTOR 25 /* Minimum possible Q factor */ 47 #define LVPSA_MAXQFACTOR 1200 /* Maximum possible Q factor */ 48 49 #define LVPSA_MAXLEVELDECAYFACTOR \ 50 0x4111 /* Decay factor for the maximum values calculation */ 51 #define LVPSA_MAXLEVELDECAYSHIFT \ 52 14 /* Decay shift for the maximum values calculation */ 53 54 #define LVPSA_MAXUNSIGNEDCHAR 0xFF 55 56 #define LVPSA_FsInvertShift 31 57 #define LVPSA_GAINSHIFT 11 58 #define LVPSA_FREQSHIFT 25 59 60 /********************************************************************************** 61 TYPES DEFINITIONS 62 ***********************************************************************************/ 63 64 #define LVPSA_InternalRefreshTime 0x0014 /* 20 ms (50Hz) in Q16.0 */ 65 #define LVPSA_InternalRefreshTimeInv 0x0666 /* 1/20ms left shifted by 15 */ 66 #define LVPSA_InternalRefreshTimeShift 15 67 68 /* Precision of the filter */ 69 typedef enum { 70 LVPSA_SimplePrecisionFilter, /* Simple precision */ 71 LVPSA_DoublePrecisionFilter /* Double precision */ 72 } LVPSA_BPFilterPrecision_en; 73 74 typedef struct { 75 LVM_CHAR bControlPending; /* Flag incating a change of the control parameters */ 76 LVM_UINT16 nBands; /* Number of bands of the spectrum analyzer */ 77 LVM_UINT16 MaxInputBlockSize; /* Maximum input data buffer size */ 78 79 LVPSA_ControlParams_t CurrentParams; /* Current control parameters of the module */ 80 LVPSA_ControlParams_t NewParams; /* New control parameters given by the user */ 81 void* pScratch; 82 /* Pointer to bundle scratch buffer */ 83 84 LVPSA_BPFilterPrecision_en* pBPFiltersPrecision; /* Points a nBands elements array that contains 85 the filter precision for each band */ 86 std::vector<android::audio_utils::BiquadFilter<LVM_FLOAT>> 87 specBiquad; /* Biquad filter instances */ 88 /* Points a nBands elements array that contains the QPD filter instance for each band */ 89 QPD_FLOAT_State_t* pQPD_States; 90 /* Points a nBands elements array that contains the QPD filter taps for each band */ 91 QPD_FLOAT_Taps_t* pQPD_Taps; 92 93 /* Points a nBands elements array that contains the post-filter gains for each band */ 94 LVM_FLOAT* pPostGains; 95 LVPSA_FilterParam_t* 96 pFiltersParams; /* Copy of the filters parameters from the input parameters */ 97 98 LVM_UINT16 nSamplesBufferUpdate; /* Number of samples to make 20ms */ 99 LVM_INT32 BufferUpdateSamplesCount; /* Counter used to know when to put a new value in the 100 buffer */ 101 LVM_UINT16 nRelevantFilters; /* Number of relevant filters depending on sampling frequency and 102 bands center frequency */ 103 LVM_UINT16 LocalSamplesCount; /* Counter used to update the SpectralDataBufferAudioTime */ 104 105 LVM_UINT16 DownSamplingFactor; /* Down sampling factor depending on the sampling frequency */ 106 LVM_UINT16 DownSamplingCount; /* Counter used for the downsampling handling */ 107 108 LVM_UINT16 SpectralDataBufferDuration; /* Length of the buffer in time (ms) defined by the 109 application */ 110 LVM_UINT8* pSpectralDataBufferStart; /* Starting address of the buffer */ 111 LVM_UINT8* pSpectralDataBufferWritePointer; /* Current position of the writing pointer of the 112 buffer */ 113 LVPSA_Time SpectralDataBufferAudioTime; /* AudioTime at which the last value save occurred in 114 the buffer */ 115 LVM_UINT32 116 SpectralDataBufferLength; /* Number of spectrum data value that the buffer can contain 117 (per band) = SpectralDataBufferDuration/20ms */ 118 119 LVM_UINT8* pPreviousPeaks; /* Points to a nBands elements array that contains the previous peak 120 value of the level detection. Those values are decremented after 121 each call to the GetSpectrum function */ 122 123 } LVPSA_InstancePr_t, *pLVPSA_InstancePr_t; 124 125 /********************************************************************************** 126 FUNCTIONS PROTOTYPE 127 ***********************************************************************************/ 128 /************************************************************************************/ 129 /* */ 130 /* FUNCTION: LVPSA_ApplyNewSettings */ 131 /* */ 132 /* DESCRIPTION: */ 133 /* Reinitialize some parameters and changes filters' coefficients if */ 134 /* some control parameters have changed. */ 135 /* */ 136 /* PARAMETERS: */ 137 /* pInst Pointer to the instance */ 138 /* */ 139 /* RETURNS: */ 140 /* LVPSA_OK Always succeeds */ 141 /* */ 142 /************************************************************************************/ 143 LVPSA_RETURN LVPSA_ApplyNewSettings(LVPSA_InstancePr_t* pInst); 144 145 #endif /* _LVPSA_PRIVATE_H */ 146