From 2c8e5cab3faa6d360e222b7a6c40a80083d021ac Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Fri, 9 Jul 2010 12:28:50 -0700 Subject: First submission of audio effect library from NXP software. This CL contains the first open sourceable version of the audio effect library from NXP software. The effects implemented are: - Bass boost - Virtualizer (stereo widening) - Equalizer - Spectrum analyzer Source file for the effect engines are located under libeffects/lvm/lib The wrapper implementing the interface with the audio effect framework in under libeffects/lvm/wrapper The code of other effect libraries has also been reorganized fo clarity: - the effect factory is now under libeffects/factory - the test equalizer and reverb effects are under libeffect/testlibs - the visualizer is under libeffects/virtualizer Change-Id: I8d91e2181f81b89f8fc0c1e1e6bf552c5809b2eb --- media/libeffects/Android.mk | 127 - media/libeffects/AudioBiquadFilter.cpp | 260 -- media/libeffects/AudioBiquadFilter.h | 180 -- media/libeffects/AudioCoefInterpolator.cpp | 84 - media/libeffects/AudioCoefInterpolator.h | 98 - media/libeffects/AudioCommon.h | 92 - media/libeffects/AudioEqualizer.cpp | 315 --- media/libeffects/AudioEqualizer.h | 246 -- media/libeffects/AudioFormatAdapter.h | 184 -- media/libeffects/AudioHighShelfFilterCoef.inl | 225 -- media/libeffects/AudioLowShelfFilterCoef.inl | 375 --- media/libeffects/AudioPeakingFilter.cpp | 121 - media/libeffects/AudioPeakingFilter.h | 151 -- media/libeffects/AudioPeakingFilterCoef.inl | 2700 -------------------- media/libeffects/AudioShelvingFilter.cpp | 109 - media/libeffects/AudioShelvingFilter.h | 146 -- media/libeffects/EffectEqualizer.cpp | 653 ----- media/libeffects/EffectReverb.c | 2135 ---------------- media/libeffects/EffectReverb.h | 437 ---- media/libeffects/EffectVisualizer.cpp | 401 --- media/libeffects/EffectsFactory.c | 642 ----- media/libeffects/EffectsFactory.h | 56 - media/libeffects/EffectsMath.c | 143 -- media/libeffects/EffectsMath.h | 424 --- media/libeffects/factory/Android.mk | 25 + media/libeffects/factory/EffectsFactory.c | 642 +++++ media/libeffects/factory/EffectsFactory.h | 56 + media/libeffects/lvm/lib/Android.mk | 124 + media/libeffects/lvm/lib/Bass/lib/LVDBE.h | 472 ++++ media/libeffects/lvm/lib/Bass/src/LVDBE_Coeffs.h | 518 ++++ media/libeffects/lvm/lib/Bass/src/LVDBE_Control.c | 377 +++ media/libeffects/lvm/lib/Bass/src/LVDBE_Init.c | 267 ++ media/libeffects/lvm/lib/Bass/src/LVDBE_Private.h | 148 ++ media/libeffects/lvm/lib/Bass/src/LVDBE_Process.c | 205 ++ media/libeffects/lvm/lib/Bass/src/LVDBE_Tables.c | 463 ++++ media/libeffects/lvm/lib/Bass/src/LVDBE_Tables.h | 93 + media/libeffects/lvm/lib/Bundle/lib/LVM.h | 637 +++++ .../lvm/lib/Bundle/src/LVM_API_Specials.c | 158 ++ media/libeffects/lvm/lib/Bundle/src/LVM_Buffers.c | 878 +++++++ media/libeffects/lvm/lib/Bundle/src/LVM_Coeffs.h | 573 +++++ media/libeffects/lvm/lib/Bundle/src/LVM_Control.c | 1032 ++++++++ media/libeffects/lvm/lib/Bundle/src/LVM_Init.c | 1003 ++++++++ media/libeffects/lvm/lib/Bundle/src/LVM_Private.h | 292 +++ media/libeffects/lvm/lib/Bundle/src/LVM_Process.c | 283 ++ media/libeffects/lvm/lib/Bundle/src/LVM_Tables.c | 397 +++ media/libeffects/lvm/lib/Bundle/src/LVM_Tables.h | 67 + media/libeffects/lvm/lib/Common/lib/AGC.h | 92 + media/libeffects/lvm/lib/Common/lib/BIQUAD.h | 341 +++ media/libeffects/lvm/lib/Common/lib/CompLim.h | 91 + media/libeffects/lvm/lib/Common/lib/Filter.h | 71 + media/libeffects/lvm/lib/Common/lib/InstAlloc.h | 99 + media/libeffects/lvm/lib/Common/lib/LVM_Common.h | 69 + media/libeffects/lvm/lib/Common/lib/LVM_Macros.h | 130 + media/libeffects/lvm/lib/Common/lib/LVM_Timer.h | 89 + media/libeffects/lvm/lib/Common/lib/LVM_Types.h | 195 ++ media/libeffects/lvm/lib/Common/lib/Mixer.h | 135 + .../lvm/lib/Common/lib/ScalarArithmetic.h | 68 + .../lvm/lib/Common/lib/VectorArithmetic.h | 189 ++ .../lib/Common/src/AGC_MIX_VOL_2St1Mon_D32_WRA.c | 204 ++ media/libeffects/lvm/lib/Common/src/Abs_32.c | 58 + .../libeffects/lvm/lib/Common/src/Add2_Sat_16x16.c | 64 + .../libeffects/lvm/lib/Common/src/Add2_Sat_32x32.c | 69 + .../lib/Common/src/BP_1I_D16F16C14_TRC_WRA_01.c | 90 + .../Common/src/BP_1I_D16F16Css_TRC_WRA_01_Init.c | 59 + .../src/BP_1I_D16F16Css_TRC_WRA_01_Private.h | 38 + .../lib/Common/src/BP_1I_D16F32C30_TRC_WRA_01.c | 92 + .../Common/src/BP_1I_D16F32Cll_TRC_WRA_01_Init.c | 69 + .../src/BP_1I_D16F32Cll_TRC_WRA_01_Private.h | 38 + .../lib/Common/src/BP_1I_D32F32C30_TRC_WRA_02.c | 90 + .../Common/src/BP_1I_D32F32Cll_TRC_WRA_02_Init.c | 60 + .../src/BP_1I_D32F32Cll_TRC_WRA_02_Private.h | 38 + .../lib/Common/src/BQ_1I_D16F16C15_TRC_WRA_01.c | 94 + .../Common/src/BQ_1I_D16F16Css_TRC_WRA_01_Init.c | 66 + .../src/BQ_1I_D16F16Css_TRC_WRA_01_Private.h | 38 + .../lib/Common/src/BQ_1I_D16F32C14_TRC_WRA_01.c | 93 + .../src/BQ_1I_D16F32Css_TRC_WRA_01_Private.h | 38 + .../Common/src/BQ_1I_D16F32Css_TRC_WRA_01_init.c | 67 + .../lib/Common/src/BQ_2I_D16F16C14_TRC_WRA_01.c | 123 + .../lib/Common/src/BQ_2I_D16F16C15_TRC_WRA_01.c | 123 + .../Common/src/BQ_2I_D16F16Css_TRC_WRA_01_Init.c | 67 + .../src/BQ_2I_D16F16Css_TRC_WRA_01_Private.h | 40 + .../lib/Common/src/BQ_2I_D16F32C13_TRC_WRA_01.c | 127 + .../lib/Common/src/BQ_2I_D16F32C14_TRC_WRA_01.c | 126 + .../lib/Common/src/BQ_2I_D16F32C15_TRC_WRA_01.c | 126 + .../src/BQ_2I_D16F32Css_TRC_WRA_01_Private.h | 40 + .../Common/src/BQ_2I_D16F32Css_TRC_WRA_01_init.c | 67 + .../lib/Common/src/BQ_2I_D32F32C30_TRC_WRA_01.c | 135 + .../Common/src/BQ_2I_D32F32Cll_TRC_WRA_01_Init.c | 66 + .../src/BQ_2I_D32F32Cll_TRC_WRA_01_Private.h | 41 + .../lvm/lib/Common/src/CompLim_private.h | 52 + media/libeffects/lvm/lib/Common/src/Copy_16.c | 66 + .../lib/Common/src/Core_MixHard_2St_D32C31_SAT.c | 69 + .../lvm/lib/Common/src/Core_MixInSoft_D32C31_SAT.c | 103 + .../lib/Common/src/Core_MixSoft_1St_D32C31_WRA.c | 112 + .../lvm/lib/Common/src/DC_2I_D16_TRC_WRA_01.c | 76 + .../lvm/lib/Common/src/DC_2I_D16_TRC_WRA_01_Init.c | 36 + .../lib/Common/src/DC_2I_D16_TRC_WRA_01_Private.h | 43 + .../lib/Common/src/DelayAllPass_Sat_32x16To32.c | 113 + .../libeffects/lvm/lib/Common/src/DelayMix_16x16.c | 81 + .../libeffects/lvm/lib/Common/src/DelayWrite_32.c | 66 + .../lib/Common/src/FO_1I_D16F16C15_TRC_WRA_01.c | 83 + .../Common/src/FO_1I_D16F16Css_TRC_WRA_01_Init.c | 63 + .../src/FO_1I_D16F16Css_TRC_WRA_01_Private.h | 40 + .../lib/Common/src/FO_1I_D32F32C31_TRC_WRA_01.c | 83 + .../Common/src/FO_1I_D32F32Cll_TRC_WRA_01_Init.c | 66 + .../src/FO_1I_D32F32Cll_TRC_WRA_01_Private.h | 41 + .../Common/src/FO_2I_D16F32C15_LShx_TRC_WRA_01.c | 137 + .../src/FO_2I_D16F32Css_LShx_TRC_WRA_01_Init.c | 65 + .../src/FO_2I_D16F32Css_LShx_TRC_WRA_01_Private.h | 41 + media/libeffects/lvm/lib/Common/src/Filters.h | 74 + .../lvm/lib/Common/src/From2iToMS_16x16.c | 65 + .../lvm/lib/Common/src/From2iToMono_16.c | 57 + .../lvm/lib/Common/src/From2iToMono_32.c | 58 + media/libeffects/lvm/lib/Common/src/InstAlloc.c | 194 ++ .../lvm/lib/Common/src/Int16LShiftToInt32_16x32.c | 56 + .../lib/Common/src/Int32RShiftToInt16_Sat_32x16.c | 68 + .../libeffects/lvm/lib/Common/src/JoinTo2i_32x32.c | 63 + .../src/LVC_Core_MixHard_1St_2i_D16C31_SAT.c | 77 + .../Common/src/LVC_Core_MixHard_2St_D16C31_SAT.c | 67 + .../lib/Common/src/LVC_Core_MixInSoft_D16C31_SAT.c | 136 + .../src/LVC_Core_MixSoft_1St_2i_D16C31_WRA.c | 151 ++ .../Common/src/LVC_Core_MixSoft_1St_D16C31_WRA.c | 114 + .../lvm/lib/Common/src/LVC_MixInSoft_D16C31_SAT.c | 120 + .../lib/Common/src/LVC_MixSoft_1St_2i_D16C31_SAT.c | 160 ++ .../lib/Common/src/LVC_MixSoft_1St_D16C31_SAT.c | 119 + .../lib/Common/src/LVC_MixSoft_2St_D16C31_SAT.c | 78 + media/libeffects/lvm/lib/Common/src/LVC_Mixer.h | 144 ++ .../lvm/lib/Common/src/LVC_Mixer_GetCurrent.c | 50 + .../lvm/lib/Common/src/LVC_Mixer_GetTarget.c | 51 + .../libeffects/lvm/lib/Common/src/LVC_Mixer_Init.c | 76 + .../lvm/lib/Common/src/LVC_Mixer_Private.h | 136 + .../lvm/lib/Common/src/LVC_Mixer_SetTarget.c | 75 + .../lvm/lib/Common/src/LVC_Mixer_SetTimeConstant.c | 84 + .../src/LVC_Mixer_VarSlope_SetTimeConstant.c | 104 + media/libeffects/lvm/lib/Common/src/LVM_FO_HPF.c | 109 + media/libeffects/lvm/lib/Common/src/LVM_FO_LPF.c | 106 + media/libeffects/lvm/lib/Common/src/LVM_GetOmega.c | 79 + .../lvm/lib/Common/src/LVM_Mixer_FilterCoeffs.h | 100 + .../lvm/lib/Common/src/LVM_Mixer_TimeConstant.c | 165 ++ .../libeffects/lvm/lib/Common/src/LVM_Polynomial.c | 105 + media/libeffects/lvm/lib/Common/src/LVM_Power10.c | 87 + media/libeffects/lvm/lib/Common/src/LVM_Timer.c | 57 + .../libeffects/lvm/lib/Common/src/LVM_Timer_Init.c | 63 + .../lvm/lib/Common/src/LVM_Timer_Private.h | 61 + media/libeffects/lvm/lib/Common/src/LoadConst_16.c | 51 + media/libeffects/lvm/lib/Common/src/LoadConst_32.c | 52 + .../lvm/lib/Common/src/MSTo2i_Sat_16x16.c | 88 + .../lvm/lib/Common/src/Mac3s_Sat_16x16.c | 81 + .../lvm/lib/Common/src/Mac3s_Sat_32x16.c | 80 + .../lvm/lib/Common/src/MixInSoft_D32C31_SAT.c | 104 + .../lvm/lib/Common/src/MixSoft_1St_D32C31_WRA.c | 104 + .../lvm/lib/Common/src/MixSoft_2St_D32C31_SAT.c | 72 + .../libeffects/lvm/lib/Common/src/Mixer_private.h | 44 + media/libeffects/lvm/lib/Common/src/MonoTo2I_16.c | 57 + media/libeffects/lvm/lib/Common/src/MonoTo2I_32.c | 58 + media/libeffects/lvm/lib/Common/src/Mult3s_32x16.c | 60 + .../libeffects/lvm/lib/Common/src/NonLinComp_D16.c | 125 + .../lib/Common/src/PK_2I_D32F32C14G11_TRC_WRA_01.c | 130 + .../lib/Common/src/PK_2I_D32F32C30G11_TRC_WRA_01.c | 128 + .../src/PK_2I_D32F32CllGss_TRC_WRA_01_Init.c | 47 + .../src/PK_2I_D32F32CllGss_TRC_WRA_01_Private.h | 40 + .../src/PK_2I_D32F32CssGss_TRC_WRA_01_Init.c | 46 + .../src/PK_2I_D32F32CssGss_TRC_WRA_01_Private.h | 41 + .../lvm/lib/Common/src/Shift_Sat_v16xv16.c | 89 + .../lvm/lib/Common/src/Shift_Sat_v32xv32.c | 92 + media/libeffects/lvm/lib/Common/src/dB_to_Lin32.c | 109 + media/libeffects/lvm/lib/Common/src/mult3s_16x16.c | 56 + media/libeffects/lvm/lib/Eq/lib/LVEQNB.h | 484 ++++ media/libeffects/lvm/lib/Eq/src/LVEQNB_CalcCoef.c | 306 +++ media/libeffects/lvm/lib/Eq/src/LVEQNB_Coeffs.h | 106 + media/libeffects/lvm/lib/Eq/src/LVEQNB_Control.c | 501 ++++ media/libeffects/lvm/lib/Eq/src/LVEQNB_Init.c | 329 +++ media/libeffects/lvm/lib/Eq/src/LVEQNB_Private.h | 141 + media/libeffects/lvm/lib/Eq/src/LVEQNB_Process.c | 208 ++ media/libeffects/lvm/lib/Eq/src/LVEQNB_Tables.c | 203 ++ .../lvm/lib/SpectrumAnalyzer/lib/LVPSA.h | 298 +++ .../lvm/lib/SpectrumAnalyzer/src/LVPSA_Control.c | 715 ++++++ .../lvm/lib/SpectrumAnalyzer/src/LVPSA_Init.c | 197 ++ .../lvm/lib/SpectrumAnalyzer/src/LVPSA_Memory.c | 177 ++ .../lvm/lib/SpectrumAnalyzer/src/LVPSA_Private.h | 159 ++ .../lvm/lib/SpectrumAnalyzer/src/LVPSA_Process.c | 260 ++ .../lvm/lib/SpectrumAnalyzer/src/LVPSA_QPD.h | 98 + .../lvm/lib/SpectrumAnalyzer/src/LVPSA_QPD_Init.c | 50 + .../lib/SpectrumAnalyzer/src/LVPSA_QPD_Process.c | 220 ++ .../lvm/lib/SpectrumAnalyzer/src/LVPSA_Tables.c | 250 ++ media/libeffects/lvm/lib/StereoWidening/lib/LVCS.h | 396 +++ .../lvm/lib/StereoWidening/src/LVCS_BypassMix.c | 303 +++ .../lvm/lib/StereoWidening/src/LVCS_BypassMix.h | 89 + .../lvm/lib/StereoWidening/src/LVCS_Control.c | 273 ++ .../lvm/lib/StereoWidening/src/LVCS_Equaliser.c | 167 ++ .../lvm/lib/StereoWidening/src/LVCS_Equaliser.h | 66 + .../lib/StereoWidening/src/LVCS_Headphone_Coeffs.h | 398 +++ .../lvm/lib/StereoWidening/src/LVCS_Init.c | 233 ++ .../lvm/lib/StereoWidening/src/LVCS_Private.h | 171 ++ .../lvm/lib/StereoWidening/src/LVCS_Process.c | 271 ++ .../lib/StereoWidening/src/LVCS_ReverbGenerator.c | 272 ++ .../lib/StereoWidening/src/LVCS_ReverbGenerator.h | 98 + .../lib/StereoWidening/src/LVCS_StereoEnhancer.c | 266 ++ .../lib/StereoWidening/src/LVCS_StereoEnhancer.h | 88 + .../lvm/lib/StereoWidening/src/LVCS_Tables.c | 456 ++++ .../lvm/lib/StereoWidening/src/LVCS_Tables.h | 159 ++ media/libeffects/lvm/wrapper/Android.mk | 30 + .../libeffects/lvm/wrapper/Bundle/EffectBundle.cpp | 2609 +++++++++++++++++++ media/libeffects/lvm/wrapper/Bundle/EffectBundle.h | 193 ++ media/libeffects/testlibs/Android.mk_ | 66 + media/libeffects/testlibs/AudioBiquadFilter.cpp | 260 ++ media/libeffects/testlibs/AudioBiquadFilter.h | 180 ++ .../libeffects/testlibs/AudioCoefInterpolator.cpp | 84 + media/libeffects/testlibs/AudioCoefInterpolator.h | 98 + media/libeffects/testlibs/AudioCommon.h | 92 + media/libeffects/testlibs/AudioEqualizer.cpp | 315 +++ media/libeffects/testlibs/AudioEqualizer.h | 246 ++ media/libeffects/testlibs/AudioFormatAdapter.h | 184 ++ .../testlibs/AudioHighShelfFilterCoef.inl | 225 ++ .../testlibs/AudioLowShelfFilterCoef.inl | 375 +++ media/libeffects/testlibs/AudioPeakingFilter.cpp | 121 + media/libeffects/testlibs/AudioPeakingFilter.h | 151 ++ .../libeffects/testlibs/AudioPeakingFilterCoef.inl | 2700 ++++++++++++++++++++ media/libeffects/testlibs/AudioShelvingFilter.cpp | 109 + media/libeffects/testlibs/AudioShelvingFilter.h | 146 ++ media/libeffects/testlibs/EffectEqualizer.cpp | 654 +++++ media/libeffects/testlibs/EffectReverb.c | 2135 ++++++++++++++++ media/libeffects/testlibs/EffectReverb.h | 437 ++++ media/libeffects/testlibs/EffectsMath.c | 143 ++ media/libeffects/testlibs/EffectsMath.h | 424 +++ media/libeffects/visualizer/Android.mk | 30 + media/libeffects/visualizer/EffectVisualizer.cpp | 401 +++ 227 files changed, 40040 insertions(+), 10304 deletions(-) delete mode 100644 media/libeffects/Android.mk delete mode 100644 media/libeffects/AudioBiquadFilter.cpp delete mode 100644 media/libeffects/AudioBiquadFilter.h delete mode 100644 media/libeffects/AudioCoefInterpolator.cpp delete mode 100644 media/libeffects/AudioCoefInterpolator.h delete mode 100644 media/libeffects/AudioCommon.h delete mode 100644 media/libeffects/AudioEqualizer.cpp delete mode 100644 media/libeffects/AudioEqualizer.h delete mode 100644 media/libeffects/AudioFormatAdapter.h delete mode 100644 media/libeffects/AudioHighShelfFilterCoef.inl delete mode 100644 media/libeffects/AudioLowShelfFilterCoef.inl delete mode 100644 media/libeffects/AudioPeakingFilter.cpp delete mode 100644 media/libeffects/AudioPeakingFilter.h delete mode 100644 media/libeffects/AudioPeakingFilterCoef.inl delete mode 100644 media/libeffects/AudioShelvingFilter.cpp delete mode 100644 media/libeffects/AudioShelvingFilter.h delete mode 100644 media/libeffects/EffectEqualizer.cpp delete mode 100644 media/libeffects/EffectReverb.c delete mode 100644 media/libeffects/EffectReverb.h delete mode 100644 media/libeffects/EffectVisualizer.cpp delete mode 100644 media/libeffects/EffectsFactory.c delete mode 100644 media/libeffects/EffectsFactory.h delete mode 100644 media/libeffects/EffectsMath.c delete mode 100644 media/libeffects/EffectsMath.h create mode 100644 media/libeffects/factory/Android.mk create mode 100644 media/libeffects/factory/EffectsFactory.c create mode 100644 media/libeffects/factory/EffectsFactory.h create mode 100644 media/libeffects/lvm/lib/Android.mk create mode 100755 media/libeffects/lvm/lib/Bass/lib/LVDBE.h create mode 100755 media/libeffects/lvm/lib/Bass/src/LVDBE_Coeffs.h create mode 100755 media/libeffects/lvm/lib/Bass/src/LVDBE_Control.c create mode 100755 media/libeffects/lvm/lib/Bass/src/LVDBE_Init.c create mode 100755 media/libeffects/lvm/lib/Bass/src/LVDBE_Private.h create mode 100755 media/libeffects/lvm/lib/Bass/src/LVDBE_Process.c create mode 100755 media/libeffects/lvm/lib/Bass/src/LVDBE_Tables.c create mode 100755 media/libeffects/lvm/lib/Bass/src/LVDBE_Tables.h create mode 100755 media/libeffects/lvm/lib/Bundle/lib/LVM.h create mode 100755 media/libeffects/lvm/lib/Bundle/src/LVM_API_Specials.c create mode 100755 media/libeffects/lvm/lib/Bundle/src/LVM_Buffers.c create mode 100755 media/libeffects/lvm/lib/Bundle/src/LVM_Coeffs.h create mode 100755 media/libeffects/lvm/lib/Bundle/src/LVM_Control.c create mode 100755 media/libeffects/lvm/lib/Bundle/src/LVM_Init.c create mode 100755 media/libeffects/lvm/lib/Bundle/src/LVM_Private.h create mode 100755 media/libeffects/lvm/lib/Bundle/src/LVM_Process.c create mode 100755 media/libeffects/lvm/lib/Bundle/src/LVM_Tables.c create mode 100755 media/libeffects/lvm/lib/Bundle/src/LVM_Tables.h create mode 100755 media/libeffects/lvm/lib/Common/lib/AGC.h create mode 100755 media/libeffects/lvm/lib/Common/lib/BIQUAD.h create mode 100755 media/libeffects/lvm/lib/Common/lib/CompLim.h create mode 100755 media/libeffects/lvm/lib/Common/lib/Filter.h create mode 100755 media/libeffects/lvm/lib/Common/lib/InstAlloc.h create mode 100755 media/libeffects/lvm/lib/Common/lib/LVM_Common.h create mode 100755 media/libeffects/lvm/lib/Common/lib/LVM_Macros.h create mode 100755 media/libeffects/lvm/lib/Common/lib/LVM_Timer.h create mode 100755 media/libeffects/lvm/lib/Common/lib/LVM_Types.h create mode 100755 media/libeffects/lvm/lib/Common/lib/Mixer.h create mode 100755 media/libeffects/lvm/lib/Common/lib/ScalarArithmetic.h create mode 100755 media/libeffects/lvm/lib/Common/lib/VectorArithmetic.h create mode 100755 media/libeffects/lvm/lib/Common/src/AGC_MIX_VOL_2St1Mon_D32_WRA.c create mode 100755 media/libeffects/lvm/lib/Common/src/Abs_32.c create mode 100755 media/libeffects/lvm/lib/Common/src/Add2_Sat_16x16.c create mode 100755 media/libeffects/lvm/lib/Common/src/Add2_Sat_32x32.c create mode 100755 media/libeffects/lvm/lib/Common/src/BP_1I_D16F16C14_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/BP_1I_D16F16Css_TRC_WRA_01_Init.c create mode 100755 media/libeffects/lvm/lib/Common/src/BP_1I_D16F16Css_TRC_WRA_01_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/BP_1I_D16F32C30_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/BP_1I_D16F32Cll_TRC_WRA_01_Init.c create mode 100755 media/libeffects/lvm/lib/Common/src/BP_1I_D16F32Cll_TRC_WRA_01_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/BP_1I_D32F32C30_TRC_WRA_02.c create mode 100755 media/libeffects/lvm/lib/Common/src/BP_1I_D32F32Cll_TRC_WRA_02_Init.c create mode 100755 media/libeffects/lvm/lib/Common/src/BP_1I_D32F32Cll_TRC_WRA_02_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_1I_D16F16C15_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_1I_D16F16Css_TRC_WRA_01_Init.c create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_1I_D16F16Css_TRC_WRA_01_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_1I_D16F32C14_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_1I_D16F32Css_TRC_WRA_01_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_1I_D16F32Css_TRC_WRA_01_init.c create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16C14_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16C15_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16Css_TRC_WRA_01_Init.c create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16Css_TRC_WRA_01_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32C13_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32C14_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32C15_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32Css_TRC_WRA_01_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32Css_TRC_WRA_01_init.c create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_2I_D32F32C30_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_2I_D32F32Cll_TRC_WRA_01_Init.c create mode 100755 media/libeffects/lvm/lib/Common/src/BQ_2I_D32F32Cll_TRC_WRA_01_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/CompLim_private.h create mode 100755 media/libeffects/lvm/lib/Common/src/Copy_16.c create mode 100755 media/libeffects/lvm/lib/Common/src/Core_MixHard_2St_D32C31_SAT.c create mode 100755 media/libeffects/lvm/lib/Common/src/Core_MixInSoft_D32C31_SAT.c create mode 100755 media/libeffects/lvm/lib/Common/src/Core_MixSoft_1St_D32C31_WRA.c create mode 100755 media/libeffects/lvm/lib/Common/src/DC_2I_D16_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/DC_2I_D16_TRC_WRA_01_Init.c create mode 100755 media/libeffects/lvm/lib/Common/src/DC_2I_D16_TRC_WRA_01_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/DelayAllPass_Sat_32x16To32.c create mode 100755 media/libeffects/lvm/lib/Common/src/DelayMix_16x16.c create mode 100755 media/libeffects/lvm/lib/Common/src/DelayWrite_32.c create mode 100755 media/libeffects/lvm/lib/Common/src/FO_1I_D16F16C15_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/FO_1I_D16F16Css_TRC_WRA_01_Init.c create mode 100755 media/libeffects/lvm/lib/Common/src/FO_1I_D16F16Css_TRC_WRA_01_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/FO_1I_D32F32C31_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/FO_1I_D32F32Cll_TRC_WRA_01_Init.c create mode 100755 media/libeffects/lvm/lib/Common/src/FO_1I_D32F32Cll_TRC_WRA_01_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/FO_2I_D16F32C15_LShx_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/FO_2I_D16F32Css_LShx_TRC_WRA_01_Init.c create mode 100755 media/libeffects/lvm/lib/Common/src/FO_2I_D16F32Css_LShx_TRC_WRA_01_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/Filters.h create mode 100755 media/libeffects/lvm/lib/Common/src/From2iToMS_16x16.c create mode 100755 media/libeffects/lvm/lib/Common/src/From2iToMono_16.c create mode 100755 media/libeffects/lvm/lib/Common/src/From2iToMono_32.c create mode 100755 media/libeffects/lvm/lib/Common/src/InstAlloc.c create mode 100755 media/libeffects/lvm/lib/Common/src/Int16LShiftToInt32_16x32.c create mode 100755 media/libeffects/lvm/lib/Common/src/Int32RShiftToInt16_Sat_32x16.c create mode 100755 media/libeffects/lvm/lib/Common/src/JoinTo2i_32x32.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_Core_MixHard_1St_2i_D16C31_SAT.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_Core_MixHard_2St_D16C31_SAT.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_Core_MixInSoft_D16C31_SAT.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_Core_MixSoft_1St_2i_D16C31_WRA.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_Core_MixSoft_1St_D16C31_WRA.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_MixInSoft_D16C31_SAT.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_MixSoft_1St_2i_D16C31_SAT.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_MixSoft_1St_D16C31_SAT.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_MixSoft_2St_D16C31_SAT.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_Mixer.h create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_Mixer_GetCurrent.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_Mixer_GetTarget.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_Mixer_Init.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_Mixer_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_Mixer_SetTarget.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_Mixer_SetTimeConstant.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVC_Mixer_VarSlope_SetTimeConstant.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVM_FO_HPF.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVM_FO_LPF.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVM_GetOmega.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVM_Mixer_FilterCoeffs.h create mode 100755 media/libeffects/lvm/lib/Common/src/LVM_Mixer_TimeConstant.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVM_Polynomial.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVM_Power10.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVM_Timer.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVM_Timer_Init.c create mode 100755 media/libeffects/lvm/lib/Common/src/LVM_Timer_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/LoadConst_16.c create mode 100755 media/libeffects/lvm/lib/Common/src/LoadConst_32.c create mode 100755 media/libeffects/lvm/lib/Common/src/MSTo2i_Sat_16x16.c create mode 100755 media/libeffects/lvm/lib/Common/src/Mac3s_Sat_16x16.c create mode 100755 media/libeffects/lvm/lib/Common/src/Mac3s_Sat_32x16.c create mode 100755 media/libeffects/lvm/lib/Common/src/MixInSoft_D32C31_SAT.c create mode 100755 media/libeffects/lvm/lib/Common/src/MixSoft_1St_D32C31_WRA.c create mode 100755 media/libeffects/lvm/lib/Common/src/MixSoft_2St_D32C31_SAT.c create mode 100755 media/libeffects/lvm/lib/Common/src/Mixer_private.h create mode 100755 media/libeffects/lvm/lib/Common/src/MonoTo2I_16.c create mode 100755 media/libeffects/lvm/lib/Common/src/MonoTo2I_32.c create mode 100755 media/libeffects/lvm/lib/Common/src/Mult3s_32x16.c create mode 100755 media/libeffects/lvm/lib/Common/src/NonLinComp_D16.c create mode 100755 media/libeffects/lvm/lib/Common/src/PK_2I_D32F32C14G11_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/PK_2I_D32F32C30G11_TRC_WRA_01.c create mode 100755 media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CllGss_TRC_WRA_01_Init.c create mode 100755 media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CllGss_TRC_WRA_01_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CssGss_TRC_WRA_01_Init.c create mode 100755 media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CssGss_TRC_WRA_01_Private.h create mode 100755 media/libeffects/lvm/lib/Common/src/Shift_Sat_v16xv16.c create mode 100755 media/libeffects/lvm/lib/Common/src/Shift_Sat_v32xv32.c create mode 100755 media/libeffects/lvm/lib/Common/src/dB_to_Lin32.c create mode 100755 media/libeffects/lvm/lib/Common/src/mult3s_16x16.c create mode 100755 media/libeffects/lvm/lib/Eq/lib/LVEQNB.h create mode 100755 media/libeffects/lvm/lib/Eq/src/LVEQNB_CalcCoef.c create mode 100755 media/libeffects/lvm/lib/Eq/src/LVEQNB_Coeffs.h create mode 100755 media/libeffects/lvm/lib/Eq/src/LVEQNB_Control.c create mode 100755 media/libeffects/lvm/lib/Eq/src/LVEQNB_Init.c create mode 100755 media/libeffects/lvm/lib/Eq/src/LVEQNB_Private.h create mode 100755 media/libeffects/lvm/lib/Eq/src/LVEQNB_Process.c create mode 100755 media/libeffects/lvm/lib/Eq/src/LVEQNB_Tables.c create mode 100755 media/libeffects/lvm/lib/SpectrumAnalyzer/lib/LVPSA.h create mode 100755 media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Control.c create mode 100755 media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Init.c create mode 100755 media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Memory.c create mode 100755 media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Private.h create mode 100755 media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Process.c create mode 100755 media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_QPD.h create mode 100755 media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_QPD_Init.c create mode 100755 media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_QPD_Process.c create mode 100755 media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Tables.c create mode 100755 media/libeffects/lvm/lib/StereoWidening/lib/LVCS.h create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_BypassMix.c create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_BypassMix.h create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_Control.c create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_Equaliser.c create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_Equaliser.h create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_Headphone_Coeffs.h create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_Init.c create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_Private.h create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_Process.c create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_ReverbGenerator.c create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_ReverbGenerator.h create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_StereoEnhancer.c create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_StereoEnhancer.h create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_Tables.c create mode 100755 media/libeffects/lvm/lib/StereoWidening/src/LVCS_Tables.h create mode 100644 media/libeffects/lvm/wrapper/Android.mk create mode 100644 media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp create mode 100644 media/libeffects/lvm/wrapper/Bundle/EffectBundle.h create mode 100644 media/libeffects/testlibs/Android.mk_ create mode 100644 media/libeffects/testlibs/AudioBiquadFilter.cpp create mode 100644 media/libeffects/testlibs/AudioBiquadFilter.h create mode 100644 media/libeffects/testlibs/AudioCoefInterpolator.cpp create mode 100644 media/libeffects/testlibs/AudioCoefInterpolator.h create mode 100644 media/libeffects/testlibs/AudioCommon.h create mode 100644 media/libeffects/testlibs/AudioEqualizer.cpp create mode 100644 media/libeffects/testlibs/AudioEqualizer.h create mode 100644 media/libeffects/testlibs/AudioFormatAdapter.h create mode 100644 media/libeffects/testlibs/AudioHighShelfFilterCoef.inl create mode 100644 media/libeffects/testlibs/AudioLowShelfFilterCoef.inl create mode 100644 media/libeffects/testlibs/AudioPeakingFilter.cpp create mode 100644 media/libeffects/testlibs/AudioPeakingFilter.h create mode 100644 media/libeffects/testlibs/AudioPeakingFilterCoef.inl create mode 100644 media/libeffects/testlibs/AudioShelvingFilter.cpp create mode 100644 media/libeffects/testlibs/AudioShelvingFilter.h create mode 100644 media/libeffects/testlibs/EffectEqualizer.cpp create mode 100644 media/libeffects/testlibs/EffectReverb.c create mode 100644 media/libeffects/testlibs/EffectReverb.h create mode 100644 media/libeffects/testlibs/EffectsMath.c create mode 100644 media/libeffects/testlibs/EffectsMath.h create mode 100644 media/libeffects/visualizer/Android.mk create mode 100644 media/libeffects/visualizer/EffectVisualizer.cpp diff --git a/media/libeffects/Android.mk b/media/libeffects/Android.mk deleted file mode 100644 index fc4ceb6..0000000 --- a/media/libeffects/Android.mk +++ /dev/null @@ -1,127 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -# -TEST_EFFECT_LIBRARIES := true - -# Effect factory library -include $(CLEAR_VARS) - -LOCAL_SRC_FILES:= \ - EffectsFactory.c - -LOCAL_SHARED_LIBRARIES := \ - libcutils - -LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES) -LOCAL_MODULE:= libeffects - -ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true) -LOCAL_LDLIBS += -ldl -endif - -ifneq ($(TARGET_SIMULATOR),true) -LOCAL_SHARED_LIBRARIES += libdl -endif - -LOCAL_C_INCLUDES := \ - -include $(BUILD_SHARED_LIBRARY) - - -ifeq ($(TEST_EFFECT_LIBRARIES),true) -# Test Reverb library -include $(CLEAR_VARS) - -LOCAL_SRC_FILES:= \ - EffectReverb.c.arm \ - EffectsMath.c.arm -LOCAL_CFLAGS+= -O2 - -LOCAL_SHARED_LIBRARIES := \ - libcutils - -LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/soundfx -LOCAL_MODULE:= libreverb - -ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true) -LOCAL_LDLIBS += -ldl -endif - -ifneq ($(TARGET_SIMULATOR),true) -LOCAL_SHARED_LIBRARIES += libdl -endif - -LOCAL_C_INCLUDES := \ - $(call include-path-for, graphics corecg) - -LOCAL_PRELINK_MODULE := false - -include $(BUILD_SHARED_LIBRARY) - -# Test Equalizer library -include $(CLEAR_VARS) - -LOCAL_SRC_FILES:= \ - EffectsMath.c.arm \ - EffectEqualizer.cpp \ - AudioBiquadFilter.cpp.arm \ - AudioCoefInterpolator.cpp.arm \ - AudioPeakingFilter.cpp.arm \ - AudioShelvingFilter.cpp.arm \ - AudioEqualizer.cpp.arm - -LOCAL_CFLAGS+= -O2 - -LOCAL_SHARED_LIBRARIES := \ - libcutils - -LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/soundfx -LOCAL_MODULE:= libequalizer - -ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true) -LOCAL_LDLIBS += -ldl -endif - -ifneq ($(TARGET_SIMULATOR),true) -LOCAL_SHARED_LIBRARIES += libdl -endif - -LOCAL_C_INCLUDES := \ - $(call include-path-for, graphics corecg) \ - system/media/opensles/include - -LOCAL_PRELINK_MODULE := false - -include $(BUILD_SHARED_LIBRARY) - -endif - - -# Visualizer library -include $(CLEAR_VARS) - -LOCAL_SRC_FILES:= \ - EffectVisualizer.cpp - -LOCAL_CFLAGS+= -O2 - -LOCAL_SHARED_LIBRARIES := \ - libcutils - -LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/soundfx -LOCAL_MODULE:= libvisualizer - -ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true) -LOCAL_LDLIBS += -ldl -endif - -ifneq ($(TARGET_SIMULATOR),true) -LOCAL_SHARED_LIBRARIES += libdl -endif - -LOCAL_C_INCLUDES := \ - $(call include-path-for, graphics corecg) - -LOCAL_PRELINK_MODULE := false - -include $(BUILD_SHARED_LIBRARY) diff --git a/media/libeffects/AudioBiquadFilter.cpp b/media/libeffects/AudioBiquadFilter.cpp deleted file mode 100644 index 72917a3..0000000 --- a/media/libeffects/AudioBiquadFilter.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/* //device/servers/AudioFlinger/AudioBiquadFilter.cpp -** -** Copyright 2009, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -#include -#include - -#include "AudioBiquadFilter.h" - -#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) -#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) - -namespace android { - -const audio_coef_t AudioBiquadFilter::IDENTITY_COEFS[AudioBiquadFilter::NUM_COEFS] = { AUDIO_COEF_ONE, 0, 0, 0, 0 }; - -AudioBiquadFilter::AudioBiquadFilter(int nChannels, int sampleRate) { - configure(nChannels, sampleRate); - reset(); -} - -void AudioBiquadFilter::configure(int nChannels, int sampleRate) { - assert(nChannels > 0 && nChannels <= MAX_CHANNELS); - assert(sampleRate > 0); - mNumChannels = nChannels; - mMaxDelta = static_cast(MAX_DELTA_PER_SEC) - * AUDIO_COEF_ONE - / sampleRate; - clear(); -} - -void AudioBiquadFilter::reset() { - memcpy(mCoefs, IDENTITY_COEFS, sizeof(mCoefs)); - mCoefDirtyBits = 0; - setState(STATE_BYPASS); -} - -void AudioBiquadFilter::clear() { - memset(mDelays, 0, sizeof(mDelays)); -} - -void AudioBiquadFilter::setCoefs(const audio_coef_t coefs[NUM_COEFS], bool immediate) { - memcpy(mTargetCoefs, coefs, sizeof(mTargetCoefs)); - if (mState & STATE_ENABLED_MASK) { - if (UNLIKELY(immediate)) { - memcpy(mCoefs, coefs, sizeof(mCoefs)); - setState(STATE_NORMAL); - } else { - setState(STATE_TRANSITION_TO_NORMAL); - } - } -} - -void AudioBiquadFilter::process(const audio_sample_t in[], audio_sample_t out[], - int frameCount) { - (this->*mCurProcessFunc)(in, out, frameCount); -} - -void AudioBiquadFilter::enable(bool immediate) { - if (UNLIKELY(immediate)) { - memcpy(mCoefs, mTargetCoefs, sizeof(mCoefs)); - setState(STATE_NORMAL); - } else { - setState(STATE_TRANSITION_TO_NORMAL); - } -} - -void AudioBiquadFilter::disable(bool immediate) { - if (UNLIKELY(immediate)) { - memcpy(mCoefs, IDENTITY_COEFS, sizeof(mCoefs)); - setState(STATE_BYPASS); - } else { - setState(STATE_TRANSITION_TO_BYPASS); - } -} - -void AudioBiquadFilter::setState(state_t state) { - switch (state) { - case STATE_BYPASS: - mCurProcessFunc = &AudioBiquadFilter::process_bypass; - break; - case STATE_TRANSITION_TO_BYPASS: - if (mNumChannels == 1) { - mCurProcessFunc = &AudioBiquadFilter::process_transition_bypass_mono; - } else { - mCurProcessFunc = &AudioBiquadFilter::process_transition_bypass_multi; - } - mCoefDirtyBits = (1 << NUM_COEFS) - 1; - break; - case STATE_TRANSITION_TO_NORMAL: - if (mNumChannels == 1) { - mCurProcessFunc = &AudioBiquadFilter::process_transition_normal_mono; - } else { - mCurProcessFunc = &AudioBiquadFilter::process_transition_normal_multi; - } - mCoefDirtyBits = (1 << NUM_COEFS) - 1; - break; - case STATE_NORMAL: - if (mNumChannels == 1) { - mCurProcessFunc = &AudioBiquadFilter::process_normal_mono; - } else { - mCurProcessFunc = &AudioBiquadFilter::process_normal_multi; - } - break; - } - mState = state; -} - -bool AudioBiquadFilter::updateCoefs(const audio_coef_t coefs[NUM_COEFS], - int frameCount) { - int64_t maxDelta = mMaxDelta * frameCount; - for (int i = 0; i < NUM_COEFS; ++i) { - if (mCoefDirtyBits & (1< maxDelta) { - mCoefs[i] += maxDelta; - } else if (diff < -maxDelta) { - mCoefs[i] -= maxDelta; - } else { - mCoefs[i] = coefs[i]; - mCoefDirtyBits ^= (1< 0) { - audio_sample_t x0 = *(in++); - audio_coef_sample_acc_t acc; - acc = mul_coef_sample(b0, x0); - acc = mac_coef_sample(b1, x1, acc); - acc = mac_coef_sample(b2, x2, acc); - acc = mac_coef_sample(a1, y1, acc); - acc = mac_coef_sample(a2, y2, acc); - audio_sample_t y0 = coef_sample_acc_to_sample(acc); - y2 = y1; - y1 = y0; - x2 = x1; - x1 = x0; - (*out++) = y0; - } - mDelays[0][0] = x1; - mDelays[0][1] = x2; - mDelays[0][2] = y1; - mDelays[0][3] = y2; -} - -void AudioBiquadFilter::process_transition_normal_mono(const audio_sample_t * in, - audio_sample_t * out, - int frameCount) { - if (updateCoefs(mTargetCoefs, frameCount)) { - setState(STATE_NORMAL); - } - process_normal_mono(in, out, frameCount); -} - -void AudioBiquadFilter::process_transition_bypass_mono(const audio_sample_t * in, - audio_sample_t * out, - int frameCount) { - if (updateCoefs(IDENTITY_COEFS, frameCount)) { - setState(STATE_NORMAL); - } - process_normal_mono(in, out, frameCount); -} - -void AudioBiquadFilter::process_normal_multi(const audio_sample_t * in, - audio_sample_t * out, - int frameCount) { - const audio_coef_t b0 = mCoefs[0]; - const audio_coef_t b1 = mCoefs[1]; - const audio_coef_t b2 = mCoefs[2]; - const audio_coef_t a1 = mCoefs[3]; - const audio_coef_t a2 = mCoefs[4]; - for (int ch = 0; ch < mNumChannels; ++ch) { - size_t nFrames = frameCount; - audio_sample_t x1 = mDelays[ch][0]; - audio_sample_t x2 = mDelays[ch][1]; - audio_sample_t y1 = mDelays[ch][2]; - audio_sample_t y2 = mDelays[ch][3]; - while (nFrames-- > 0) { - audio_sample_t x0 = *in; - audio_coef_sample_acc_t acc; - acc = mul_coef_sample(b0, x0); - acc = mac_coef_sample(b1, x1, acc); - acc = mac_coef_sample(b2, x2, acc); - acc = mac_coef_sample(a1, y1, acc); - acc = mac_coef_sample(a2, y2, acc); - audio_sample_t y0 = coef_sample_acc_to_sample(acc); - y2 = y1; - y1 = y0; - x2 = x1; - x1 = x0; - *out = y0; - in += mNumChannels; - out += mNumChannels; - } - mDelays[ch][0] = x1; - mDelays[ch][1] = x2; - mDelays[ch][2] = y1; - mDelays[ch][3] = y2; - in -= frameCount * mNumChannels - 1; - out -= frameCount * mNumChannels - 1; - } -} - -void AudioBiquadFilter::process_transition_normal_multi(const audio_sample_t * in, - audio_sample_t * out, - int frameCount) { - if (updateCoefs(mTargetCoefs, frameCount)) { - setState(STATE_NORMAL); - } - process_normal_multi(in, out, frameCount); -} - -void AudioBiquadFilter::process_transition_bypass_multi(const audio_sample_t * in, - audio_sample_t * out, - int frameCount) { - if (updateCoefs(IDENTITY_COEFS, frameCount)) { - setState(STATE_NORMAL); - } - process_normal_multi(in, out, frameCount); -} - -} diff --git a/media/libeffects/AudioBiquadFilter.h b/media/libeffects/AudioBiquadFilter.h deleted file mode 100644 index 2b0e2d6..0000000 --- a/media/libeffects/AudioBiquadFilter.h +++ /dev/null @@ -1,180 +0,0 @@ -/* //device/include/server/AudioFlinger/AudioBiquadFilter.h -** -** Copyright 2007, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -#ifndef ANDROID_AUDIO_BIQUAD_FILTER_H -#define ANDROID_AUDIO_BIQUAD_FILTER_H - -#include "AudioCommon.h" - -namespace android { -// A biquad filter. -// Implements the recursion y[n]=a0*y[n-1]+a1*y[n-2]+b0*x[n]+b1*x[n-1]+b2*x[n-2] -// (the a0 and a1 coefficients have an opposite sign to the common convention) -// The filter works on fixed sized blocks of data (frameCount multi-channel -// samples, as defined during construction). An arbitrary number of interlaced -// channels is supported. -// Filter can operate in an enabled (active) or disabled (bypassed) states. -// A mechanism for suppression of artifacts caused by abrupt coefficient changes -// is implemented: normally, when the enable(), disable() and setCoefs() methods -// are called without the immediate flag set, the filter smoothly transitions -// from its current state to the desired state. -class AudioBiquadFilter { -public: - // Max number of channels (can be changed here, and everything should work). - static const int MAX_CHANNELS = 2; - // Number of coefficients. - static const int NUM_COEFS = 5; - - // Constructor. - // nChannels Number of input/output channels. - // sampleRate Sample rate, in Hz. - AudioBiquadFilter(int nChannels, int sampleRate); - - // Reconfiguration of the filter. Implies clear(). - // nChannels Number of input/output channels. - // sampleRate Sample rate, in Hz. - void configure(int nChannels, int sampleRate); - - // Resets the internal state of the filter. - // Coefficients are reset to identity, state becomes disabled. This change - // happens immediately and might cause discontinuities in the output. - // Delay lines are not cleared. - void reset(); - - // Clears the delay lines. - // This change happens immediately and might cause discontinuities in the - // output. - void clear(); - - // Sets the coefficients. - // If called when filter is disabled, will have no immediate effect, but the - // new coefficients will be set and used next time the filter is enabled. - // coefs The new coefficients. - // immediate If true, transitions to new coefficients smoothly, without - // introducing discontinuities in the output. Otherwise, - // transitions immediately. - void setCoefs(const audio_coef_t coefs[NUM_COEFS], bool immediate = false); - - // Process a buffer of data. Always processes frameCount multi-channel - // samples. Processing can be done in-place, by passing the same buffer as - // both arguments. - // in The input buffer. Should be of size frameCount * nChannels. - // out The output buffer. Should be of size frameCount * nChannels. - // frameCount Number of multi-channel samples to process. - void process(const audio_sample_t in[], audio_sample_t out[], - int frameCount); - - // Enables (activates) the filter. - // immediate If true, transitions to new state smoothly, without - // introducing discontinuities in the output. Otherwise, - // transitions immediately. - void enable(bool immediate = false); - - // Disables (bypasses) the filter. - // immediate If true, transitions to new state smoothly, without - // introducing discontinuities in the output. Otherwise, - // transitions immediately. - void disable(bool immediate = false); - -private: - // A prototype of the actual processing function. Has the same semantics as - // the process() method. - typedef void (AudioBiquadFilter::*process_func)(const audio_sample_t[], - audio_sample_t[], - int frameCount); - - // The maximum rate of coefficient change, measured in coefficient units per - // second. - static const audio_coef_t MAX_DELTA_PER_SEC = 2000; - - // Coefficients of identity transformation. - static const audio_coef_t IDENTITY_COEFS[NUM_COEFS]; - - // Filter state. - enum state_t { - // Bypass. - STATE_BYPASS = 0x01, - // In the process of smooth transition to bypass state. - STATE_TRANSITION_TO_BYPASS = 0x02, - // In the process of smooth transition to normal (enabled) state. - STATE_TRANSITION_TO_NORMAL = 0x04, - // In normal (enabled) state. - STATE_NORMAL = 0x05, - // A bit-mask for determining whether the filter is enabled or disabled - // in the eyes of the client. - STATE_ENABLED_MASK = 0x04 - }; - - // Number of channels. - int mNumChannels; - // Current state. - state_t mState; - // Maximum coefficient delta per sample. - audio_coef_t mMaxDelta; - - // A bit-mask designating for which coefficients the current value is not - // necessarily identical to the target value (since we're in transition - // state). - uint32_t mCoefDirtyBits; - // The current coefficients. - audio_coef_t mCoefs[NUM_COEFS]; - // The target coefficients. Will not be identical to mCoefs if we are in a - // transition state. - audio_coef_t mTargetCoefs[NUM_COEFS]; - - // The delay lines. - audio_sample_t mDelays[MAX_CHANNELS][4]; - - // Current processing function (determines according to current state and - // number of channels). - process_func mCurProcessFunc; - - // Sets a new state. Updates the processing function accordingly, and sets - // the dirty bits if changing to a transition state. - void setState(state_t state); - - // In a transition state, modifies the current coefs towards the passed - // coefs, while keeping a smooth change rate. Whenever a coef reaches its - // target value, the dirty bit is cleared. If all are clear, the function - // returns true, and we can then change to our target state. - bool updateCoefs(const audio_coef_t coefs[NUM_COEFS], int frameCount); - - // Processing function when in disabled state. - void process_bypass(const audio_sample_t * in, audio_sample_t * out, - int frameCount); - // Processing function when in normal state, mono. - void process_normal_mono(const audio_sample_t * in, audio_sample_t * out, - int frameCount); - // Processing function when transitioning to normal state, mono. - void process_transition_normal_mono(const audio_sample_t * in, - audio_sample_t * out, int frameCount); - // Processing function when transitioning to bypass state, mono. - void process_transition_bypass_mono(const audio_sample_t * in, - audio_sample_t * out, int frameCount); - // Processing function when in normal state, multi-channel. - void process_normal_multi(const audio_sample_t * in, audio_sample_t * out, - int frameCount); - // Processing function when transitioning to normal state, multi-channel. - void process_transition_normal_multi(const audio_sample_t * in, - audio_sample_t * out, int frameCount); - // Processing function when transitioning to bypass state, multi-channel. - void process_transition_bypass_multi(const audio_sample_t * in, - audio_sample_t * out, int frameCount); -}; -} - -#endif // ANDROID_AUDIO_BIQUAD_FILTER_H diff --git a/media/libeffects/AudioCoefInterpolator.cpp b/media/libeffects/AudioCoefInterpolator.cpp deleted file mode 100644 index 039ab9f..0000000 --- a/media/libeffects/AudioCoefInterpolator.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* //device/servers/AudioFlinger/AudioCoefInterpolator.cpp - ** - ** Copyright 2008, The Android Open Source Project - ** - ** Licensed under the Apache License, Version 2.0 (the "License"); - ** you may not use this file except in compliance with the License. - ** You may obtain a copy of the License at - ** - ** http://www.apache.org/licenses/LICENSE-2.0 - ** - ** Unless required by applicable law or agreed to in writing, software - ** distributed under the License is distributed on an "AS IS" BASIS, - ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ** See the License for the specific language governing permissions and - ** limitations under the License. - */ - -#include -#include "AudioCoefInterpolator.h" - -#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) -#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) - -namespace android { - -AudioCoefInterpolator::AudioCoefInterpolator(size_t nInDims, - const size_t inDims[], - size_t nOutDims, - const audio_coef_t * table) { - mNumInDims = nInDims; - memcpy(mInDims, inDims, nInDims * sizeof(size_t)); - mNumOutDims = nOutDims; - mTable = table; - // Initialize offsets array - size_t dim = nInDims - 1; - mInDimOffsets[nInDims - 1] = nOutDims; - while (dim-- > 0) { - mInDimOffsets[dim] = mInDimOffsets[dim + 1] * mInDims[dim + 1]; - } -} - -void AudioCoefInterpolator::getCoef(const int intCoord[], uint32_t fracCoord[], - audio_coef_t out[]) { - size_t index = 0; - size_t dim = mNumInDims; - while (dim-- > 0) { - if (UNLIKELY(intCoord[dim] < 0)) { - fracCoord[dim] = 0; - } else if (UNLIKELY(intCoord[dim] >= (int)mInDims[dim] - 1)) { - fracCoord[dim] = 0; - index += mInDimOffsets[dim] * (mInDims[dim] - 1); - } else { - index += mInDimOffsets[dim] * intCoord[dim]; - } - } - getCoefRecurse(index, fracCoord, out, 0); -} - -void AudioCoefInterpolator::getCoefRecurse(size_t index, - const uint32_t fracCoord[], - audio_coef_t out[], size_t dim) { - if (dim == mNumInDims) { - memcpy(out, mTable + index, mNumOutDims * sizeof(audio_coef_t)); - } else { - getCoefRecurse(index, fracCoord, out, dim + 1); - if (LIKELY(fracCoord != 0)) { - audio_coef_t tempCoef[MAX_OUT_DIMS]; - getCoefRecurse(index + mInDimOffsets[dim], fracCoord, tempCoef, - dim + 1); - size_t d = mNumOutDims; - while (d-- > 0) { - out[d] = interp(out[d], tempCoef[d], fracCoord[dim]); - } - } - } -} - -audio_coef_t AudioCoefInterpolator::interp(audio_coef_t lo, audio_coef_t hi, - uint32_t frac) { - int64_t delta = static_cast(hi-lo) * frac; - return lo + static_cast (delta >> 32); -} - -} diff --git a/media/libeffects/AudioCoefInterpolator.h b/media/libeffects/AudioCoefInterpolator.h deleted file mode 100644 index 13e5697..0000000 --- a/media/libeffects/AudioCoefInterpolator.h +++ /dev/null @@ -1,98 +0,0 @@ -/* //device/include/server/AudioFlinger/AudioCoefInterpolator.h - ** - ** Copyright 2007, The Android Open Source Project - ** - ** Licensed under the Apache License, Version 2.0 (the "License"); - ** you may not use this file except in compliance with the License. - ** You may obtain a copy of the License at - ** - ** http://www.apache.org/licenses/LICENSE-2.0 - ** - ** Unless required by applicable law or agreed to in writing, software - ** distributed under the License is distributed on an "AS IS" BASIS, - ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ** See the License for the specific language governing permissions and - ** limitations under the License. - */ - -#ifndef ANDROID_AUDIO_COEF_INTERPOLATOR_H -#define ANDROID_AUDIO_COEF_INTERPOLATOR_H - -#include "AudioCommon.h" - -namespace android { - -// A helper class for linear interpolation of N-D -> M-D coefficient tables. -// This class provides support for out-of-range indexes. -// Details: -// The purpose is efficient approximation of a N-dimensional vector to -// M-dimensional function. The approximation is based on a table of output -// values on a uniform grid of the input values. Values not on the grid are -// linearly interpolated. -// Access to values are done by specifying input values in table index units, -// having an integer and a fractional part, e.g. retrieving a value from index -// 1.4 will result in linear interpolation between index 1 and index 2. -class AudioCoefInterpolator { -public: - // Constructor. - // nInDims Number of input dimensions (limited to MAX_IN_DIMS). - // inDims An array of size nInDims with the size of the table on each - // respective dimension. - // nOutDims Number of output dimensions (limited to MAX_OUT_DIMS). - // table The coefficient table. Should be of size: - // inDims[0]*inDims[1]*...*inDims[nInDims-1]*nOutDims, where - // func([i,j,k]) = table(i,j,k,:) - AudioCoefInterpolator(size_t nInDims, const size_t inDims[], - size_t nOutDims, const audio_coef_t * table); - - // Get the value of the approximated function at a given point. - // intCoord The integer part of the input value. Should be an array of - // size nInDims. - // fracCoord The fractional part of the input value. Should be an array - // of size nInDims. This value is in 32-bit precision. - // out An array for the output value. Should be of size nOutDims. - void getCoef(const int intCoord[], uint32_t fracCoord[], audio_coef_t out[]); - -private: - // Maximum allowed number of input dimensions. - static const size_t MAX_IN_DIMS = 8; - // Maximum allowed number of output dimensions. - static const size_t MAX_OUT_DIMS = 8; - - // Number of input dimensions. - size_t mNumInDims; - // Number of input dimensions. - size_t mInDims[MAX_IN_DIMS]; - // The offset between two consecutive indexes of each dimension. This is in - // fact a cumulative product of mInDims (done in reverse). - size_t mInDimOffsets[MAX_IN_DIMS]; - // Number of output dimensions. - size_t mNumOutDims; - // The coefficient table. - const audio_coef_t * mTable; - - // A recursive function for getting an interpolated coefficient value. - // The recursion depth is the number of input dimensions. - // At each step, we fetch two interpolated values of the current dimension, - // by two recursive calls to this method for the next dimensions. We then - // linearly interpolate these values over the current dimension. - // index The linear integer index of the value we need to interpolate. - // fracCoord A vector of fractional coordinates for each of the input - // dimensions. - // out Where the output should be written. Needs to be of size - // mNumOutDims. - // dim The input dimensions we are currently interpolating. This - // value will be increased on recursive calls. - void getCoefRecurse(size_t index, const uint32_t fracCoord[], - audio_coef_t out[], size_t dim); - - // Scalar interpolation of two data points. - // lo The first data point. - // hi The second data point. - // frac A 32-bit fraction designating the weight of the second point. - static audio_coef_t interp(audio_coef_t lo, audio_coef_t hi, uint32_t frac); -}; - -} - -#endif // ANDROID_AUDIO_COEF_INTERPOLATOR_H diff --git a/media/libeffects/AudioCommon.h b/media/libeffects/AudioCommon.h deleted file mode 100644 index 444f93a..0000000 --- a/media/libeffects/AudioCommon.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -** -** Copyright 2009, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -#ifndef ANDROID_AUDIO_COMMON_H -#define ANDROID_AUDIO_COMMON_H - -#include -#include - -namespace android { - -// Audio coefficient type. -typedef int32_t audio_coef_t; -// Audio sample type. -typedef int32_t audio_sample_t; -// Accumulator type for coef x sample. -typedef int64_t audio_coef_sample_acc_t; - -// Number of fraction bits for audio coefficient. -static const int AUDIO_COEF_PRECISION = 24; -// Audio coefficient with the value of 1.0 -static const audio_coef_t AUDIO_COEF_ONE = 1 << AUDIO_COEF_PRECISION; -// Audio coefficient with the value of 0.5 -static const audio_coef_t AUDIO_COEF_HALF = 1 << (AUDIO_COEF_PRECISION - 1); -// Number of fraction bits for audio sample. -static const int AUDIO_SAMPLE_PRECISION = 24; -// Audio sample with the value of 1.0 -static const audio_sample_t AUDIO_SAMPLE_ONE = 1 << AUDIO_SAMPLE_PRECISION; - -// TODO: These are just temporary naive implementations of the necessary -// arithmetic operations needed for the filter. They should be moved to a more -// generic location and implemented more efficiently. - -// Multiply a sample by a coefficient to return an accumulator. -inline audio_coef_sample_acc_t mul_coef_sample(audio_coef_t x, audio_sample_t y) { - return ((audio_coef_sample_acc_t) (x)) * y; -} - -// Multiply and accumulate sample by a coefficient to return an accumulator. -inline audio_coef_sample_acc_t mac_coef_sample(audio_coef_t x, audio_sample_t y, audio_coef_sample_acc_t acc) { - return acc + ((audio_coef_sample_acc_t) (x)) * y; -} - -// Convert a sample-coefficient accumulator to a sample. -inline audio_sample_t coef_sample_acc_to_sample(audio_coef_sample_acc_t acc) { - if (acc < 0) { - acc += AUDIO_COEF_ONE - 1; - } - return (audio_sample_t) (acc >> AUDIO_COEF_PRECISION); -} - -// Convert a S15 sample to audio_sample_t -inline audio_sample_t s15_to_audio_sample_t(int16_t s15) { - return audio_sample_t(s15) << 9; -} - -// Convert a audio_sample_t sample to S15 (no clipping) -inline int16_t audio_sample_t_to_s15(audio_sample_t sample) { - return int16_t((sample + (1 << 8)) >> 9); -} - -// Convert a audio_sample_t sample to S15 (with clipping) -inline int16_t audio_sample_t_to_s15_clip(audio_sample_t sample) { - // TODO: optimize for targets supporting this as an atomic operation. - if (__builtin_expect(sample >= (0x7FFF << 9), 0)) { - return 0x7FFF; - } else if (__builtin_expect(sample <= -(0x8000 << 9), 0)) { - return 0x8000; - } else { - return audio_sample_t_to_s15(sample); - } -} - -//////////////////////////////////////////////////////////////////////////////// - -} - -#endif // ANDROID_AUDIO_COMMON_H diff --git a/media/libeffects/AudioEqualizer.cpp b/media/libeffects/AudioEqualizer.cpp deleted file mode 100644 index 44c9476..0000000 --- a/media/libeffects/AudioEqualizer.cpp +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Copyright 2009, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "AudioEqualizer" - -#include -#include -#include -#include - -#include "AudioEqualizer.h" -#include "AudioPeakingFilter.h" -#include "AudioShelvingFilter.h" -#include "EffectsMath.h" - -namespace android { - -size_t AudioEqualizer::GetInstanceSize(int nBands) { - assert(nBands >= 2); - return sizeof(AudioEqualizer) + - sizeof(AudioShelvingFilter) * 2 + - sizeof(AudioPeakingFilter) * (nBands - 2); -} - -AudioEqualizer * AudioEqualizer::CreateInstance(void * pMem, int nBands, - int nChannels, int sampleRate, - const PresetConfig * presets, - int nPresets) { - LOGV("AudioEqualizer::CreateInstance(pMem=%p, nBands=%d, nChannels=%d, " - "sampleRate=%d, nPresets=%d)", - pMem, nBands, nChannels, sampleRate, nPresets); - assert(nBands >= 2); - bool ownMem = false; - if (pMem == NULL) { - pMem = malloc(GetInstanceSize(nBands)); - if (pMem == NULL) { - return NULL; - } - ownMem = true; - } - return new (pMem) AudioEqualizer(pMem, nBands, nChannels, sampleRate, - ownMem, presets, nPresets); -} - -void AudioEqualizer::configure(int nChannels, int sampleRate) { - LOGV("AudioEqualizer::configure(nChannels=%d, sampleRate=%d)", nChannels, - sampleRate); - mpLowShelf->configure(nChannels, sampleRate); - for (int i = 0; i < mNumPeaking; ++i) { - mpPeakingFilters[i].configure(nChannels, sampleRate); - } - mpHighShelf->configure(nChannels, sampleRate); -} - -void AudioEqualizer::clear() { - LOGV("AudioEqualizer::clear()"); - mpLowShelf->clear(); - for (int i = 0; i < mNumPeaking; ++i) { - mpPeakingFilters[i].clear(); - } - mpHighShelf->clear(); -} - -void AudioEqualizer::free() { - LOGV("AudioEqualizer::free()"); - if (mpMem != NULL) { - ::free(mpMem); - } -} - -void AudioEqualizer::reset() { - LOGV("AudioEqualizer::reset()"); - const int32_t bottom = Effects_log2(kMinFreq); - const int32_t top = Effects_log2(mSampleRate * 500); - const int32_t jump = (top - bottom) / (mNumPeaking + 2); - int32_t centerFreq = bottom + jump/2; - - mpLowShelf->reset(); - mpLowShelf->setFrequency(Effects_exp2(centerFreq)); - centerFreq += jump; - for (int i = 0; i < mNumPeaking; ++i) { - mpPeakingFilters[i].reset(); - mpPeakingFilters[i].setFrequency(Effects_exp2(centerFreq)); - centerFreq += jump; - } - mpHighShelf->reset(); - mpHighShelf->setFrequency(Effects_exp2(centerFreq)); - commit(true); - mCurPreset = PRESET_CUSTOM; -} - -void AudioEqualizer::setGain(int band, int32_t millibel) { - LOGV("AudioEqualizer::setGain(band=%d, millibel=%d)", band, millibel); - assert(band >= 0 && band < mNumPeaking + 2); - if (band == 0) { - mpLowShelf->setGain(millibel); - } else if (band == mNumPeaking + 1) { - mpHighShelf->setGain(millibel); - } else { - mpPeakingFilters[band - 1].setGain(millibel); - } - mCurPreset = PRESET_CUSTOM; -} - -void AudioEqualizer::setFrequency(int band, uint32_t millihertz) { - LOGV("AudioEqualizer::setFrequency(band=%d, millihertz=%d)", band, - millihertz); - assert(band >= 0 && band < mNumPeaking + 2); - if (band == 0) { - mpLowShelf->setFrequency(millihertz); - } else if (band == mNumPeaking + 1) { - mpHighShelf->setFrequency(millihertz); - } else { - mpPeakingFilters[band - 1].setFrequency(millihertz); - } - mCurPreset = PRESET_CUSTOM; -} - -void AudioEqualizer::setBandwidth(int band, uint32_t cents) { - LOGV("AudioEqualizer::setBandwidth(band=%d, cents=%d)", band, cents); - assert(band >= 0 && band < mNumPeaking + 2); - if (band > 0 && band < mNumPeaking + 1) { - mpPeakingFilters[band - 1].setBandwidth(cents); - mCurPreset = PRESET_CUSTOM; - } -} - -int32_t AudioEqualizer::getGain(int band) const { - assert(band >= 0 && band < mNumPeaking + 2); - if (band == 0) { - return mpLowShelf->getGain(); - } else if (band == mNumPeaking + 1) { - return mpHighShelf->getGain(); - } else { - return mpPeakingFilters[band - 1].getGain(); - } -} - -uint32_t AudioEqualizer::getFrequency(int band) const { - assert(band >= 0 && band < mNumPeaking + 2); - if (band == 0) { - return mpLowShelf->getFrequency(); - } else if (band == mNumPeaking + 1) { - return mpHighShelf->getFrequency(); - } else { - return mpPeakingFilters[band - 1].getFrequency(); - } -} - -uint32_t AudioEqualizer::getBandwidth(int band) const { - assert(band >= 0 && band < mNumPeaking + 2); - if (band == 0 || band == mNumPeaking + 1) { - return 0; - } else { - return mpPeakingFilters[band - 1].getBandwidth(); - } -} - -void AudioEqualizer::getBandRange(int band, uint32_t & low, - uint32_t & high) const { - assert(band >= 0 && band < mNumPeaking + 2); - if (band == 0) { - low = 0; - high = mpLowShelf->getFrequency(); - } else if (band == mNumPeaking + 1) { - low = mpHighShelf->getFrequency(); - high = mSampleRate * 500; - } else { - mpPeakingFilters[band - 1].getBandRange(low, high); - } -} - -const char * AudioEqualizer::getPresetName(int preset) const { - assert(preset < mNumPresets && preset >= PRESET_CUSTOM); - if (preset == PRESET_CUSTOM) { - return "Custom"; - } else { - return mpPresets[preset].name; - } -} - -int AudioEqualizer::getNumPresets() const { - return mNumPresets; -} - -int AudioEqualizer::getPreset() const { - return mCurPreset; -} - -void AudioEqualizer::setPreset(int preset) { - LOGV("AudioEqualizer::setPreset(preset=%d)", preset); - assert(preset < mNumPresets && preset >= 0); - const PresetConfig &presetCfg = mpPresets[preset]; - for (int band = 0; band < (mNumPeaking + 2); ++band) { - const BandConfig & bandCfg = presetCfg.bandConfigs[band]; - setGain(band, bandCfg.gain); - setFrequency(band, bandCfg.freq); - setBandwidth(band, bandCfg.bandwidth); - } - mCurPreset = preset; -} - -void AudioEqualizer::commit(bool immediate) { - LOGV("AudioEqualizer::commit(immediate=%d)", immediate); - mpLowShelf->commit(immediate); - for (int i = 0; i < mNumPeaking; ++i) { - mpPeakingFilters[i].commit(immediate); - } - mpHighShelf->commit(immediate); -} - -void AudioEqualizer::process(const audio_sample_t * pIn, - audio_sample_t * pOut, - int frameCount) { -// LOGV("AudioEqualizer::process(frameCount=%d)", frameCount); - mpLowShelf->process(pIn, pOut, frameCount); - for (int i = 0; i < mNumPeaking; ++i) { - mpPeakingFilters[i].process(pIn, pOut, frameCount); - } - mpHighShelf->process(pIn, pOut, frameCount); -} - -void AudioEqualizer::enable(bool immediate) { - LOGV("AudioEqualizer::enable(immediate=%d)", immediate); - mpLowShelf->enable(immediate); - for (int i = 0; i < mNumPeaking; ++i) { - mpPeakingFilters[i].enable(immediate); - } - mpHighShelf->enable(immediate); -} - -void AudioEqualizer::disable(bool immediate) { - LOGV("AudioEqualizer::disable(immediate=%d)", immediate); - mpLowShelf->disable(immediate); - for (int i = 0; i < mNumPeaking; ++i) { - mpPeakingFilters[i].disable(immediate); - } - mpHighShelf->disable(immediate); -} - -int AudioEqualizer::getMostRelevantBand(uint32_t targetFreq) const { - // First, find the two bands that the target frequency is between. - uint32_t low = mpLowShelf->getFrequency(); - if (targetFreq <= low) { - return 0; - } - uint32_t high = mpHighShelf->getFrequency(); - if (targetFreq >= high) { - return mNumPeaking + 1; - } - int band = mNumPeaking; - for (int i = 0; i < mNumPeaking; ++i) { - uint32_t freq = mpPeakingFilters[i].getFrequency(); - if (freq >= targetFreq) { - high = freq; - band = i; - break; - } - low = freq; - } - // Now, low is right below the target and high is right above. See which one - // is closer on a log scale. - low = Effects_log2(low); - high = Effects_log2(high); - targetFreq = Effects_log2(targetFreq); - if (high - targetFreq < targetFreq - low) { - return band + 1; - } else { - return band; - } -} - - -AudioEqualizer::AudioEqualizer(void * pMem, int nBands, int nChannels, - int sampleRate, bool ownMem, - const PresetConfig * presets, int nPresets) - : mSampleRate(sampleRate) - , mpPresets(presets) - , mNumPresets(nPresets) { - assert(pMem != NULL); - assert(nPresets == 0 || nPresets > 0 && presets != NULL); - mpMem = ownMem ? pMem : NULL; - - pMem = (char *) pMem + sizeof(AudioEqualizer); - mpLowShelf = new (pMem) AudioShelvingFilter(AudioShelvingFilter::kLowShelf, - nChannels, sampleRate); - pMem = (char *) pMem + sizeof(AudioShelvingFilter); - mpHighShelf = new (pMem) AudioShelvingFilter(AudioShelvingFilter::kHighShelf, - nChannels, sampleRate); - pMem = (char *) pMem + sizeof(AudioShelvingFilter); - mNumPeaking = nBands - 2; - if (mNumPeaking > 0) { - mpPeakingFilters = reinterpret_cast(pMem); - for (int i = 0; i < mNumPeaking; ++i) { - new (&mpPeakingFilters[i]) AudioPeakingFilter(nChannels, - sampleRate); - } - } - reset(); -} - -} diff --git a/media/libeffects/AudioEqualizer.h b/media/libeffects/AudioEqualizer.h deleted file mode 100644 index 4028462..0000000 --- a/media/libeffects/AudioEqualizer.h +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright 2009, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AUDIOEQUALIZER_H_ -#define AUDIOEQUALIZER_H_ - -#include "AudioCommon.h" - -namespace android { - -class AudioShelvingFilter; -class AudioPeakingFilter; - -// A parametric audio equalizer. Supports an arbitrary number of bands and -// presets. -// The EQ is composed of a low-shelf, zero or more peaking filters and a high -// shelf, where each band has frequency and gain controls, and the peaking -// filters have an additional bandwidth control. -class AudioEqualizer { -public: - // Configuration of a single band. - struct BandConfig { - // Gain in millibel. - int32_t gain; - // Frequency in millihertz. - uint32_t freq; - // Bandwidth in cents (ignored on shelving filters). - uint32_t bandwidth; - }; - - // Preset configuration. - struct PresetConfig { - // Human-readable name. - const char * name; - // An array of size nBands where each element is a configuration for the - // corresponding band. - const BandConfig * bandConfigs; - }; - - // This value is used when requesting current preset, and EQ is not using a - // preset. - static const int PRESET_CUSTOM = -1; - - // Get the required memory size for an instance of this class. - // nBands Number of bands required in the instance. - static size_t GetInstanceSize(int nBands); - - // Create an instance of this class. - // If succeeds, a respective call is expected to freeInstance(), regardless - // of who owns the context memory. - // pMem A memory buffer of at least the size returned by - // GetInstanceSize(), where the instance context is to be - // stored. If NULL, it will be automatically allocated (using - // malloc). - // nBands Number of bands. Must be >= 2. - // nChannels Number of input/output channels (interlaced). - // sampleRate The input/output sample rate, in Hz. - // presets The presets configuration. May be NULL, but in that case the - // client is required not to call preset-related functions. - // This array is owned by the client and is not copied. It - // must be kept valid by the client as long as the instance is - // alive. - // nPresets Number of elements in the presets array. - // returns The instance if success. NULL if pMem is NULL and allocation - // failed. - static AudioEqualizer * CreateInstance(void * pMem, int nBands, - int nChannels, - int sampleRate, - const PresetConfig * presets, - int nPresets); - - // Reconfiguration of the filter. Changes input/output format, but does not - // alter current parameter values. Causes reset of the delay lines. - // nChannels Number of input/output channels (interlaced). - // sampleRate The input/output sample rate, in Hz. - void configure(int nChannels, int sampleRate); - - // Resets the filter parameters to the following values: - // frequency: 0 - // gain: 0 - // bandwidth: 1200 cents. - // It also disables the filter. Does not clear the delay lines. - void reset(); - - // Clears delay lines. Does not alter parameter values. - void clear(); - - // Frees the object. Will free the memory if the object owned it, i.e. if - // a NULL pointer was passed to CreateInstance as pMem. - void free(); - - // Sets gain value. Actual change will only take place upon commit(). - // This value will be remembered even if the filter is in disabled() state. - // band The band to set the gain for. - // millibel Gain value in millibel (1/100 of decibel). - void setGain(int band, int32_t millibel); - - // Gets gain of a certain band. This is always the last value set (or - // default value after reset). - // band The band to get the gain for. - // returns Gain value in millibel (1/100 of decibel). - int32_t getGain(int band) const; - - // Sets cutoff frequency value. Actual change will only take place upon - // commit(). - // This value will be remembered even if the filter is in disabled() state. - // band The band to set the frequency for. - // millihertz Frequency value in mHz. - void setFrequency(int band, uint32_t millihertz); - - // Gets frequency of a certain band. This is always the last value set (or - // default value after reset). - // band The band to get the frequency for. - // returns Frequency value in mHz. - uint32_t getFrequency(int band) const; - - // Sets bandwidth value. Actual change will only take place upon commit(). - // This value will be remembered even if the filter is in disabled() state. - // If called on the first or last band, this call is ignored. - // band The band to set the frequency for. - // cents Bandwidth value in cents (1/1200 octave). - void setBandwidth(int band, uint32_t cents); - - // Gets bandwidth of a certain band. This is always the last value set (or - // default value after reset). For the first and last bands, 0 is always - // returned. - // band The band to get the bandwidth for. - // returns Bandwidth value in cents (1/1200 octave). - uint32_t getBandwidth(int band) const; - - // Gets lower and upper boundaries of a band. - // For the low shelf, the low bound is 0 and the high bound is the band - // frequency. - // For the high shelf, the low bound is the band frequency and the high - // bound is Nyquist. - // For the peaking filters, they are the gain[dB]/2 points. - void getBandRange(int band, uint32_t & low, uint32_t & high) const; - - // Gets a human-readable name for a preset ID. Will return "Custom" if - // PRESET_CUSTOM is passed. - // preset The preset ID. Must be less than number of presets. - const char * getPresetName(int preset) const; - - // Gets the number of presets. - int getNumPresets() const; - - // Gets the currently set preset ID. - // Will return PRESET_CUSTOM in case the EQ parameters have been modified - // manually since a preset was set. - int getPreset() const; - - // Sets the current preset by ID. - // All the band parameters will be overridden. - // Change will not be applied until commit() is called. - // preset The preset ID. Must be less than number of presets. - // PRESET_CUSTOM is NOT a valid value here. - void setPreset(int preset); - - // Applies all parameter changes done to this point in time. - // If the filter is disabled, the new parameters will take place when it is - // enabled again. Does not introduce artifacts, unless immediate is set. - // immediate Whether to apply change abruptly (ignored if filter is - // disabled). - void commit(bool immediate = false); - - // Process a buffer of input data. The input and output should contain - // frameCount * nChannels interlaced samples. Processing can be done - // in-place, by passing the same buffer as both arguments. - // pIn Input buffer. - // pOut Output buffer. - // frameCount Number of frames to produce on each call to process(). - void process(const audio_sample_t * pIn, audio_sample_t * pOut, - int frameCount); - - // Enables the filter, so it would start processing input. Does not - // introduce artifacts, unless immediate is set. - // immediate Whether to apply change abruptly. - void enable(bool immediate = false); - - // Disabled (bypasses) the filter. Does not introduce artifacts, unless - // immediate is set. - // immediate Whether to apply change abruptly. - void disable(bool immediate = false); - - // Returns the band with the maximum influence on a given frequency. - // Result is unaffected by whether EQ is enabled or not, or by whether - // changes have been committed or not. - // targetFreq The target frequency, in millihertz. - int getMostRelevantBand(uint32_t targetFreq) const; - -private: - // Bottom frequency, in mHz. - static const int kMinFreq = 20000; - // Sample rate, in Hz. - int mSampleRate; - // Number of peaking filters. Total number of bands is +2. - int mNumPeaking; - // Preset configurations. - const PresetConfig * mpPresets; - // Number of elements in mpPresets; - int mNumPresets; - // Current preset. - int mCurPreset; - - // Memory space to free when instance is deleted, or NULL if no memory is - // owned. - void * mpMem; - // The low-shelving filter. - AudioShelvingFilter * mpLowShelf; - // The high-shelving filter. - AudioShelvingFilter * mpHighShelf; - // An array of size mNumPeaking of peaking filters. - AudioPeakingFilter * mpPeakingFilters; - - // Constructor. Resets the filter (see reset()). Must call init() doing - // anything else. - // pMem Memory buffer for bands. - // nChannels Number of input/output channels (interlaced). - // sampleRate The input/output sample rate, in Hz. - // ownMem Whether pMem is owned by me. - // presets The presets configuration. May be NULL, but in that case the - // client is required not to call preset-related functions. - // This array is owned by the client and is not copied. It - // must be kept valid by the client as long as the instance is - // alive. - // nPresets Number of elements in the presets array. - AudioEqualizer(void * pMem, int nBands, int nChannels, int sampleRate, - bool ownMem, const PresetConfig * presets, int nPresets); -}; - -} - -#endif // AUDIOEQUALIZER_H_ diff --git a/media/libeffects/AudioFormatAdapter.h b/media/libeffects/AudioFormatAdapter.h deleted file mode 100644 index d93ebe9..0000000 --- a/media/libeffects/AudioFormatAdapter.h +++ /dev/null @@ -1,184 +0,0 @@ -/* /android/src/frameworks/base/media/libeffects/AudioFormatAdapter.h -** -** Copyright 2009, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -#ifndef AUDIOFORMATADAPTER_H_ -#define AUDIOFORMATADAPTER_H_ - -#include - - -#define min(x,y) (((x) < (y)) ? (x) : (y)) - -namespace android { - -// An adapter for an audio processor working on audio_sample_t samples with a -// buffer override behavior to arbitrary sample formats and buffer behaviors. -// The adapter may work on any processing class which has a processing function -// with the following signature: -// void process(const audio_sample_t * pIn, -// audio_sample_t * pOut, -// int frameCount); -// It is assumed that the underlying processor works in S7.24 format and an -// overwrite behavior. -// -// Usage is simple: just work with the processor normally, but instead of -// calling its process() function directly, work with the process() function of -// the adapter. -// The adapter supports re-configuration to a different format on the fly. -// -// T The processor class. -// bufSize The maximum number of samples (single channel) to process on a -// single call to the underlying processor. Setting this to a small -// number will save a little memory, but will cost function call -// overhead, resulting from multiple calls to the underlying process() -// per a single call to this class's process(). -template -class AudioFormatAdapter { -public: - // Configure the adapter. - // processor The underlying audio processor. - // nChannels Number of input and output channels. The adapter does not do - // channel conversion - this parameter must be in sync with the - // actual processor. - // pcmFormat The desired input/output sample format. - // behavior The desired behavior (overwrite or accumulate). - void configure(T & processor, int nChannels, uint8_t pcmFormat, - uint32_t behavior) { - mpProcessor = &processor; - mNumChannels = nChannels; - mPcmFormat = pcmFormat; - mBehavior = behavior; - mMaxSamplesPerCall = bufSize / nChannels; - } - - // Process a block of samples. - // pIn A buffer of samples with the format specified on - // configure(). - // pOut A buffer of samples with the format specified on - // configure(). May be the same as pIn. - // numSamples The number of multi-channel samples to process. - void process(const void * pIn, void * pOut, uint32_t numSamples) { - while (numSamples > 0) { - uint32_t numSamplesIter = min(numSamples, mMaxSamplesPerCall); - uint32_t nSamplesChannels = numSamplesIter * mNumChannels; - if (mPcmFormat == SAMPLE_FORMAT_PCM_S7_24) { - if (mBehavior == EFFECT_BUFFER_ACCESS_WRITE) { - mpProcessor->process( - reinterpret_cast (pIn), - reinterpret_cast (pOut), - numSamplesIter); - } else if (mBehavior == EFFECT_BUFFER_ACCESS_ACCUMULATE) { - mpProcessor->process( - reinterpret_cast (pIn), - mBuffer, numSamplesIter); - MixOutput(pOut, numSamplesIter); - } else { - assert(false); - } - pIn = reinterpret_cast (pIn) - + nSamplesChannels; - pOut = reinterpret_cast (pOut) - + nSamplesChannels; - } else { - ConvertInput(pIn, nSamplesChannels); - mpProcessor->process(mBuffer, mBuffer, numSamplesIter); - ConvertOutput(pOut, nSamplesChannels); - } - numSamples -= numSamplesIter; - } - } - -private: - // The underlying processor. - T * mpProcessor; - // The number of input/output channels. - int mNumChannels; - // The desired PCM format. - uint8_t mPcmFormat; - // The desired buffer behavior. - uint32_t mBehavior; - // An intermediate buffer for processing. - audio_sample_t mBuffer[bufSize]; - // The buffer size, divided by the number of channels - represents the - // maximum number of multi-channel samples that can be stored in the - // intermediate buffer. - size_t mMaxSamplesPerCall; - - // Converts a buffer of input samples to audio_sample_t format. - // Output is written to the intermediate buffer. - // pIn The input buffer with the format designated in configure(). - // When function exist will point to the next unread input - // sample. - // numSamples The number of single-channel samples to process. - void ConvertInput(const void *& pIn, uint32_t numSamples) { - if (mPcmFormat == SAMPLE_FORMAT_PCM_S15) { - const int16_t * pIn16 = reinterpret_cast(pIn); - audio_sample_t * pOut = mBuffer; - while (numSamples-- > 0) { - *(pOut++) = s15_to_audio_sample_t(*(pIn16++)); - } - pIn = pIn16; - } else { - assert(false); - } - } - - // Converts audio_sample_t samples from the intermediate buffer to the - // output buffer, converting to the desired format and buffer behavior. - // pOut The buffer to write the output to. - // When function exist will point to the next output sample. - // numSamples The number of single-channel samples to process. - void ConvertOutput(void *& pOut, uint32_t numSamples) { - if (mPcmFormat == SAMPLE_FORMAT_PCM_S15) { - const audio_sample_t * pIn = mBuffer; - int16_t * pOut16 = reinterpret_cast(pOut); - if (mBehavior == EFFECT_BUFFER_ACCESS_WRITE) { - while (numSamples-- > 0) { - *(pOut16++) = audio_sample_t_to_s15_clip(*(pIn++)); - } - } else if (mBehavior == EFFECT_BUFFER_ACCESS_ACCUMULATE) { - while (numSamples-- > 0) { - *(pOut16++) += audio_sample_t_to_s15_clip(*(pIn++)); - } - } else { - assert(false); - } - pOut = pOut16; - } else { - assert(false); - } - } - - // Accumulate data from the intermediate buffer to the output. Output is - // assumed to be of audio_sample_t type. - // pOut The buffer to mix the output to. - // When function exist will point to the next output sample. - // numSamples The number of single-channel samples to process. - void MixOutput(void *& pOut, uint32_t numSamples) { - const audio_sample_t * pIn = mBuffer; - audio_sample_t * pOut24 = reinterpret_cast(pOut); - numSamples *= mNumChannels; - while (numSamples-- > 0) { - *(pOut24++) += *(pIn++); - } - pOut = pOut24; - } -}; - -} - -#endif // AUDIOFORMATADAPTER_H_ diff --git a/media/libeffects/AudioHighShelfFilterCoef.inl b/media/libeffects/AudioHighShelfFilterCoef.inl deleted file mode 100644 index ebba139..0000000 --- a/media/libeffects/AudioHighShelfFilterCoef.inl +++ /dev/null @@ -1,225 +0,0 @@ -13679, -21575, -8921, -32315056, --15582015, -26172, -37678, -14797, -31891096, --15192527, -51020, -64449, -23945, -31322988, --14685186, -101817, -106144, -37744, -30562882, --14031372, -208996, -162163, -58536, -29548538, --13201017, -442996, -207459, -93300, -28200792, --12167331, -971423, -128786, -169690, -26422744, --10915428, -2200461, --465686, -394986, -24103317, --9455862, -5119991, --2777199, -1147245, -21129473, --7842294, -12120379, --10198160, -3631544, -17411837, --6188384, -28834234, --31647135, -11337795, -12924960, --4672638, -68037766, --88974388, -33477255, -7752680, --3516098, -157369944, --232063160, -92282129, -2113926, --2925624, -353720112, --567427144, -237164112, --3659993, --3019871, -769091151, --1309871949, -570539430, --9202114, --3779302, -66791, -121706, -55888, -30571245, --14038415, -120426, -212178, -94820, -29559679, --13209886, -217130, -365165, -157610, -28215554, --12178243, -391489, -617016, -255010, -26442131, --10928431, -705862, -1015147, -398457, -24128430, --9470680, -1272682, -1605251, -596102, -21161334, --7858153, -2294668, -2386833, -848523, -17451072, --6203880, -4137327, -3198789, -1155536, -12971362, --4685798, -7459675, -3470266, -1567219, -7804818, --3524761, -13449926, -1738911, -2347406, -2169089, --2928116, -24250455, --5211241, -4358971, --3605298, --3015671, -43724001, --23849570, -9823315, --9151253, --3769277, -78835150, --66542375, -23686373, --14161143, --5040790, -142141173, --156324261, -56024234, --18451275, --6612656, -256283057, --335606326, -126341244, --21970004, --8270755, -16777216, -33554432, -16777216, --33554432, --16777216, -16777216, -33554432, -16777216, --33554432, --16777216, -16777216, -33554432, -16777216, --33554432, --16777216, -16777216, -33554432, -16777216, --33554432, --16777216, -16777216, -33554432, -16777216, --33554432, --16777216, -16777216, -33554432, -16777216, --33554432, --16777216, -16777216, -33554432, -16777216, --33554432, --16777216, -16777216, -33554432, -16777216, --33554432, --16777216, -16777216, -33554432, -16777216, --33554432, --16777216, -16777216, -33554432, -16777216, --33554432, --16777216, -16777216, -33554432, -16777216, --33554432, --16777216, -16777216, -33554432, -16777216, --33554432, --16777216, -16777216, -33554432, -16777216, --33554432, --16777216, -16777216, -33554432, -16777216, --33554432, --16777216, -16777216, -33554432, -16777216, --33554432, --16777216, diff --git a/media/libeffects/AudioLowShelfFilterCoef.inl b/media/libeffects/AudioLowShelfFilterCoef.inl deleted file mode 100644 index b57deb4..0000000 --- a/media/libeffects/AudioLowShelfFilterCoef.inl +++ /dev/null @@ -1,375 +0,0 @@ -16212506, --32420574, -16208068, -32401411, --15662521, -16356129, --32706246, -16350118, -32695525, --15939752, -16464399, --32920670, -16456274, -32914686, --16149441, -16546128, --33081289, -16535165, -33077955, --16307411, -16608101, --33201422, -16593328, -33199569, --16426067, -16655539, --33291174, -16635647, -33290147, --16514997, -16692478, --33358171, -16665715, -33357608, --16581540, -16722089, --33408149, -16686099, -33407850, --16631271, -16746930, --33445409, -16698549, -33445267, --16668405, -16769156, --33473168, -16704138, -33473133, --16696114, -16790706, --33493827, -16703348, -33493886, --16716779, -16813466, --33509166, -16696111, -33509342, --16732186, -16839437, --33520498, -16681802, -33520852, --16743669, -16870911, --33528765, -16659191, -33529424, --16752226, -16910681, --33534607, -16626337, -33535807, --16758602, -15667401, --31326224, -15658825, -31252161, --14623074, -15945865, --31880007, -15934146, -31838205, --15144597, -16157521, --32299091, -16141578, -32275604, --15545369, -16318267, --32614903, -16296651, -32601755, --15850850, -16440710, --32852157, -16411473, -32844820, --16082303, -16534751, --33029985, -16495281, -33025910, --16256891, -16608171, --33163043, -16554957, -33160803, --16388152, -16667145, --33262468, -16595477, -33261275, --16486599, -16716699, --33336671, -16620252, -33336105, --16560301, -16761100, --33391976, -16631379, -33391836, --16615404, -16804207, --33433103, -16629806, -33433341, --16656560, -16849794, --33463551, -16615399, -33464251, --16687277, -16901887, --33485857, -16586933, -33487271, --16710189, -16965125, --33501781, -16542000, -33504415, --16727274, -17045198, --33512384, -16476824, -33517183, --16740008, -14635201, --29254376, -14619184, -28977711, --12753834, -15157556, --30292825, -15135285, -30133938, --13674513, -15561511, --31092298, -15530817, -31001860, --14405551, -15872211, --31702342, -15830187, -31651218, --14976306, -16111094, --32164834, -16053843, -32136101, --15416453, -16295848, --32513802, -16218140, -32497757, --15752817, -16440852, --32776179, -16335665, -32767326, --16008155, -16557804, --32972907, -16415715, -32968179, --16201031, -16656403, --33120052, -16464758, -33117802, --16346195, -16745001, --33229805, -16486810, -33229247, --16455153, -16831240, --33311306, -16483692, -33312252, --16536771, -16922682, --33371278, -16455145, -33374070, --16597819, -17027472, --33414465, -16398818, -33420110, --16643430, -17155108, --33443875, -16310110, -33454398, --16677479, -17317384, --33460760, -16181887, -33479933, --16702882, -12792703, --25557388, -12764716, -24590507, --9747085, -13706465, --27372621, -13666215, -26798296, --11169790, -14439425, --28821830, -14382518, -28486469, --12380088, -15018453, --29957273, -14939030, -29764018, --13373522, -15472460, --30834757, -15362688, -30724568, --14168120, -15828725, --31506123, -15678118, -31443928, --14791822, -16111406, --32015988, -15905901, -31981391, --15274688, -16341329, --32400984, -16062061, -32382398, --15644761, -16536484, --32690238, -16158133, -32681354, --15926286, -16712853, --32906337, -16201432, -32904128, --16139278, -16885430, --33066336, -16195306, -33070090, --16299767, -17069377, --33182599, -16139282, -33193711, --16420332, -17281371, --33263294, -16029039, -33285785, --16510702, -17541271, --33312390, -15856243, -33354359, --16578329, -17874330, --33328902, -15608287, -33405430, --16628873, -9881279, --19719268, -9838084, -16734303, --5927111, -11264857, --22463447, -11198784, -20577584, --7572288, -12460736, --24823046, -12362697, -23667359, --9201903, -13459805, --26776851, -13317799, -26085683, --10691555, -14276287, --28349256, -14074406, -27943899, --11978834, -14936943, --29588248, -14654011, -29354533, --13047453, -15473300, --30549299, -15081036, -30417203, --13909216, -15917271, --31285788, -15377817, -31213972, --14589687, -16299384, --31844320, -15562006, -31809683, --15118811, -16648774, --32262999, -15645414, -32254329, --15525641, -16994277, --32571090, -15633607, -32585895, --15835862, -17366374, --32789019, -15525801, -32833003, --16070975, -17799955, --32927834, -15314895, -33017107, --16248361, -18338206, --32987318, -14987686, -33154246, --16381747, -19038270, --32951545, -14525592, -33256392, --16481800, diff --git a/media/libeffects/AudioPeakingFilter.cpp b/media/libeffects/AudioPeakingFilter.cpp deleted file mode 100644 index 60fefe6..0000000 --- a/media/libeffects/AudioPeakingFilter.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* //device/include/server/AudioFlinger/AudioPeakingFilter.cpp - ** - ** Copyright 2007, The Android Open Source Project - ** - ** Licensed under the Apache License, Version 2.0 (the "License"); - ** you may not use this file except in compliance with the License. - ** You may obtain a copy of the License at - ** - ** http://www.apache.org/licenses/LICENSE-2.0 - ** - ** Unless required by applicable law or agreed to in writing, software - ** distributed under the License is distributed on an "AS IS" BASIS, - ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ** See the License for the specific language governing permissions and - ** limitations under the License. - */ - -#include "AudioPeakingFilter.h" -#include "AudioCommon.h" -#include "EffectsMath.h" - -#include -#include - -#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) -#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) - -namespace android { -// Format of the coefficient table: -// kCoefTable[freq][gain][bw][coef] -// freq - peak frequency, in octaves below Nyquist,from -9 to -1. -// gain - gain, in millibel, starting at -9600, jumps of 1024, to 4736 millibel. -// bw - bandwidth, starting at 1 cent, jumps of 1024, to 3073 cents. -// coef - 0: b0 -// 1: b1 -// 2: b2 -// 3: -a1 -// 4: -a2 -static const size_t kInDims[3] = {9, 15, 4}; -static const audio_coef_t kCoefTable[9*15*4*5] = { -#include "AudioPeakingFilterCoef.inl" -}; - -AudioCoefInterpolator AudioPeakingFilter::mCoefInterp(3, kInDims, 5, (const audio_coef_t*) kCoefTable); - -AudioPeakingFilter::AudioPeakingFilter(int nChannels, int sampleRate) - : mBiquad(nChannels, sampleRate) { - configure(nChannels, sampleRate); - reset(); -} - -void AudioPeakingFilter::configure(int nChannels, int sampleRate) { - mNiquistFreq = sampleRate * 500; - mFrequencyFactor = ((1ull) << 42) / mNiquistFreq; - mBiquad.configure(nChannels, sampleRate); - setFrequency(mNominalFrequency); - commit(true); -} - -void AudioPeakingFilter::reset() { - setGain(0); - setFrequency(0); - setBandwidth(2400); - commit(true); -} - -void AudioPeakingFilter::setFrequency(uint32_t millihertz) { - mNominalFrequency = millihertz; - if (UNLIKELY(millihertz > mNiquistFreq / 2)) { - millihertz = mNiquistFreq / 2; - } - uint32_t normFreq = static_cast( - (static_cast(millihertz) * mFrequencyFactor) >> 10); - if (LIKELY(normFreq > (1 << 23))) { - mFrequency = (Effects_log2(normFreq) - ((32-9) << 15)) << (FREQ_PRECISION_BITS - 15); - } else { - mFrequency = 0; - } -} - -void AudioPeakingFilter::setGain(int32_t millibel) { - mGain = millibel + 9600; -} - -void AudioPeakingFilter::setBandwidth(uint32_t cents) { - mBandwidth = cents - 1; -} - -void AudioPeakingFilter::commit(bool immediate) { - audio_coef_t coefs[5]; - int intCoord[3] = { - mFrequency >> FREQ_PRECISION_BITS, - mGain >> GAIN_PRECISION_BITS, - mBandwidth >> BANDWIDTH_PRECISION_BITS - }; - uint32_t fracCoord[3] = { - mFrequency << (32 - FREQ_PRECISION_BITS), - static_cast(mGain) << (32 - GAIN_PRECISION_BITS), - mBandwidth << (32 - BANDWIDTH_PRECISION_BITS) - }; - mCoefInterp.getCoef(intCoord, fracCoord, coefs); - mBiquad.setCoefs(coefs, immediate); -} - -void AudioPeakingFilter::getBandRange(uint32_t & low, uint32_t & high) const { - // Half bandwidth, in octaves, 15-bit precision - int32_t halfBW = (((mBandwidth + 1) / 2) << 15) / 1200; - - low = static_cast((static_cast(mNominalFrequency) * Effects_exp2(-halfBW + (16 << 15))) >> 16); - if (UNLIKELY(halfBW >= (16 << 15))) { - high = mNiquistFreq; - } else { - high = static_cast((static_cast(mNominalFrequency) * Effects_exp2(halfBW + (16 << 15))) >> 16); - if (UNLIKELY(high > mNiquistFreq)) { - high = mNiquistFreq; - } - } -} - -} - diff --git a/media/libeffects/AudioPeakingFilter.h b/media/libeffects/AudioPeakingFilter.h deleted file mode 100644 index d0f49c9..0000000 --- a/media/libeffects/AudioPeakingFilter.h +++ /dev/null @@ -1,151 +0,0 @@ -/* //device/include/server/AudioFlinger/AudioPeakingFilter.h -** -** Copyright 2009, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -#ifndef ANDROID_AUDIO_PEAKING_FILTER_H -#define ANDROID_AUDIO_PEAKING_FILTER_H - -#include "AudioBiquadFilter.h" -#include "AudioCoefInterpolator.h" - -namespace android { - -// A peaking audio filter, with unity skirt gain, and controllable peak -// frequency, gain and bandwidth. -// This filter is able to suppress introduce discontinuities and other artifacts -// in the output, even when changing parameters abruptly. -// Parameters can be set to any value - this class will make sure to clip them -// when they are out of supported range. -// -// Implementation notes: -// This class uses an underlying biquad filter whose parameters are determined -// using a linear interpolation from a coefficient table, using a -// AudioCoefInterpolator. -// All is left for this class to do is mapping between high-level parameters to -// fractional indices into the coefficient table. -class AudioPeakingFilter { -public: - // Constructor. Resets the filter (see reset()). - // nChannels Number of input/output channels (interlaced). - // sampleRate The input/output sample rate, in Hz. - AudioPeakingFilter(int nChannels, int sampleRate); - - // Reconfiguration of the filter. Changes input/output format, but does not - // alter current parameter values. Clears delay lines. - // nChannels Number of input/output channels (interlaced). - // sampleRate The input/output sample rate, in Hz. - void configure(int nChannels, int sampleRate); - - // Resets the filter parameters to the following values: - // frequency: 0 - // gain: 0 - // bandwidth: 1200 cents. - // It also disables the filter. Does not clear the delay lines. - void reset(); - - // Clears delay lines. Does not alter parameter values. - void clear() { mBiquad.clear(); } - - // Sets gain value. Actual change will only take place upon commit(). - // This value will be remembered even if the filter is in disabled() state. - // millibel Gain value in millibel (1/100 of decibel). - void setGain(int32_t millibel); - - // Gets the gain, in millibel, as set. - int32_t getGain() const { return mGain - 9600; } - - // Sets bandwidth value. Actual change will only take place upon commit(). - // This value will be remembered even if the filter is in disabled() state. - // cents Bandwidth value in cents (1/1200 octave). - void setBandwidth(uint32_t cents); - - // Gets the gain, in cents, as set. - uint32_t getBandwidth() const { return mBandwidth + 1; } - - // Sets frequency value. Actual change will only take place upon commit(). - // This value will be remembered even if the filter is in disabled() state. - // millihertz Frequency value in mHz. - void setFrequency(uint32_t millihertz); - - // Gets the frequency, in mHz, as set. - uint32_t getFrequency() const { return mNominalFrequency; } - - // Gets gain[dB]/2 points. - // Results in mHz, and are computed based on the nominal values set, not on - // possibly rounded or truncated actual values. - void getBandRange(uint32_t & low, uint32_t & high) const; - - // Applies all parameter changes done to this point in time. - // If the filter is disabled, the new parameters will take place when it is - // enabled again. Does not introduce artifacts, unless immediate is set. - // immediate Whether to apply change abruptly (ignored if filter is - // disabled). - void commit(bool immediate = false); - - // Process a buffer of input data. The input and output should contain - // frameCount * nChannels interlaced samples. Processing can be done - // in-place, by passing the same buffer as both arguments. - // in Input buffer. - // out Output buffer. - // frameCount Number of frames to produce. - void process(const audio_sample_t in[], audio_sample_t out[], - int frameCount) { mBiquad.process(in, out, frameCount); } - - // Enables the filter, so it would start processing input. Does not - // introduce artifacts, unless immediate is set. - // immediate Whether to apply change abruptly. - void enable(bool immediate = false) { mBiquad.enable(immediate); } - - // Disabled (bypasses) the filter. Does not introduce artifacts, unless - // immediate is set. - // immediate Whether to apply change abruptly. - void disable(bool immediate = false) { mBiquad.disable(immediate); } - -private: - // Precision for the mFrequency member. - static const int FREQ_PRECISION_BITS = 26; - // Precision for the mGain member. - static const int GAIN_PRECISION_BITS = 10; - // Precision for the mBandwidth member. - static const int BANDWIDTH_PRECISION_BITS = 10; - - // Nyquist, in mHz. - uint32_t mNiquistFreq; - // Fractional index into the gain dimension of the coef table in - // GAIN_PRECISION_BITS precision. - int32_t mGain; - // Fractional index into the bandwidth dimension of the coef table in - // BANDWIDTH_PRECISION_BITS precision. - uint32_t mBandwidth; - // Fractional index into the frequency dimension of the coef table in - // FREQ_PRECISION_BITS precision. - uint32_t mFrequency; - // Nominal value of frequency, as set. - uint32_t mNominalFrequency; - // 1/Nyquist[mHz], in 42-bit precision (very small). - // Used for scaling the frequency. - uint32_t mFrequencyFactor; - - // A biquad filter, used for the actual processing. - AudioBiquadFilter mBiquad; - // A coefficient interpolator, used for mapping the high level parameters to - // the low-level biquad coefficients. - static AudioCoefInterpolator mCoefInterp; -}; - -} - -#endif // ANDROID_AUDIO_PEAKING_FILTER_H diff --git a/media/libeffects/AudioPeakingFilterCoef.inl b/media/libeffects/AudioPeakingFilterCoef.inl deleted file mode 100644 index 374c6e1..0000000 --- a/media/libeffects/AudioPeakingFilterCoef.inl +++ /dev/null @@ -1,2700 +0,0 @@ -16769751, --33538871, -16769751, -33538871, --16762286, -11468083, --22935566, -11467915, -22935566, --6158781, -8532673, --17064763, -8532412, -17064763, --287869, -6567366, --13134160, -6567042, -13134160, -3642808, -16773075, --33545518, -16773075, -33545518, --16768934, -13349658, --26698459, -13349304, -26698459, --9921746, -10923581, --21846147, -10922977, -21846147, --5069342, -9009390, --18017641, -9008590, -18017641, --1240764, -16774919, --33549207, -16774919, -33549207, --16772622, -14686150, --29371047, -14685450, -29371047, --12594384, -12933736, --25865697, -12932448, -25865697, --9088968, -11350364, --22698482, -11348545, -22698482, --5921693, -16775943, --33551252, -16775941, -33551252, --16774668, -15549746, --31097569, -15548408, -31097569, --14320938, -14404163, --28805197, -14401577, -28805197, --12028524, -13261978, --26519626, -13258147, -26519626, --9742909, -16776511, --33552387, -16776508, -33552387, --16775803, -16074349, --32145600, -16071856, -32145600, --15368989, -15374244, --30742933, -15369268, -30742933, --13966296, -14629431, --29250695, -14621814, -29250695, --12474030, -16776826, --33553017, -16776822, -33553017, --16776432, -16381548, --32757900, -16376968, -32757900, --15981300, -15972161, --31934402, -15962842, -31934402, --15157787, -15518882, --31022614, -15504316, -31022614, --14245982, -16777003, --33553366, -16776995, -33553366, --16776781, -16558315, --33107660, -16549969, -33107660, --16331067, -16326848, --32635910, -16309677, -32635910, --15859308, -16064456, --32101133, -16037281, -32101133, --15324521, -16777103, --33553559, -16777088, -33553559, --16776975, -16660325, --33304885, -16645187, -33304885, --16528296, -16535200, --33038436, -16503858, -33038436, --16261842, -16391425, --32732273, -16341464, -32732273, --15955673, -16777162, --33553667, -16777136, -33553667, --16777082, -16721651, --33415288, -16694267, -33415288, --16638701, -16661761, --33265997, -16604862, -33265997, --16489407, -16592417, --33093137, -16501343, -33093137, --16316544, -16777203, --33553726, -16777155, -33553726, --16777142, -16763466, --33476836, -16714001, -33476836, --16700251, -16748588, --33393565, -16645605, -33393565, --16616978, -16731288, --33296733, -16566071, -33296733, --16520144, -16777238, --33553759, -16777152, -33553759, --16777175, -16800489, --33511071, -16711212, -33511071, --16734485, -16825723, --33464740, -16639647, -33464740, --16688154, -16855137, --33410736, -16556228, -33410736, --16634149, -16777282, --33553778, -16777127, -33553778, --16777193, -16845889, --33530088, -16684830, -33530088, --16753503, -16920437, --33504347, -16584541, -33504347, --16727762, -17007449, --33474302, -16467484, -33474302, --16697716, -16777349, --33553788, -16777070, -33553788, --16777203, -16915880, --33540645, -16625396, -33540645, --16764060, -17066504, --33526354, -16460481, -33526354, --16749769, -17242444, --33509662, -16267849, -33509662, --16733077, -16777464, --33553793, -16776961, -33553793, --16777209, -17035487, --33546503, -16511647, -33546503, --16769918, -17316137, --33538572, -16223067, -33538572, --16761988, -17644089, --33529306, -15885848, -33529306, --16752721, -16777668, --33553796, -16776760, -33553796, --16777212, -17247484, --33549752, -16302900, -33549752, --16773168, -17758603, --33545353, -15787381, -33545353, --16768768, -18356007, --33540211, -15184835, -33540211, --16763626, -16762293, --33522062, -16762293, -33522062, --16747370, -8711405, --17421242, -8711149, -17421242, --645338, -5721250, --11441288, -5720900, -11441288, -5335066, -4082836, --8164655, -4082434, -8164655, -8611946, -16768936, --33535347, -16768936, -33535347, --16760656, -11085056, --22167856, -11084469, -22167856, --5392309, -8098223, --16194333, -8097329, -16194333, -581664, -6158323, --12314623, -6157228, -12314623, -4461665, -16772623, --33542719, -16772622, -33542719, --16768029, -13058634, --26114055, -13057388, -26114055, --9338806, -10523211, --21042742, -10521116, -21042742, --4267110, -8576560, --17149081, -8573812, -17149081, --373156, -16774670, --33546810, -16774667, -33546810, --16772120, -14489725, --28974776, -14487233, -28974776, --12199742, -12619509, --25232587, -12614979, -25232587, --8457271, -10965151, --21922319, -10958818, -21922319, --5146753, -16775805, --33549079, -16775800, -33549079, --16774390, -15428102, --30849095, -15423317, -30849095, --14074202, -14188157, --28364996, -14178975, -28364996, --11589916, -12969900, --25924346, -12956398, -25924346, --9149082, -16776437, --33550338, -16776428, -33550338, --16775648, -16004216, --31997074, -15995268, -31997074, --15222267, -15241233, --30462393, -15223454, -30462393, --13687471, -14437070, --28844880, -14409982, -28844880, --12069836, -16776789, --33551036, -16776773, -33551036, --16776347, -16345158, --32671383, -16328685, -32671383, --15896627, -15900462, --31765104, -15867034, -31765104, --14990280, -15410846, --30767279, -15358750, -30767279, --13992380, -16776990, --33551423, -16776960, -33551423, --16776734, -16545156, --33057769, -16515103, -33057769, --16283043, -16300504, --32536823, -16238769, -32536823, --15762058, -16024071, --31948201, -15926537, -31948201, --15173391, -16777109, --33551638, -16777056, -33551638, --16776949, -16666542, --33276035, -16611999, -33276035, --16501325, -16548270, --32981225, -16435439, -32981225, --16206493, -16412621, --32643103, -16232940, -32643103, --15868346, -16777189, --33551757, -16777094, -33551757, --16777068, -16749778, --33398338, -16651075, -33398338, --16623637, -16720233, --33232976, -16515245, -33232976, --16458262, -16686059, --33041706, -16358135, -33041706, --16266978, -16777261, --33551823, -16777089, -33551823, --16777134, -16823703, --33466559, -16645376, -33466559, --16691863, -16873974, --33374267, -16502806, -33374267, --16599564, -16932398, --33267006, -16337114, -33267006, --16492295, -16777348, --33551860, -16777038, -33551860, --16777170, -16914465, --33504517, -16592574, -33504517, --16729824, -17063236, --33453150, -16392432, -33453150, --16678453, -17236595, --33393293, -16159213, -33393293, --16618592, -16777483, --33551880, -16776924, -33551880, --16777191, -17054436, --33525606, -16473695, -33525606, --16750914, -17355321, --33497061, -16144262, -33497061, --16722367, -17706453, --33463749, -15759816, -33463749, --16689053, -16777713, --33551891, -16776705, -33551891, --16777202, -17293646, --33537314, -16246194, -33537314, --16762623, -17854571, --33521465, -15669419, -33521465, --16746773, -18509706, --33502954, -14995772, -33502954, --16728261, -16778120, --33551898, -16776304, -33551898, --16777208, -17717639, --33543811, -15828698, -33543811, --16769121, -18739501, --33535016, -14798040, -33535016, --16760325, -19933534, --33524738, -13593729, -33524738, --16750047, -16747397, --33484705, -16747396, -33484705, --16717577, -5883112, --11762335, -5882767, -11762335, -5011337, -3448701, --6894903, -3448279, -6894903, -9880236, -2324286, --4646714, -2323828, -4646714, -12129102, -16760665, --33511232, -16760663, -33511232, --16744112, -8276984, --16548106, -8276108, -16548106, -224124, -5337400, --10670406, -5336221, -10670406, -6103596, -3771525, --7539439, -3770185, -7539439, -9235506, -16768033, --33525963, -16768030, -33525963, --16758848, -10689564, --21370649, -10687524, -21370649, --4599872, -7666068, --15324466, -7663015, -15324466, -1448133, -5761266, --11515371, -5757575, -11515371, -5258376, -16772124, --33534139, -16772118, -33534139, --16767026, -12751423, --25490780, -12747036, -25490780, --8721243, -10113942, --20214533, -10106682, -20214533, --3443407, -8145025, --16275741, -8135620, -16275741, -496571, -16774395, --33538675, -16774385, -33538675, --16771564, -14280137, --28542819, -14271281, -28542819, --11774202, -12292391, --24561476, -12276485, -24561476, --7791660, -10572949, --21117532, -10550945, -21117532, --4346678, -16775657, --33541192, -16775639, -33541192, --16774081, -15299683, --30573051, -15282579, -30573051, --13805046, -13964251, --27887539, -13931690, -27887539, --11118724, -12672686, --25290241, -12625174, -25290241, --8520644, -16776363, --33542588, -16776330, -33542588, --16775477, -15935196, --31828699, -15903092, -31828699, --15061072, -15112356, --30152153, -15048881, -30152153, --13384021, -14253857, --28402950, -14157649, -28402950, --11634291, -16776763, --33543362, -16776704, -33543362, --16776252, -16319830, --32570615, -16260598, -32570615, --15803212, -15851783, --31574208, -15731938, -31574208, --14806505, -15339614, --30483871, -15153441, -30483871, --13715838, -16777001, --33543791, -16776896, -33543791, --16776681, -16557673, --32997208, -16449476, -32997208, --16229933, -16326977, --32422299, -16105089, -32422299, --15654851, -16067244, --31775024, -15717353, -31775024, --15007381, -16777163, --33544029, -16776972, -33544029, --16776919, -16722590, --33238660, -16526083, -33238660, --16471458, -16664322, --32912610, -16258203, -32912610, --16145310, -16597629, --32539419, -15951593, -32539419, --15772007, -16777306, --33544162, -16776962, -33544162, --16777051, -16869955, --33374105, -16514205, -33374105, --16606944, -16969714, --33190996, -16231282, -33190996, --16423780, -17084972, --32979442, -15904406, -32979442, --16212162, -16777480, --33544235, -16776860, -33544235, --16777125, -17051328, --33449703, -16408452, -33449703, --16682565, -17347583, --33347437, -16009901, -33347437, --16580267, -17691668, --33228659, -15547002, -33228659, --16461454, -16777750, --33544275, -16776632, -33544275, --16777165, -17331222, --33491780, -16170648, -33491780, --16724654, -17931550, --33434840, -15513363, -33434840, --16667697, -18630855, --33368512, -14747710, -33368512, --16601349, -16778210, --33544298, -16776194, -33544298, --16777188, -17809628, --33515162, -15715631, -33515162, --16748043, -18929991, --33483514, -14563611, -33483514, --16716385, -20237212, --33446587, -13219451, -33446587, --16679448, -16779025, --33544310, -16775392, -33544310, --16777200, -18657612, --33528145, -14880634, -33528145, --16761030, -20699844, --33510571, -12820822, -33510571, --16743451, -23084863, --33490047, -10415274, -33490047, --16722921, -16717684, --33395091, -16717682, -33395091, --16658149, -3567009, --7125006, -3566590, -7125006, -9643617, -1921926, --3838751, -1921455, -3838751, -12933835, -1248662, --2493824, -1248170, -2493824, -14280384, -16744147, --33447952, -16744143, -33447952, --16711074, -5493785, --10973174, -5492622, -10973174, -5790808, -3173694, --6338342, -3172292, -6338342, -10431230, -2124754, --4242881, -2123244, -4242881, -12529218, -16758861, --33477342, -16758855, -33477342, --16740500, -7843885, --15665884, -7840892, -15665884, -1092439, -4968649, --9921376, -4964692, -9921376, -6843875, -3478437, --6944043, -3473981, -6944043, -9824798, -16767035, --33493665, -16767024, -33493665, --16756842, -10284421, --20536999, -10277346, -20536999, --3784550, -7240254, --14452686, -7229862, -14452686, -2307100, -5379798, --10734231, -5367379, -10734231, -6030039, -16771575, --33502725, -16771555, -33502725, --16765913, -12431046, --24816749, -12415632, -24816749, --8069462, -9702049, --19355664, -9676957, -19355664, --2601790, -7722611, --15394544, -7690499, -15394544, -1364106, -16774099, --33507752, -16774063, -33507752, --16770946, -14062583, --28059903, -14031160, -28059903, --11316527, -11962999, --23841519, -11907273, -23841519, --7093056, -10188929, --20277142, -10112667, -20277142, --3524380, -16775510, --33510541, -16775445, -33510541, --16773738, -15175102, --30252637, -15114019, -30252637, --13511905, -13753207, --27358123, -13637911, -27358123, --10613901, -12400971, --24605416, -12234119, -24605416, --7857874, -16776310, --33512088, -16776193, -33512088, --16775287, -15888242, --31623221, -15773117, -31623221, --14884143, -15028972, --29795608, -14802570, -29795608, --13054325, -14142237, --27909578, -13801000, -27909578, --11166021, -16776787, --33512946, -16776575, -33512946, --16776146, -16345172, --32438302, -16132251, -32438302, --15700207, -15905856, --31344484, -15476429, -31344484, --14605069, -15428324, --30155514, -14763558, -30155514, --13414665, -16777110, --33513422, -16776729, -33513422, --16776623, -16668950, --32908744, -16279482, -32908744, --16171216, -16555594, --32275015, -15758344, -32275015, --15536722, -16428465, --31564284, -15173886, -31564284, --14825134, -16777395, --33513686, -16776708, -33513686, --16776887, -16961758, --33175594, -16253845, -33175594, --16438387, -17158212, --32815329, -15696692, -32815329, --16077688, -17382578, --32403880, -15060381, -32403880, --15665743, -16777745, --33513832, -16776505, -33513832, --16777033, -17323903, --33325470, -16041757, -33325470, --16588444, -17911332, --33122874, -15251488, -33122874, --16385604, -18589203, --32889086, -14339546, -32889086, --16151534, -16778283, --33513913, -16776048, -33513913, --16777115, -17883505, --33409180, -15565966, -33409180, --16672255, -19078451, --33295944, -14257648, -33295944, --16558883, -20465440, --33164510, -12739067, -33164510, --16427290, -16779203, --33513958, -16775173, -33513958, --16777160, -18840265, --33455789, -14655871, -33455789, --16718921, -21075121, --33392715, -12357866, -33392715, --16655771, -23677621, --33319266, -9681828, -33319266, --16582233, -16780834, --33513983, -16773567, -33513983, --16777185, -20536227, --33481696, -12985848, -33481696, --16744859, -24614855, --33446630, -8872112, -33446630, --16709751, -29373075, --33405721, -4072934, -33405721, --16668793, -16658572, --33156710, -16658568, -33156710, --16539925, -1995694, --3971702, -1995225, -3971702, -12786296, -1019334, --2028355, -1018835, -2028355, -14739047, -648397, --1290041, -647886, -1290041, -15480933, -16711208, --33261470, -16711201, -33261470, --16645192, -3284873, --6536727, -3283483, -6536727, -10208860, -1752746, --3487071, -1751198, -3487071, -13273272, -1134254, --2255981, -1132642, -2255981, -14510319, -16740546, --33319859, -16740534, -33319859, --16703864, -5119019, --10184853, -5115113, -10184853, -6543083, -2916766, --5800820, -2912122, -5800820, -10948329, -1940950, --3858260, -1935979, -3858260, -12900288, -16756866, --33352332, -16756844, -33352332, --16736493, -7416141, --14750709, -7405941, -14750709, -1955134, -4618132, --9178604, -4604884, -9178604, -7554200, -3205731, --6365873, -3190944, -6365873, -10380541, -16765937, --33370369, -16765897, -33370369, --16754618, -9875714, --19631961, -9851238, -19631961, --2949736, -6828874, --13556870, -6793592, -13556870, -3154751, -5021920, --9953987, -4980230, -9953987, -6775066, -16770983, --33380381, -16770911, -33380381, --16764679, -12107731, --24045066, -12053679, -24045066, --7384194, -9304697, --18433704, -9218200, -18433704, --1745681, -7330173, --14480925, -7220819, -14480925, -2226224, -16773804, --33385937, -16773674, -33385937, --16770261, -13857067, --27469883, -13745731, -27469883, --10825583, -11667230, --23028209, -11472403, -23028209, --6362417, -9861509, --19365642, -9597835, -19365642, --2682128, -16775405, --33389019, -16775170, -33389019, --16773358, -15094166, --29826057, -14876207, -29826057, --13193157, -13629575, --26722225, -13221948, -26722225, --10074307, -12261304, --23822520, -11676482, -23822520, --7160571, -16776358, --33390729, -16775935, -33390729, --16775076, -15939973, --31315809, -15527360, -31315809, --14690117, -15140254, --29331850, -14333520, -29331850, --12696558, -14324552, --27308240, -13115821, -27308240, --10663157, -16777004, --33391677, -16776241, -33391677, --16776029, -16564519, --32208051, -15799374, -32208051, --15586676, -16349720, --31011538, -14811870, -31011538, --14384374, -16117884, --29720119, -13746038, -29720119, --13086705, -16777574, --33392203, -16776199, -33392203, --16776558, -17142623, --32725183, -15740903, -32725183, --16106310, -17523746, --32028793, -14660021, -32028793, --15406551, -17949452, --31250941, -13452699, -31250941, --14624935, -16778273, --33392495, -16775794, -33392495, --16776851, -17864511, --33019221, -15314476, -33019221, --16401771, -19019582, --32622294, -13760557, -32622294, --16002923, -20335886, --32169961, -11989731, -32169961, --15548401, -16779350, --33392657, -16774879, -33392657, --16777014, -18982972, --33184592, -14362186, -33184592, --16567942, -21350554, --32961046, -11769976, -32961046, --16343314, -24079688, --32703362, -8781912, -32703362, --16084383, -16781190, --33392746, -16773130, -33392746, --16777104, -20896303, --33277026, -12541737, -33277026, --16660824, -25343199, --33151977, -7969185, -33151977, --16535169, -30502384, --33006896, -2664219, -33006896, --16389387, -16784451, --33392796, -16769918, -33392796, --16777154, -24288258, --33328516, -9201520, -33328516, --16712562, -32423187, --33258828, -996567, -33258828, --16642538, -41895320, --33177686, --8557101, -33177686, --16561003, -16541595, --32447498, -16541587, -32447498, --16305966, -1060925, --2080590, -1060426, -2080590, -14655865, -525478, --1030256, -524962, -1030256, -15726776, -330321, --647437, -329800, -647437, -16117095, -16645717, --32651734, -16645703, -32651734, --16514203, -1820789, --3570095, -1819248, -3570095, -13137179, -924575, --1812018, -922942, -1812018, -14929699, -586684, --1149186, -585016, -1149186, -15605516, -16704036, --32766121, -16704011, -32766121, --16630831, -3020875, --5921138, -3016266, -5921138, -10740076, -1597573, --3128764, -1592487, -3128764, -13587156, -1030124, --2015487, -1024848, -2015487, -14722244, -16736565, --32829909, -16736521, -32829909, --16695869, -4762013, --9328185, -4748922, -9328185, -7266281, -2679566, --5241091, -2664205, -5241091, -11433446, -1773912, --3463620, -1757564, -3463620, -13245740, -16754673, --32865395, -16754593, -32865395, --16732050, -7001772, --13700468, -6967104, -13700468, -2808340, -4293363, --8378312, -4249089, -8378312, -8234764, -2960061, --5758307, -2911058, -5758307, -10906097, -16764756, --32885110, -16764611, -32885110, --16752151, -9480188, --18513215, -9395722, -18513215, --2098694, -6453693, --12542171, -6334194, -12542171, -3989330, -4710641, --9103264, -4570966, -9103264, -7495609, -16770393, --32896054, -16770133, -32896054, --16763310, -11816276, --22992949, -11627131, -22992949, --6666191, -8975726, --17314789, -8678280, -17314789, --876790, -7032408, --13430164, -6660869, -13430164, -3083940, -16773593, --32902127, -16773124, -32902127, --16769502, -13735615, --26557052, -13341720, -26557052, --10300120, -11528165, --21946606, -10848400, -21946606, --5599349, -9752563, --18238110, -8842853, -18238110, --1818200, -16775499, --32905496, -16774654, -32905496, --16772937, -15200588, --29054957, -14423589, -29054957, --12846961, -13857004, --25769995, -12417855, -25769995, --9497643, -12624453, --22756500, -10577873, -22756500, --6425111, -16776792, --32907365, -16775267, -32907365, --16774843, -16366344, --30654089, -14888294, -30654089, --14477422, -15978753, --28526295, -13106406, -28526295, --12307942, -15588057, --26381456, -11310242, -26381456, --10121083, -16777933, --32908402, -16775183, -32908402, --16775900, -17493802, --31619287, -14744943, -31619287, --15461529, -18212414, --30325234, -12706927, -30325234, --14142124, -18982725, --28938081, -10522286, -28938081, --12727795, -16779330, --32908977, -16774372, -32908977, --16776486, -18928041, --32181280, -13883707, -32181280, --16034532, -21163118, --31424334, -10876855, -31424334, --15262757, -23650871, --30581814, -7530076, -30581814, --14403731, -16781484, --32909296, -16772543, -32909296, --16776811, -21161996, --32501674, -11976424, -32501674, --16361204, -25812009, --32068975, -6885234, -32068975, --15920027, -31103385, --31576594, -1091831, -31576594, --15418000, -16785164, --32909473, -16769043, -32909473, --16776991, -24988064, --32682139, -8334356, -32682139, --16545204, -33795794, --32438043, --722252, -32438043, --16296325, -43946128, --32156738, --11159403, -32156738, --16009510, -16791687, --32909571, -16762620, -32909571, --16777091, -31772521, --32783096, -1652834, -32783096, --16648139, -47961229, --32646423, --14675225, -32646423, --16508788, -66751682, --32487785, --33627423, -32487785, --16347043, -16312500, --30141556, -16312485, -30141556, --15847769, -547598, --1011354, -547084, -1011354, -15682534, -266448, --491849, -265925, -491849, -16244843, -166111, --306446, -165584, -306446, -16445521, -16516262, --30518049, -16516236, -30518049, --16255282, -962487, --1776938, -960857, -1776938, -14853872, -474742, --875656, -473062, -875656, -15829413, -297520, --548176, -295821, -548176, -16183875, -16631492, --30730944, -16631443, -30730944, --16485719, -1660146, --3062870, -1655081, -3062870, -13461989, -838172, --1543806, -832831, -1543806, -15106213, -530135, --974532, -524691, -974532, -15722390, -16696110, --30850307, -16696022, -30850307, --16614916, -2776642, --5116472, -2761387, -5116472, -11239187, -1456845, --2676477, -1440152, -2676477, -13880219, -936151, --1713835, -918891, -1713835, -14922174, -16732191, --30916910, -16732031, -30916910, --16687006, -4430219, --8145523, -4386431, -8145523, -7960566, -2467715, --4512857, -2416966, -4512857, -11892535, -1628113, --2958725, -1574387, -2958725, -13574716, -16752314, --30953973, -16752025, -30953973, --16727123, -6622193, --12127616, -6504644, -12127616, -3650379, -4016541, --7285135, -3868831, -7285135, -8891843, -2762675, --4954883, -2600451, -4954883, -11414089, -16763575, --30974568, -16763055, -30974568, --16749415, -9150431, --16639142, -8859646, -16639142, --1232861, -6182181, --11049974, -5778225, -11049974, -4816810, -4518629, --7917532, -4051247, -7917532, -8207341, -16769973, --30986002, -16769034, -30986002, --16761791, -11676269, --20964630, -11015683, -20964630, --5914736, -8893418, --15489638, -7872446, -15489638, -11352, -7041383, --11845939, -5780568, -11845939, -3955265, -16773783, --30992347, -16772092, -30992347, --16768659, -13953280, --24496534, -12561577, -24496534, --9737641, -11970921, --19931025, -9602265, -19931025, --4795970, -10413172, --16343421, -7276820, -16343421, --912775, -16776368, --30995868, -16773318, -30995868, --16772470, -16007790, --27021343, -13239901, -27021343, --12470475, -15365527, --23700024, -10287194, -23700024, --8875505, -14785947, --20702857, -7622664, -20702857, --5631395, -16778650, --30997821, -16773150, -30997821, --16774583, -18157056, --28659649, -12863925, -28659649, --14243764, -19443806, --26476950, -9214638, -26476950, --11881228, -20728681, --24297433, -5570671, -24297433, --9522136, -16781445, --30998904, -16771527, -30998904, --16775756, -20988060, --29656921, -11112361, -29656921, --15323204, -25187743, --28317150, -5462520, -28317150, --13873047, -29672124, --26886556, --570326, -26886556, --12324582, -16785752, --30999505, -16767870, -30999505, --16776406, -25444300, --30240545, -7287830, -30240545, --15954914, -34434980, --29452472, --2555854, -29452472, --15101910, -44441242, --28575379, --13511474, -28575379, --14152552, -16793112, --30999838, -16760871, -30999838, --16776767, -33095506, --30574250, --2177, -30574250, --16316113, -50408034, --30122291, --17803902, -30122291, --15826917, -70153765, --29606811, --38107583, -29606811, --15268966, -16806158, --31000023, -16748025, -31000023, --16776967, -46670155, --30762526, --13373037, -30762526, --16519902, -78789544, --30507092, --45768905, -30507092, --16243423, -115942747, --30211627, --83241918, -30211627, --15923613, -15872835, --22447559, -15872807, -22447559, --14968426, -277754, --392434, -277231, -392434, -16222231, -133061, --187804, -132533, -187804, -16511622, -81763, --115256, -81233, -115256, -16614220, -16263303, --22999746, -16263250, -22999746, --15749337, -494605, --698290, -492927, -698290, -15789685, -238776, --336475, -237071, -336475, -16301369, -147228, --207000, -145514, -207000, -16484473, -16488278, --23317877, -16488181, -23317877, --16199242, -872378, --1229961, -867049, -1229961, -15037788, -426889, --599839, -421411, -599839, -15928916, -264840, --370629, -259308, -370629, -16253068, -16615785, --23498145, -16615609, -23498145, --16454179, -1513757, --2129016, -1497126, -2129016, -13766333, -758261, --1060001, -740806, -1060001, -15278149, -475551, --659971, -457789, -659971, -15843875, -16687407, --23599332, -16687089, -23599332, --16597280, -2557116, --3580647, -2506684, -3580647, -11713416, -1332007, --1845009, -1277230, -1845009, -14167979, -851272, --1163942, -794791, -1163942, -15131154, -16727486, --23655830, -16726910, -23655830, --16677180, -4144749, --5758163, -3998523, -5758163, -8633944, -2297803, --3131069, -2130198, -3131069, -12349216, -1516025, --2019070, -1339371, -2019070, -13921820, -16749957, --23687282, -16748918, -23687282, --16721660, -6342807, --8688774, -5944975, -8688774, -4489434, -3855722, --5104454, -3363066, -5104454, -9558428, -2678286, --3407564, -2140738, -3407564, -11958192, -16762736, --23704762, -16760861, -23704762, --16746380, -9059948, --12106014, -8060542, -12106014, --343274, -6231959, --7847669, -4866322, -7847669, -5678936, -4678573, --5508603, -3111768, -5508603, -8986875, -16770353, --23714468, -16766970, -23714468, --16760107, -12100768, --15483427, -9796104, -15483427, --5119656, -9659401, --11180047, -6151573, -11180047, -966242, -8066003, --8371376, -3772911, -8371376, -4938302, -16775520, --23719855, -16769420, -23719855, --16767725, -15410647, --18317794, -10494626, -18317794, --9128056, -14477439, --14624233, -6204350, -14624233, --3904573, -13754127, --11761419, -2879032, -11761419, -144058, -16780083, --23722844, -16769084, -23722844, --16771951, -19348947, --20387735, -9483664, -20387735, --12055395, -21467038, --17637855, -3476656, -17637855, --8166478, -23369301, --15168181, --1918253, -15168181, --4673832, -16785673, --23724501, -16765839, -23724501, --16774296, -24868547, --21750945, -5891934, -21750945, --13983265, -32392543, --19913847, --4230110, -19913847, --11385217, -39938641, --18071353, --14381888, -18071353, --8779537, -16794288, --23725421, -16758525, -23725421, --16775596, -33739025, --22588636, --1793870, -22588636, --15167940, -50727371, --21448926, --20394010, -21448926, --13556146, -69082218, --20217540, --40490298, -20217540, --11814703, -16809008, --23725931, -16744526, -23725931, --16776318, -49053594, --23081666, --16411189, -23081666, --15865189, -82824296, --22406908, --51136143, -22406908, --14910937, -121049915, --21643138, --90441895, -21643138, --13830803, -16835099, --23726214, -16718835, -23726214, --16776718, -76261468, --23364505, --43219068, -23364505, --16265184, -140080603, --22976059, --107587549, -22976059, --15715838, -214348557, --22524014, --182494791, -22524014, --15076550, -15060971, -0, -15060916, -0, --13344671, -137715, -0, -137188, -0, -16502313, -62494, -0, -61964, -0, -16652757, -35499, -0, -34969, -0, -16706748, -15779939, -0, -15779837, -0, --14782560, -247059, -0, -245356, -0, -16284801, -112726, -0, -111009, -0, -16553481, -64282, -0, -62560, -0, -16650375, -16209124, -0, -16208934, -0, --15640842, -441483, -0, -436010, -0, -15899723, -203401, -0, -197848, -0, -16375967, -116794, -0, -111212, -0, -16549211, -16457433, -0, -16457085, -0, --16137302, -783510, -0, -766083, -0, -15227623, -367229, -0, -349349, -0, -16060638, -213457, -0, -195409, -0, -16368349, -16598556, -0, -16597923, -0, --16419263, -1374332, -0, -1319705, -0, -14083179, -663683, -0, -606536, -0, -15506996, -394077, -0, -335974, -0, -16047166, -16678051, -0, -16676903, -0, --16577738, -2365010, -0, -2198183, -0, -12214023, -1201479, -0, -1021183, -0, -14554554, -739666, -0, -554025, -0, -15483525, -16722789, -0, -16720714, -0, --16666287, -3953214, -0, -3464275, -0, -9359728, -2180807, -0, -1624291, -0, -12972118, -1423936, -0, -838564, -0, -14514716, -16748282, -0, -16744535, -0, --16715601, -6353786, -0, -5003926, -0, -5419504, -3973108, -0, -2314944, -0, -10489165, -2837511, -0, -1032284, -0, -12907421, -16763496, -0, -16756735, -0, --16743015, -9775978, -0, -6325602, -0, -675636, -7269959, -0, -2584558, -0, -6922698, -5878520, -0, -507384, -0, -10391313, -16773826, -0, -16761629, -0, --16758239, -14526462, -0, -6429723, -0, --4178968, -13351086, -0, -1026117, -0, -2400012, -12566846, -0, --2579306, -0, -6789676, -16782950, -0, -16760954, -0, --16766688, -21346996, -0, -3817102, -0, --8386881, -24548257, -0, --5261828, -0, --2509212, -27136746, -0, --12602908, -0, -2243378, -16794129, -0, -16754463, -0, --16771376, -31942756, -0, --3625011, -0, --11540529, -45048673, -0, --21256423, -0, --7015034, -57646140, -0, --38203817, -0, --2665107, -16811358, -0, -16739835, -0, --16773977, -49676415, -0, --19243342, -0, --13655857, -82339984, -0, --55005915, -0, --10556853, -118287496, -0, --94363999, -0, --7146281, -16840799, -0, -16711837, -0, --16775419, -80691383, -0, --48942961, -0, --14971206, -149858505, -0, --120064524, -0, --13016765, -233520652, -0, --206090695, -0, --10652741, -16892981, -0, -16660455, -0, --16776220, -136000868, -0, --103472696, -0, --15750956, -271801469, -0, --240442250, -0, --14582003, -446309601, -0, --416452524, -0, --13079862, diff --git a/media/libeffects/AudioShelvingFilter.cpp b/media/libeffects/AudioShelvingFilter.cpp deleted file mode 100644 index b8650ba..0000000 --- a/media/libeffects/AudioShelvingFilter.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* /android/src/frameworks/base/libs/audioflinger/AudioShelvingFilter.cpp -** -** Copyright 2009, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -#include "AudioShelvingFilter.h" -#include "AudioCommon.h" -#include "EffectsMath.h" - -#include -#include - -#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) -#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) - -namespace android { -// Format of the coefficient tables: -// kCoefTable[freq][gain][coef] -// freq - cutoff frequency, in octaves below Nyquist,from -10 to -6 in low -// shelf, -2 to 0 in high shelf. -// gain - gain, in millibel, starting at -9600, jumps of 1024, to 4736 millibel. -// coef - 0: b0 -// 1: b1 -// 2: b2 -// 3: -a1 -// 4: -a2 -static const size_t kHiInDims[2] = {3, 15}; -static const audio_coef_t kHiCoefTable[3*15*5] = { -#include "AudioHighShelfFilterCoef.inl" -}; -static const size_t kLoInDims[2] = {5, 15}; -static const audio_coef_t kLoCoefTable[5*15*5] = { -#include "AudioLowShelfFilterCoef.inl" -}; - -AudioCoefInterpolator AudioShelvingFilter::mHiCoefInterp(2, kHiInDims, 5, (const audio_coef_t*) kHiCoefTable); -AudioCoefInterpolator AudioShelvingFilter::mLoCoefInterp(2, kLoInDims, 5, (const audio_coef_t*) kLoCoefTable); - -AudioShelvingFilter::AudioShelvingFilter(ShelfType type, int nChannels, - int sampleRate) - : mType(type), - mBiquad(nChannels, sampleRate) { - configure(nChannels, sampleRate); -} - -void AudioShelvingFilter::configure(int nChannels, int sampleRate) { - mNiquistFreq = sampleRate * 500; - mFrequencyFactor = ((1ull) << 42) / mNiquistFreq; - mBiquad.configure(nChannels, sampleRate); - setFrequency(mNominalFrequency); - commit(true); -} - -void AudioShelvingFilter::reset() { - setGain(0); - setFrequency(mType == kLowShelf ? 0 : mNiquistFreq); - commit(true); -} - -void AudioShelvingFilter::setFrequency(uint32_t millihertz) { - mNominalFrequency = millihertz; - if (UNLIKELY(millihertz > mNiquistFreq / 2)) { - millihertz = mNiquistFreq / 2; - } - uint32_t normFreq = static_cast( - (static_cast(millihertz) * mFrequencyFactor) >> 10); - uint32_t log2minFreq = (mType == kLowShelf ? (32-10) : (32-2)); - if (LIKELY(normFreq > (1U << log2minFreq))) { - mFrequency = (Effects_log2(normFreq) - (log2minFreq << 15)) << (FREQ_PRECISION_BITS - 15); - } else { - mFrequency = 0; - } -} - -void AudioShelvingFilter::setGain(int32_t millibel) { - mGain = millibel + 9600; -} - -void AudioShelvingFilter::commit(bool immediate) { - audio_coef_t coefs[5]; - int intCoord[2] = { - mFrequency >> FREQ_PRECISION_BITS, - mGain >> GAIN_PRECISION_BITS - }; - uint32_t fracCoord[2] = { - mFrequency << (32 - FREQ_PRECISION_BITS), - static_cast(mGain) << (32 - GAIN_PRECISION_BITS) - }; - if (mType == kHighShelf) { - mHiCoefInterp.getCoef(intCoord, fracCoord, coefs); - } else { - mLoCoefInterp.getCoef(intCoord, fracCoord, coefs); - } - mBiquad.setCoefs(coefs, immediate); -} - -} diff --git a/media/libeffects/AudioShelvingFilter.h b/media/libeffects/AudioShelvingFilter.h deleted file mode 100644 index f72d793..0000000 --- a/media/libeffects/AudioShelvingFilter.h +++ /dev/null @@ -1,146 +0,0 @@ -/* /android/src/frameworks/base/libs/audioflinger/AudioShelvingFilter.h -** -** Copyright 2009, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -#ifndef AUDIO_SHELVING_FILTER_H -#define AUDIO_SHELVING_FILTER_H - -#include "AudioBiquadFilter.h" -#include "AudioCoefInterpolator.h" - -namespace android { - -// A shelving audio filter, with unity skirt gain, and controllable cutoff -// frequency and gain. -// This filter is able to suppress introduce discontinuities and other artifacts -// in the output, even when changing parameters abruptly. -// Parameters can be set to any value - this class will make sure to clip them -// when they are out of supported range. -// -// Implementation notes: -// This class uses an underlying biquad filter whose parameters are determined -// using a linear interpolation from a coefficient table, using a -// AudioCoefInterpolator. -// All is left for this class to do is mapping between high-level parameters to -// fractional indices into the coefficient table. -class AudioShelvingFilter { -public: - // Shelf type - enum ShelfType { - kLowShelf, - kHighShelf - }; - - // Constructor. Resets the filter (see reset()). - // type Type of the filter (high shelf or low shelf). - // nChannels Number of input/output channels (interlaced). - // sampleRate The input/output sample rate, in Hz. - AudioShelvingFilter(ShelfType type, int nChannels, int sampleRate); - - // Reconfiguration of the filter. Changes input/output format, but does not - // alter current parameter values. Clears delay lines. - // nChannels Number of input/output channels (interlaced). - // sampleRate The input/output sample rate, in Hz. - void configure(int nChannels, int sampleRate); - - // Resets the filter parameters to the following values: - // frequency: 0 - // gain: 0 - // It also disables the filter. Does not clear the delay lines. - void reset(); - - // Clears delay lines. Does not alter parameter values. - void clear() { mBiquad.clear(); } - - // Sets gain value. Actual change will only take place upon commit(). - // This value will be remembered even if the filter is in disabled() state. - // millibel Gain value in millibel (1/100 of decibel). - void setGain(int32_t millibel); - - // Gets the gain, in millibel, as set. - int32_t getGain() const { return mGain - 9600; } - - // Sets cutoff frequency value. Actual change will only take place upon - // commit(). - // This value will be remembered even if the filter is in disabled() state. - // millihertz Frequency value in mHz. - void setFrequency(uint32_t millihertz); - - // Gets the frequency, in mHz, as set. - uint32_t getFrequency() const { return mNominalFrequency; } - - // Applies all parameter changes done to this point in time. - // If the filter is disabled, the new parameters will take place when it is - // enabled again. Does not introduce artifacts, unless immediate is set. - // immediate Whether to apply change abruptly (ignored if filter is - // disabled). - void commit(bool immediate = false); - - // Process a buffer of input data. The input and output should contain - // frameCount * nChannels interlaced samples. Processing can be done - // in-place, by passing the same buffer as both arguments. - // in Input buffer. - // out Output buffer. - // frameCount Number of frames to produce. - void process(const audio_sample_t in[], audio_sample_t out[], - int frameCount) { mBiquad.process(in, out, frameCount); } - - // Enables the filter, so it would start processing input. Does not - // introduce artifacts, unless immediate is set. - // immediate Whether to apply change abruptly. - void enable(bool immediate = false) { mBiquad.enable(immediate); } - - // Disabled (bypasses) the filter. Does not introduce artifacts, unless - // immediate is set. - // immediate Whether to apply change abruptly. - void disable(bool immediate = false) { mBiquad.disable(immediate); } - -private: - // Precision for the mFrequency member. - static const int FREQ_PRECISION_BITS = 26; - // Precision for the mGain member. - static const int GAIN_PRECISION_BITS = 10; - - // Shelf type. - ShelfType mType; - // Nyquist, in mHz. - uint32_t mNiquistFreq; - // Fractional index into the gain dimension of the coef table in - // GAIN_PRECISION_BITS precision. - int32_t mGain; - // Fractional index into the frequency dimension of the coef table in - // FREQ_PRECISION_BITS precision. - uint32_t mFrequency; - // Nominal value of frequency, as set. - uint32_t mNominalFrequency; - // 1/Nyquist[mHz], in 42-bit precision (very small). - // Used for scaling the frequency. - uint32_t mFrequencyFactor; - - // A biquad filter, used for the actual processing. - AudioBiquadFilter mBiquad; - // A coefficient interpolator, used for mapping the high level parameters to - // the low-level biquad coefficients. This one is used for the high shelf. - static AudioCoefInterpolator mHiCoefInterp; - // A coefficient interpolator, used for mapping the high level parameters to - // the low-level biquad coefficients. This one is used for the low shelf. - static AudioCoefInterpolator mLoCoefInterp; -}; - -} - - -#endif // AUDIO_SHELVING_FILTER_H diff --git a/media/libeffects/EffectEqualizer.cpp b/media/libeffects/EffectEqualizer.cpp deleted file mode 100644 index af0c411..0000000 --- a/media/libeffects/EffectEqualizer.cpp +++ /dev/null @@ -1,653 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "Equalizer" -#define ARRAY_SIZE(array) (sizeof array / sizeof array[0]) -//#define LOG_NDEBUG 0 -#include -#include -#include -#include -#include -#include "AudioEqualizer.h" -#include "AudioBiquadFilter.h" -#include "AudioFormatAdapter.h" -#include - -// effect_interface_t interface implementation for equalizer effect -extern "C" const struct effect_interface_s gEqualizerInterface; - -enum equalizer_state_e { - EQUALIZER_STATE_UNINITIALIZED, - EQUALIZER_STATE_INITIALIZED, - EQUALIZER_STATE_ACTIVE, -}; - -namespace android { -namespace { - -// Google Graphic Equalizer UUID: e25aa840-543b-11df-98a5-0002a5d5c51b -const effect_descriptor_t gEqualizerDescriptor = { - {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type - {0xe25aa840, 0x543b, 0x11df, 0x98a5, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid - EFFECT_API_VERSION, - (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST), - 0, // TODO - 1, - "Graphic Equalizer", - "Google Inc.", -}; - -/////////////////// BEGIN EQ PRESETS /////////////////////////////////////////// -const int kNumBands = 5; -const uint32_t gFreqs[kNumBands] = { 50000, 125000, 900000, 3200000, 6300000 }; -const uint32_t gBandwidths[kNumBands] = { 0, 3600, 3600, 2400, 0 }; - -const AudioEqualizer::BandConfig gBandsClassic[kNumBands] = { - { 300, gFreqs[0], gBandwidths[0] }, - { 400, gFreqs[1], gBandwidths[1] }, - { 0, gFreqs[2], gBandwidths[2] }, - { 200, gFreqs[3], gBandwidths[3] }, - { -300, gFreqs[4], gBandwidths[4] } -}; - -const AudioEqualizer::BandConfig gBandsJazz[kNumBands] = { - { -600, gFreqs[0], gBandwidths[0] }, - { 200, gFreqs[1], gBandwidths[1] }, - { 400, gFreqs[2], gBandwidths[2] }, - { -400, gFreqs[3], gBandwidths[3] }, - { -600, gFreqs[4], gBandwidths[4] } -}; - -const AudioEqualizer::BandConfig gBandsPop[kNumBands] = { - { 400, gFreqs[0], gBandwidths[0] }, - { -400, gFreqs[1], gBandwidths[1] }, - { 300, gFreqs[2], gBandwidths[2] }, - { -400, gFreqs[3], gBandwidths[3] }, - { 600, gFreqs[4], gBandwidths[4] } -}; - -const AudioEqualizer::BandConfig gBandsRock[kNumBands] = { - { 700, gFreqs[0], gBandwidths[0] }, - { 400, gFreqs[1], gBandwidths[1] }, - { -400, gFreqs[2], gBandwidths[2] }, - { 400, gFreqs[3], gBandwidths[3] }, - { 200, gFreqs[4], gBandwidths[4] } -}; - -const AudioEqualizer::PresetConfig gEqualizerPresets[] = { - { "Classic", gBandsClassic }, - { "Jazz", gBandsJazz }, - { "Pop", gBandsPop }, - { "Rock", gBandsRock } -}; - -/////////////////// END EQ PRESETS ///////////////////////////////////////////// - -static const size_t kBufferSize = 32; - -typedef AudioFormatAdapter FormatAdapter; - -struct EqualizerContext { - const struct effect_interface_s *itfe; - effect_config_t config; - FormatAdapter adapter; - AudioEqualizer * pEqualizer; - uint32_t state; -}; - -//--- local function prototypes - -int Equalizer_init(EqualizerContext *pContext); -int Equalizer_configure(EqualizerContext *pContext, effect_config_t *pConfig); -int Equalizer_getParameter(AudioEqualizer * pEqualizer, int32_t *pParam, size_t *pValueSize, void *pValue); -int Equalizer_setParameter(AudioEqualizer * pEqualizer, int32_t *pParam, void *pValue); - - -// -//--- Effect Library Interface Implementation -// - -extern "C" int EffectQueryNumberEffects(uint32_t *pNumEffects) { - *pNumEffects = 1; - return 0; -} /* end EffectQueryNumberEffects */ - -extern "C" int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor) { - if (pDescriptor == NULL) { - return -EINVAL; - } - if (index > 0) { - return -EINVAL; - } - memcpy(pDescriptor, &gEqualizerDescriptor, sizeof(effect_descriptor_t)); - return 0; -} /* end EffectQueryNext */ - -extern "C" int EffectCreate(effect_uuid_t *uuid, - int32_t sessionId, - int32_t ioId, - effect_interface_t *pInterface) { - int ret; - int i; - - LOGV("EffectLibCreateEffect start"); - - if (pInterface == NULL || uuid == NULL) { - return -EINVAL; - } - - if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) != 0) { - return -EINVAL; - } - - EqualizerContext *pContext = new EqualizerContext; - - pContext->itfe = &gEqualizerInterface; - pContext->pEqualizer = NULL; - pContext->state = EQUALIZER_STATE_UNINITIALIZED; - - ret = Equalizer_init(pContext); - if (ret < 0) { - LOGW("EffectLibCreateEffect() init failed"); - delete pContext; - return ret; - } - - *pInterface = (effect_interface_t)pContext; - pContext->state = EQUALIZER_STATE_INITIALIZED; - - LOGV("EffectLibCreateEffect %p, size %d", pContext, AudioEqualizer::GetInstanceSize(kNumBands)+sizeof(EqualizerContext)); - - return 0; - -} /* end EffectCreate */ - -extern "C" int EffectRelease(effect_interface_t interface) { - EqualizerContext * pContext = (EqualizerContext *)interface; - - LOGV("EffectLibReleaseEffect %p", interface); - if (pContext == NULL) { - return -EINVAL; - } - - pContext->state = EQUALIZER_STATE_UNINITIALIZED; - pContext->pEqualizer->free(); - delete pContext; - - return 0; -} /* end EffectRelease */ - - -// -//--- local functions -// - -#define CHECK_ARG(cond) { \ - if (!(cond)) { \ - LOGV("Invalid argument: "#cond); \ - return -EINVAL; \ - } \ -} - -//---------------------------------------------------------------------------- -// Equalizer_configure() -//---------------------------------------------------------------------------- -// Purpose: Set input and output audio configuration. -// -// Inputs: -// pContext: effect engine context -// pConfig: pointer to effect_config_t structure holding input and output -// configuration parameters -// -// Outputs: -// -//---------------------------------------------------------------------------- - -int Equalizer_configure(EqualizerContext *pContext, effect_config_t *pConfig) -{ - LOGV("Equalizer_configure start"); - - CHECK_ARG(pContext != NULL); - CHECK_ARG(pConfig != NULL); - - CHECK_ARG(pConfig->inputCfg.samplingRate == pConfig->outputCfg.samplingRate); - CHECK_ARG(pConfig->inputCfg.channels == pConfig->outputCfg.channels); - CHECK_ARG(pConfig->inputCfg.format == pConfig->outputCfg.format); - CHECK_ARG((pConfig->inputCfg.channels == CHANNEL_MONO) || (pConfig->inputCfg.channels == CHANNEL_STEREO)); - CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE - || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE); - CHECK_ARG(pConfig->inputCfg.format == SAMPLE_FORMAT_PCM_S7_24 - || pConfig->inputCfg.format == SAMPLE_FORMAT_PCM_S15); - - int channelCount; - if (pConfig->inputCfg.channels == CHANNEL_MONO) { - channelCount = 1; - } else { - channelCount = 2; - } - CHECK_ARG(channelCount <= AudioBiquadFilter::MAX_CHANNELS); - - memcpy(&pContext->config, pConfig, sizeof(effect_config_t)); - - pContext->pEqualizer->configure(channelCount, - pConfig->inputCfg.samplingRate); - - pContext->adapter.configure(*pContext->pEqualizer, channelCount, - pConfig->inputCfg.format, - pConfig->outputCfg.accessMode); - - return 0; -} // end Equalizer_configure - - -//---------------------------------------------------------------------------- -// Equalizer_init() -//---------------------------------------------------------------------------- -// Purpose: Initialize engine with default configuration and creates -// AudioEqualizer instance. -// -// Inputs: -// pContext: effect engine context -// -// Outputs: -// -//---------------------------------------------------------------------------- - -int Equalizer_init(EqualizerContext *pContext) -{ - int status; - - LOGV("Equalizer_init start"); - - CHECK_ARG(pContext != NULL); - - if (pContext->pEqualizer != NULL) { - pContext->pEqualizer->free(); - } - - pContext->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; - pContext->config.inputCfg.channels = CHANNEL_STEREO; - pContext->config.inputCfg.format = SAMPLE_FORMAT_PCM_S15; - pContext->config.inputCfg.samplingRate = 44100; - pContext->config.inputCfg.bufferProvider.getBuffer = NULL; - pContext->config.inputCfg.bufferProvider.releaseBuffer = NULL; - pContext->config.inputCfg.bufferProvider.cookie = NULL; - pContext->config.inputCfg.mask = EFFECT_CONFIG_ALL; - pContext->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; - pContext->config.outputCfg.channels = CHANNEL_STEREO; - pContext->config.outputCfg.format = SAMPLE_FORMAT_PCM_S15; - pContext->config.outputCfg.samplingRate = 44100; - pContext->config.outputCfg.bufferProvider.getBuffer = NULL; - pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL; - pContext->config.outputCfg.bufferProvider.cookie = NULL; - pContext->config.outputCfg.mask = EFFECT_CONFIG_ALL; - - pContext->pEqualizer = AudioEqualizer::CreateInstance( - NULL, - kNumBands, - AudioBiquadFilter::MAX_CHANNELS, - 44100, - gEqualizerPresets, - ARRAY_SIZE(gEqualizerPresets)); - - for (int i = 0; i < kNumBands; ++i) { - pContext->pEqualizer->setFrequency(i, gFreqs[i]); - pContext->pEqualizer->setBandwidth(i, gBandwidths[i]); - } - - pContext->pEqualizer->enable(true); - - Equalizer_configure(pContext, &pContext->config); - - return 0; -} // end Equalizer_init - - -//---------------------------------------------------------------------------- -// Equalizer_getParameter() -//---------------------------------------------------------------------------- -// Purpose: -// Get a Equalizer parameter -// -// Inputs: -// pEqualizer - handle to instance data -// pParam - pointer to parameter -// pValue - pointer to variable to hold retrieved value -// pValueSize - pointer to value size: maximum size as input -// -// Outputs: -// *pValue updated with parameter value -// *pValueSize updated with actual value size -// -// -// Side Effects: -// -//---------------------------------------------------------------------------- - -int Equalizer_getParameter(AudioEqualizer * pEqualizer, int32_t *pParam, size_t *pValueSize, void *pValue) -{ - int status = 0; - int32_t param = *pParam++; - int32_t param2; - char *name; - - switch (param) { - case EQ_PARAM_NUM_BANDS: - case EQ_PARAM_CUR_PRESET: - case EQ_PARAM_GET_NUM_OF_PRESETS: - if (*pValueSize < sizeof(int16_t)) { - return -EINVAL; - } - *pValueSize = sizeof(int16_t); - break; - - case EQ_PARAM_LEVEL_RANGE: - case EQ_PARAM_BAND_FREQ_RANGE: - if (*pValueSize < 2 * sizeof(int32_t)) { - return -EINVAL; - } - *pValueSize = 2 * sizeof(int32_t); - break; - case EQ_PARAM_BAND_LEVEL: - case EQ_PARAM_GET_BAND: - case EQ_PARAM_CENTER_FREQ: - if (*pValueSize < sizeof(int32_t)) { - return -EINVAL; - } - *pValueSize = sizeof(int32_t); - break; - - case EQ_PARAM_GET_PRESET_NAME: - break; - - default: - return -EINVAL; - } - - switch (param) { - case EQ_PARAM_NUM_BANDS: - *(int16_t *)pValue = kNumBands; - LOGV("Equalizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue); - break; - - case EQ_PARAM_LEVEL_RANGE: - *(int32_t *)pValue = -9600; - *((int32_t *)pValue + 1) = 4800; - LOGV("Equalizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d", *(int32_t *)pValue, *((int32_t *)pValue + 1)); - break; - - case EQ_PARAM_BAND_LEVEL: - param2 = *pParam; - if (param2 >= kNumBands) { - status = -EINVAL; - break; - } - *(int32_t *)pValue = pEqualizer->getGain(param2); - LOGV("Equalizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", param2, *(int32_t *)pValue); - break; - - case EQ_PARAM_CENTER_FREQ: - param2 = *pParam; - if (param2 >= kNumBands) { - status = -EINVAL; - break; - } - *(int32_t *)pValue = pEqualizer->getFrequency(param2); - LOGV("Equalizer_getParameter() EQ_PARAM_CENTER_FREQ band %d, frequency %d", param2, *(int32_t *)pValue); - break; - - case EQ_PARAM_BAND_FREQ_RANGE: - param2 = *pParam; - if (param2 >= kNumBands) { - status = -EINVAL; - break; - } - pEqualizer->getBandRange(param2, *(uint32_t *)pValue, *((uint32_t *)pValue + 1)); - LOGV("Equalizer_getParameter() EQ_PARAM_BAND_FREQ_RANGE band %d, min %d, max %d", param2, *(int32_t *)pValue, *((int32_t *)pValue + 1)); - break; - - case EQ_PARAM_GET_BAND: - param2 = *pParam; - *(int32_t *)pValue = pEqualizer->getMostRelevantBand(param2); - LOGV("Equalizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d", param2, *(int32_t *)pValue); - break; - - case EQ_PARAM_CUR_PRESET: - *(int16_t *)pValue = pEqualizer->getPreset(); - LOGV("Equalizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue); - break; - - case EQ_PARAM_GET_NUM_OF_PRESETS: - *(int16_t *)pValue = pEqualizer->getNumPresets(); - LOGV("Equalizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue); - break; - - case EQ_PARAM_GET_PRESET_NAME: - param2 = *pParam; - if (param2 >= pEqualizer->getNumPresets()) { - status = -EINVAL; - break; - } - name = (char *)pValue; - strncpy(name, pEqualizer->getPresetName(param2), *pValueSize - 1); - name[*pValueSize - 1] = 0; - *pValueSize = strlen(name) + 1; - LOGV("Equalizer_getParameter() EQ_PARAM_GET_PRESET_NAME preset %d, name %s len %d", param2, gEqualizerPresets[param2].name, *pValueSize); - break; - - default: - LOGV("Equalizer_getParameter() invalid param %d", param); - status = -EINVAL; - break; - } - - return status; -} // end Equalizer_getParameter - - -//---------------------------------------------------------------------------- -// Equalizer_setParameter() -//---------------------------------------------------------------------------- -// Purpose: -// Set a Equalizer parameter -// -// Inputs: -// pEqualizer - handle to instance data -// pParam - pointer to parameter -// pValue - pointer to value -// -// Outputs: -// -// -// Side Effects: -// -//---------------------------------------------------------------------------- - -int Equalizer_setParameter (AudioEqualizer * pEqualizer, int32_t *pParam, void *pValue) -{ - int status = 0; - int32_t preset; - int32_t band; - int32_t level; - int32_t param = *pParam++; - - - switch (param) { - case EQ_PARAM_CUR_PRESET: - preset = *(int16_t *)pValue; - - LOGV("setParameter() EQ_PARAM_CUR_PRESET %d", preset); - if (preset >= pEqualizer->getNumPresets()) { - status = -EINVAL; - break; - } - pEqualizer->setPreset(preset); - pEqualizer->commit(true); - break; - case EQ_PARAM_BAND_LEVEL: - band = *pParam; - level = *(int32_t *)pValue; - LOGV("setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level); - if (band >= kNumBands) { - status = -EINVAL; - break; - } - pEqualizer->setGain(band, level); - pEqualizer->commit(true); - break; - default: - LOGV("setParameter() invalid param %d", param); - break; - } - - return status; -} // end Equalizer_setParameter - -} // namespace -} // namespace - - -// -//--- Effect Control Interface Implementation -// - -extern "C" int Equalizer_process(effect_interface_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) -{ - android::EqualizerContext * pContext = (android::EqualizerContext *) self; - - if (pContext == NULL) { - return -EINVAL; - } - if (inBuffer == NULL || inBuffer->raw == NULL || - outBuffer == NULL || outBuffer->raw == NULL || - inBuffer->frameCount != outBuffer->frameCount) { - return -EINVAL; - } - - if (pContext->state == EQUALIZER_STATE_UNINITIALIZED) { - return -EINVAL; - } - if (pContext->state == EQUALIZER_STATE_INITIALIZED) { - return -ENODATA; - } - - pContext->adapter.process(inBuffer->raw, outBuffer->raw, outBuffer->frameCount); - - return 0; -} // end Equalizer_process - -extern "C" int Equalizer_command(effect_interface_t self, int cmdCode, int cmdSize, - void *pCmdData, int *replySize, void *pReplyData) { - - android::EqualizerContext * pContext = (android::EqualizerContext *) self; - int retsize; - - if (pContext == NULL || pContext->state == EQUALIZER_STATE_UNINITIALIZED) { - return -EINVAL; - } - - android::AudioEqualizer * pEqualizer = pContext->pEqualizer; - - LOGV("Equalizer_command command %d cmdSize %d",cmdCode, cmdSize); - - switch (cmdCode) { - case EFFECT_CMD_INIT: - if (pReplyData == NULL || *replySize != sizeof(int)) { - return -EINVAL; - } - *(int *) pReplyData = Equalizer_init(pContext); - break; - case EFFECT_CMD_CONFIGURE: - if (pCmdData == NULL || cmdSize != sizeof(effect_config_t) - || pReplyData == NULL || *replySize != sizeof(int)) { - return -EINVAL; - } - *(int *) pReplyData = Equalizer_configure(pContext, - (effect_config_t *) pCmdData); - break; - case EFFECT_CMD_RESET: - Equalizer_configure(pContext, &pContext->config); - break; - case EFFECT_CMD_GET_PARAM: { - if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || - pReplyData == NULL || *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))) { - return -EINVAL; - } - effect_param_t *p = (effect_param_t *)pCmdData; - memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); - p = (effect_param_t *)pReplyData; - int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); - p->status = android::Equalizer_getParameter(pEqualizer, (int32_t *)p->data, &p->vsize, - p->data + voffset); - *replySize = sizeof(effect_param_t) + voffset + p->vsize; - LOGV("Equalizer_command EFFECT_CMD_GET_PARAM *pCmdData %d, *replySize %d, *pReplyData %08x %08x", - *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), *replySize, - *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset), - *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset + sizeof(int32_t))); - - } break; - case EFFECT_CMD_SET_PARAM: { - LOGV("Equalizer_command EFFECT_CMD_SET_PARAM cmdSize %d pCmdData %p, *replySize %d, pReplyData %p", cmdSize, pCmdData, *replySize, pReplyData); - if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || - pReplyData == NULL || *replySize != sizeof(int32_t)) { - return -EINVAL; - } - effect_param_t *p = (effect_param_t *) pCmdData; - *(int *)pReplyData = android::Equalizer_setParameter(pEqualizer, (int32_t *)p->data, - p->data + p->psize); - } break; - case EFFECT_CMD_ENABLE: - if (pReplyData == NULL || *replySize != sizeof(int)) { - return -EINVAL; - } - if (pContext->state != EQUALIZER_STATE_INITIALIZED) { - return -ENOSYS; - } - pContext->state = EQUALIZER_STATE_ACTIVE; - LOGV("EFFECT_CMD_ENABLE() OK"); - *(int *)pReplyData = 0; - break; - case EFFECT_CMD_DISABLE: - if (pReplyData == NULL || *replySize != sizeof(int)) { - return -EINVAL; - } - if (pContext->state != EQUALIZER_STATE_ACTIVE) { - return -ENOSYS; - } - pContext->state = EQUALIZER_STATE_INITIALIZED; - LOGV("EFFECT_CMD_DISABLE() OK"); - *(int *)pReplyData = 0; - break; - case EFFECT_CMD_SET_DEVICE: - case EFFECT_CMD_SET_VOLUME: - case EFFECT_CMD_SET_AUDIO_MODE: - break; - default: - LOGW("Equalizer_command invalid command %d",cmdCode); - return -EINVAL; - } - - return 0; -} - -// effect_interface_t interface implementation for equalizer effect -const struct effect_interface_s gEqualizerInterface = { - Equalizer_process, - Equalizer_command -}; - - diff --git a/media/libeffects/EffectReverb.c b/media/libeffects/EffectReverb.c deleted file mode 100644 index 2ce7558..0000000 --- a/media/libeffects/EffectReverb.c +++ /dev/null @@ -1,2135 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "EffectReverb" -//#define LOG_NDEBUG 0 -#include -#include -#include -#include -#include "EffectReverb.h" -#include "EffectsMath.h" - -// effect_interface_t interface implementation for reverb effect -const struct effect_interface_s gReverbInterface = { - Reverb_Process, - Reverb_Command -}; - -// Google auxiliary environmental reverb UUID: 1f0ae2e0-4ef7-11df-bc09-0002a5d5c51b -static const effect_descriptor_t gAuxEnvReverbDescriptor = { - {0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, {0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e}}, - {0x1f0ae2e0, 0x4ef7, 0x11df, 0xbc09, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, - EFFECT_API_VERSION, - // flags other than EFFECT_FLAG_TYPE_AUXILIARY set for test purpose - EFFECT_FLAG_TYPE_AUXILIARY | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_AUDIO_MODE_IND, - 0, // TODO - 33, - "Aux Environmental Reverb", - "Google Inc." -}; - -// Google insert environmental reverb UUID: aa476040-6342-11df-91a4-0002a5d5c51b -static const effect_descriptor_t gInsertEnvReverbDescriptor = { - {0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, {0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e}}, - {0xaa476040, 0x6342, 0x11df, 0x91a4, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, - EFFECT_API_VERSION, - EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST, - 0, // TODO - 33, - "Insert Environmental reverb", - "Google Inc." -}; - -// Google auxiliary preset reverb UUID: 63909320-53a6-11df-bdbd-0002a5d5c51b -static const effect_descriptor_t gAuxPresetReverbDescriptor = { - {0x47382d60, 0xddd8, 0x11db, 0xbf3a, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, - {0x63909320, 0x53a6, 0x11df, 0xbdbd, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, - EFFECT_API_VERSION, - EFFECT_FLAG_TYPE_AUXILIARY, - 0, // TODO - 33, - "Aux Preset Reverb", - "Google Inc." -}; - -// Google insert preset reverb UUID: d93dc6a0-6342-11df-b128-0002a5d5c51b -static const effect_descriptor_t gInsertPresetReverbDescriptor = { - {0x47382d60, 0xddd8, 0x11db, 0xbf3a, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, - {0xd93dc6a0, 0x6342, 0x11df, 0xb128, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, - EFFECT_API_VERSION, - EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST, - 0, // TODO - 33, - "Insert Preset Reverb", - "Google Inc." -}; - -// gDescriptors contains pointers to all defined effect descriptor in this library -static const effect_descriptor_t * const gDescriptors[] = { - &gAuxEnvReverbDescriptor, - &gInsertEnvReverbDescriptor, - &gAuxPresetReverbDescriptor, - &gInsertPresetReverbDescriptor -}; - -/*---------------------------------------------------------------------------- - * Effect API implementation - *--------------------------------------------------------------------------*/ - -/*--- Effect Library Interface Implementation ---*/ - -int EffectQueryNumberEffects(uint32_t *pNumEffects) { - *pNumEffects = sizeof(gDescriptors) / sizeof(const effect_descriptor_t *); - return 0; -} - -int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor) { - if (pDescriptor == NULL) { - return -EINVAL; - } - if (index >= sizeof(gDescriptors) / sizeof(const effect_descriptor_t *)) { - return -EINVAL; - } - memcpy(pDescriptor, gDescriptors[index], - sizeof(effect_descriptor_t)); - return 0; -} - -int EffectCreate(effect_uuid_t *uuid, - int32_t sessionId, - int32_t ioId, - effect_interface_t *pInterface) { - int ret; - int i; - reverb_module_t *module; - const effect_descriptor_t *desc; - int aux = 0; - int preset = 0; - - LOGV("EffectLibCreateEffect start"); - - if (pInterface == NULL || uuid == NULL) { - return -EINVAL; - } - - for (i = 0; gDescriptors[i] != NULL; i++) { - desc = gDescriptors[i]; - if (memcmp(uuid, &desc->uuid, sizeof(effect_uuid_t)) - == 0) { - break; - } - } - - if (gDescriptors[i] == NULL) { - return -ENOENT; - } - - module = malloc(sizeof(reverb_module_t)); - - module->itfe = &gReverbInterface; - - module->context.mState = REVERB_STATE_UNINITIALIZED; - - if (memcmp(&desc->type, SL_IID_PRESETREVERB, sizeof(effect_uuid_t)) == 0) { - preset = 1; - } - if ((desc->flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { - aux = 1; - } - ret = Reverb_Init(module, aux, preset); - if (ret < 0) { - LOGW("EffectLibCreateEffect() init failed"); - free(module); - return ret; - } - - *pInterface = (effect_interface_t) module; - - module->context.mState = REVERB_STATE_INITIALIZED; - - LOGV("EffectLibCreateEffect %p ,size %d", module, sizeof(reverb_module_t)); - - return 0; -} - -int EffectRelease(effect_interface_t interface) { - reverb_module_t *pRvbModule = (reverb_module_t *)interface; - - LOGV("EffectLibReleaseEffect %p", interface); - if (interface == NULL) { - return -EINVAL; - } - - pRvbModule->context.mState = REVERB_STATE_UNINITIALIZED; - - free(pRvbModule); - return 0; -} - - -/*--- Effect Control Interface Implementation ---*/ - -static int Reverb_Process(effect_interface_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) { - reverb_object_t *pReverb; - int16_t *pSrc, *pDst; - reverb_module_t *pRvbModule = (reverb_module_t *)self; - - if (pRvbModule == NULL) { - return -EINVAL; - } - - if (inBuffer == NULL || inBuffer->raw == NULL || - outBuffer == NULL || outBuffer->raw == NULL || - inBuffer->frameCount != outBuffer->frameCount) { - return -EINVAL; - } - - pReverb = (reverb_object_t*) &pRvbModule->context; - - if (pReverb->mState == REVERB_STATE_UNINITIALIZED) { - return -EINVAL; - } - if (pReverb->mState == REVERB_STATE_INITIALIZED) { - return -ENODATA; - } - - //if bypassed or the preset forces the signal to be completely dry - if (pReverb->m_bBypass != 0) { - if (inBuffer->raw != outBuffer->raw) { - int16_t smp; - pSrc = inBuffer->s16; - pDst = outBuffer->s16; - size_t count = inBuffer->frameCount; - if (pRvbModule->config.inputCfg.channels == pRvbModule->config.outputCfg.channels) { - count *= 2; - while (count--) { - *pDst++ = *pSrc++; - } - } else { - while (count--) { - smp = *pSrc++; - *pDst++ = smp; - *pDst++ = smp; - } - } - } - return 0; - } - - if (pReverb->m_nNextRoom != pReverb->m_nCurrentRoom) { - ReverbUpdateRoom(pReverb, true); - } - - pSrc = inBuffer->s16; - pDst = outBuffer->s16; - size_t numSamples = outBuffer->frameCount; - while (numSamples) { - uint32_t processedSamples; - if (numSamples > (uint32_t) pReverb->m_nUpdatePeriodInSamples) { - processedSamples = (uint32_t) pReverb->m_nUpdatePeriodInSamples; - } else { - processedSamples = numSamples; - } - - /* increment update counter */ - pReverb->m_nUpdateCounter += (int16_t) processedSamples; - /* check if update counter needs to be reset */ - if (pReverb->m_nUpdateCounter >= pReverb->m_nUpdatePeriodInSamples) { - /* update interval has elapsed, so reset counter */ - pReverb->m_nUpdateCounter -= pReverb->m_nUpdatePeriodInSamples; - ReverbUpdateXfade(pReverb, pReverb->m_nUpdatePeriodInSamples); - - } /* end if m_nUpdateCounter >= update interval */ - - Reverb(pReverb, processedSamples, pDst, pSrc); - - numSamples -= processedSamples; - if (pReverb->m_Aux) { - pSrc += processedSamples; - } else { - pSrc += processedSamples * NUM_OUTPUT_CHANNELS; - } - pDst += processedSamples * NUM_OUTPUT_CHANNELS; - } - - return 0; -} - - -static int Reverb_Command(effect_interface_t self, int cmdCode, int cmdSize, - void *pCmdData, int *replySize, void *pReplyData) { - reverb_module_t *pRvbModule = (reverb_module_t *) self; - reverb_object_t *pReverb; - int retsize; - - if (pRvbModule == NULL || - pRvbModule->context.mState == REVERB_STATE_UNINITIALIZED) { - return -EINVAL; - } - - pReverb = (reverb_object_t*) &pRvbModule->context; - - LOGV("Reverb_Command command %d cmdSize %d",cmdCode, cmdSize); - - switch (cmdCode) { - case EFFECT_CMD_INIT: - if (pReplyData == NULL || *replySize != sizeof(int)) { - return -EINVAL; - } - *(int *) pReplyData = Reverb_Init(pRvbModule, pReverb->m_Aux, pReverb->m_Preset); - if (*(int *) pReplyData == 0) { - pRvbModule->context.mState = REVERB_STATE_INITIALIZED; - } - break; - case EFFECT_CMD_CONFIGURE: - if (pCmdData == NULL || cmdSize != sizeof(effect_config_t) - || pReplyData == NULL || *replySize != sizeof(int)) { - return -EINVAL; - } - *(int *) pReplyData = Reverb_Configure(pRvbModule, - (effect_config_t *)pCmdData, false); - break; - case EFFECT_CMD_RESET: - Reverb_Reset(pReverb, false); - break; - case EFFECT_CMD_GET_PARAM: - LOGV("Reverb_Command EFFECT_CMD_GET_PARAM pCmdData %p, *replySize %d, pReplyData: %p",pCmdData, *replySize, pReplyData); - - if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || - pReplyData == NULL || *replySize < (int) sizeof(effect_param_t)) { - return -EINVAL; - } - effect_param_t *rep = (effect_param_t *) pReplyData; - memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + sizeof(int32_t)); - LOGV("Reverb_Command EFFECT_CMD_GET_PARAM param %d, replySize %d",*(int32_t *)rep->data, rep->vsize); - rep->status = Reverb_getParameter(pReverb, *(int32_t *)rep->data, &rep->vsize, - rep->data + sizeof(int32_t)); - *replySize = sizeof(effect_param_t) + sizeof(int32_t) + rep->vsize; - break; - case EFFECT_CMD_SET_PARAM: - LOGV("Reverb_Command EFFECT_CMD_SET_PARAM cmdSize %d pCmdData %p, *replySize %d, pReplyData %p", - cmdSize, pCmdData, *replySize, pReplyData); - if (pCmdData == NULL || (cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t))) - || pReplyData == NULL || *replySize != (int)sizeof(int32_t)) { - return -EINVAL; - } - effect_param_t *cmd = (effect_param_t *) pCmdData; - *(int *)pReplyData = Reverb_setParameter(pReverb, *(int32_t *)cmd->data, - cmd->vsize, cmd->data + sizeof(int32_t)); - break; - case EFFECT_CMD_ENABLE: - if (pReplyData == NULL || *replySize != sizeof(int)) { - return -EINVAL; - } - if (pReverb->mState != REVERB_STATE_INITIALIZED) { - return -ENOSYS; - } - pReverb->mState = REVERB_STATE_ACTIVE; - LOGV("EFFECT_CMD_ENABLE() OK"); - *(int *)pReplyData = 0; - break; - case EFFECT_CMD_DISABLE: - if (pReplyData == NULL || *replySize != sizeof(int)) { - return -EINVAL; - } - if (pReverb->mState != REVERB_STATE_ACTIVE) { - return -ENOSYS; - } - pReverb->mState = REVERB_STATE_INITIALIZED; - LOGV("EFFECT_CMD_DISABLE() OK"); - *(int *)pReplyData = 0; - break; - case EFFECT_CMD_SET_DEVICE: - if (pCmdData == NULL || cmdSize != (int)sizeof(uint32_t)) { - return -EINVAL; - } - LOGV("Reverb_Command EFFECT_CMD_SET_DEVICE: 0x%08x", *(uint32_t *)pCmdData); - break; - case EFFECT_CMD_SET_VOLUME: { - // audio output is always stereo => 2 channel volumes - if (pCmdData == NULL || cmdSize != (int)sizeof(uint32_t) * 2) { - return -EINVAL; - } - float left = (float)(*(uint32_t *)pCmdData) / (1 << 24); - float right = (float)(*((uint32_t *)pCmdData + 1)) / (1 << 24); - LOGV("Reverb_Command EFFECT_CMD_SET_VOLUME: left %f, right %f ", left, right); - break; - } - case EFFECT_CMD_SET_AUDIO_MODE: - if (pCmdData == NULL || cmdSize != (int)sizeof(uint32_t)) { - return -EINVAL; - } - LOGV("Reverb_Command EFFECT_CMD_SET_AUDIO_MODE: %d", *(uint32_t *)pCmdData); - break; - default: - LOGW("Reverb_Command invalid command %d",cmdCode); - return -EINVAL; - } - - return 0; -} - - -/*---------------------------------------------------------------------------- - * Reverb internal functions - *--------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------- - * Reverb_Init() - *---------------------------------------------------------------------------- - * Purpose: - * Initialize reverb context and apply default parameters - * - * Inputs: - * pRvbModule - pointer to reverb effect module - * aux - indicates if the reverb is used as auxiliary (1) or insert (0) - * preset - indicates if the reverb is used in preset (1) or environmental (0) mode - * - * Outputs: - * - * Side Effects: - * - *---------------------------------------------------------------------------- - */ - -int Reverb_Init(reverb_module_t *pRvbModule, int aux, int preset) { - int ret; - - LOGV("Reverb_Init module %p, aux: %d, preset: %d", pRvbModule,aux, preset); - - memset(&pRvbModule->context, 0, sizeof(reverb_object_t)); - - pRvbModule->context.m_Aux = (uint16_t)aux; - pRvbModule->context.m_Preset = (uint16_t)preset; - - pRvbModule->config.inputCfg.samplingRate = 44100; - if (aux) { - pRvbModule->config.inputCfg.channels = CHANNEL_MONO; - } else { - pRvbModule->config.inputCfg.channels = CHANNEL_STEREO; - } - pRvbModule->config.inputCfg.format = SAMPLE_FORMAT_PCM_S15; - pRvbModule->config.inputCfg.bufferProvider.getBuffer = NULL; - pRvbModule->config.inputCfg.bufferProvider.releaseBuffer = NULL; - pRvbModule->config.inputCfg.bufferProvider.cookie = NULL; - pRvbModule->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; - pRvbModule->config.inputCfg.mask = EFFECT_CONFIG_ALL; - pRvbModule->config.outputCfg.samplingRate = 44100; - pRvbModule->config.outputCfg.channels = CHANNEL_STEREO; - pRvbModule->config.outputCfg.format = SAMPLE_FORMAT_PCM_S15; - pRvbModule->config.outputCfg.bufferProvider.getBuffer = NULL; - pRvbModule->config.outputCfg.bufferProvider.releaseBuffer = NULL; - pRvbModule->config.outputCfg.bufferProvider.cookie = NULL; - pRvbModule->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; - pRvbModule->config.outputCfg.mask = EFFECT_CONFIG_ALL; - - ret = Reverb_Configure(pRvbModule, &pRvbModule->config, true); - if (ret < 0) { - LOGV("Reverb_Init error %d on module %p", ret, pRvbModule); - } - - return ret; -} - -/*---------------------------------------------------------------------------- - * Reverb_Init() - *---------------------------------------------------------------------------- - * Purpose: - * Set input and output audio configuration. - * - * Inputs: - * pRvbModule - pointer to reverb effect module - * pConfig - pointer to effect_config_t structure containing input - * and output audio parameters configuration - * init - true if called from init function - * Outputs: - * - * Side Effects: - * - *---------------------------------------------------------------------------- - */ - -int Reverb_Configure(reverb_module_t *pRvbModule, effect_config_t *pConfig, - bool init) { - reverb_object_t *pReverb = &pRvbModule->context; - int bufferSizeInSamples; - int updatePeriodInSamples; - int xfadePeriodInSamples; - - // Check configuration compatibility with build options - if (pConfig->inputCfg.samplingRate - != pConfig->outputCfg.samplingRate - || pConfig->outputCfg.channels != OUTPUT_CHANNELS - || pConfig->inputCfg.format != SAMPLE_FORMAT_PCM_S15 - || pConfig->outputCfg.format != SAMPLE_FORMAT_PCM_S15) { - LOGV("Reverb_Configure invalid config"); - return -EINVAL; - } - if ((pReverb->m_Aux && (pConfig->inputCfg.channels != CHANNEL_MONO)) || - (!pReverb->m_Aux && (pConfig->inputCfg.channels != CHANNEL_STEREO))) { - LOGV("Reverb_Configure invalid config"); - return -EINVAL; - } - - memcpy(&pRvbModule->config, pConfig, sizeof(effect_config_t)); - - pReverb->m_nSamplingRate = pRvbModule->config.outputCfg.samplingRate; - - switch (pReverb->m_nSamplingRate) { - case 8000: - pReverb->m_nUpdatePeriodInBits = 5; - bufferSizeInSamples = 4096; - pReverb->m_nCosWT_5KHz = -23170; - break; - case 16000: - pReverb->m_nUpdatePeriodInBits = 6; - bufferSizeInSamples = 8192; - pReverb->m_nCosWT_5KHz = -12540; - break; - case 22050: - pReverb->m_nUpdatePeriodInBits = 7; - bufferSizeInSamples = 8192; - pReverb->m_nCosWT_5KHz = 4768; - break; - case 32000: - pReverb->m_nUpdatePeriodInBits = 7; - bufferSizeInSamples = 16384; - pReverb->m_nCosWT_5KHz = 18205; - break; - case 44100: - pReverb->m_nUpdatePeriodInBits = 8; - bufferSizeInSamples = 16384; - pReverb->m_nCosWT_5KHz = 24799; - break; - case 48000: - pReverb->m_nUpdatePeriodInBits = 8; - bufferSizeInSamples = 16384; - pReverb->m_nCosWT_5KHz = 25997; - break; - default: - LOGV("Reverb_Configure invalid sampling rate %d", pReverb->m_nSamplingRate); - return -EINVAL; - } - - // Define a mask for circular addressing, so that array index - // can wraparound and stay in array boundary of 0, 1, ..., (buffer size -1) - // The buffer size MUST be a power of two - pReverb->m_nBufferMask = (int32_t) (bufferSizeInSamples - 1); - /* reverb parameters are updated every 2^(pReverb->m_nUpdatePeriodInBits) samples */ - updatePeriodInSamples = (int32_t) (0x1L << pReverb->m_nUpdatePeriodInBits); - /* - calculate the update counter by bitwise ANDING with this value to - generate a 2^n modulo value - */ - pReverb->m_nUpdatePeriodInSamples = (int32_t) updatePeriodInSamples; - - xfadePeriodInSamples = (int32_t) (REVERB_XFADE_PERIOD_IN_SECONDS - * (double) pReverb->m_nSamplingRate); - - // set xfade parameters - pReverb->m_nPhaseIncrement - = (int16_t) (65536 / ((int16_t) xfadePeriodInSamples - / (int16_t) updatePeriodInSamples)); - - if (init) { - ReverbReadInPresets(pReverb); - - // for debugging purposes, allow noise generator - pReverb->m_bUseNoise = true; - - // for debugging purposes, allow bypass - pReverb->m_bBypass = 0; - - pReverb->m_nNextRoom = 1; - - pReverb->m_nNoise = (int16_t) 0xABCD; - } - - Reverb_Reset(pReverb, init); - - return 0; -} - -/*---------------------------------------------------------------------------- - * Reverb_Reset() - *---------------------------------------------------------------------------- - * Purpose: - * Reset internal states and clear delay lines. - * - * Inputs: - * pReverb - pointer to reverb context - * init - true if called from init function - * - * Outputs: - * - * Side Effects: - * - *---------------------------------------------------------------------------- - */ - -void Reverb_Reset(reverb_object_t *pReverb, bool init) { - int bufferSizeInSamples = (int32_t) (pReverb->m_nBufferMask + 1); - int maxApSamples; - int maxDelaySamples; - int maxEarlySamples; - int ap1In; - int delay0In; - int delay1In; - int32_t i; - uint16_t nOffset; - - maxApSamples = ((int32_t) (MAX_AP_TIME * pReverb->m_nSamplingRate) >> 16); - maxDelaySamples = ((int32_t) (MAX_DELAY_TIME * pReverb->m_nSamplingRate) - >> 16); - maxEarlySamples = ((int32_t) (MAX_EARLY_TIME * pReverb->m_nSamplingRate) - >> 16); - - ap1In = (AP0_IN + maxApSamples + GUARD); - delay0In = (ap1In + maxApSamples + GUARD); - delay1In = (delay0In + maxDelaySamples + GUARD); - // Define the max offsets for the end points of each section - // i.e., we don't expect a given section's taps to go beyond - // the following limits - - pReverb->m_nEarly0in = (delay1In + maxDelaySamples + GUARD); - pReverb->m_nEarly1in = (pReverb->m_nEarly0in + maxEarlySamples + GUARD); - - pReverb->m_sAp0.m_zApIn = AP0_IN; - - pReverb->m_zD0In = delay0In; - - pReverb->m_sAp1.m_zApIn = ap1In; - - pReverb->m_zD1In = delay1In; - - pReverb->m_zOutLpfL = 0; - pReverb->m_zOutLpfR = 0; - - pReverb->m_nRevFbkR = 0; - pReverb->m_nRevFbkL = 0; - - // set base index into circular buffer - pReverb->m_nBaseIndex = 0; - - // clear the reverb delay line - for (i = 0; i < bufferSizeInSamples; i++) { - pReverb->m_nDelayLine[i] = 0; - } - - ReverbUpdateRoom(pReverb, init); - - pReverb->m_nUpdateCounter = 0; - - pReverb->m_nPhase = -32768; - - pReverb->m_nSin = 0; - pReverb->m_nCos = 0; - pReverb->m_nSinIncrement = 0; - pReverb->m_nCosIncrement = 0; - - // set delay tap lengths - nOffset = ReverbCalculateNoise(pReverb); - - pReverb->m_zD1Cross = pReverb->m_nDelay1Out - pReverb->m_nMaxExcursion - + nOffset; - - nOffset = ReverbCalculateNoise(pReverb); - - pReverb->m_zD0Cross = pReverb->m_nDelay0Out - pReverb->m_nMaxExcursion - - nOffset; - - nOffset = ReverbCalculateNoise(pReverb); - - pReverb->m_zD0Self = pReverb->m_nDelay0Out - pReverb->m_nMaxExcursion - - nOffset; - - nOffset = ReverbCalculateNoise(pReverb); - - pReverb->m_zD1Self = pReverb->m_nDelay1Out - pReverb->m_nMaxExcursion - + nOffset; -} - -/*---------------------------------------------------------------------------- - * Reverb_getParameter() - *---------------------------------------------------------------------------- - * Purpose: - * Get a Reverb parameter - * - * Inputs: - * pReverb - handle to instance data - * param - parameter - * pValue - pointer to variable to hold retrieved value - * pSize - pointer to value size: maximum size as input - * - * Outputs: - * *pValue updated with parameter value - * *pSize updated with actual value size - * - * - * Side Effects: - * - *---------------------------------------------------------------------------- - */ -int Reverb_getParameter(reverb_object_t *pReverb, int32_t param, size_t *pSize, - void *pValue) { - int32_t *pValue32; - int16_t *pValue16; - t_reverb_properties *pProperties; - int32_t i; - int32_t temp; - int32_t temp2; - size_t size; - - if (pReverb->m_Preset) { - if (param != REVERB_PARAM_PRESET || *pSize < sizeof(int16_t)) { - return -EINVAL; - } - size = sizeof(int16_t); - pValue16 = (int16_t *)pValue; - // REVERB_PRESET_NONE is mapped to bypass - if (pReverb->m_bBypass != 0) { - *pValue16 = (int16_t)REVERB_PRESET_NONE; - } else { - *pValue16 = (int16_t)(pReverb->m_nNextRoom + 1); - } - LOGV("get REVERB_PARAM_PRESET, preset %d", *pValue16); - } else { - switch (param) { - case REVERB_PARAM_ROOM_LEVEL: - case REVERB_PARAM_ROOM_HF_LEVEL: - case REVERB_PARAM_DECAY_HF_RATIO: - case REVERB_PARAM_REFLECTIONS_LEVEL: - case REVERB_PARAM_REVERB_LEVEL: - case REVERB_PARAM_DIFFUSION: - case REVERB_PARAM_DENSITY: - size = sizeof(int16_t); - break; - - case REVERB_PARAM_BYPASS: - case REVERB_PARAM_DECAY_TIME: - case REVERB_PARAM_REFLECTIONS_DELAY: - case REVERB_PARAM_REVERB_DELAY: - size = sizeof(int32_t); - break; - - case REVERB_PARAM_PROPERTIES: - size = sizeof(t_reverb_properties); - break; - - default: - return -EINVAL; - } - - if (*pSize < size) { - return -EINVAL; - } - - pValue32 = (int32_t *) pValue; - pValue16 = (int16_t *) pValue; - pProperties = (t_reverb_properties *) pValue; - - switch (param) { - case REVERB_PARAM_BYPASS: - *pValue32 = (int32_t) pReverb->m_bBypass; - break; - - case REVERB_PARAM_PROPERTIES: - pValue16 = &pProperties->roomLevel; - /* FALL THROUGH */ - - case REVERB_PARAM_ROOM_LEVEL: - // Convert m_nRoomLpfFwd to millibels - temp = (pReverb->m_nRoomLpfFwd << 15) - / (32767 - pReverb->m_nRoomLpfFbk); - *pValue16 = Effects_Linear16ToMillibels(temp); - - LOGV("get REVERB_PARAM_ROOM_LEVEL %d, gain %d, m_nRoomLpfFwd %d, m_nRoomLpfFbk %d", *pValue16, temp, pReverb->m_nRoomLpfFwd, pReverb->m_nRoomLpfFbk); - - if (param == REVERB_PARAM_ROOM_LEVEL) { - break; - } - pValue16 = &pProperties->roomHFLevel; - /* FALL THROUGH */ - - case REVERB_PARAM_ROOM_HF_LEVEL: - // The ratio between linear gain at 0Hz and at 5000Hz for the room low pass is: - // (1 + a1) / sqrt(a1^2 + 2*C*a1 + 1) where: - // - a1 is minus the LP feedback gain: -pReverb->m_nRoomLpfFbk - // - C is cos(2piWT) @ 5000Hz: pReverb->m_nCosWT_5KHz - - temp = MULT_EG1_EG1(pReverb->m_nRoomLpfFbk, pReverb->m_nRoomLpfFbk); - LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, a1^2 %d", temp); - temp2 = MULT_EG1_EG1(pReverb->m_nRoomLpfFbk, pReverb->m_nCosWT_5KHz) - << 1; - LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, 2 Cos a1 %d", temp2); - temp = 32767 + temp - temp2; - LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, a1^2 + 2 Cos a1 + 1 %d", temp); - temp = Effects_Sqrt(temp) * 181; - LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, SQRT(a1^2 + 2 Cos a1 + 1) %d", temp); - temp = ((32767 - pReverb->m_nRoomLpfFbk) << 15) / temp; - - LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, gain %d, m_nRoomLpfFwd %d, m_nRoomLpfFbk %d", temp, pReverb->m_nRoomLpfFwd, pReverb->m_nRoomLpfFbk); - - *pValue16 = Effects_Linear16ToMillibels(temp); - - if (param == REVERB_PARAM_ROOM_HF_LEVEL) { - break; - } - pValue32 = &pProperties->decayTime; - /* FALL THROUGH */ - - case REVERB_PARAM_DECAY_TIME: - // Calculate reverb feedback path gain - temp = (pReverb->m_nRvbLpfFwd << 15) / (32767 - pReverb->m_nRvbLpfFbk); - temp = Effects_Linear16ToMillibels(temp); - - // Calculate decay time: g = -6000 d/DT , g gain in millibels, d reverb delay, DT decay time - temp = (-6000 * pReverb->m_nLateDelay) / temp; - - // Convert samples to ms - *pValue32 = (temp * 1000) / pReverb->m_nSamplingRate; - - LOGV("get REVERB_PARAM_DECAY_TIME, samples %d, ms %d", temp, *pValue32); - - if (param == REVERB_PARAM_DECAY_TIME) { - break; - } - pValue16 = &pProperties->decayHFRatio; - /* FALL THROUGH */ - - case REVERB_PARAM_DECAY_HF_RATIO: - // If r is the decay HF ratio (r = REVERB_PARAM_DECAY_HF_RATIO/1000) we have: - // DT_5000Hz = DT_0Hz * r - // and G_5000Hz = -6000 * d / DT_5000Hz and G_0Hz = -6000 * d / DT_0Hz in millibels so : - // r = G_0Hz/G_5000Hz in millibels - // The linear gain at 5000Hz is b0 / sqrt(a1^2 + 2*C*a1 + 1) where: - // - a1 is minus the LP feedback gain: -pReverb->m_nRvbLpfFbk - // - b0 is the LP forward gain: pReverb->m_nRvbLpfFwd - // - C is cos(2piWT) @ 5000Hz: pReverb->m_nCosWT_5KHz - if (pReverb->m_nRvbLpfFbk == 0) { - *pValue16 = 1000; - LOGV("get REVERB_PARAM_DECAY_HF_RATIO, pReverb->m_nRvbLpfFbk == 0, ratio %d", *pValue16); - } else { - temp = MULT_EG1_EG1(pReverb->m_nRvbLpfFbk, pReverb->m_nRvbLpfFbk); - temp2 = MULT_EG1_EG1(pReverb->m_nRvbLpfFbk, pReverb->m_nCosWT_5KHz) - << 1; - temp = 32767 + temp - temp2; - temp = Effects_Sqrt(temp) * 181; - temp = (pReverb->m_nRvbLpfFwd << 15) / temp; - // The linear gain at 0Hz is b0 / (a1 + 1) - temp2 = (pReverb->m_nRvbLpfFwd << 15) / (32767 - - pReverb->m_nRvbLpfFbk); - - temp = Effects_Linear16ToMillibels(temp); - temp2 = Effects_Linear16ToMillibels(temp2); - LOGV("get REVERB_PARAM_DECAY_HF_RATIO, gain 5KHz %d mB, gain DC %d mB", temp, temp2); - - if (temp == 0) - temp = 1; - temp = (int16_t) ((1000 * temp2) / temp); - if (temp > 1000) - temp = 1000; - - *pValue16 = temp; - LOGV("get REVERB_PARAM_DECAY_HF_RATIO, ratio %d", *pValue16); - } - - if (param == REVERB_PARAM_DECAY_HF_RATIO) { - break; - } - pValue16 = &pProperties->reflectionsLevel; - /* FALL THROUGH */ - - case REVERB_PARAM_REFLECTIONS_LEVEL: - *pValue16 = Effects_Linear16ToMillibels(pReverb->m_nEarlyGain); - - LOGV("get REVERB_PARAM_REFLECTIONS_LEVEL, %d", *pValue16); - if (param == REVERB_PARAM_REFLECTIONS_LEVEL) { - break; - } - pValue32 = &pProperties->reflectionsDelay; - /* FALL THROUGH */ - - case REVERB_PARAM_REFLECTIONS_DELAY: - // convert samples to ms - *pValue32 = (pReverb->m_nEarlyDelay * 1000) / pReverb->m_nSamplingRate; - - LOGV("get REVERB_PARAM_REFLECTIONS_DELAY, samples %d, ms %d", pReverb->m_nEarlyDelay, *pValue32); - - if (param == REVERB_PARAM_REFLECTIONS_DELAY) { - break; - } - pValue16 = &pProperties->reverbLevel; - /* FALL THROUGH */ - - case REVERB_PARAM_REVERB_LEVEL: - // Convert linear gain to millibels - *pValue16 = Effects_Linear16ToMillibels(pReverb->m_nLateGain << 2); - - LOGV("get REVERB_PARAM_REVERB_LEVEL %d", *pValue16); - - if (param == REVERB_PARAM_REVERB_LEVEL) { - break; - } - pValue32 = &pProperties->reverbDelay; - /* FALL THROUGH */ - - case REVERB_PARAM_REVERB_DELAY: - // convert samples to ms - *pValue32 = (pReverb->m_nLateDelay * 1000) / pReverb->m_nSamplingRate; - - LOGV("get REVERB_PARAM_REVERB_DELAY, samples %d, ms %d", pReverb->m_nLateDelay, *pValue32); - - if (param == REVERB_PARAM_REVERB_DELAY) { - break; - } - pValue16 = &pProperties->diffusion; - /* FALL THROUGH */ - - case REVERB_PARAM_DIFFUSION: - temp = (int16_t) ((1000 * (pReverb->m_sAp0.m_nApGain - AP0_GAIN_BASE)) - / AP0_GAIN_RANGE); - - if (temp < 0) - temp = 0; - if (temp > 1000) - temp = 1000; - - *pValue16 = temp; - LOGV("get REVERB_PARAM_DIFFUSION, %d, AP0 gain %d", *pValue16, pReverb->m_sAp0.m_nApGain); - - if (param == REVERB_PARAM_DIFFUSION) { - break; - } - pValue16 = &pProperties->density; - /* FALL THROUGH */ - - case REVERB_PARAM_DENSITY: - // Calculate AP delay in time units - temp = ((pReverb->m_sAp0.m_zApOut - pReverb->m_sAp0.m_zApIn) << 16) - / pReverb->m_nSamplingRate; - - temp = (int16_t) ((1000 * (temp - AP0_TIME_BASE)) / AP0_TIME_RANGE); - - if (temp < 0) - temp = 0; - if (temp > 1000) - temp = 1000; - - *pValue16 = temp; - - LOGV("get REVERB_PARAM_DENSITY, %d, AP0 delay smps %d", *pValue16, pReverb->m_sAp0.m_zApOut - pReverb->m_sAp0.m_zApIn); - break; - - default: - break; - } - } - - *pSize = size; - - LOGV("Reverb_getParameter, context %p, param %d, value %d", - pReverb, param, *(int *)pValue); - - return 0; -} /* end Reverb_getParameter */ - -/*---------------------------------------------------------------------------- - * Reverb_setParameter() - *---------------------------------------------------------------------------- - * Purpose: - * Set a Reverb parameter - * - * Inputs: - * pReverb - handle to instance data - * param - parameter - * pValue - pointer to parameter value - * size - value size - * - * Outputs: - * - * - * Side Effects: - * - *---------------------------------------------------------------------------- - */ -int Reverb_setParameter(reverb_object_t *pReverb, int32_t param, size_t size, - void *pValue) { - int32_t value32; - int16_t value16; - t_reverb_properties *pProperties; - int32_t i; - int32_t temp; - int32_t temp2; - reverb_preset_t *pPreset; - int maxSamples; - int32_t averageDelay; - size_t paramSize; - - LOGV("Reverb_setParameter, context %p, param %d, value16 %d, value32 %d", - pReverb, param, *(int16_t *)pValue, *(int32_t *)pValue); - - if (pReverb->m_Preset) { - if (param != REVERB_PARAM_PRESET || size != sizeof(int16_t)) { - return -EINVAL; - } - value16 = *(int16_t *)pValue; - LOGV("set REVERB_PARAM_PRESET, preset %d", value16); - if (value16 < REVERB_PRESET_NONE || value16 > REVERB_PRESET_PLATE) { - return -EINVAL; - } - // REVERB_PRESET_NONE is mapped to bypass - if (value16 == REVERB_PRESET_NONE) { - pReverb->m_bBypass = 1; - } else { - pReverb->m_bBypass = 0; - pReverb->m_nNextRoom = value16 - 1; - } - } else { - switch (param) { - case REVERB_PARAM_ROOM_LEVEL: - case REVERB_PARAM_ROOM_HF_LEVEL: - case REVERB_PARAM_DECAY_HF_RATIO: - case REVERB_PARAM_REFLECTIONS_LEVEL: - case REVERB_PARAM_REVERB_LEVEL: - case REVERB_PARAM_DIFFUSION: - case REVERB_PARAM_DENSITY: - paramSize = sizeof(int16_t); - break; - - case REVERB_PARAM_BYPASS: - case REVERB_PARAM_DECAY_TIME: - case REVERB_PARAM_REFLECTIONS_DELAY: - case REVERB_PARAM_REVERB_DELAY: - paramSize = sizeof(int32_t); - break; - - case REVERB_PARAM_PROPERTIES: - paramSize = sizeof(t_reverb_properties); - break; - - default: - return -EINVAL; - } - - if (size != paramSize) { - return -EINVAL; - } - - if (paramSize == sizeof(int16_t)) { - value16 = *(int16_t *) pValue; - } else if (paramSize == sizeof(int32_t)) { - value32 = *(int32_t *) pValue; - } else { - pProperties = (t_reverb_properties *) pValue; - } - - pPreset = &pReverb->m_sPreset.m_sPreset[pReverb->m_nNextRoom]; - - switch (param) { - case REVERB_PARAM_BYPASS: - pReverb->m_bBypass = (uint16_t)value32; - break; - - case REVERB_PARAM_PROPERTIES: - value16 = pProperties->roomLevel; - /* FALL THROUGH */ - - case REVERB_PARAM_ROOM_LEVEL: - // Convert millibels to linear 16 bit signed => m_nRoomLpfFwd - if (value16 > 0) - return -EINVAL; - - temp = Effects_MillibelsToLinear16(value16); - - pReverb->m_nRoomLpfFwd - = MULT_EG1_EG1(temp, (32767 - pReverb->m_nRoomLpfFbk)); - - LOGV("REVERB_PARAM_ROOM_LEVEL, gain %d, new m_nRoomLpfFwd %d, m_nRoomLpfFbk %d", temp, pReverb->m_nRoomLpfFwd, pReverb->m_nRoomLpfFbk); - if (param == REVERB_PARAM_ROOM_LEVEL) - break; - value16 = pProperties->roomHFLevel; - /* FALL THROUGH */ - - case REVERB_PARAM_ROOM_HF_LEVEL: - - // Limit to 0 , -40dB range because of low pass implementation - if (value16 > 0 || value16 < -4000) - return -EINVAL; - // Convert attenuation @ 5000H expressed in millibels to => m_nRoomLpfFbk - // m_nRoomLpfFbk is -a1 where a1 is the solution of: - // a1^2 + 2*(C-dG^2)/(1-dG^2)*a1 + 1 = 0 where: - // - C is cos(2*pi*5000/Fs) (pReverb->m_nCosWT_5KHz) - // - dG is G0/Gf (G0 is the linear gain at DC and Gf is the wanted gain at 5000Hz) - - // Save current DC gain m_nRoomLpfFwd / (32767 - m_nRoomLpfFbk) to keep it unchanged - // while changing HF level - temp2 = (pReverb->m_nRoomLpfFwd << 15) / (32767 - - pReverb->m_nRoomLpfFbk); - if (value16 == 0) { - pReverb->m_nRoomLpfFbk = 0; - } else { - int32_t dG2, b, delta; - - // dG^2 - temp = Effects_MillibelsToLinear16(value16); - LOGV("REVERB_PARAM_ROOM_HF_LEVEL, HF gain %d", temp); - temp = (1 << 30) / temp; - LOGV("REVERB_PARAM_ROOM_HF_LEVEL, 1/ HF gain %d", temp); - dG2 = (int32_t) (((int64_t) temp * (int64_t) temp) >> 15); - LOGV("REVERB_PARAM_ROOM_HF_LEVEL, 1/ HF gain ^ 2 %d", dG2); - // b = 2*(C-dG^2)/(1-dG^2) - b = (int32_t) ((((int64_t) 1 << (15 + 1)) - * ((int64_t) pReverb->m_nCosWT_5KHz - (int64_t) dG2)) - / ((int64_t) 32767 - (int64_t) dG2)); - - // delta = b^2 - 4 - delta = (int32_t) ((((int64_t) b * (int64_t) b) >> 15) - (1 << (15 - + 2))); - - LOGV_IF(delta > (1<<30), " delta overflow %d", delta); - - LOGV("REVERB_PARAM_ROOM_HF_LEVEL, dG2 %d, b %d, delta %d, m_nCosWT_5KHz %d", dG2, b, delta, pReverb->m_nCosWT_5KHz); - // m_nRoomLpfFbk = -a1 = - (- b + sqrt(delta)) / 2 - pReverb->m_nRoomLpfFbk = (b - Effects_Sqrt(delta) * 181) >> 1; - } - LOGV("REVERB_PARAM_ROOM_HF_LEVEL, olg DC gain %d new m_nRoomLpfFbk %d, old m_nRoomLpfFwd %d", - temp2, pReverb->m_nRoomLpfFbk, pReverb->m_nRoomLpfFwd); - - pReverb->m_nRoomLpfFwd - = MULT_EG1_EG1(temp2, (32767 - pReverb->m_nRoomLpfFbk)); - LOGV("REVERB_PARAM_ROOM_HF_LEVEL, new m_nRoomLpfFwd %d", pReverb->m_nRoomLpfFwd); - - if (param == REVERB_PARAM_ROOM_HF_LEVEL) - break; - value32 = pProperties->decayTime; - /* FALL THROUGH */ - - case REVERB_PARAM_DECAY_TIME: - - // Convert milliseconds to => m_nRvbLpfFwd (function of m_nRvbLpfFbk) - // convert ms to samples - value32 = (value32 * pReverb->m_nSamplingRate) / 1000; - - // calculate valid decay time range as a function of current reverb delay and - // max feed back gain. Min value <=> -40dB in one pass, Max value <=> feedback gain = -1 dB - // Calculate attenuation for each round in late reverb given a total attenuation of -6000 millibels. - // g = -6000 d/DT , g gain in millibels, d reverb delay, DT decay time - averageDelay = pReverb->m_nLateDelay - pReverb->m_nMaxExcursion; - averageDelay += ((pReverb->m_sAp0.m_zApOut - pReverb->m_sAp0.m_zApIn) - + (pReverb->m_sAp1.m_zApOut - pReverb->m_sAp1.m_zApIn)) >> 1; - - temp = (-6000 * averageDelay) / value32; - LOGV("REVERB_PARAM_DECAY_TIME, delay smps %d, DT smps %d, gain mB %d",averageDelay, value32, temp); - if (temp < -4000 || temp > -100) - return -EINVAL; - - // calculate low pass gain by adding reverb input attenuation (pReverb->m_nLateGain) and substrating output - // xfade and sum gain (max +9dB) - temp -= Effects_Linear16ToMillibels(pReverb->m_nLateGain) + 900; - temp = Effects_MillibelsToLinear16(temp); - - // DC gain (temp) = b0 / (1 + a1) = pReverb->m_nRvbLpfFwd / (32767 - pReverb->m_nRvbLpfFbk) - pReverb->m_nRvbLpfFwd - = MULT_EG1_EG1(temp, (32767 - pReverb->m_nRvbLpfFbk)); - - LOGV("REVERB_PARAM_DECAY_TIME, gain %d, new m_nRvbLpfFwd %d, old m_nRvbLpfFbk %d, reverb gain %d", temp, pReverb->m_nRvbLpfFwd, pReverb->m_nRvbLpfFbk, Effects_Linear16ToMillibels(pReverb->m_nLateGain)); - - if (param == REVERB_PARAM_DECAY_TIME) - break; - value16 = pProperties->decayHFRatio; - /* FALL THROUGH */ - - case REVERB_PARAM_DECAY_HF_RATIO: - - // We limit max value to 1000 because reverb filter is lowpass only - if (value16 < 100 || value16 > 1000) - return -EINVAL; - // Convert per mille to => m_nLpfFwd, m_nLpfFbk - - // Save current DC gain m_nRoomLpfFwd / (32767 - m_nRoomLpfFbk) to keep it unchanged - // while changing HF level - temp2 = (pReverb->m_nRvbLpfFwd << 15) / (32767 - pReverb->m_nRvbLpfFbk); - - if (value16 == 1000) { - pReverb->m_nRvbLpfFbk = 0; - } else { - int32_t dG2, b, delta; - - temp = Effects_Linear16ToMillibels(temp2); - // G_5000Hz = G_DC * (1000/REVERB_PARAM_DECAY_HF_RATIO) in millibels - - value32 = ((int32_t) 1000 << 15) / (int32_t) value16; - LOGV("REVERB_PARAM_DECAY_HF_RATIO, DC gain %d, DC gain mB %d, 1000/R %d", temp2, temp, value32); - - temp = (int32_t) (((int64_t) temp * (int64_t) value32) >> 15); - - if (temp < -4000) { - LOGV("REVERB_PARAM_DECAY_HF_RATIO HF gain overflow %d mB", temp); - temp = -4000; - } - - temp = Effects_MillibelsToLinear16(temp); - LOGV("REVERB_PARAM_DECAY_HF_RATIO, HF gain %d", temp); - // dG^2 - temp = (temp2 << 15) / temp; - dG2 = (int32_t) (((int64_t) temp * (int64_t) temp) >> 15); - - // b = 2*(C-dG^2)/(1-dG^2) - b = (int32_t) ((((int64_t) 1 << (15 + 1)) - * ((int64_t) pReverb->m_nCosWT_5KHz - (int64_t) dG2)) - / ((int64_t) 32767 - (int64_t) dG2)); - - // delta = b^2 - 4 - delta = (int32_t) ((((int64_t) b * (int64_t) b) >> 15) - (1 << (15 - + 2))); - - // m_nRoomLpfFbk = -a1 = - (- b + sqrt(delta)) / 2 - pReverb->m_nRvbLpfFbk = (b - Effects_Sqrt(delta) * 181) >> 1; - - LOGV("REVERB_PARAM_DECAY_HF_RATIO, dG2 %d, b %d, delta %d", dG2, b, delta); - - } - - LOGV("REVERB_PARAM_DECAY_HF_RATIO, gain %d, m_nRvbLpfFbk %d, m_nRvbLpfFwd %d", temp2, pReverb->m_nRvbLpfFbk, pReverb->m_nRvbLpfFwd); - - pReverb->m_nRvbLpfFwd - = MULT_EG1_EG1(temp2, (32767 - pReverb->m_nRvbLpfFbk)); - - if (param == REVERB_PARAM_DECAY_HF_RATIO) - break; - value16 = pProperties->reflectionsLevel; - /* FALL THROUGH */ - - case REVERB_PARAM_REFLECTIONS_LEVEL: - // We limit max value to 0 because gain is limited to 0dB - if (value16 > 0 || value16 < -6000) - return -EINVAL; - - // Convert millibels to linear 16 bit signed and recompute m_sEarlyL.m_nGain[i] and m_sEarlyR.m_nGain[i]. - value16 = Effects_MillibelsToLinear16(value16); - for (i = 0; i < REVERB_MAX_NUM_REFLECTIONS; i++) { - pReverb->m_sEarlyL.m_nGain[i] - = MULT_EG1_EG1(pPreset->m_sEarlyL.m_nGain[i],value16); - pReverb->m_sEarlyR.m_nGain[i] - = MULT_EG1_EG1(pPreset->m_sEarlyR.m_nGain[i],value16); - } - pReverb->m_nEarlyGain = value16; - LOGV("REVERB_PARAM_REFLECTIONS_LEVEL, m_nEarlyGain %d", pReverb->m_nEarlyGain); - - if (param == REVERB_PARAM_REFLECTIONS_LEVEL) - break; - value32 = pProperties->reflectionsDelay; - /* FALL THROUGH */ - - case REVERB_PARAM_REFLECTIONS_DELAY: - // We limit max value MAX_EARLY_TIME - // convert ms to time units - temp = (value32 * 65536) / 1000; - if (temp < 0 || temp > MAX_EARLY_TIME) - return -EINVAL; - - maxSamples = (int32_t) (MAX_EARLY_TIME * pReverb->m_nSamplingRate) - >> 16; - temp = (temp * pReverb->m_nSamplingRate) >> 16; - for (i = 0; i < REVERB_MAX_NUM_REFLECTIONS; i++) { - temp2 = temp + (((int32_t) pPreset->m_sEarlyL.m_zDelay[i] - * pReverb->m_nSamplingRate) >> 16); - if (temp2 > maxSamples) - temp2 = maxSamples; - pReverb->m_sEarlyL.m_zDelay[i] = pReverb->m_nEarly0in + temp2; - temp2 = temp + (((int32_t) pPreset->m_sEarlyR.m_zDelay[i] - * pReverb->m_nSamplingRate) >> 16); - if (temp2 > maxSamples) - temp2 = maxSamples; - pReverb->m_sEarlyR.m_zDelay[i] = pReverb->m_nEarly1in + temp2; - } - pReverb->m_nEarlyDelay = temp; - - LOGV("REVERB_PARAM_REFLECTIONS_DELAY, m_nEarlyDelay smps %d max smp delay %d", pReverb->m_nEarlyDelay, maxSamples); - - // Convert milliseconds to sample count => m_nEarlyDelay - if (param == REVERB_PARAM_REFLECTIONS_DELAY) - break; - value16 = pProperties->reverbLevel; - /* FALL THROUGH */ - - case REVERB_PARAM_REVERB_LEVEL: - // We limit max value to 0 because gain is limited to 0dB - if (value16 > 0 || value16 < -6000) - return -EINVAL; - // Convert millibels to linear 16 bits (gange 0 - 8191) => m_nLateGain. - pReverb->m_nLateGain = Effects_MillibelsToLinear16(value16) >> 2; - - LOGV("REVERB_PARAM_REVERB_LEVEL, m_nLateGain %d", pReverb->m_nLateGain); - - if (param == REVERB_PARAM_REVERB_LEVEL) - break; - value32 = pProperties->reverbDelay; - /* FALL THROUGH */ - - case REVERB_PARAM_REVERB_DELAY: - // We limit max value to MAX_DELAY_TIME - // convert ms to time units - temp = (value32 * 65536) / 1000; - if (temp < 0 || temp > MAX_DELAY_TIME) - return -EINVAL; - - maxSamples = (int32_t) (MAX_DELAY_TIME * pReverb->m_nSamplingRate) - >> 16; - temp = (temp * pReverb->m_nSamplingRate) >> 16; - if ((temp + pReverb->m_nMaxExcursion) > maxSamples) { - temp = maxSamples - pReverb->m_nMaxExcursion; - } - if (temp < pReverb->m_nMaxExcursion) { - temp = pReverb->m_nMaxExcursion; - } - - temp -= pReverb->m_nLateDelay; - pReverb->m_nDelay0Out += temp; - pReverb->m_nDelay1Out += temp; - pReverb->m_nLateDelay += temp; - - LOGV("REVERB_PARAM_REVERB_DELAY, m_nLateDelay smps %d max smp delay %d", pReverb->m_nLateDelay, maxSamples); - - // Convert milliseconds to sample count => m_nDelay1Out + m_nMaxExcursion - if (param == REVERB_PARAM_REVERB_DELAY) - break; - - value16 = pProperties->diffusion; - /* FALL THROUGH */ - - case REVERB_PARAM_DIFFUSION: - if (value16 < 0 || value16 > 1000) - return -EINVAL; - - // Convert per mille to m_sAp0.m_nApGain, m_sAp1.m_nApGain - pReverb->m_sAp0.m_nApGain = AP0_GAIN_BASE + ((int32_t) value16 - * AP0_GAIN_RANGE) / 1000; - pReverb->m_sAp1.m_nApGain = AP1_GAIN_BASE + ((int32_t) value16 - * AP1_GAIN_RANGE) / 1000; - - LOGV("REVERB_PARAM_DIFFUSION, m_sAp0.m_nApGain %d m_sAp1.m_nApGain %d", pReverb->m_sAp0.m_nApGain, pReverb->m_sAp1.m_nApGain); - - if (param == REVERB_PARAM_DIFFUSION) - break; - - value16 = pProperties->density; - /* FALL THROUGH */ - - case REVERB_PARAM_DENSITY: - if (value16 < 0 || value16 > 1000) - return -EINVAL; - - // Convert per mille to m_sAp0.m_zApOut, m_sAp1.m_zApOut - maxSamples = (int32_t) (MAX_AP_TIME * pReverb->m_nSamplingRate) >> 16; - - temp = AP0_TIME_BASE + ((int32_t) value16 * AP0_TIME_RANGE) / 1000; - /*lint -e{702} shift for performance */ - temp = (temp * pReverb->m_nSamplingRate) >> 16; - if (temp > maxSamples) - temp = maxSamples; - pReverb->m_sAp0.m_zApOut = (uint16_t) (pReverb->m_sAp0.m_zApIn + temp); - - LOGV("REVERB_PARAM_DENSITY, Ap0 delay smps %d", temp); - - temp = AP1_TIME_BASE + ((int32_t) value16 * AP1_TIME_RANGE) / 1000; - /*lint -e{702} shift for performance */ - temp = (temp * pReverb->m_nSamplingRate) >> 16; - if (temp > maxSamples) - temp = maxSamples; - pReverb->m_sAp1.m_zApOut = (uint16_t) (pReverb->m_sAp1.m_zApIn + temp); - - LOGV("Ap1 delay smps %d", temp); - - break; - - default: - break; - } - } - - return 0; -} /* end Reverb_setParameter */ - -/*---------------------------------------------------------------------------- - * ReverbUpdateXfade - *---------------------------------------------------------------------------- - * Purpose: - * Update the xfade parameters as required - * - * Inputs: - * nNumSamplesToAdd - number of samples to write to buffer - * - * Outputs: - * - * - * Side Effects: - * - xfade parameters will be changed - * - *---------------------------------------------------------------------------- - */ -static int ReverbUpdateXfade(reverb_object_t *pReverb, int nNumSamplesToAdd) { - uint16_t nOffset; - int16_t tempCos; - int16_t tempSin; - - if (pReverb->m_nXfadeCounter >= pReverb->m_nXfadeInterval) { - /* update interval has elapsed, so reset counter */ - pReverb->m_nXfadeCounter = 0; - - // Pin the sin,cos values to min / max values to ensure that the - // modulated taps' coefs are zero (thus no clicks) - if (pReverb->m_nPhaseIncrement > 0) { - // if phase increment > 0, then sin -> 1, cos -> 0 - pReverb->m_nSin = 32767; - pReverb->m_nCos = 0; - - // reset the phase to match the sin, cos values - pReverb->m_nPhase = 32767; - - // modulate the cross taps because their tap coefs are zero - nOffset = ReverbCalculateNoise(pReverb); - - pReverb->m_zD1Cross = pReverb->m_nDelay1Out - - pReverb->m_nMaxExcursion + nOffset; - - nOffset = ReverbCalculateNoise(pReverb); - - pReverb->m_zD0Cross = pReverb->m_nDelay0Out - - pReverb->m_nMaxExcursion - nOffset; - } else { - // if phase increment < 0, then sin -> 0, cos -> 1 - pReverb->m_nSin = 0; - pReverb->m_nCos = 32767; - - // reset the phase to match the sin, cos values - pReverb->m_nPhase = -32768; - - // modulate the self taps because their tap coefs are zero - nOffset = ReverbCalculateNoise(pReverb); - - pReverb->m_zD0Self = pReverb->m_nDelay0Out - - pReverb->m_nMaxExcursion - nOffset; - - nOffset = ReverbCalculateNoise(pReverb); - - pReverb->m_zD1Self = pReverb->m_nDelay1Out - - pReverb->m_nMaxExcursion + nOffset; - - } // end if-else (pReverb->m_nPhaseIncrement > 0) - - // Reverse the direction of the sin,cos so that the - // tap whose coef was previously increasing now decreases - // and vice versa - pReverb->m_nPhaseIncrement = -pReverb->m_nPhaseIncrement; - - } // end if counter >= update interval - - //compute what phase will be next time - pReverb->m_nPhase += pReverb->m_nPhaseIncrement; - - //calculate what the new sin and cos need to reach by the next update - ReverbCalculateSinCos(pReverb->m_nPhase, &tempSin, &tempCos); - - //calculate the per-sample increment required to get there by the next update - /*lint -e{702} shift for performance */ - pReverb->m_nSinIncrement = (tempSin - pReverb->m_nSin) - >> pReverb->m_nUpdatePeriodInBits; - - /*lint -e{702} shift for performance */ - pReverb->m_nCosIncrement = (tempCos - pReverb->m_nCos) - >> pReverb->m_nUpdatePeriodInBits; - - /* increment update counter */ - pReverb->m_nXfadeCounter += (uint16_t) nNumSamplesToAdd; - - return 0; - -} /* end ReverbUpdateXfade */ - -/*---------------------------------------------------------------------------- - * ReverbCalculateNoise - *---------------------------------------------------------------------------- - * Purpose: - * Calculate a noise sample and limit its value - * - * Inputs: - * nMaxExcursion - noise value is limited to this value - * pnNoise - return new noise sample in this (not limited) - * - * Outputs: - * new limited noise value - * - * Side Effects: - * - *pnNoise noise value is updated - * - *---------------------------------------------------------------------------- - */ -static uint16_t ReverbCalculateNoise(reverb_object_t *pReverb) { - int16_t nNoise = pReverb->m_nNoise; - - // calculate new noise value - if (pReverb->m_bUseNoise) { - nNoise = (int16_t) (nNoise * 5 + 1); - } else { - nNoise = 0; - } - - pReverb->m_nNoise = nNoise; - // return the limited noise value - return (pReverb->m_nMaxExcursion & nNoise); - -} /* end ReverbCalculateNoise */ - -/*---------------------------------------------------------------------------- - * ReverbCalculateSinCos - *---------------------------------------------------------------------------- - * Purpose: - * Calculate a new sin and cosine value based on the given phase - * - * Inputs: - * nPhase - phase angle - * pnSin - input old value, output new value - * pnCos - input old value, output new value - * - * Outputs: - * - * Side Effects: - * - *pnSin, *pnCos are updated - * - *---------------------------------------------------------------------------- - */ -static int ReverbCalculateSinCos(int16_t nPhase, int16_t *pnSin, int16_t *pnCos) { - int32_t nTemp; - int32_t nNetAngle; - - // -1 <= nPhase < 1 - // However, for the calculation, we need a value - // that ranges from -1/2 to +1/2, so divide the phase by 2 - /*lint -e{702} shift for performance */ - nNetAngle = nPhase >> 1; - - /* - Implement the following - sin(x) = (2-4*c)*x^2 + c + x - cos(x) = (2-4*c)*x^2 + c - x - - where c = 1/sqrt(2) - using the a0 + x*(a1 + x*a2) approach - */ - - /* limit the input "angle" to be between -0.5 and +0.5 */ - if (nNetAngle > EG1_HALF) { - nNetAngle = EG1_HALF; - } else if (nNetAngle < EG1_MINUS_HALF) { - nNetAngle = EG1_MINUS_HALF; - } - - /* calculate sin */ - nTemp = EG1_ONE + MULT_EG1_EG1(REVERB_PAN_G2, nNetAngle); - nTemp = REVERB_PAN_G0 + MULT_EG1_EG1(nTemp, nNetAngle); - *pnSin = (int16_t) SATURATE_EG1(nTemp); - - /* calculate cos */ - nTemp = -EG1_ONE + MULT_EG1_EG1(REVERB_PAN_G2, nNetAngle); - nTemp = REVERB_PAN_G0 + MULT_EG1_EG1(nTemp, nNetAngle); - *pnCos = (int16_t) SATURATE_EG1(nTemp); - - return 0; -} /* end ReverbCalculateSinCos */ - -/*---------------------------------------------------------------------------- - * Reverb - *---------------------------------------------------------------------------- - * Purpose: - * apply reverb to the given signal - * - * Inputs: - * nNu - * pnSin - input old value, output new value - * pnCos - input old value, output new value - * - * Outputs: - * number of samples actually reverberated - * - * Side Effects: - * - *---------------------------------------------------------------------------- - */ -static int Reverb(reverb_object_t *pReverb, int nNumSamplesToAdd, - short *pOutputBuffer, short *pInputBuffer) { - int32_t i; - int32_t nDelayOut0; - int32_t nDelayOut1; - uint16_t nBase; - - uint32_t nAddr; - int32_t nTemp1; - int32_t nTemp2; - int32_t nApIn; - int32_t nApOut; - - int32_t j; - int32_t nEarlyOut; - - int32_t tempValue; - - // get the base address - nBase = pReverb->m_nBaseIndex; - - for (i = 0; i < nNumSamplesToAdd; i++) { - // ********** Left Allpass - start - nApIn = *pInputBuffer; - if (!pReverb->m_Aux) { - pInputBuffer++; - } - // store to early delay line - nAddr = CIRCULAR(nBase, pReverb->m_nEarly0in, pReverb->m_nBufferMask); - pReverb->m_nDelayLine[nAddr] = (short) nApIn; - - // left input = (left dry * m_nLateGain) + right feedback from previous period - - nApIn = SATURATE(nApIn + pReverb->m_nRevFbkR); - nApIn = MULT_EG1_EG1(nApIn, pReverb->m_nLateGain); - - // fetch allpass delay line out - //nAddr = CIRCULAR(nBase, psAp0->m_zApOut, pReverb->m_nBufferMask); - nAddr - = CIRCULAR(nBase, pReverb->m_sAp0.m_zApOut, pReverb->m_nBufferMask); - nDelayOut0 = pReverb->m_nDelayLine[nAddr]; - - // calculate allpass feedforward; subtract the feedforward result - nTemp1 = MULT_EG1_EG1(nApIn, pReverb->m_sAp0.m_nApGain); - nApOut = SATURATE(nDelayOut0 - nTemp1); // allpass output - - // calculate allpass feedback; add the feedback result - nTemp1 = MULT_EG1_EG1(nApOut, pReverb->m_sAp0.m_nApGain); - nTemp1 = SATURATE(nApIn + nTemp1); - - // inject into allpass delay - nAddr - = CIRCULAR(nBase, pReverb->m_sAp0.m_zApIn, pReverb->m_nBufferMask); - pReverb->m_nDelayLine[nAddr] = (short) nTemp1; - - // inject allpass output into delay line - nAddr = CIRCULAR(nBase, pReverb->m_zD0In, pReverb->m_nBufferMask); - pReverb->m_nDelayLine[nAddr] = (short) nApOut; - - // ********** Left Allpass - end - - // ********** Right Allpass - start - nApIn = (*pInputBuffer++); - // store to early delay line - nAddr = CIRCULAR(nBase, pReverb->m_nEarly1in, pReverb->m_nBufferMask); - pReverb->m_nDelayLine[nAddr] = (short) nApIn; - - // right input = (right dry * m_nLateGain) + left feedback from previous period - /*lint -e{702} use shift for performance */ - nApIn = SATURATE(nApIn + pReverb->m_nRevFbkL); - nApIn = MULT_EG1_EG1(nApIn, pReverb->m_nLateGain); - - // fetch allpass delay line out - nAddr - = CIRCULAR(nBase, pReverb->m_sAp1.m_zApOut, pReverb->m_nBufferMask); - nDelayOut1 = pReverb->m_nDelayLine[nAddr]; - - // calculate allpass feedforward; subtract the feedforward result - nTemp1 = MULT_EG1_EG1(nApIn, pReverb->m_sAp1.m_nApGain); - nApOut = SATURATE(nDelayOut1 - nTemp1); // allpass output - - // calculate allpass feedback; add the feedback result - nTemp1 = MULT_EG1_EG1(nApOut, pReverb->m_sAp1.m_nApGain); - nTemp1 = SATURATE(nApIn + nTemp1); - - // inject into allpass delay - nAddr - = CIRCULAR(nBase, pReverb->m_sAp1.m_zApIn, pReverb->m_nBufferMask); - pReverb->m_nDelayLine[nAddr] = (short) nTemp1; - - // inject allpass output into delay line - nAddr = CIRCULAR(nBase, pReverb->m_zD1In, pReverb->m_nBufferMask); - pReverb->m_nDelayLine[nAddr] = (short) nApOut; - - // ********** Right Allpass - end - - // ********** D0 output - start - // fetch delay line self out - nAddr = CIRCULAR(nBase, pReverb->m_zD0Self, pReverb->m_nBufferMask); - nDelayOut0 = pReverb->m_nDelayLine[nAddr]; - - // calculate delay line self out - nTemp1 = MULT_EG1_EG1(nDelayOut0, pReverb->m_nSin); - - // fetch delay line cross out - nAddr = CIRCULAR(nBase, pReverb->m_zD1Cross, pReverb->m_nBufferMask); - nDelayOut0 = pReverb->m_nDelayLine[nAddr]; - - // calculate delay line self out - nTemp2 = MULT_EG1_EG1(nDelayOut0, pReverb->m_nCos); - - // calculate unfiltered delay out - nDelayOut0 = SATURATE(nTemp1 + nTemp2); - - // ********** D0 output - end - - // ********** D1 output - start - // fetch delay line self out - nAddr = CIRCULAR(nBase, pReverb->m_zD1Self, pReverb->m_nBufferMask); - nDelayOut1 = pReverb->m_nDelayLine[nAddr]; - - // calculate delay line self out - nTemp1 = MULT_EG1_EG1(nDelayOut1, pReverb->m_nSin); - - // fetch delay line cross out - nAddr = CIRCULAR(nBase, pReverb->m_zD0Cross, pReverb->m_nBufferMask); - nDelayOut1 = pReverb->m_nDelayLine[nAddr]; - - // calculate delay line self out - nTemp2 = MULT_EG1_EG1(nDelayOut1, pReverb->m_nCos); - - // calculate unfiltered delay out - nDelayOut1 = SATURATE(nTemp1 + nTemp2); - - // ********** D1 output - end - - // ********** mixer and feedback - start - // sum is fedback to right input (R + L) - nDelayOut0 = (short) SATURATE(nDelayOut0 + nDelayOut1); - - // difference is feedback to left input (R - L) - /*lint -e{685} lint complains that it can't saturate negative */ - nDelayOut1 = (short) SATURATE(nDelayOut1 - nDelayOut0); - - // ********** mixer and feedback - end - - // calculate lowpass filter (mixer scale factor included in LPF feedforward) - nTemp1 = MULT_EG1_EG1(nDelayOut0, pReverb->m_nRvbLpfFwd); - - nTemp2 = MULT_EG1_EG1(pReverb->m_nRevFbkL, pReverb->m_nRvbLpfFbk); - - // calculate filtered delay out and simultaneously update LPF state variable - // filtered delay output is stored in m_nRevFbkL - pReverb->m_nRevFbkL = (short) SATURATE(nTemp1 + nTemp2); - - // calculate lowpass filter (mixer scale factor included in LPF feedforward) - nTemp1 = MULT_EG1_EG1(nDelayOut1, pReverb->m_nRvbLpfFwd); - - nTemp2 = MULT_EG1_EG1(pReverb->m_nRevFbkR, pReverb->m_nRvbLpfFbk); - - // calculate filtered delay out and simultaneously update LPF state variable - // filtered delay output is stored in m_nRevFbkR - pReverb->m_nRevFbkR = (short) SATURATE(nTemp1 + nTemp2); - - // ********** start early reflection generator, left - //psEarly = &(pReverb->m_sEarlyL); - - - for (j = 0; j < REVERB_MAX_NUM_REFLECTIONS; j++) { - // fetch delay line out - //nAddr = CIRCULAR(nBase, psEarly->m_zDelay[j], pReverb->m_nBufferMask); - nAddr - = CIRCULAR(nBase, pReverb->m_sEarlyL.m_zDelay[j], pReverb->m_nBufferMask); - - nTemp1 = pReverb->m_nDelayLine[nAddr]; - - // calculate reflection - //nTemp1 = MULT_EG1_EG1(nDelayOut0, psEarly->m_nGain[j]); - nTemp1 = MULT_EG1_EG1(nTemp1, pReverb->m_sEarlyL.m_nGain[j]); - - nDelayOut0 = SATURATE(nDelayOut0 + nTemp1); - - } // end for (j=0; j < REVERB_MAX_NUM_REFLECTIONS; j++) - - // apply lowpass to early reflections and reverb output - //nTemp1 = MULT_EG1_EG1(nEarlyOut, psEarly->m_nRvbLpfFwd); - nTemp1 = MULT_EG1_EG1(nDelayOut0, pReverb->m_nRoomLpfFwd); - - //nTemp2 = MULT_EG1_EG1(psEarly->m_zLpf, psEarly->m_nLpfFbk); - nTemp2 = MULT_EG1_EG1(pReverb->m_zOutLpfL, pReverb->m_nRoomLpfFbk); - - // calculate filtered out and simultaneously update LPF state variable - // filtered output is stored in m_zOutLpfL - pReverb->m_zOutLpfL = (short) SATURATE(nTemp1 + nTemp2); - - //sum with output buffer - tempValue = *pOutputBuffer; - *pOutputBuffer++ = (short) SATURATE(tempValue+pReverb->m_zOutLpfL); - - // ********** end early reflection generator, left - - // ********** start early reflection generator, right - //psEarly = &(pReverb->m_sEarlyR); - - for (j = 0; j < REVERB_MAX_NUM_REFLECTIONS; j++) { - // fetch delay line out - nAddr - = CIRCULAR(nBase, pReverb->m_sEarlyR.m_zDelay[j], pReverb->m_nBufferMask); - nTemp1 = pReverb->m_nDelayLine[nAddr]; - - // calculate reflection - nTemp1 = MULT_EG1_EG1(nTemp1, pReverb->m_sEarlyR.m_nGain[j]); - - nDelayOut1 = SATURATE(nDelayOut1 + nTemp1); - - } // end for (j=0; j < REVERB_MAX_NUM_REFLECTIONS; j++) - - // apply lowpass to early reflections - nTemp1 = MULT_EG1_EG1(nDelayOut1, pReverb->m_nRoomLpfFwd); - - nTemp2 = MULT_EG1_EG1(pReverb->m_zOutLpfR, pReverb->m_nRoomLpfFbk); - - // calculate filtered out and simultaneously update LPF state variable - // filtered output is stored in m_zOutLpfR - pReverb->m_zOutLpfR = (short) SATURATE(nTemp1 + nTemp2); - - //sum with output buffer - tempValue = *pOutputBuffer; - *pOutputBuffer++ = (short) SATURATE(tempValue + pReverb->m_zOutLpfR); - - // ********** end early reflection generator, right - - // decrement base addr for next sample period - nBase--; - - pReverb->m_nSin += pReverb->m_nSinIncrement; - pReverb->m_nCos += pReverb->m_nCosIncrement; - - } // end for (i=0; i < nNumSamplesToAdd; i++) - - // store the most up to date version - pReverb->m_nBaseIndex = nBase; - - return 0; -} /* end Reverb */ - -/*---------------------------------------------------------------------------- - * ReverbUpdateRoom - *---------------------------------------------------------------------------- - * Purpose: - * Update the room's preset parameters as required - * - * Inputs: - * - * Outputs: - * - * - * Side Effects: - * - reverb paramters (fbk, fwd, etc) will be changed - * - m_nCurrentRoom := m_nNextRoom - *---------------------------------------------------------------------------- - */ -static int ReverbUpdateRoom(reverb_object_t *pReverb, bool fullUpdate) { - int temp; - int i; - int maxSamples; - int earlyDelay; - int earlyGain; - - reverb_preset_t *pPreset = - &pReverb->m_sPreset.m_sPreset[pReverb->m_nNextRoom]; - - if (fullUpdate) { - pReverb->m_nRvbLpfFwd = pPreset->m_nRvbLpfFwd; - pReverb->m_nRvbLpfFbk = pPreset->m_nRvbLpfFbk; - - pReverb->m_nEarlyGain = pPreset->m_nEarlyGain; - //stored as time based, convert to sample based - pReverb->m_nLateGain = pPreset->m_nLateGain; - pReverb->m_nRoomLpfFbk = pPreset->m_nRoomLpfFbk; - pReverb->m_nRoomLpfFwd = pPreset->m_nRoomLpfFwd; - - // set the early reflections gains - earlyGain = pPreset->m_nEarlyGain; - for (i = 0; i < REVERB_MAX_NUM_REFLECTIONS; i++) { - pReverb->m_sEarlyL.m_nGain[i] - = MULT_EG1_EG1(pPreset->m_sEarlyL.m_nGain[i],earlyGain); - pReverb->m_sEarlyR.m_nGain[i] - = MULT_EG1_EG1(pPreset->m_sEarlyR.m_nGain[i],earlyGain); - } - - pReverb->m_nMaxExcursion = pPreset->m_nMaxExcursion; - - pReverb->m_sAp0.m_nApGain = pPreset->m_nAp0_ApGain; - pReverb->m_sAp1.m_nApGain = pPreset->m_nAp1_ApGain; - - // set the early reflections delay - earlyDelay = ((int) pPreset->m_nEarlyDelay * pReverb->m_nSamplingRate) - >> 16; - pReverb->m_nEarlyDelay = earlyDelay; - maxSamples = (int32_t) (MAX_EARLY_TIME * pReverb->m_nSamplingRate) - >> 16; - for (i = 0; i < REVERB_MAX_NUM_REFLECTIONS; i++) { - //stored as time based, convert to sample based - temp = earlyDelay + (((int) pPreset->m_sEarlyL.m_zDelay[i] - * pReverb->m_nSamplingRate) >> 16); - if (temp > maxSamples) - temp = maxSamples; - pReverb->m_sEarlyL.m_zDelay[i] = pReverb->m_nEarly0in + temp; - //stored as time based, convert to sample based - temp = earlyDelay + (((int) pPreset->m_sEarlyR.m_zDelay[i] - * pReverb->m_nSamplingRate) >> 16); - if (temp > maxSamples) - temp = maxSamples; - pReverb->m_sEarlyR.m_zDelay[i] = pReverb->m_nEarly1in + temp; - } - - maxSamples = (int32_t) (MAX_DELAY_TIME * pReverb->m_nSamplingRate) - >> 16; - //stored as time based, convert to sample based - /*lint -e{702} shift for performance */ - temp = (pPreset->m_nLateDelay * pReverb->m_nSamplingRate) >> 16; - if ((temp + pReverb->m_nMaxExcursion) > maxSamples) { - temp = maxSamples - pReverb->m_nMaxExcursion; - } - temp -= pReverb->m_nLateDelay; - pReverb->m_nDelay0Out += temp; - pReverb->m_nDelay1Out += temp; - pReverb->m_nLateDelay += temp; - - maxSamples = (int32_t) (MAX_AP_TIME * pReverb->m_nSamplingRate) >> 16; - //stored as time based, convert to absolute sample value - temp = pPreset->m_nAp0_ApOut; - /*lint -e{702} shift for performance */ - temp = (temp * pReverb->m_nSamplingRate) >> 16; - if (temp > maxSamples) - temp = maxSamples; - pReverb->m_sAp0.m_zApOut = (uint16_t) (pReverb->m_sAp0.m_zApIn + temp); - - //stored as time based, convert to absolute sample value - temp = pPreset->m_nAp1_ApOut; - /*lint -e{702} shift for performance */ - temp = (temp * pReverb->m_nSamplingRate) >> 16; - if (temp > maxSamples) - temp = maxSamples; - pReverb->m_sAp1.m_zApOut = (uint16_t) (pReverb->m_sAp1.m_zApIn + temp); - //gpsReverbObject->m_sAp1.m_zApOut = pPreset->m_nAp1_ApOut; - } - - //stored as time based, convert to sample based - temp = pPreset->m_nXfadeInterval; - /*lint -e{702} shift for performance */ - temp = (temp * pReverb->m_nSamplingRate) >> 16; - pReverb->m_nXfadeInterval = (uint16_t) temp; - //gsReverbObject.m_nXfadeInterval = pPreset->m_nXfadeInterval; - pReverb->m_nXfadeCounter = pReverb->m_nXfadeInterval + 1; // force update on first iteration - - pReverb->m_nCurrentRoom = pReverb->m_nNextRoom; - - return 0; - -} /* end ReverbUpdateRoom */ - -/*---------------------------------------------------------------------------- - * ReverbReadInPresets() - *---------------------------------------------------------------------------- - * Purpose: sets global reverb preset bank to defaults - * - * Inputs: - * - * Outputs: - * - *---------------------------------------------------------------------------- - */ -static int ReverbReadInPresets(reverb_object_t *pReverb) { - - int preset; - - // this is for test only. OpenSL ES presets are mapped to 4 presets. - // REVERB_PRESET_NONE is mapped to bypass - for (preset = 0; preset < REVERB_NUM_PRESETS; preset++) { - reverb_preset_t *pPreset = &pReverb->m_sPreset.m_sPreset[preset]; - switch (preset + 1) { - case REVERB_PRESET_PLATE: - case REVERB_PRESET_SMALLROOM: - pPreset->m_nRvbLpfFbk = 5077; - pPreset->m_nRvbLpfFwd = 11076; - pPreset->m_nEarlyGain = 27690; - pPreset->m_nEarlyDelay = 1311; - pPreset->m_nLateGain = 8191; - pPreset->m_nLateDelay = 3932; - pPreset->m_nRoomLpfFbk = 3692; - pPreset->m_nRoomLpfFwd = 20474; - pPreset->m_sEarlyL.m_zDelay[0] = 1376; - pPreset->m_sEarlyL.m_nGain[0] = 22152; - pPreset->m_sEarlyL.m_zDelay[1] = 1462; - pPreset->m_sEarlyL.m_nGain[1] = 17537; - pPreset->m_sEarlyL.m_zDelay[2] = 0; - pPreset->m_sEarlyL.m_nGain[2] = 14768; - pPreset->m_sEarlyL.m_zDelay[3] = 1835; - pPreset->m_sEarlyL.m_nGain[3] = 14307; - pPreset->m_sEarlyL.m_zDelay[4] = 0; - pPreset->m_sEarlyL.m_nGain[4] = 13384; - pPreset->m_sEarlyR.m_zDelay[0] = 721; - pPreset->m_sEarlyR.m_nGain[0] = 20306; - pPreset->m_sEarlyR.m_zDelay[1] = 2621; - pPreset->m_sEarlyR.m_nGain[1] = 17537; - pPreset->m_sEarlyR.m_zDelay[2] = 0; - pPreset->m_sEarlyR.m_nGain[2] = 14768; - pPreset->m_sEarlyR.m_zDelay[3] = 0; - pPreset->m_sEarlyR.m_nGain[3] = 16153; - pPreset->m_sEarlyR.m_zDelay[4] = 0; - pPreset->m_sEarlyR.m_nGain[4] = 13384; - pPreset->m_nMaxExcursion = 127; - pPreset->m_nXfadeInterval = 6470; //6483; - pPreset->m_nAp0_ApGain = 14768; - pPreset->m_nAp0_ApOut = 792; - pPreset->m_nAp1_ApGain = 14777; - pPreset->m_nAp1_ApOut = 1191; - pPreset->m_rfu4 = 0; - pPreset->m_rfu5 = 0; - pPreset->m_rfu6 = 0; - pPreset->m_rfu7 = 0; - pPreset->m_rfu8 = 0; - pPreset->m_rfu9 = 0; - pPreset->m_rfu10 = 0; - break; - case REVERB_PRESET_MEDIUMROOM: - case REVERB_PRESET_LARGEROOM: - pPreset->m_nRvbLpfFbk = 5077; - pPreset->m_nRvbLpfFwd = 12922; - pPreset->m_nEarlyGain = 27690; - pPreset->m_nEarlyDelay = 1311; - pPreset->m_nLateGain = 8191; - pPreset->m_nLateDelay = 3932; - pPreset->m_nRoomLpfFbk = 3692; - pPreset->m_nRoomLpfFwd = 21703; - pPreset->m_sEarlyL.m_zDelay[0] = 1376; - pPreset->m_sEarlyL.m_nGain[0] = 22152; - pPreset->m_sEarlyL.m_zDelay[1] = 1462; - pPreset->m_sEarlyL.m_nGain[1] = 17537; - pPreset->m_sEarlyL.m_zDelay[2] = 0; - pPreset->m_sEarlyL.m_nGain[2] = 14768; - pPreset->m_sEarlyL.m_zDelay[3] = 1835; - pPreset->m_sEarlyL.m_nGain[3] = 14307; - pPreset->m_sEarlyL.m_zDelay[4] = 0; - pPreset->m_sEarlyL.m_nGain[4] = 13384; - pPreset->m_sEarlyR.m_zDelay[0] = 721; - pPreset->m_sEarlyR.m_nGain[0] = 20306; - pPreset->m_sEarlyR.m_zDelay[1] = 2621; - pPreset->m_sEarlyR.m_nGain[1] = 17537; - pPreset->m_sEarlyR.m_zDelay[2] = 0; - pPreset->m_sEarlyR.m_nGain[2] = 14768; - pPreset->m_sEarlyR.m_zDelay[3] = 0; - pPreset->m_sEarlyR.m_nGain[3] = 16153; - pPreset->m_sEarlyR.m_zDelay[4] = 0; - pPreset->m_sEarlyR.m_nGain[4] = 13384; - pPreset->m_nMaxExcursion = 127; - pPreset->m_nXfadeInterval = 6449; - pPreset->m_nAp0_ApGain = 15691; - pPreset->m_nAp0_ApOut = 774; - pPreset->m_nAp1_ApGain = 16317; - pPreset->m_nAp1_ApOut = 1155; - pPreset->m_rfu4 = 0; - pPreset->m_rfu5 = 0; - pPreset->m_rfu6 = 0; - pPreset->m_rfu7 = 0; - pPreset->m_rfu8 = 0; - pPreset->m_rfu9 = 0; - pPreset->m_rfu10 = 0; - break; - case REVERB_PRESET_MEDIUMHALL: - pPreset->m_nRvbLpfFbk = 6461; - pPreset->m_nRvbLpfFwd = 14307; - pPreset->m_nEarlyGain = 27690; - pPreset->m_nEarlyDelay = 1311; - pPreset->m_nLateGain = 8191; - pPreset->m_nLateDelay = 3932; - pPreset->m_nRoomLpfFbk = 3692; - pPreset->m_nRoomLpfFwd = 24569; - pPreset->m_sEarlyL.m_zDelay[0] = 1376; - pPreset->m_sEarlyL.m_nGain[0] = 22152; - pPreset->m_sEarlyL.m_zDelay[1] = 1462; - pPreset->m_sEarlyL.m_nGain[1] = 17537; - pPreset->m_sEarlyL.m_zDelay[2] = 0; - pPreset->m_sEarlyL.m_nGain[2] = 14768; - pPreset->m_sEarlyL.m_zDelay[3] = 1835; - pPreset->m_sEarlyL.m_nGain[3] = 14307; - pPreset->m_sEarlyL.m_zDelay[4] = 0; - pPreset->m_sEarlyL.m_nGain[4] = 13384; - pPreset->m_sEarlyR.m_zDelay[0] = 721; - pPreset->m_sEarlyR.m_nGain[0] = 20306; - pPreset->m_sEarlyR.m_zDelay[1] = 2621; - pPreset->m_sEarlyR.m_nGain[1] = 17537; - pPreset->m_sEarlyR.m_zDelay[2] = 0; - pPreset->m_sEarlyR.m_nGain[2] = 14768; - pPreset->m_sEarlyR.m_zDelay[3] = 0; - pPreset->m_sEarlyR.m_nGain[3] = 16153; - pPreset->m_sEarlyR.m_zDelay[4] = 0; - pPreset->m_sEarlyR.m_nGain[4] = 13384; - pPreset->m_nMaxExcursion = 127; - pPreset->m_nXfadeInterval = 6391; - pPreset->m_nAp0_ApGain = 15230; - pPreset->m_nAp0_ApOut = 708; - pPreset->m_nAp1_ApGain = 15547; - pPreset->m_nAp1_ApOut = 1023; - pPreset->m_rfu4 = 0; - pPreset->m_rfu5 = 0; - pPreset->m_rfu6 = 0; - pPreset->m_rfu7 = 0; - pPreset->m_rfu8 = 0; - pPreset->m_rfu9 = 0; - pPreset->m_rfu10 = 0; - break; - case REVERB_PRESET_LARGEHALL: - pPreset->m_nRvbLpfFbk = 8307; - pPreset->m_nRvbLpfFwd = 14768; - pPreset->m_nEarlyGain = 27690; - pPreset->m_nEarlyDelay = 1311; - pPreset->m_nLateGain = 8191; - pPreset->m_nLateDelay = 3932; - pPreset->m_nRoomLpfFbk = 3692; - pPreset->m_nRoomLpfFwd = 24569; - pPreset->m_sEarlyL.m_zDelay[0] = 1376; - pPreset->m_sEarlyL.m_nGain[0] = 22152; - pPreset->m_sEarlyL.m_zDelay[1] = 2163; - pPreset->m_sEarlyL.m_nGain[1] = 17537; - pPreset->m_sEarlyL.m_zDelay[2] = 0; - pPreset->m_sEarlyL.m_nGain[2] = 14768; - pPreset->m_sEarlyL.m_zDelay[3] = 1835; - pPreset->m_sEarlyL.m_nGain[3] = 14307; - pPreset->m_sEarlyL.m_zDelay[4] = 0; - pPreset->m_sEarlyL.m_nGain[4] = 13384; - pPreset->m_sEarlyR.m_zDelay[0] = 721; - pPreset->m_sEarlyR.m_nGain[0] = 20306; - pPreset->m_sEarlyR.m_zDelay[1] = 2621; - pPreset->m_sEarlyR.m_nGain[1] = 17537; - pPreset->m_sEarlyR.m_zDelay[2] = 0; - pPreset->m_sEarlyR.m_nGain[2] = 14768; - pPreset->m_sEarlyR.m_zDelay[3] = 0; - pPreset->m_sEarlyR.m_nGain[3] = 16153; - pPreset->m_sEarlyR.m_zDelay[4] = 0; - pPreset->m_sEarlyR.m_nGain[4] = 13384; - pPreset->m_nMaxExcursion = 127; - pPreset->m_nXfadeInterval = 6388; - pPreset->m_nAp0_ApGain = 15691; - pPreset->m_nAp0_ApOut = 711; - pPreset->m_nAp1_ApGain = 16317; - pPreset->m_nAp1_ApOut = 1029; - pPreset->m_rfu4 = 0; - pPreset->m_rfu5 = 0; - pPreset->m_rfu6 = 0; - pPreset->m_rfu7 = 0; - pPreset->m_rfu8 = 0; - pPreset->m_rfu9 = 0; - pPreset->m_rfu10 = 0; - break; - } - } - - return 0; -} diff --git a/media/libeffects/EffectReverb.h b/media/libeffects/EffectReverb.h deleted file mode 100644 index ee8e390..0000000 --- a/media/libeffects/EffectReverb.h +++ /dev/null @@ -1,437 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_EFFECTREVERB_H_ -#define ANDROID_EFFECTREVERB_H_ - -#include -#include - - -/*------------------------------------ - * defines - *------------------------------------ -*/ - -/* -CIRCULAR() calculates the array index using modulo arithmetic. -The "trick" is that modulo arithmetic is simplified by masking -the effective address where the mask is (2^n)-1. This only works -if the buffer size is a power of two. -*/ -#define CIRCULAR(base,offset,size) (uint32_t)( \ - ( \ - ((int32_t)(base)) + ((int32_t)(offset)) \ - ) \ - & size \ - ) - -#define NUM_OUTPUT_CHANNELS 2 -#define OUTPUT_CHANNELS CHANNEL_STEREO - -#define REVERB_BUFFER_SIZE_IN_SAMPLES_MAX 16384 - -#define REVERB_NUM_PRESETS REVERB_PRESET_PLATE // REVERB_PRESET_NONE is not included -#define REVERB_MAX_NUM_REFLECTIONS 5 // max num reflections per channel - - -// xfade parameters -#define REVERB_XFADE_PERIOD_IN_SECONDS (double) (100.0 / 1000.0) // xfade once every this many seconds - - -/**********/ -/* the entire synth uses various flags in a bit field */ - -/* if flag is set, synth reset has been requested */ -#define REVERB_FLAG_RESET_IS_REQUESTED 0x01 /* bit 0 */ -#define MASK_REVERB_RESET_IS_REQUESTED 0x01 -#define MASK_REVERB_RESET_IS_NOT_REQUESTED (uint32_t)(~MASK_REVERB_RESET_IS_REQUESTED) - -/* -by default, we always want to update ALL channel parameters -when we reset the synth (e.g., during GM ON) -*/ -#define DEFAULT_REVERB_FLAGS 0x0 - -/* coefficients for generating sin, cos */ -#define REVERB_PAN_G2 4294940151 /* -0.82842712474619 = 2 - 4/sqrt(2) */ -/* -int32_t nPanG1 = +1.0 for sin -int32_t nPanG1 = -1.0 for cos -*/ -#define REVERB_PAN_G0 23170 /* 0.707106781186547 = 1/sqrt(2) */ - -/*************************************************************/ -// define the input injection points -#define GUARD 5 // safety guard of this many samples - -#define MAX_AP_TIME (int) ((20*65536)/1000) // delay time in time units (65536th of sec) -#define MAX_DELAY_TIME (int) ((65*65536)/1000) // delay time in time units -#define MAX_EARLY_TIME (int) ((65*65536)/1000) // delay time in time units - -#define AP0_IN 0 - - -#define REVERB_DEFAULT_ROOM_NUMBER 1 // default preset number -#define DEFAULT_AP0_GAIN 19400 -#define DEFAULT_AP1_GAIN -19400 - -#define REVERB_DEFAULT_WET 32767 -#define REVERB_DEFAULT_DRY 0 - -#define REVERB_WET_MAX 32767 -#define REVERB_WET_MIN 0 -#define REVERB_DRY_MAX 32767 -#define REVERB_DRY_MIN 0 - -// constants for reverb density -// The density expressed in permilles changes the Allpass delay in a linear manner in the range defined by -// AP0_TIME_BASE to AP0_TIME_BASE + AP0_TIME_RANGE -#define AP0_TIME_BASE (int)((9*65536)/1000) -#define AP0_TIME_RANGE (int)((4*65536)/1000) -#define AP1_TIME_BASE (int)((12*65536)/1000) -#define AP1_TIME_RANGE (int)((8*65536)/1000) - -// constants for reverb diffusion -// The diffusion expressed in permilles changes the Allpass gain in a linear manner in the range defined by -// AP0_GAIN_BASE to AP0_GAIN_BASE + AP0_GAIN_RANGE -#define AP0_GAIN_BASE (int)(9830) -#define AP0_GAIN_RANGE (int)(19660-9830) -#define AP1_GAIN_BASE (int)(6553) -#define AP1_GAIN_RANGE (int)(22936-6553) - - -enum reverb_state_e { - REVERB_STATE_UNINITIALIZED, - REVERB_STATE_INITIALIZED, - REVERB_STATE_ACTIVE, -}; - -/* parameters for each allpass */ -typedef struct -{ - uint16_t m_zApOut; // delay offset for ap out - - int16_t m_nApGain; // gain for ap - - uint16_t m_zApIn; // delay offset for ap in - -} allpass_object_t; - - -/* parameters for early reflections */ -typedef struct -{ - uint16_t m_zDelay[REVERB_MAX_NUM_REFLECTIONS]; // delay offset for ap out - - int16_t m_nGain[REVERB_MAX_NUM_REFLECTIONS]; // gain for ap - -} early_reflection_object_t; - -//demo -typedef struct -{ - int16_t m_nRvbLpfFbk; - int16_t m_nRvbLpfFwd; - int16_t m_nRoomLpfFbk; - int16_t m_nRoomLpfFwd; - - int16_t m_nEarlyGain; - int16_t m_nEarlyDelay; - int16_t m_nLateGain; - int16_t m_nLateDelay; - - early_reflection_object_t m_sEarlyL; - early_reflection_object_t m_sEarlyR; - - uint16_t m_nMaxExcursion; //28 - int16_t m_nXfadeInterval; - - int16_t m_nAp0_ApGain; //30 - int16_t m_nAp0_ApOut; - int16_t m_nAp1_ApGain; - int16_t m_nAp1_ApOut; - int16_t m_nDiffusion; - - int16_t m_rfu4; - int16_t m_rfu5; - int16_t m_rfu6; - int16_t m_rfu7; - int16_t m_rfu8; - int16_t m_rfu9; - int16_t m_rfu10; //43 - -} reverb_preset_t; - -typedef struct -{ - reverb_preset_t m_sPreset[REVERB_NUM_PRESETS]; // array of presets(does not include REVERB_PRESET_NONE) - -} reverb_preset_bank_t; - - -/* parameters for each reverb */ -typedef struct -{ - /* update counter keeps track of when synth params need updating */ - /* only needs to be as large as REVERB_UPDATE_PERIOD_IN_SAMPLES */ - int16_t m_nUpdateCounter; - - uint16_t m_nBaseIndex; // base index for circular buffer - - // reverb delay line offsets, allpass parameters, etc: - - short m_nRevFbkR; // combine feedback reverb right out with dry left in - short m_zOutLpfL; // left reverb output - - allpass_object_t m_sAp0; // allpass 0 (left channel) - - uint16_t m_zD0In; // delay offset for delay line D0 in - - short m_nRevFbkL; // combine feedback reverb left out with dry right in - short m_zOutLpfR; // right reverb output - - allpass_object_t m_sAp1; // allpass 1 (right channel) - - uint16_t m_zD1In; // delay offset for delay line D1 in - - // delay output taps, notice criss cross order - uint16_t m_zD0Self; // self feeds forward d0 --> d0 - - uint16_t m_zD1Cross; // cross feeds across d1 --> d0 - - uint16_t m_zD1Self; // self feeds forward d1 --> d1 - - uint16_t m_zD0Cross; // cross feeds across d0 --> d1 - - int16_t m_nSin; // gain for self taps - - int16_t m_nCos; // gain for cross taps - - int16_t m_nSinIncrement; // increment for gain - - int16_t m_nCosIncrement; // increment for gain - - int16_t m_nRvbLpfFwd; // reverb feedback lpf forward gain (includes scaling for mixer) - - int16_t m_nRvbLpfFbk; // reverb feedback lpf feedback gain - - int16_t m_nRoomLpfFwd; // room lpf forward gain (includes scaling for mixer) - - int16_t m_nRoomLpfFbk; // room lpf feedback gain - - uint16_t m_nXfadeInterval; // update/xfade after this many samples - - uint16_t m_nXfadeCounter; // keep track of when to xfade - - int16_t m_nPhase; // -1 <= m_nPhase < 1 - // but during sin,cos calculations - // use m_nPhase/2 - - int16_t m_nPhaseIncrement; // add this to m_nPhase each frame - - int16_t m_nNoise; // random noise sample - - uint16_t m_nMaxExcursion; // the taps can excurse +/- this amount - - uint16_t m_bUseNoise; // if TRUE, use noise as input signal - - uint16_t m_bBypass; // if TRUE, then bypass reverb and copy input to output - - int16_t m_nCurrentRoom; // preset number for current room - - int16_t m_nNextRoom; // preset number for next room - - int16_t m_nEarlyGain; // gain for early (widen) signal - int16_t m_nEarlyDelay; // initial dealy for early (widen) signal - int16_t m_nEarly0in; - int16_t m_nEarly1in; - int16_t m_nLateGain; // gain for late reverb - int16_t m_nLateDelay; - - int16_t m_nDiffusion; - - early_reflection_object_t m_sEarlyL; // left channel early reflections - early_reflection_object_t m_sEarlyR; // right channel early reflections - - short m_nDelayLine[REVERB_BUFFER_SIZE_IN_SAMPLES_MAX]; // one large delay line for all reverb elements - - reverb_preset_t pPreset; - - reverb_preset_bank_t m_sPreset; - - //int8_t preset; - uint32_t m_nSamplingRate; - int32_t m_nUpdatePeriodInBits; - int32_t m_nBufferMask; - int32_t m_nUpdatePeriodInSamples; - int32_t m_nDelay0Out; - int32_t m_nDelay1Out; - int16_t m_nCosWT_5KHz; - - uint16_t m_Aux; // if TRUE, is connected as auxiliary effect - uint16_t m_Preset; // if TRUE, expose preset revert interface - - uint32_t mState; -} reverb_object_t; - - - -typedef struct reverb_module_s { - const struct effect_interface_s *itfe; - effect_config_t config; - reverb_object_t context; -} reverb_module_t; - -/*------------------------------------ - * Effect API - *------------------------------------ -*/ -int EffectQueryNumberEffects(uint32_t *pNumEffects); -int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor); -int EffectCreate(effect_uuid_t *effectUID, int32_t sessionId, int32_t ioId, effect_interface_t *pInterface); -int EffectRelease(effect_interface_t interface); - -static int Reverb_Process(effect_interface_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer); -static int Reverb_Command(effect_interface_t self, int cmdCode, int cmdSize, void *pCmdData, int *replySize, void *pReplyData); - - -/*------------------------------------ - * internal functions - *------------------------------------ -*/ - -int Reverb_Init(reverb_module_t *pRvbModule, int aux, int preset); -int Reverb_Configure(reverb_module_t *pRvbModule, effect_config_t *pConfig, bool init); -void Reverb_Reset(reverb_object_t *pReverb, bool init); - -int Reverb_setParameter (reverb_object_t *pReverb, int32_t param, size_t size, void *pValue); -int Reverb_getParameter(reverb_object_t *pReverb, int32_t param, size_t *pSize, void *pValue); - -/*---------------------------------------------------------------------------- - * ReverbUpdateXfade - *---------------------------------------------------------------------------- - * Purpose: - * Update the xfade parameters as required - * - * Inputs: - * nNumSamplesToAdd - number of samples to write to buffer - * - * Outputs: - * - * - * Side Effects: - * - xfade parameters will be changed - * - *---------------------------------------------------------------------------- -*/ -static int ReverbUpdateXfade(reverb_object_t* pReverbData, int nNumSamplesToAdd); - -/*---------------------------------------------------------------------------- - * ReverbCalculateNoise - *---------------------------------------------------------------------------- - * Purpose: - * Calculate a noise sample and limit its value - * - * Inputs: - * Pointer to reverb context - * - * Outputs: - * new limited noise value - * - * Side Effects: - * - pReverbData->m_nNoise value is updated - * - *---------------------------------------------------------------------------- -*/ -static uint16_t ReverbCalculateNoise(reverb_object_t *pReverbData); - -/*---------------------------------------------------------------------------- - * ReverbCalculateSinCos - *---------------------------------------------------------------------------- - * Purpose: - * Calculate a new sin and cosine value based on the given phase - * - * Inputs: - * nPhase - phase angle - * pnSin - input old value, output new value - * pnCos - input old value, output new value - * - * Outputs: - * - * Side Effects: - * - *pnSin, *pnCos are updated - * - *---------------------------------------------------------------------------- -*/ -static int ReverbCalculateSinCos(int16_t nPhase, int16_t *pnSin, int16_t *pnCos); - -/*---------------------------------------------------------------------------- - * Reverb - *---------------------------------------------------------------------------- - * Purpose: - * apply reverb to the given signal - * - * Inputs: - * nNu - * pnSin - input old value, output new value - * pnCos - input old value, output new value - * - * Outputs: - * number of samples actually reverberated - * - * Side Effects: - * - *---------------------------------------------------------------------------- -*/ -static int Reverb(reverb_object_t* pReverbData, int nNumSamplesToAdd, short *pOutputBuffer, short *pInputBuffer); - -/*---------------------------------------------------------------------------- - * ReverbReadInPresets() - *---------------------------------------------------------------------------- - * Purpose: sets global reverb preset bank to defaults - * - * Inputs: - * - * Outputs: - * - *---------------------------------------------------------------------------- -*/ -static int ReverbReadInPresets(reverb_object_t* pReverbData); - - -/*---------------------------------------------------------------------------- - * ReverbUpdateRoom - *---------------------------------------------------------------------------- - * Purpose: - * Update the room's preset parameters as required - * - * Inputs: - * - * Outputs: - * - * - * Side Effects: - * - reverb paramters (fbk, fwd, etc) will be changed - * - m_nCurrentRoom := m_nNextRoom - *---------------------------------------------------------------------------- -*/ -static int ReverbUpdateRoom(reverb_object_t* pReverbData, bool fullUpdate); - - -static int ReverbComputeConstants(reverb_object_t *pReverbData, uint32_t samplingRate); - -#endif /*ANDROID_EFFECTREVERB_H_*/ diff --git a/media/libeffects/EffectVisualizer.cpp b/media/libeffects/EffectVisualizer.cpp deleted file mode 100644 index bcda06e..0000000 --- a/media/libeffects/EffectVisualizer.cpp +++ /dev/null @@ -1,401 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "Visualizer" -//#define LOG_NDEBUG 0 -#include -#include -#include -#include -#include -#include - -namespace android { - -// effect_interface_t interface implementation for visualizer effect -extern "C" const struct effect_interface_s gVisualizerInterface; - -// Google Visualizer UUID: d069d9e0-8329-11df-9168-0002a5d5c51b -const effect_descriptor_t gVisualizerDescriptor = { - {0xe46b26a0, 0xdddd, 0x11db, 0x8afd, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type - {0xd069d9e0, 0x8329, 0x11df, 0x9168, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid - EFFECT_API_VERSION, - (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST), - 0, // TODO - 1, - "Visualizer", - "Google Inc.", -}; - -enum visualizer_state_e { - VISUALIZER_STATE_UNINITIALIZED, - VISUALIZER_STATE_INITIALIZED, - VISUALIZER_STATE_ACTIVE, -}; - -struct VisualizerContext { - const struct effect_interface_s *mItfe; - effect_config_t mConfig; - uint32_t mState; - uint32_t mCaptureIdx; - uint32_t mCaptureSize; - uint32_t mCurrentBuf; - uint8_t mCaptureBuf[2][VISUALIZER_CAPTURE_SIZE_MAX]; -}; - - -// -//--- Local functions -// - -void Visualizer_reset(VisualizerContext *pContext) -{ - pContext->mCaptureIdx = 0; - pContext->mCurrentBuf = 0; - memset(pContext->mCaptureBuf[0], 0, VISUALIZER_CAPTURE_SIZE_MAX); - memset(pContext->mCaptureBuf[1], 0, VISUALIZER_CAPTURE_SIZE_MAX); -} - -//---------------------------------------------------------------------------- -// Visualizer_configure() -//---------------------------------------------------------------------------- -// Purpose: Set input and output audio configuration. -// -// Inputs: -// pContext: effect engine context -// pConfig: pointer to effect_config_t structure holding input and output -// configuration parameters -// -// Outputs: -// -//---------------------------------------------------------------------------- - -int Visualizer_configure(VisualizerContext *pContext, effect_config_t *pConfig) -{ - LOGV("Visualizer_configure start"); - - if (pConfig->inputCfg.samplingRate != pConfig->outputCfg.samplingRate) return -EINVAL; - if (pConfig->inputCfg.channels != pConfig->outputCfg.channels) return -EINVAL; - if (pConfig->inputCfg.format != pConfig->outputCfg.format) return -EINVAL; - if (pConfig->inputCfg.channels != CHANNEL_STEREO) return -EINVAL; - if (pConfig->outputCfg.accessMode != EFFECT_BUFFER_ACCESS_WRITE && - pConfig->outputCfg.accessMode != EFFECT_BUFFER_ACCESS_ACCUMULATE) return -EINVAL; - if (pConfig->inputCfg.format != SAMPLE_FORMAT_PCM_S15) return -EINVAL; - - memcpy(&pContext->mConfig, pConfig, sizeof(effect_config_t)); - - Visualizer_reset(pContext); - - return 0; -} - - -//---------------------------------------------------------------------------- -// Visualizer_init() -//---------------------------------------------------------------------------- -// Purpose: Initialize engine with default configuration. -// -// Inputs: -// pContext: effect engine context -// -// Outputs: -// -//---------------------------------------------------------------------------- - -int Visualizer_init(VisualizerContext *pContext) -{ - pContext->mConfig.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; - pContext->mConfig.inputCfg.channels = CHANNEL_STEREO; - pContext->mConfig.inputCfg.format = SAMPLE_FORMAT_PCM_S15; - pContext->mConfig.inputCfg.samplingRate = 44100; - pContext->mConfig.inputCfg.bufferProvider.getBuffer = NULL; - pContext->mConfig.inputCfg.bufferProvider.releaseBuffer = NULL; - pContext->mConfig.inputCfg.bufferProvider.cookie = NULL; - pContext->mConfig.inputCfg.mask = EFFECT_CONFIG_ALL; - pContext->mConfig.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; - pContext->mConfig.outputCfg.channels = CHANNEL_STEREO; - pContext->mConfig.outputCfg.format = SAMPLE_FORMAT_PCM_S15; - pContext->mConfig.outputCfg.samplingRate = 44100; - pContext->mConfig.outputCfg.bufferProvider.getBuffer = NULL; - pContext->mConfig.outputCfg.bufferProvider.releaseBuffer = NULL; - pContext->mConfig.outputCfg.bufferProvider.cookie = NULL; - pContext->mConfig.outputCfg.mask = EFFECT_CONFIG_ALL; - - pContext->mCaptureSize = VISUALIZER_CAPTURE_SIZE_MAX; - - Visualizer_configure(pContext, &pContext->mConfig); - - return 0; -} - -// -//--- Effect Library Interface Implementation -// - -extern "C" int EffectQueryNumberEffects(uint32_t *pNumEffects) { - *pNumEffects = 1; - return 0; -} - -extern "C" int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor) { - if (pDescriptor == NULL) { - return -EINVAL; - } - if (index > 0) { - return -EINVAL; - } - memcpy(pDescriptor, &gVisualizerDescriptor, sizeof(effect_descriptor_t)); - return 0; -} - -extern "C" int EffectCreate(effect_uuid_t *uuid, - int32_t sessionId, - int32_t ioId, - effect_interface_t *pInterface) { - int ret; - int i; - - if (pInterface == NULL || uuid == NULL) { - return -EINVAL; - } - - if (memcmp(uuid, &gVisualizerDescriptor.uuid, sizeof(effect_uuid_t)) != 0) { - return -EINVAL; - } - - VisualizerContext *pContext = new VisualizerContext; - - pContext->mItfe = &gVisualizerInterface; - pContext->mState = VISUALIZER_STATE_UNINITIALIZED; - - ret = Visualizer_init(pContext); - if (ret < 0) { - LOGW("EffectCreate() init failed"); - delete pContext; - return ret; - } - - *pInterface = (effect_interface_t)pContext; - - pContext->mState = VISUALIZER_STATE_INITIALIZED; - - LOGV("EffectCreate %p", pContext); - - return 0; - -} - -extern "C" int EffectRelease(effect_interface_t interface) { - VisualizerContext * pContext = (VisualizerContext *)interface; - - LOGV("EffectRelease %p", interface); - if (pContext == NULL) { - return -EINVAL; - } - pContext->mState = VISUALIZER_STATE_UNINITIALIZED; - delete pContext; - - return 0; -} - -// -//--- Effect Control Interface Implementation -// - -static inline int16_t clamp16(int32_t sample) -{ - if ((sample>>15) ^ (sample>>31)) - sample = 0x7FFF ^ (sample>>31); - return sample; -} - -extern "C" int Visualizer_process( - effect_interface_t self,audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) -{ - android::VisualizerContext * pContext = (android::VisualizerContext *)self; - - if (pContext == NULL) { - return -EINVAL; - } - if (pContext->mState != VISUALIZER_STATE_ACTIVE) { - return -ENODATA; - } - - if (inBuffer == NULL || inBuffer->raw == NULL || - outBuffer == NULL || outBuffer->raw == NULL || - inBuffer->frameCount != outBuffer->frameCount || - inBuffer->frameCount == 0) { - return -EINVAL; - } - - // all code below assumes stereo 16 bit PCM output and input - uint32_t captIdx; - uint32_t inIdx; - uint8_t *buf = pContext->mCaptureBuf[pContext->mCurrentBuf]; - for (inIdx = 0, captIdx = pContext->mCaptureIdx; - inIdx < inBuffer->frameCount && captIdx < pContext->mCaptureSize; - inIdx++, captIdx++) { - int32_t smp = inBuffer->s16[2 * inIdx] + inBuffer->s16[2 * inIdx + 1]; - smp = (smp + (1 << 8)) >> 9; - buf[captIdx] = ((uint8_t)smp)^0x80; - } - pContext->mCaptureIdx = captIdx; - - // go to next buffer when buffer full - if (pContext->mCaptureIdx == pContext->mCaptureSize) { - pContext->mCurrentBuf ^= 1; - pContext->mCaptureIdx = 0; - } - - if (inBuffer->raw != outBuffer->raw) { - if (pContext->mConfig.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) { - for (size_t i = 0; i < outBuffer->frameCount*2; i++) { - outBuffer->s16[i] = clamp16(outBuffer->s16[i] + inBuffer->s16[i]); - } - } else { - memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount * 2 * sizeof(int16_t)); - } - } - return 0; -} // end Visualizer_process - -extern "C" int Visualizer_command(effect_interface_t self, int cmdCode, int cmdSize, - void *pCmdData, int *replySize, void *pReplyData) { - - android::VisualizerContext * pContext = (android::VisualizerContext *)self; - int retsize; - - if (pContext == NULL || pContext->mState == VISUALIZER_STATE_UNINITIALIZED) { - return -EINVAL; - } - -// LOGV("Visualizer_command command %d cmdSize %d",cmdCode, cmdSize); - - switch (cmdCode) { - case EFFECT_CMD_INIT: - if (pReplyData == NULL || *replySize != sizeof(int)) { - return -EINVAL; - } - *(int *) pReplyData = Visualizer_init(pContext); - break; - case EFFECT_CMD_CONFIGURE: - if (pCmdData == NULL || cmdSize != sizeof(effect_config_t) - || pReplyData == NULL || *replySize != sizeof(int)) { - return -EINVAL; - } - *(int *) pReplyData = Visualizer_configure(pContext, - (effect_config_t *) pCmdData); - break; - case EFFECT_CMD_RESET: - Visualizer_reset(pContext); - break; - case EFFECT_CMD_ENABLE: - if (pReplyData == NULL || *replySize != sizeof(int)) { - return -EINVAL; - } - if (pContext->mState != VISUALIZER_STATE_INITIALIZED) { - return -ENOSYS; - } - pContext->mState = VISUALIZER_STATE_ACTIVE; - LOGV("EFFECT_CMD_ENABLE() OK"); - *(int *)pReplyData = 0; - break; - case EFFECT_CMD_DISABLE: - if (pReplyData == NULL || *replySize != sizeof(int)) { - return -EINVAL; - } - if (pContext->mState != VISUALIZER_STATE_ACTIVE) { - return -ENOSYS; - } - pContext->mState = VISUALIZER_STATE_INITIALIZED; - LOGV("EFFECT_CMD_DISABLE() OK"); - *(int *)pReplyData = 0; - break; - case EFFECT_CMD_GET_PARAM: { - if (pCmdData == NULL || - cmdSize != (int)(sizeof(effect_param_t) + sizeof(uint32_t)) || - pReplyData == NULL || - *replySize < (int)(sizeof(effect_param_t) + sizeof(uint32_t) + sizeof(uint32_t))) { - return -EINVAL; - } - memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + sizeof(uint32_t)); - effect_param_t *p = (effect_param_t *)pReplyData; - p->status = 0; - *replySize = sizeof(effect_param_t) + sizeof(uint32_t); - if (p->psize != sizeof(uint32_t) || - *(uint32_t *)p->data != VISU_PARAM_CAPTURE_SIZE) { - p->status = -EINVAL; - break; - } - LOGV("get mCaptureSize = %d", pContext->mCaptureSize); - *((uint32_t *)p->data + 1) = pContext->mCaptureSize; - p->vsize = sizeof(uint32_t); - *replySize += sizeof(uint32_t); - } break; - case EFFECT_CMD_SET_PARAM: { - if (pCmdData == NULL || - cmdSize != (int)(sizeof(effect_param_t) + sizeof(uint32_t) + sizeof(uint32_t)) || - pReplyData == NULL || *replySize != sizeof(int32_t)) { - return -EINVAL; - } - *(int32_t *)pReplyData = 0; - effect_param_t *p = (effect_param_t *)pCmdData; - if (p->psize != sizeof(uint32_t) || - p->vsize != sizeof(uint32_t) || - *(uint32_t *)p->data != VISU_PARAM_CAPTURE_SIZE) { - *(int32_t *)pReplyData = -EINVAL; - break;; - } - pContext->mCaptureSize = *((uint32_t *)p->data + 1); - LOGV("set mCaptureSize = %d", pContext->mCaptureSize); - } break; - case EFFECT_CMD_SET_DEVICE: - case EFFECT_CMD_SET_VOLUME: - case EFFECT_CMD_SET_AUDIO_MODE: - break; - - - case VISU_CMD_CAPTURE: - if (pReplyData == NULL || *replySize != (int)pContext->mCaptureSize) { - LOGV("VISU_CMD_CAPTURE() error *replySize %d pContext->mCaptureSize %d", - *replySize, pContext->mCaptureSize); - return -EINVAL; - } - if (pContext->mState == VISUALIZER_STATE_ACTIVE) { - memcpy(pReplyData, - pContext->mCaptureBuf[pContext->mCurrentBuf ^ 1], - pContext->mCaptureSize); - } else { - memset(pReplyData, 0x80, pContext->mCaptureSize); - } - break; - - default: - LOGW("Visualizer_command invalid command %d",cmdCode); - return -EINVAL; - } - - return 0; -} - -// effect_interface_t interface implementation for visualizer effect -const struct effect_interface_s gVisualizerInterface = { - Visualizer_process, - Visualizer_command -}; - -} // namespace - diff --git a/media/libeffects/EffectsFactory.c b/media/libeffects/EffectsFactory.c deleted file mode 100644 index edd6184..0000000 --- a/media/libeffects/EffectsFactory.c +++ /dev/null @@ -1,642 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "EffectsFactory" -//#define LOG_NDEBUG 0 - -#include "EffectsFactory.h" -#include -#include -#include - - -static list_elem_t *gEffectList; // list of effect_entry_t: all currently created effects -static list_elem_t *gLibraryList; // list of lib_entry_t: all currently loaded libraries -static pthread_mutex_t gLibLock = PTHREAD_MUTEX_INITIALIZER; // controls access to gLibraryList -static uint32_t gNumEffects; // total number number of effects -static list_elem_t *gCurLib; // current library in enumeration process -static list_elem_t *gCurEffect; // current effect in enumeration process -static uint32_t gCurEffectIdx; // current effect index in enumeration process - -static const char * const gEffectLibPath = "/system/lib/soundfx"; // path to built-in effect libraries -static int gInitDone; // true is global initialization has been preformed -static int gNextLibId; // used by loadLibrary() to allocate unique library handles -static int gCanQueryEffect; // indicates that call to EffectQueryEffect() is valid, i.e. that the list of effects - // was not modified since last call to EffectQueryNumberEffects() - -///////////////////////////////////////////////// -// Local functions prototypes -///////////////////////////////////////////////// - -static int init(); -static int loadLibrary(const char *libPath, int *handle); -static int unloadLibrary(int handle); -static void resetEffectEnumeration(); -static uint32_t updateNumEffects(); -static int findEffect(effect_uuid_t *uuid, lib_entry_t **lib, effect_descriptor_t **desc); -static void dumpEffectDescriptor(effect_descriptor_t *desc, char *str, size_t len); - -///////////////////////////////////////////////// -// Effect Control Interface functions -///////////////////////////////////////////////// - -int Effect_Process(effect_interface_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) -{ - int ret = init(); - if (ret < 0) { - return ret; - } - effect_entry_t *fx = (effect_entry_t *)self; - pthread_mutex_lock(&gLibLock); - if (fx->lib == NULL) { - pthread_mutex_unlock(&gLibLock); - return -EPIPE; - } - pthread_mutex_lock(&fx->lib->lock); - pthread_mutex_unlock(&gLibLock); - - ret = (*fx->subItfe)->process(fx->subItfe, inBuffer, outBuffer); - pthread_mutex_unlock(&fx->lib->lock); - return ret; -} - -int Effect_Command(effect_interface_t self, int cmdCode, int cmdSize, void *pCmdData, int *replySize, void *pReplyData) -{ - int ret = init(); - if (ret < 0) { - return ret; - } - effect_entry_t *fx = (effect_entry_t *)self; - pthread_mutex_lock(&gLibLock); - if (fx->lib == NULL) { - pthread_mutex_unlock(&gLibLock); - return -EPIPE; - } - pthread_mutex_lock(&fx->lib->lock); - pthread_mutex_unlock(&gLibLock); - - ret = (*fx->subItfe)->command(fx->subItfe, cmdCode, cmdSize, pCmdData, replySize, pReplyData); - pthread_mutex_unlock(&fx->lib->lock); - return ret; -} - -const struct effect_interface_s gInterface = { - Effect_Process, - Effect_Command -}; - -///////////////////////////////////////////////// -// Effect Factory Interface functions -///////////////////////////////////////////////// - -int EffectQueryNumberEffects(uint32_t *pNumEffects) -{ - int ret = init(); - if (ret < 0) { - return ret; - } - if (pNumEffects == NULL) { - return -EINVAL; - } - - pthread_mutex_lock(&gLibLock); - *pNumEffects = gNumEffects; - gCanQueryEffect = 1; - pthread_mutex_unlock(&gLibLock); - LOGV("EffectQueryNumberEffects(): %d", *pNumEffects); - return ret; -} - -int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor) -{ - int ret = init(); - if (ret < 0) { - return ret; - } - if (pDescriptor == NULL || - index >= gNumEffects) { - return -EINVAL; - } - if (gCanQueryEffect == 0) { - return -ENOSYS; - } - - pthread_mutex_lock(&gLibLock); - ret = -ENOENT; - if (index < gCurEffectIdx) { - resetEffectEnumeration(); - } - while (gCurLib) { - if (gCurEffect) { - if (index == gCurEffectIdx) { - memcpy(pDescriptor, gCurEffect->object, sizeof(effect_descriptor_t)); - ret = 0; - break; - } else { - gCurEffect = gCurEffect->next; - gCurEffectIdx++; - } - } else { - gCurLib = gCurLib->next; - gCurEffect = ((lib_entry_t *)gCurLib->object)->effects; - } - } - -#if (LOG_NDEBUG == 0) - char str[256]; - dumpEffectDescriptor(pDescriptor, str, 256); - LOGV("EffectQueryEffect() desc:%s", str); -#endif - pthread_mutex_unlock(&gLibLock); - return ret; -} - -int EffectGetDescriptor(effect_uuid_t *uuid, effect_descriptor_t *pDescriptor) -{ - lib_entry_t *l = NULL; - effect_descriptor_t *d = NULL; - - int ret = init(); - if (ret < 0) { - return ret; - } - if (pDescriptor == NULL || uuid == NULL) { - return -EINVAL; - } - pthread_mutex_lock(&gLibLock); - ret = findEffect(uuid, &l, &d); - if (ret == 0) { - memcpy(pDescriptor, d, sizeof(effect_descriptor_t)); - } - pthread_mutex_unlock(&gLibLock); - return ret; -} - -int EffectCreate(effect_uuid_t *uuid, int32_t sessionId, int32_t ioId, effect_interface_t *pInterface) -{ - list_elem_t *e = gLibraryList; - lib_entry_t *l = NULL; - effect_descriptor_t *d = NULL; - effect_interface_t itfe; - effect_entry_t *fx; - int found = 0; - int ret; - - if (uuid == NULL || pInterface == NULL) { - return -EINVAL; - } - - LOGV("EffectCreate() UUID: %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n", - uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion, - uuid->clockSeq, uuid->node[0], uuid->node[1],uuid->node[2], - uuid->node[3],uuid->node[4],uuid->node[5]); - - ret = init(); - - if (ret < 0) { - LOGW("EffectCreate() init error: %d", ret); - return ret; - } - - pthread_mutex_lock(&gLibLock); - - ret = findEffect(uuid, &l, &d); - if (ret < 0){ - goto exit; - } - - // create effect in library - ret = l->createFx(uuid, sessionId, ioId, &itfe); - if (ret != 0) { - LOGW("EffectCreate() library %s: could not create fx %s, error %d", l->path, d->name, ret); - goto exit; - } - - // add entry to effect list - fx = (effect_entry_t *)malloc(sizeof(effect_entry_t)); - fx->subItfe = itfe; - fx->itfe = (struct effect_interface_s *)&gInterface; - fx->lib = l; - - e = (list_elem_t *)malloc(sizeof(list_elem_t)); - e->object = fx; - e->next = gEffectList; - gEffectList = e; - - *pInterface = (effect_interface_t)fx; - - LOGV("EffectCreate() created entry %p with sub itfe %p in library %s", *pInterface, itfe, l->path); - -exit: - pthread_mutex_unlock(&gLibLock); - return ret; -} - -int EffectRelease(effect_interface_t interface) -{ - effect_entry_t *fx; - list_elem_t *e1; - list_elem_t *e2; - - int ret = init(); - if (ret < 0) { - return ret; - } - - // remove effect from effect list - pthread_mutex_lock(&gLibLock); - e1 = gEffectList; - e2 = NULL; - while (e1) { - if (e1->object == interface) { - if (e2) { - e2->next = e1->next; - } else { - gEffectList = e1->next; - } - fx = (effect_entry_t *)e1->object; - free(e1); - break; - } - e2 = e1; - e1 = e1->next; - } - if (e1 == NULL) { - ret = -ENOENT; - goto exit; - } - - // release effect in library - if (fx->lib == NULL) { - LOGW("EffectRelease() fx %p library already unloaded", interface); - } else { - pthread_mutex_lock(&fx->lib->lock); - fx->lib->releaseFx(fx->subItfe); - pthread_mutex_unlock(&fx->lib->lock); - } - free(fx); - -exit: - pthread_mutex_unlock(&gLibLock); - return ret; -} - -int EffectLoadLibrary(const char *libPath, int *handle) -{ - int ret = init(); - if (ret < 0) { - return ret; - } - if (libPath == NULL) { - return -EINVAL; - } - - ret = loadLibrary(libPath, handle); - updateNumEffects(); - return ret; -} - -int EffectUnloadLibrary(int handle) -{ - int ret = init(); - if (ret < 0) { - return ret; - } - - ret = unloadLibrary(handle); - updateNumEffects(); - return ret; -} - -int EffectIsNullUuid(effect_uuid_t *uuid) -{ - if (memcmp(uuid, EFFECT_UUID_NULL, sizeof(effect_uuid_t))) { - return 0; - } - return 1; -} - -///////////////////////////////////////////////// -// Local functions -///////////////////////////////////////////////// - -int init() { - struct dirent *ent; - DIR *dir = NULL; - char libpath[PATH_MAX]; - int hdl; - - if (gInitDone) { - return 0; - } - - pthread_mutex_init(&gLibLock, NULL); - - // load built-in libraries - dir = opendir(gEffectLibPath); - if (dir == NULL) { - return -ENODEV; - } - while ((ent = readdir(dir)) != NULL) { - LOGV("init() reading file %s", ent->d_name); - if ((strlen(ent->d_name) < 3) || - strncmp(ent->d_name, "lib", 3) != 0 || - strncmp(ent->d_name + strlen(ent->d_name) - 3, ".so", 3) != 0) { - continue; - } - strcpy(libpath, gEffectLibPath); - strcat(libpath, "/"); - strcat(libpath, ent->d_name); - if (loadLibrary(libpath, &hdl) < 0) { - LOGW("init() failed to load library %s",libpath); - } - } - closedir(dir); - updateNumEffects(); - gInitDone = 1; - LOGV("init() done"); - return 0; -} - - -int loadLibrary(const char *libPath, int *handle) -{ - void *hdl; - effect_QueryNumberEffects_t queryNumFx; - effect_QueryEffect_t queryFx; - effect_CreateEffect_t createFx; - effect_ReleaseEffect_t releaseFx; - uint32_t numFx; - uint32_t fx; - int ret; - list_elem_t *e, *descHead = NULL; - lib_entry_t *l; - - if (handle == NULL) { - return -EINVAL; - } - - *handle = 0; - - hdl = dlopen(libPath, RTLD_NOW); - if (hdl == 0) { - LOGW("could open lib %s", libPath); - return -ENODEV; - } - - // Check functions availability - queryNumFx = (effect_QueryNumberEffects_t)dlsym(hdl, "EffectQueryNumberEffects"); - if (queryNumFx == NULL) { - LOGW("could not get EffectQueryNumberEffects from lib %s", libPath); - ret = -ENODEV; - goto error; - } - queryFx = (effect_QueryEffect_t)dlsym(hdl, "EffectQueryEffect"); - if (queryFx == NULL) { - LOGW("could not get EffectQueryEffect from lib %s", libPath); - ret = -ENODEV; - goto error; - } - createFx = (effect_CreateEffect_t)dlsym(hdl, "EffectCreate"); - if (createFx == NULL) { - LOGW("could not get EffectCreate from lib %s", libPath); - ret = -ENODEV; - goto error; - } - releaseFx = (effect_ReleaseEffect_t)dlsym(hdl, "EffectRelease"); - if (releaseFx == NULL) { - LOGW("could not get EffectRelease from lib %s", libPath); - ret = -ENODEV; - goto error; - } - - // load effect descriptors - ret = queryNumFx(&numFx); - if (ret) { - goto error; - } - - for (fx = 0; fx < numFx; fx++) { - effect_descriptor_t *d = malloc(sizeof(effect_descriptor_t)); - if (d == NULL) { - ret = -ENOMEM; - goto error; - } - ret = queryFx(fx, d); - if (ret == 0) { -#if (LOG_NDEBUG==0) - char s[256]; - dumpEffectDescriptor(d, s, 256); - LOGV("loadLibrary() read descriptor %p:%s",d, s); -#endif - if (d->apiVersion != EFFECT_API_VERSION) { - LOGW("Bad API version %04x on lib %s", d->apiVersion, libPath); - free(d); - continue; - } - e = malloc(sizeof(list_elem_t)); - if (e == NULL) { - free(d); - ret = -ENOMEM; - goto error; - } - e->object = d; - e->next = descHead; - descHead = e; - } else { - LOGW("Error querying effect # %d on lib %s", fx, libPath); - } - } - - pthread_mutex_lock(&gLibLock); - - // add entry for library in gLibraryList - l = malloc(sizeof(lib_entry_t)); - l->id = ++gNextLibId; - l->handle = hdl; - strncpy(l->path, libPath, PATH_MAX); - l->createFx = createFx; - l->releaseFx = releaseFx; - l->effects = descHead; - pthread_mutex_init(&l->lock, NULL); - - e = malloc(sizeof(list_elem_t)); - e->next = gLibraryList; - e->object = l; - gLibraryList = e; - pthread_mutex_unlock(&gLibLock); - LOGV("loadLibrary() linked library %p", l); - - *handle = l->id; - - return 0; - -error: - LOGW("loadLibrary() error: %d on lib: %s", ret, libPath); - while (descHead) { - free(descHead->object); - e = descHead->next; - free(descHead); - descHead = e;; - } - dlclose(hdl); - return ret; -} - -int unloadLibrary(int handle) -{ - void *hdl; - int ret; - list_elem_t *el1, *el2; - lib_entry_t *l; - effect_entry_t *fx; - - pthread_mutex_lock(&gLibLock); - el1 = gLibraryList; - el2 = NULL; - while (el1) { - l = (lib_entry_t *)el1->object; - if (handle == l->id) { - if (el2) { - el2->next = el1->next; - } else { - gLibraryList = el1->next; - } - free(el1); - break; - } - el2 = el1; - el1 = el1->next; - } - pthread_mutex_unlock(&gLibLock); - if (el1 == NULL) { - return -ENOENT; - } - - // clear effect descriptor list - el1 = l->effects; - while (el1) { - free(el1->object); - el2 = el1->next; - free(el1); - el1 = el2; - } - - // disable all effects from this library - pthread_mutex_lock(&l->lock); - - el1 = gEffectList; - while (el1) { - fx = (effect_entry_t *)el1->object; - if (fx->lib == l) { - fx->lib = NULL; - } - el1 = el1->next; - } - pthread_mutex_unlock(&l->lock); - - dlclose(l->handle); - free(l); - return 0; -} - -void resetEffectEnumeration() -{ - gCurLib = gLibraryList; - gCurEffect = NULL; - if (gCurLib) { - gCurEffect = ((lib_entry_t *)gCurLib->object)->effects; - } - gCurEffectIdx = 0; -} - -uint32_t updateNumEffects() { - list_elem_t *e; - uint32_t cnt = 0; - - resetEffectEnumeration(); - - e = gLibraryList; - while (e) { - lib_entry_t *l = (lib_entry_t *)e->object; - list_elem_t *efx = l->effects; - while (efx) { - cnt++; - efx = efx->next; - } - e = e->next; - } - gNumEffects = cnt; - gCanQueryEffect = 0; - return cnt; -} - -int findEffect(effect_uuid_t *uuid, lib_entry_t **lib, effect_descriptor_t **desc) -{ - list_elem_t *e = gLibraryList; - lib_entry_t *l = NULL; - effect_descriptor_t *d = NULL; - int found = 0; - int ret = 0; - - while (e && !found) { - l = (lib_entry_t *)e->object; - list_elem_t *efx = l->effects; - while (efx) { - d = (effect_descriptor_t *)efx->object; - if (memcmp(&d->uuid, uuid, sizeof(effect_uuid_t)) == 0) { - found = 1; - break; - } - efx = efx->next; - } - e = e->next; - } - if (!found) { - LOGV("findEffect() effect not found"); - ret = -ENOENT; - } else { - LOGV("findEffect() found effect: %s in lib %s", d->name, l->path); - *lib = l; - *desc = d; - } - - return ret; -} - -void dumpEffectDescriptor(effect_descriptor_t *desc, char *str, size_t len) { - char s[256]; - - snprintf(str, len, "\nEffect Descriptor %p:\n", desc); - sprintf(s, "- UUID: %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n", - desc->uuid.timeLow, desc->uuid.timeMid, desc->uuid.timeHiAndVersion, - desc->uuid.clockSeq, desc->uuid.node[0], desc->uuid.node[1],desc->uuid.node[2], - desc->uuid.node[3],desc->uuid.node[4],desc->uuid.node[5]); - strncat(str, s, len); - sprintf(s, "- TYPE: %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n", - desc->type.timeLow, desc->type.timeMid, desc->type.timeHiAndVersion, - desc->type.clockSeq, desc->type.node[0], desc->type.node[1],desc->type.node[2], - desc->type.node[3],desc->type.node[4],desc->type.node[5]); - strncat(str, s, len); - sprintf(s, "- apiVersion: %04X\n- flags: %08X\n", - desc->apiVersion, desc->flags); - strncat(str, s, len); - sprintf(s, "- name: %s\n", desc->name); - strncat(str, s, len); - sprintf(s, "- implementor: %s\n", desc->implementor); - strncat(str, s, len); -} - diff --git a/media/libeffects/EffectsFactory.h b/media/libeffects/EffectsFactory.h deleted file mode 100644 index 8f543ca..0000000 --- a/media/libeffects/EffectsFactory.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_EFFECTSFACTORY_H_ -#define ANDROID_EFFECTSFACTORY_H_ - -#include -#include -#include -#include - - -#if __cplusplus -extern "C" { -#endif - -typedef struct list_elem_s { - void *object; - struct list_elem_s *next; -} list_elem_t; - -typedef struct lib_entry_s { - char path[PATH_MAX]; - void *handle; - int id; - effect_CreateEffect_t createFx; - effect_ReleaseEffect_t releaseFx; - list_elem_t *effects; //list of effect_descriptor_t - pthread_mutex_t lock; -} lib_entry_t; - -typedef struct effect_entry_s { - struct effect_interface_s *itfe; - effect_interface_t subItfe; - lib_entry_t *lib; -} effect_entry_t; - -#if __cplusplus -} // extern "C" -#endif - - -#endif /*ANDROID_EFFECTSFACTORY_H_*/ diff --git a/media/libeffects/EffectsMath.c b/media/libeffects/EffectsMath.c deleted file mode 100644 index 41ec662..0000000 --- a/media/libeffects/EffectsMath.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#define LOG_TAG "EFFECTSMATH" -//#define LOG_NDEBUG 0 -#include -#include - -#include "EffectsMath.h" - -// gLogTab contains pre-calculated values of log2(1 + ai5*2^-1 + ai4*2^-2 + ai3*2^-3 + ai2*2^-4 + ai1*2^-5 + ai0*2^-6) -// for integers in the range 0 to 63 (i = ai5*2^5 + ai4*2^4 + ai3*2^3 + ai2*2^2 + ai1*2^1 + ai0*2^0) -// It is used for a better than piece wise approximation of lin to log2 conversion - -static const uint16_t gLogTab[] = -{ - 0, 733, 1455, 2166, - 2866, 3556, 4236, 4907, - 5568, 6220, 6863, 7498, - 8124, 8742, 9352, 9954, - 10549, 11136, 11716, 12289, - 12855, 13415, 13968, 14514, - 15055, 15589, 16117, 16639, - 17156, 17667, 18173, 18673, - 19168, 19658, 20143, 20623, - 21098, 21568, 22034, 22495, - 22952, 23404, 23852, 24296, - 24736, 25172, 25604, 26031, - 26455, 26876, 27292, 27705, - 28114, 28520, 28922, 29321, - 29717, 30109, 30498, 30884, - 31267, 31647, 32024, 32397, - 32768 -}; - -int32_t Effects_log2(uint32_t x) { - int32_t exp = 31 - __builtin_clz(x); - uint32_t segStart = x >> (exp - 6); - uint32_t i = segStart & 0x3F; - int32_t log = (int32_t)gLogTab[i]; - int32_t logEnd = (int32_t)gLogTab[i+1]; - segStart <<= exp - 6; - - return (exp << 15) + log + (((x - segStart) * (logEnd - log)) >> (exp - 6)); -} - -// gExpTab[i] = (2^(i>>6)) << 22 -static const uint32_t gExpTab[] = { - 4194304, 4239977, 4286147, 4332820, - 4380002, 4427697, 4475911, 4524651, - 4573921, 4623728, 4674077, 4724974, - 4776426, 4828438, 4881016, 4934167, - 4987896, 5042211, 5097117, 5152621, - 5208729, 5265449, 5322786, 5380747, - 5439339, 5498570, 5558445, 5618973, - 5680159, 5742012, 5804539, 5867746, - 5931642, 5996233, 6061528, 6127533, - 6194258, 6261709, 6329894, 6398822, - 6468501, 6538938, 6610143, 6682122, - 6754886, 6828442, 6902799, 6977965, - 7053950, 7130763, 7208412, 7286906, - 7366255, 7446469, 7527555, 7609525, - 7692387, 7776152, 7860829, 7946428, - 8032959, 8120432, 8208857, 8298246, - 8388608 -}; - - -uint32_t Effects_exp2(int32_t x) { - int32_t i = x >> 15; - assert(i < 32); - x &= (1 << 15) - 1; - int32_t j = x >> 9; - x &= (1 << 9) - 1; - uint32_t exp = gExpTab[j]; - uint32_t expEnd = gExpTab[j+1]; - - return ((exp << 9) + (expEnd - exp) * x) >> (31 - i); -} - - -int16_t Effects_MillibelsToLinear16 (int32_t nGain) -{ - nGain = ((nGain + MB_TO_LIN_K1) << 15 ) / MB_TO_LIN_K2; - uint32_t exp2 = Effects_exp2(nGain); - - if (exp2 > 32767) exp2 = 32767; - - return (int16_t)exp2; -} - - -int16_t Effects_Linear16ToMillibels (int32_t nGain) -{ - return (int16_t)(((MB_TO_LIN_K2*Effects_log2(nGain))>>15)-MB_TO_LIN_K1); -} - - -int32_t Effects_Sqrt(int32_t in) -{ - int32_t tmp; - int32_t out = 0; - int32_t i; - int32_t j; - - - if (in == 0) return 0; - - if (in >= 0x10000000) - { - out = 0x4000; - in -= 0x10000000; - } - - j = 32 - __builtin_clz(in); - - if (j & 1) j++; - j >>= 1; - - for (i = j; i > 0; i--) { - tmp = (out << i) + (1 << ((i - 1)*2)); - if (in >= tmp) - { - out += 1 << (i-1); - in -= tmp; - } - } - - return out; -} - diff --git a/media/libeffects/EffectsMath.h b/media/libeffects/EffectsMath.h deleted file mode 100644 index 2a44399..0000000 --- a/media/libeffects/EffectsMath.h +++ /dev/null @@ -1,424 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_EFFECTSMATH_H_ -#define ANDROID_EFFECTSMATH_H_ - -#include - -#if __cplusplus -extern "C" { -#endif - -/** coefs for pan, generates sin, cos */ -#define COEFF_PAN_G2 -27146 /* -0.82842712474619 = 2 - 4/sqrt(2) */ -#define COEFF_PAN_G0 23170 /* 0.707106781186547 = 1/sqrt(2) */ - -/* -coefficients for approximating -2^x = gn2toX0 + gn2toX1*x + gn2toX2*x^2 + gn2toX3*x^3 -where x is a int.frac number representing number of octaves. -Actually, we approximate only the 2^(frac) using the power series -and implement the 2^(int) as a shift, so that -2^x == 2^(int.frac) == 2^(int) * 2^(fract) - == (gn2toX0 + gn2toX1*x + gn2toX2*x^2 + gn2toX3*x^3) << (int) - -The gn2toX.. were generated using a best fit for a 3rd -order polynomial, instead of taking the coefficients from -a truncated Taylor (or Maclaurin?) series. -*/ - -#define GN2_TO_X0 32768 /* 1 */ -#define GN2_TO_X1 22833 /* 0.696807861328125 */ -#define GN2_TO_X2 7344 /* 0.22412109375 */ -#define GN2_TO_X3 2588 /* 0.0789794921875 */ - -/*---------------------------------------------------------------------------- - * Fixed Point Math - *---------------------------------------------------------------------------- - * These macros are used for fixed point multiplies. If the processor - * supports fixed point multiplies, replace these macros with inline - * assembly code to improve performance. - *---------------------------------------------------------------------------- -*/ - -/* Fixed point multiply 0.15 x 0.15 = 0.15 returned as 32-bits */ -#define FMUL_15x15(a,b) \ - /*lint -e(704) */ \ - (((int32_t)(a) * (int32_t)(b)) >> 15) - -/* Fixed point multiply 0.7 x 0.7 = 0.15 returned as 32-bits */ -#define FMUL_7x7(a,b) \ - /*lint -e(704) */ \ - (((int32_t)(a) * (int32_t)(b) ) << 1) - -/* Fixed point multiply 0.8 x 0.8 = 0.15 returned as 32-bits */ -#define FMUL_8x8(a,b) \ - /*lint -e(704) */ \ - (((int32_t)(a) * (int32_t)(b) ) >> 1) - -/* Fixed point multiply 0.8 x 1.15 = 0.15 returned as 32-bits */ -#define FMUL_8x15(a,b) \ - /*lint -e(704) */ \ - (((int32_t)((a) << 7) * (int32_t)(b)) >> 15) - -/* macros for fractional phase accumulator */ -/* -Note: changed the _U32 to _I32 on 03/14/02. This should not -affect the phase calculations, and should allow us to reuse these -macros for other audio sample related math. -*/ -#define HARDWARE_BIT_WIDTH 32 - -#define NUM_PHASE_INT_BITS 1 -#define NUM_PHASE_FRAC_BITS 15 - -#define PHASE_FRAC_MASK (uint32_t) ((0x1L << NUM_PHASE_FRAC_BITS) -1) - -#define GET_PHASE_INT_PART(x) (uint32_t)((uint32_t)(x) >> NUM_PHASE_FRAC_BITS) -#define GET_PHASE_FRAC_PART(x) (uint32_t)((uint32_t)(x) & PHASE_FRAC_MASK) - -#define DEFAULT_PHASE_FRAC 0 -#define DEFAULT_PHASE_INT 0 - -/* -Linear interpolation calculates: -output = (1-frac) * sample[n] + (frac) * sample[n+1] - -where conceptually 0 <= frac < 1 - -For a fixed point implementation, frac is actually an integer value -with an implied binary point one position to the left. The value of -one (unity) is given by PHASE_ONE -one half and one quarter are useful for 4-point linear interp. -*/ -#define PHASE_ONE (int32_t) (0x1L << NUM_PHASE_FRAC_BITS) - -/* - Multiply the signed audio sample by the unsigned fraction. -- a is the signed audio sample -- b is the unsigned fraction (cast to signed int as long as coef - uses (n-1) or less bits, where n == hardware bit width) -*/ -#define MULT_AUDIO_COEF(audio,coef) /*lint -e704 */ \ - (int32_t)( \ - ( \ - ((int32_t)(audio)) * ((int32_t)(coef)) \ - ) \ - >> NUM_PHASE_FRAC_BITS \ - ) \ - /* lint +704 */ - -/* wet / dry calculation macros */ -#define NUM_WET_DRY_FRAC_BITS 7 // 15 -#define NUM_WET_DRY_INT_BITS 9 // 1 - -/* define a 1.0 */ -#define WET_DRY_ONE (int32_t) ((0x1L << NUM_WET_DRY_FRAC_BITS)) -#define WET_DRY_MINUS_ONE (int32_t) (~WET_DRY_ONE) -#define WET_DRY_FULL_SCALE (int32_t) (WET_DRY_ONE - 1) - -#define MULT_AUDIO_WET_DRY_COEF(audio,coef) /*lint -e(702) */ \ - (int32_t)( \ - ( \ - ((int32_t)(audio)) * ((int32_t)(coef)) \ - ) \ - >> NUM_WET_DRY_FRAC_BITS \ - ) - -/* Envelope 1 (EG1) calculation macros */ -#define NUM_EG1_INT_BITS 1 -#define NUM_EG1_FRAC_BITS 15 - -/* the max positive gain used in the synth for EG1 */ -/* SYNTH_FULL_SCALE_EG1_GAIN must match the value in the dls2eas -converter, otherwise, the values we read from the .eas file are bogus. */ -#define SYNTH_FULL_SCALE_EG1_GAIN (int32_t) ((0x1L << NUM_EG1_FRAC_BITS) -1) - -/* define a 1.0 */ -#define EG1_ONE (int32_t) ((0x1L << NUM_EG1_FRAC_BITS)) -#define EG1_MINUS_ONE (int32_t) (~SYNTH_FULL_SCALE_EG1_GAIN) - -#define EG1_HALF (int32_t) (EG1_ONE/2) -#define EG1_MINUS_HALF (int32_t) (EG1_MINUS_ONE/2) - -/* -We implement the EG1 using a linear gain value, which means that the -attack segment is handled by incrementing (adding) the linear gain. -However, EG1 treats the Decay, Sustain, and Release differently than -the Attack portion. For Decay, Sustain, and Release, the gain is -linear on dB scale, which is equivalent to exponential damping on -a linear scale. Because we use a linear gain for EG1, we implement -the Decay and Release as multiplication (instead of incrementing -as we did for the attack segment). -Therefore, we need the following macro to implement the multiplication -(i.e., exponential damping) during the Decay and Release segments of -the EG1 -*/ -#define MULT_EG1_EG1(gain,damping) /*lint -e(704) */ \ - (int32_t)( \ - ( \ - ((int32_t)(gain)) * ((int32_t)(damping)) \ - ) \ - >> NUM_EG1_FRAC_BITS \ - ) - -// Use the following macro specifically for the filter, when multiplying -// the b1 coefficient. The 0 <= |b1| < 2, which therefore might overflow -// in certain conditions because we store b1 as a 1.15 value. -// Instead, we could store b1 as b1p (b1' == b1 "prime") where -// b1p == b1/2, thus ensuring no potential overflow for b1p because -// 0 <= |b1p| < 1 -// However, during the filter calculation, we must account for the fact -// that we are using b1p instead of b1, and thereby multiply by -// an extra factor of 2. Rather than multiply by an extra factor of 2, -// we can instead shift the result right by one less, hence the -// modified shift right value of (NUM_EG1_FRAC_BITS -1) -#define MULT_EG1_EG1_X2(gain,damping) /*lint -e(702) */ \ - (int32_t)( \ - ( \ - ((int32_t)(gain)) * ((int32_t)(damping)) \ - ) \ - >> (NUM_EG1_FRAC_BITS -1) \ - ) - -#define SATURATE_EG1(x) /*lint -e{734} saturation operation */ \ - ((int32_t)(x) > SYNTH_FULL_SCALE_EG1_GAIN) ? (SYNTH_FULL_SCALE_EG1_GAIN) : \ - ((int32_t)(x) < EG1_MINUS_ONE) ? (EG1_MINUS_ONE) : (x); - - -/* use "digital cents" == "dents" instead of cents */ -/* we coudl re-use the phase frac macros, but if we do, -we must change the phase macros to cast to _I32 instead of _U32, -because using a _U32 cast causes problems when shifting the exponent -for the 2^x calculation, because right shift a negative values MUST -be sign extended, or else the 2^x calculation is wrong */ - -/* use "digital cents" == "dents" instead of cents */ -#define NUM_DENTS_FRAC_BITS 12 -#define NUM_DENTS_INT_BITS (HARDWARE_BIT_WIDTH - NUM_DENTS_FRAC_BITS) - -#define DENTS_FRAC_MASK (int32_t) ((0x1L << NUM_DENTS_FRAC_BITS) -1) - -#define GET_DENTS_INT_PART(x) /*lint -e(704) */ \ - (int32_t)((int32_t)(x) >> NUM_DENTS_FRAC_BITS) - -#define GET_DENTS_FRAC_PART(x) (int32_t)((int32_t)(x) & DENTS_FRAC_MASK) - -#define DENTS_ONE (int32_t) (0x1L << NUM_DENTS_FRAC_BITS) - -/* use CENTS_TO_DENTS to convert a value in cents to dents */ -#define CENTS_TO_DENTS (int32_t) (DENTS_ONE * (0x1L << NUM_EG1_FRAC_BITS) / 1200L) \ - - -/* -For gain, the LFO generates a value that modulates in terms -of dB. However, we use a linear gain value, so we must convert -the LFO value in dB to a linear gain. Normally, we would use -linear gain = 10^x, where x = LFO value in dB / 20. -Instead, we implement 10^x using our 2^x approximation. -because - - 10^x = 2^(log2(10^x)) = 2^(x * log2(10)) - -so we need to multiply by log2(10) which is just a constant. -Ah, but just wait -- our 2^x actually doesn't exactly implement -2^x, but it actually assumes that the input is in cents, and within -the 2^x approximation converts its input from cents to octaves -by dividing its input by 1200. - -So, in order to convert the LFO gain value in dB to something -that our existing 2^x approximation can use, multiply the LFO gain -by log2(10) * 1200 / 20 - -The divide by 20 helps convert dB to linear gain, and we might -as well incorporate that operation into this conversion. -Of course, we need to keep some fractional bits, so multiply -the constant by NUM_EG1_FRAC_BITS -*/ - -/* use LFO_GAIN_TO_CENTS to convert the LFO gain value to cents */ -#if 0 -#define DOUBLE_LOG2_10 (double) (3.32192809488736) /* log2(10) */ - -#define DOUBLE_LFO_GAIN_TO_CENTS (double) \ - ( \ - (DOUBLE_LOG2_10) * \ - 1200.0 / \ - 20.0 \ - ) - -#define LFO_GAIN_TO_CENTS (int32_t) \ - ( \ - DOUBLE_LFO_GAIN_TO_CENTS * \ - (0x1L << NUM_EG1_FRAC_BITS) \ - ) -#endif - -#define LFO_GAIN_TO_CENTS (int32_t) (1671981156L >> (23 - NUM_EG1_FRAC_BITS)) - - -#define MULT_DENTS_COEF(dents,coef) /*lint -e704 */ \ - (int32_t)( \ - ( \ - ((int32_t)(dents)) * ((int32_t)(coef)) \ - ) \ - >> NUM_DENTS_FRAC_BITS \ - ) \ - /* lint +e704 */ - - -/* we use 16-bits in the PC per audio sample */ -#define BITS_PER_AUDIO_SAMPLE 16 - -/* we define 1 as 1.0 - 1 LSbit */ -#define DISTORTION_ONE (int32_t)((0x1L << (BITS_PER_AUDIO_SAMPLE-1)) -1) -#define DISTORTION_MINUS_ONE (int32_t)(~DISTORTION_ONE) - -/* drive coef is given as int.frac */ -#define NUM_DRIVE_COEF_INT_BITS 1 -#define NUM_DRIVE_COEF_FRAC_BITS 4 - -#define MULT_AUDIO_DRIVE(audio,drive) /*lint -e(702) */ \ - (int32_t) ( \ - ( \ - ((int32_t)(audio)) * ((int32_t)(drive)) \ - ) \ - >> NUM_DRIVE_COEF_FRAC_BITS \ - ) - -#define MULT_AUDIO_AUDIO(audio1,audio2) /*lint -e(702) */ \ - (int32_t) ( \ - ( \ - ((int32_t)(audio1)) * ((int32_t)(audio2)) \ - ) \ - >> (BITS_PER_AUDIO_SAMPLE-1) \ - ) - -#define SATURATE(x) \ - ((((int32_t)(x)) > DISTORTION_ONE) ? (DISTORTION_ONE) : \ - (((int32_t)(x)) < DISTORTION_MINUS_ONE) ? (DISTORTION_MINUS_ONE) : ((int32_t)(x))); - - -/*---------------------------------------------------------------------------- - * Effects_log2() - *---------------------------------------------------------------------------- - * Purpose: - * Fixed-point log2 function. - * - * Inputs: - * Input is interpreted as an integer (should not be 0). - * - * Outputs: - * Output is in 15-bit precision. - * - * Side Effects: - * - *---------------------------------------------------------------------------- -*/ -int32_t Effects_log2(uint32_t x); - -/*---------------------------------------------------------------------------- - * Effects_exp2() - *---------------------------------------------------------------------------- - * Purpose: - * Fixed-point radix-2 exponent. - * - * Inputs: - * Input is in 15-bit precision. Must be non-negative and less than 32. - * - * Outputs: - * Output is an integer. - * - * Side Effects: - * - *---------------------------------------------------------------------------- -*/ -uint32_t Effects_exp2(int32_t x); - -/*---------------------------------------------------------------------------- - * Effects_MillibelsToLinear16() - *---------------------------------------------------------------------------- - * Purpose: - * Transform gain in millibels to linear gain multiplier: - * - * mB = 2000*log(lin/32767) - * => lin = 2^((mB+2000*log(32767))/2000*log(2)) - * => lin = Effects_exp2(((mB + K1) << 15) / K2) - * with: - * K1 = 2000*log(32767) and K2 = 2000*log(2) - * - * Inputs: - * nGain - log scale value in millibels. - * - * Outputs: - * Returns a 16-bit linear value approximately equal to 2^(nGain/1024) - * - * Side Effects: - * - *---------------------------------------------------------------------------- -*/ -#define MB_TO_LIN_K1 9031 -#define MB_TO_LIN_K2 602 -int16_t Effects_MillibelsToLinear16 (int32_t nGain); - -/*---------------------------------------------------------------------------- - * Effects_Linear16ToMillibels() - *---------------------------------------------------------------------------- - * Purpose: - * Transform linear gain multiplier to millibels - * mB = 2000*log(lin/32767) - * = 2000*log(2)*log2(lin)-2000*log(32767) - * => mB = K1*Effects_log2(lin) + K2 - * with: - * K1 = 2000*log(2) and K2 = -2000*log(32767) - * - * Inputs: - * nGain - linear multiplier ranging form 0 to 32767 (corresponding to [0 1] gain range). - * - * Outputs: - * Returns a 16-bit log value expressed in milllibels. - * - * Side Effects: - * - *---------------------------------------------------------------------------- -*/ -int16_t Effects_Linear16ToMillibels (int32_t nGain); - -/*---------------------------------------------------------------------------- - * Effects_Sqrt() - *---------------------------------------------------------------------------- - * Purpose: - * Returns the square root of the argument given. - * - * Inputs: - * in - positive number in the range 0 - 2^28 - * - * Outputs: - * Returned value: square root of in. - * - * Side Effects: - * - *---------------------------------------------------------------------------- -*/ -int32_t Effects_Sqrt(int32_t in); - -#if __cplusplus -} // extern "C" -#endif - -#endif /*ANDROID_EFFECTSMATH_H_*/ - diff --git a/media/libeffects/factory/Android.mk b/media/libeffects/factory/Android.mk new file mode 100644 index 0000000..20f58e5 --- /dev/null +++ b/media/libeffects/factory/Android.mk @@ -0,0 +1,25 @@ +LOCAL_PATH:= $(call my-dir) + +# Effect factory library +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + EffectsFactory.c + +LOCAL_SHARED_LIBRARIES := \ + libcutils + +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES) +LOCAL_MODULE:= libeffects + +ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true) +LOCAL_LDLIBS += -ldl +endif + +ifneq ($(TARGET_SIMULATOR),true) +LOCAL_SHARED_LIBRARIES += libdl +endif + +LOCAL_C_INCLUDES := \ + +include $(BUILD_SHARED_LIBRARY) diff --git a/media/libeffects/factory/EffectsFactory.c b/media/libeffects/factory/EffectsFactory.c new file mode 100644 index 0000000..edd6184 --- /dev/null +++ b/media/libeffects/factory/EffectsFactory.c @@ -0,0 +1,642 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "EffectsFactory" +//#define LOG_NDEBUG 0 + +#include "EffectsFactory.h" +#include +#include +#include + + +static list_elem_t *gEffectList; // list of effect_entry_t: all currently created effects +static list_elem_t *gLibraryList; // list of lib_entry_t: all currently loaded libraries +static pthread_mutex_t gLibLock = PTHREAD_MUTEX_INITIALIZER; // controls access to gLibraryList +static uint32_t gNumEffects; // total number number of effects +static list_elem_t *gCurLib; // current library in enumeration process +static list_elem_t *gCurEffect; // current effect in enumeration process +static uint32_t gCurEffectIdx; // current effect index in enumeration process + +static const char * const gEffectLibPath = "/system/lib/soundfx"; // path to built-in effect libraries +static int gInitDone; // true is global initialization has been preformed +static int gNextLibId; // used by loadLibrary() to allocate unique library handles +static int gCanQueryEffect; // indicates that call to EffectQueryEffect() is valid, i.e. that the list of effects + // was not modified since last call to EffectQueryNumberEffects() + +///////////////////////////////////////////////// +// Local functions prototypes +///////////////////////////////////////////////// + +static int init(); +static int loadLibrary(const char *libPath, int *handle); +static int unloadLibrary(int handle); +static void resetEffectEnumeration(); +static uint32_t updateNumEffects(); +static int findEffect(effect_uuid_t *uuid, lib_entry_t **lib, effect_descriptor_t **desc); +static void dumpEffectDescriptor(effect_descriptor_t *desc, char *str, size_t len); + +///////////////////////////////////////////////// +// Effect Control Interface functions +///////////////////////////////////////////////// + +int Effect_Process(effect_interface_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) +{ + int ret = init(); + if (ret < 0) { + return ret; + } + effect_entry_t *fx = (effect_entry_t *)self; + pthread_mutex_lock(&gLibLock); + if (fx->lib == NULL) { + pthread_mutex_unlock(&gLibLock); + return -EPIPE; + } + pthread_mutex_lock(&fx->lib->lock); + pthread_mutex_unlock(&gLibLock); + + ret = (*fx->subItfe)->process(fx->subItfe, inBuffer, outBuffer); + pthread_mutex_unlock(&fx->lib->lock); + return ret; +} + +int Effect_Command(effect_interface_t self, int cmdCode, int cmdSize, void *pCmdData, int *replySize, void *pReplyData) +{ + int ret = init(); + if (ret < 0) { + return ret; + } + effect_entry_t *fx = (effect_entry_t *)self; + pthread_mutex_lock(&gLibLock); + if (fx->lib == NULL) { + pthread_mutex_unlock(&gLibLock); + return -EPIPE; + } + pthread_mutex_lock(&fx->lib->lock); + pthread_mutex_unlock(&gLibLock); + + ret = (*fx->subItfe)->command(fx->subItfe, cmdCode, cmdSize, pCmdData, replySize, pReplyData); + pthread_mutex_unlock(&fx->lib->lock); + return ret; +} + +const struct effect_interface_s gInterface = { + Effect_Process, + Effect_Command +}; + +///////////////////////////////////////////////// +// Effect Factory Interface functions +///////////////////////////////////////////////// + +int EffectQueryNumberEffects(uint32_t *pNumEffects) +{ + int ret = init(); + if (ret < 0) { + return ret; + } + if (pNumEffects == NULL) { + return -EINVAL; + } + + pthread_mutex_lock(&gLibLock); + *pNumEffects = gNumEffects; + gCanQueryEffect = 1; + pthread_mutex_unlock(&gLibLock); + LOGV("EffectQueryNumberEffects(): %d", *pNumEffects); + return ret; +} + +int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor) +{ + int ret = init(); + if (ret < 0) { + return ret; + } + if (pDescriptor == NULL || + index >= gNumEffects) { + return -EINVAL; + } + if (gCanQueryEffect == 0) { + return -ENOSYS; + } + + pthread_mutex_lock(&gLibLock); + ret = -ENOENT; + if (index < gCurEffectIdx) { + resetEffectEnumeration(); + } + while (gCurLib) { + if (gCurEffect) { + if (index == gCurEffectIdx) { + memcpy(pDescriptor, gCurEffect->object, sizeof(effect_descriptor_t)); + ret = 0; + break; + } else { + gCurEffect = gCurEffect->next; + gCurEffectIdx++; + } + } else { + gCurLib = gCurLib->next; + gCurEffect = ((lib_entry_t *)gCurLib->object)->effects; + } + } + +#if (LOG_NDEBUG == 0) + char str[256]; + dumpEffectDescriptor(pDescriptor, str, 256); + LOGV("EffectQueryEffect() desc:%s", str); +#endif + pthread_mutex_unlock(&gLibLock); + return ret; +} + +int EffectGetDescriptor(effect_uuid_t *uuid, effect_descriptor_t *pDescriptor) +{ + lib_entry_t *l = NULL; + effect_descriptor_t *d = NULL; + + int ret = init(); + if (ret < 0) { + return ret; + } + if (pDescriptor == NULL || uuid == NULL) { + return -EINVAL; + } + pthread_mutex_lock(&gLibLock); + ret = findEffect(uuid, &l, &d); + if (ret == 0) { + memcpy(pDescriptor, d, sizeof(effect_descriptor_t)); + } + pthread_mutex_unlock(&gLibLock); + return ret; +} + +int EffectCreate(effect_uuid_t *uuid, int32_t sessionId, int32_t ioId, effect_interface_t *pInterface) +{ + list_elem_t *e = gLibraryList; + lib_entry_t *l = NULL; + effect_descriptor_t *d = NULL; + effect_interface_t itfe; + effect_entry_t *fx; + int found = 0; + int ret; + + if (uuid == NULL || pInterface == NULL) { + return -EINVAL; + } + + LOGV("EffectCreate() UUID: %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n", + uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion, + uuid->clockSeq, uuid->node[0], uuid->node[1],uuid->node[2], + uuid->node[3],uuid->node[4],uuid->node[5]); + + ret = init(); + + if (ret < 0) { + LOGW("EffectCreate() init error: %d", ret); + return ret; + } + + pthread_mutex_lock(&gLibLock); + + ret = findEffect(uuid, &l, &d); + if (ret < 0){ + goto exit; + } + + // create effect in library + ret = l->createFx(uuid, sessionId, ioId, &itfe); + if (ret != 0) { + LOGW("EffectCreate() library %s: could not create fx %s, error %d", l->path, d->name, ret); + goto exit; + } + + // add entry to effect list + fx = (effect_entry_t *)malloc(sizeof(effect_entry_t)); + fx->subItfe = itfe; + fx->itfe = (struct effect_interface_s *)&gInterface; + fx->lib = l; + + e = (list_elem_t *)malloc(sizeof(list_elem_t)); + e->object = fx; + e->next = gEffectList; + gEffectList = e; + + *pInterface = (effect_interface_t)fx; + + LOGV("EffectCreate() created entry %p with sub itfe %p in library %s", *pInterface, itfe, l->path); + +exit: + pthread_mutex_unlock(&gLibLock); + return ret; +} + +int EffectRelease(effect_interface_t interface) +{ + effect_entry_t *fx; + list_elem_t *e1; + list_elem_t *e2; + + int ret = init(); + if (ret < 0) { + return ret; + } + + // remove effect from effect list + pthread_mutex_lock(&gLibLock); + e1 = gEffectList; + e2 = NULL; + while (e1) { + if (e1->object == interface) { + if (e2) { + e2->next = e1->next; + } else { + gEffectList = e1->next; + } + fx = (effect_entry_t *)e1->object; + free(e1); + break; + } + e2 = e1; + e1 = e1->next; + } + if (e1 == NULL) { + ret = -ENOENT; + goto exit; + } + + // release effect in library + if (fx->lib == NULL) { + LOGW("EffectRelease() fx %p library already unloaded", interface); + } else { + pthread_mutex_lock(&fx->lib->lock); + fx->lib->releaseFx(fx->subItfe); + pthread_mutex_unlock(&fx->lib->lock); + } + free(fx); + +exit: + pthread_mutex_unlock(&gLibLock); + return ret; +} + +int EffectLoadLibrary(const char *libPath, int *handle) +{ + int ret = init(); + if (ret < 0) { + return ret; + } + if (libPath == NULL) { + return -EINVAL; + } + + ret = loadLibrary(libPath, handle); + updateNumEffects(); + return ret; +} + +int EffectUnloadLibrary(int handle) +{ + int ret = init(); + if (ret < 0) { + return ret; + } + + ret = unloadLibrary(handle); + updateNumEffects(); + return ret; +} + +int EffectIsNullUuid(effect_uuid_t *uuid) +{ + if (memcmp(uuid, EFFECT_UUID_NULL, sizeof(effect_uuid_t))) { + return 0; + } + return 1; +} + +///////////////////////////////////////////////// +// Local functions +///////////////////////////////////////////////// + +int init() { + struct dirent *ent; + DIR *dir = NULL; + char libpath[PATH_MAX]; + int hdl; + + if (gInitDone) { + return 0; + } + + pthread_mutex_init(&gLibLock, NULL); + + // load built-in libraries + dir = opendir(gEffectLibPath); + if (dir == NULL) { + return -ENODEV; + } + while ((ent = readdir(dir)) != NULL) { + LOGV("init() reading file %s", ent->d_name); + if ((strlen(ent->d_name) < 3) || + strncmp(ent->d_name, "lib", 3) != 0 || + strncmp(ent->d_name + strlen(ent->d_name) - 3, ".so", 3) != 0) { + continue; + } + strcpy(libpath, gEffectLibPath); + strcat(libpath, "/"); + strcat(libpath, ent->d_name); + if (loadLibrary(libpath, &hdl) < 0) { + LOGW("init() failed to load library %s",libpath); + } + } + closedir(dir); + updateNumEffects(); + gInitDone = 1; + LOGV("init() done"); + return 0; +} + + +int loadLibrary(const char *libPath, int *handle) +{ + void *hdl; + effect_QueryNumberEffects_t queryNumFx; + effect_QueryEffect_t queryFx; + effect_CreateEffect_t createFx; + effect_ReleaseEffect_t releaseFx; + uint32_t numFx; + uint32_t fx; + int ret; + list_elem_t *e, *descHead = NULL; + lib_entry_t *l; + + if (handle == NULL) { + return -EINVAL; + } + + *handle = 0; + + hdl = dlopen(libPath, RTLD_NOW); + if (hdl == 0) { + LOGW("could open lib %s", libPath); + return -ENODEV; + } + + // Check functions availability + queryNumFx = (effect_QueryNumberEffects_t)dlsym(hdl, "EffectQueryNumberEffects"); + if (queryNumFx == NULL) { + LOGW("could not get EffectQueryNumberEffects from lib %s", libPath); + ret = -ENODEV; + goto error; + } + queryFx = (effect_QueryEffect_t)dlsym(hdl, "EffectQueryEffect"); + if (queryFx == NULL) { + LOGW("could not get EffectQueryEffect from lib %s", libPath); + ret = -ENODEV; + goto error; + } + createFx = (effect_CreateEffect_t)dlsym(hdl, "EffectCreate"); + if (createFx == NULL) { + LOGW("could not get EffectCreate from lib %s", libPath); + ret = -ENODEV; + goto error; + } + releaseFx = (effect_ReleaseEffect_t)dlsym(hdl, "EffectRelease"); + if (releaseFx == NULL) { + LOGW("could not get EffectRelease from lib %s", libPath); + ret = -ENODEV; + goto error; + } + + // load effect descriptors + ret = queryNumFx(&numFx); + if (ret) { + goto error; + } + + for (fx = 0; fx < numFx; fx++) { + effect_descriptor_t *d = malloc(sizeof(effect_descriptor_t)); + if (d == NULL) { + ret = -ENOMEM; + goto error; + } + ret = queryFx(fx, d); + if (ret == 0) { +#if (LOG_NDEBUG==0) + char s[256]; + dumpEffectDescriptor(d, s, 256); + LOGV("loadLibrary() read descriptor %p:%s",d, s); +#endif + if (d->apiVersion != EFFECT_API_VERSION) { + LOGW("Bad API version %04x on lib %s", d->apiVersion, libPath); + free(d); + continue; + } + e = malloc(sizeof(list_elem_t)); + if (e == NULL) { + free(d); + ret = -ENOMEM; + goto error; + } + e->object = d; + e->next = descHead; + descHead = e; + } else { + LOGW("Error querying effect # %d on lib %s", fx, libPath); + } + } + + pthread_mutex_lock(&gLibLock); + + // add entry for library in gLibraryList + l = malloc(sizeof(lib_entry_t)); + l->id = ++gNextLibId; + l->handle = hdl; + strncpy(l->path, libPath, PATH_MAX); + l->createFx = createFx; + l->releaseFx = releaseFx; + l->effects = descHead; + pthread_mutex_init(&l->lock, NULL); + + e = malloc(sizeof(list_elem_t)); + e->next = gLibraryList; + e->object = l; + gLibraryList = e; + pthread_mutex_unlock(&gLibLock); + LOGV("loadLibrary() linked library %p", l); + + *handle = l->id; + + return 0; + +error: + LOGW("loadLibrary() error: %d on lib: %s", ret, libPath); + while (descHead) { + free(descHead->object); + e = descHead->next; + free(descHead); + descHead = e;; + } + dlclose(hdl); + return ret; +} + +int unloadLibrary(int handle) +{ + void *hdl; + int ret; + list_elem_t *el1, *el2; + lib_entry_t *l; + effect_entry_t *fx; + + pthread_mutex_lock(&gLibLock); + el1 = gLibraryList; + el2 = NULL; + while (el1) { + l = (lib_entry_t *)el1->object; + if (handle == l->id) { + if (el2) { + el2->next = el1->next; + } else { + gLibraryList = el1->next; + } + free(el1); + break; + } + el2 = el1; + el1 = el1->next; + } + pthread_mutex_unlock(&gLibLock); + if (el1 == NULL) { + return -ENOENT; + } + + // clear effect descriptor list + el1 = l->effects; + while (el1) { + free(el1->object); + el2 = el1->next; + free(el1); + el1 = el2; + } + + // disable all effects from this library + pthread_mutex_lock(&l->lock); + + el1 = gEffectList; + while (el1) { + fx = (effect_entry_t *)el1->object; + if (fx->lib == l) { + fx->lib = NULL; + } + el1 = el1->next; + } + pthread_mutex_unlock(&l->lock); + + dlclose(l->handle); + free(l); + return 0; +} + +void resetEffectEnumeration() +{ + gCurLib = gLibraryList; + gCurEffect = NULL; + if (gCurLib) { + gCurEffect = ((lib_entry_t *)gCurLib->object)->effects; + } + gCurEffectIdx = 0; +} + +uint32_t updateNumEffects() { + list_elem_t *e; + uint32_t cnt = 0; + + resetEffectEnumeration(); + + e = gLibraryList; + while (e) { + lib_entry_t *l = (lib_entry_t *)e->object; + list_elem_t *efx = l->effects; + while (efx) { + cnt++; + efx = efx->next; + } + e = e->next; + } + gNumEffects = cnt; + gCanQueryEffect = 0; + return cnt; +} + +int findEffect(effect_uuid_t *uuid, lib_entry_t **lib, effect_descriptor_t **desc) +{ + list_elem_t *e = gLibraryList; + lib_entry_t *l = NULL; + effect_descriptor_t *d = NULL; + int found = 0; + int ret = 0; + + while (e && !found) { + l = (lib_entry_t *)e->object; + list_elem_t *efx = l->effects; + while (efx) { + d = (effect_descriptor_t *)efx->object; + if (memcmp(&d->uuid, uuid, sizeof(effect_uuid_t)) == 0) { + found = 1; + break; + } + efx = efx->next; + } + e = e->next; + } + if (!found) { + LOGV("findEffect() effect not found"); + ret = -ENOENT; + } else { + LOGV("findEffect() found effect: %s in lib %s", d->name, l->path); + *lib = l; + *desc = d; + } + + return ret; +} + +void dumpEffectDescriptor(effect_descriptor_t *desc, char *str, size_t len) { + char s[256]; + + snprintf(str, len, "\nEffect Descriptor %p:\n", desc); + sprintf(s, "- UUID: %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n", + desc->uuid.timeLow, desc->uuid.timeMid, desc->uuid.timeHiAndVersion, + desc->uuid.clockSeq, desc->uuid.node[0], desc->uuid.node[1],desc->uuid.node[2], + desc->uuid.node[3],desc->uuid.node[4],desc->uuid.node[5]); + strncat(str, s, len); + sprintf(s, "- TYPE: %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n", + desc->type.timeLow, desc->type.timeMid, desc->type.timeHiAndVersion, + desc->type.clockSeq, desc->type.node[0], desc->type.node[1],desc->type.node[2], + desc->type.node[3],desc->type.node[4],desc->type.node[5]); + strncat(str, s, len); + sprintf(s, "- apiVersion: %04X\n- flags: %08X\n", + desc->apiVersion, desc->flags); + strncat(str, s, len); + sprintf(s, "- name: %s\n", desc->name); + strncat(str, s, len); + sprintf(s, "- implementor: %s\n", desc->implementor); + strncat(str, s, len); +} + diff --git a/media/libeffects/factory/EffectsFactory.h b/media/libeffects/factory/EffectsFactory.h new file mode 100644 index 0000000..8f543ca --- /dev/null +++ b/media/libeffects/factory/EffectsFactory.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EFFECTSFACTORY_H_ +#define ANDROID_EFFECTSFACTORY_H_ + +#include +#include +#include +#include + + +#if __cplusplus +extern "C" { +#endif + +typedef struct list_elem_s { + void *object; + struct list_elem_s *next; +} list_elem_t; + +typedef struct lib_entry_s { + char path[PATH_MAX]; + void *handle; + int id; + effect_CreateEffect_t createFx; + effect_ReleaseEffect_t releaseFx; + list_elem_t *effects; //list of effect_descriptor_t + pthread_mutex_t lock; +} lib_entry_t; + +typedef struct effect_entry_s { + struct effect_interface_s *itfe; + effect_interface_t subItfe; + lib_entry_t *lib; +} effect_entry_t; + +#if __cplusplus +} // extern "C" +#endif + + +#endif /*ANDROID_EFFECTSFACTORY_H_*/ diff --git a/media/libeffects/lvm/lib/Android.mk b/media/libeffects/lvm/lib/Android.mk new file mode 100644 index 0000000..a944212 --- /dev/null +++ b/media/libeffects/lvm/lib/Android.mk @@ -0,0 +1,124 @@ +LOCAL_PATH:= $(call my-dir) + +# Music bundle + +include $(CLEAR_VARS) + +LOCAL_ARM_MODE := arm + +LOCAL_SRC_FILES:= \ + StereoWidening/src/LVCS_BypassMix.c \ + StereoWidening/src/LVCS_Control.c \ + StereoWidening/src/LVCS_Equaliser.c \ + StereoWidening/src/LVCS_Init.c \ + StereoWidening/src/LVCS_Process.c \ + StereoWidening/src/LVCS_ReverbGenerator.c \ + StereoWidening/src/LVCS_StereoEnhancer.c \ + StereoWidening/src/LVCS_Tables.c \ + Bass/src/LVDBE_Control.c \ + Bass/src/LVDBE_Init.c \ + Bass/src/LVDBE_Process.c \ + Bass/src/LVDBE_Tables.c \ + Bundle/src/LVM_API_Specials.c \ + Bundle/src/LVM_Buffers.c \ + Bundle/src/LVM_Init.c \ + Bundle/src/LVM_Process.c \ + Bundle/src/LVM_Tables.c \ + Bundle/src/LVM_Control.c \ + SpectrumAnalyzer/src/LVPSA_Control.c \ + SpectrumAnalyzer/src/LVPSA_Init.c \ + SpectrumAnalyzer/src/LVPSA_Memory.c \ + SpectrumAnalyzer/src/LVPSA_Process.c \ + SpectrumAnalyzer/src/LVPSA_QPD_Init.c \ + SpectrumAnalyzer/src/LVPSA_QPD_Process.c \ + SpectrumAnalyzer/src/LVPSA_Tables.c \ + Eq/src/LVEQNB_CalcCoef.c \ + Eq/src/LVEQNB_Control.c \ + Eq/src/LVEQNB_Init.c \ + Eq/src/LVEQNB_Process.c \ + Eq/src/LVEQNB_Tables.c \ + Common/src/InstAlloc.c \ + Common/src/DC_2I_D16_TRC_WRA_01.c \ + Common/src/DC_2I_D16_TRC_WRA_01_Init.c \ + Common/src/FO_2I_D16F32C15_LShx_TRC_WRA_01.c \ + Common/src/FO_2I_D16F32Css_LShx_TRC_WRA_01_Init.c \ + Common/src/FO_1I_D16F16C15_TRC_WRA_01.c \ + Common/src/FO_1I_D16F16Css_TRC_WRA_01_Init.c \ + Common/src/BP_1I_D16F32C30_TRC_WRA_01.c \ + Common/src/BP_1I_D16F16C14_TRC_WRA_01.c \ + Common/src/BP_1I_D32F32C30_TRC_WRA_02.c \ + Common/src/BP_1I_D16F16Css_TRC_WRA_01_Init.c \ + Common/src/BP_1I_D16F32Cll_TRC_WRA_01_Init.c \ + Common/src/BP_1I_D32F32Cll_TRC_WRA_02_Init.c \ + Common/src/BQ_2I_D32F32Cll_TRC_WRA_01_Init.c \ + Common/src/BQ_2I_D32F32C30_TRC_WRA_01.c \ + Common/src/BQ_2I_D16F32C15_TRC_WRA_01.c \ + Common/src/BQ_2I_D16F32C14_TRC_WRA_01.c \ + Common/src/BQ_2I_D16F32C13_TRC_WRA_01.c \ + Common/src/BQ_2I_D16F32Css_TRC_WRA_01_init.c \ + Common/src/BQ_2I_D16F16C15_TRC_WRA_01.c \ + Common/src/BQ_2I_D16F16C14_TRC_WRA_01.c \ + Common/src/BQ_2I_D16F16Css_TRC_WRA_01_Init.c \ + Common/src/BQ_1I_D16F16C15_TRC_WRA_01.c \ + Common/src/BQ_1I_D16F16Css_TRC_WRA_01_Init.c \ + Common/src/BQ_1I_D16F32C14_TRC_WRA_01.c \ + Common/src/BQ_1I_D16F32Css_TRC_WRA_01_init.c \ + Common/src/PK_2I_D32F32C30G11_TRC_WRA_01.c \ + Common/src/PK_2I_D32F32C14G11_TRC_WRA_01.c \ + Common/src/PK_2I_D32F32CssGss_TRC_WRA_01_Init.c \ + Common/src/PK_2I_D32F32CllGss_TRC_WRA_01_Init.c \ + Common/src/Int16LShiftToInt32_16x32.c \ + Common/src/From2iToMono_16.c \ + Common/src/Copy_16.c \ + Common/src/MonoTo2I_16.c \ + Common/src/LoadConst_16.c \ + Common/src/dB_to_Lin32.c \ + Common/src/Shift_Sat_v16xv16.c \ + Common/src/Abs_32.c \ + Common/src/Int32RShiftToInt16_Sat_32x16.c \ + Common/src/From2iToMono_32.c \ + Common/src/mult3s_16x16.c \ + Common/src/NonLinComp_D16.c \ + Common/src/DelayMix_16x16.c \ + Common/src/MSTo2i_Sat_16x16.c \ + Common/src/From2iToMS_16x16.c \ + Common/src/Mac3s_Sat_16x16.c \ + Common/src/Add2_Sat_16x16.c \ + Common/src/LVC_MixSoft_1St_2i_D16C31_SAT.c \ + Common/src/LVC_MixSoft_1St_D16C31_SAT.c \ + Common/src/LVC_Mixer_VarSlope_SetTimeConstant.c \ + Common/src/LVC_Mixer_SetTimeConstant.c \ + Common/src/LVC_Mixer_SetTarget.c \ + Common/src/LVC_Mixer_GetTarget.c \ + Common/src/LVC_Mixer_Init.c \ + Common/src/LVC_Core_MixHard_1St_2i_D16C31_SAT.c \ + Common/src/LVC_Core_MixSoft_1St_2i_D16C31_WRA.c \ + Common/src/LVC_Core_MixInSoft_D16C31_SAT.c \ + Common/src/LVC_Mixer_GetCurrent.c \ + Common/src/LVC_MixSoft_2St_D16C31_SAT.c \ + Common/src/LVC_Core_MixSoft_1St_D16C31_WRA.c \ + Common/src/LVC_Core_MixHard_2St_D16C31_SAT.c \ + Common/src/LVC_MixInSoft_D16C31_SAT.c \ + Common/src/AGC_MIX_VOL_2St1Mon_D32_WRA.c \ + Common/src/LVM_Timer.c \ + Common/src/LVM_Timer_Init.c + +LOCAL_MODULE:= libmusicbundle + +LOCAL_PRELINK_MODULE := false + +LOCAL_C_INCLUDES += \ + $(LOCAL_PATH)/Eq/lib \ + $(LOCAL_PATH)/Eq/src \ + $(LOCAL_PATH)/Bass/lib \ + $(LOCAL_PATH)/Bass/src \ + $(LOCAL_PATH)/Common/lib \ + $(LOCAL_PATH)/Common/src \ + $(LOCAL_PATH)/Bundle/lib \ + $(LOCAL_PATH)/Bundle/src \ + $(LOCAL_PATH)/SpectrumAnalyzer/lib \ + $(LOCAL_PATH)/SpectrumAnalyzer/src \ + $(LOCAL_PATH)/StereoWidening/src \ + $(LOCAL_PATH)/StereoWidening/lib + +include $(BUILD_STATIC_LIBRARY) diff --git a/media/libeffects/lvm/lib/Bass/lib/LVDBE.h b/media/libeffects/lvm/lib/Bass/lib/LVDBE.h new file mode 100755 index 0000000..48731df --- /dev/null +++ b/media/libeffects/lvm/lib/Bass/lib/LVDBE.h @@ -0,0 +1,472 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************************** + + $Author: nxp007753 $ + $Revision: 1081 $ + $Date: 2010-07-05 11:48:44 +0200 (Mon, 05 Jul 2010) $ + +*****************************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Header file for the application layer interface of Dynamic Bass Enhancement */ +/* module. */ +/* */ +/* This files includes all definitions, types, structures and function */ +/* prototypes required by the calling layer. All other types, structures and */ +/* functions are private. */ +/* */ +/****************************************************************************************/ +/* */ +/* Note: 1 */ +/* ======= */ +/* The algorithm can execute either with separate input and output buffers or with */ +/* a common buffer, i.e. the data is processed in-place. */ +/* */ +/****************************************************************************************/ +/* */ +/* Note: 2 */ +/* ======= */ +/* The Dynamic Bass Enhancement algorithm always processes data as stereo input. Mono*/ +/* format data is not supported. The data is interleaved as follows: */ +/* */ +/* Byte Offset Stereo Input Mono-In-Stereo Input */ +/* =========== ============ ==================== */ +/* 0 Left Sample #1 Mono Sample #1 */ +/* 2 Right Sample #1 Mono Sample #1 */ +/* 4 Left Sample #2 Mono Sample #2 */ +/* 6 Right Sample #2 Mono Sample #2 */ +/* . . . */ +/* . . . */ +/* */ +/* Mono format data is not supported, the calling routine must convert a Mono stream */ +/* in to Mono-In-Stereo format. */ +/* */ +/****************************************************************************************/ + +#ifndef __LVDBE_H__ +#define __LVDBE_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVM_Types.h" + + +/****************************************************************************************/ +/* */ +/* Definitions */ +/* */ +/****************************************************************************************/ + +/* 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 +#define LVDBE_EFFECT_09DB 9 +#define LVDBE_EFFECT_12DB 12 +#define LVDBE_EFFECT_15DB 15 + + +/****************************************************************************************/ +/* */ +/* Types */ +/* */ +/****************************************************************************************/ + +/* Instance handle */ +typedef void *LVDBE_Handle_t; + + +/* Operating modes */ +typedef enum +{ + LVDBE_OFF = 0, + LVDBE_ON = 1, + LVDBE_MODE_MAX = LVM_MAXINT_32 +} LVDBE_Mode_en; + + +/* High pass filter */ +typedef enum +{ + LVDBE_HPF_OFF = 0, + LVDBE_HPF_ON = 1, + LVDBE_HPF_MAX = LVM_MAXINT_32 +} LVDBE_FilterSelect_en; + + +/* Volume control */ +typedef enum +{ + LVDBE_VOLUME_OFF = 0, + LVDBE_VOLUME_ON = 1, + 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_STATUS_MAX = LVM_MAXINT_32 +} LVDBE_ReturnStatus_en; + + +/****************************************************************************************/ +/* */ +/* Linked enumerated type and capability definitions */ +/* */ +/* The capability definitions are used to define the required capabilities at */ +/* initialisation, these are added together to give the capability word. The */ +/* enumerated type is used to select the mode through a control function at run time. */ +/* */ +/* The capability definition is related to the enumerated type value by the equation: */ +/* */ +/* Capability_value = 2^Enumerated_value */ +/* */ +/* For example, a module could be configurd at initialisation to support two sample */ +/* rates only by calling the init function with the value: */ +/* Capabilities.SampleRate = LVDBE_CAP_32000 + LVCS_DBE_44100; */ +/* */ +/* and at run time it would be passed the value LVDBE_FS_32000 through the control */ +/* function to select operation at 32kHz */ +/* */ +/****************************************************************************************/ + +/* + * Bass Enhancement centre frequency + */ +#define LVDBE_CAP_CENTRE_55Hz 1 +#define LVDBE_CAP_CENTRE_66Hz 2 +#define LVDBE_CAP_CENTRE_78Hz 4 +#define LVDBE_CAP_CENTRE_90Hz 8 + +typedef enum +{ + LVDBE_CENTRE_55HZ = 0, + LVDBE_CENTRE_66HZ = 1, + LVDBE_CENTRE_78HZ = 2, + LVDBE_CENTRE_90HZ = 3, + LVDBE_CENTRE_MAX = LVM_MAXINT_32 +} LVDBE_CentreFreq_en; + + +/* + * Supported sample rates in samples per second + */ +#define LVDBE_CAP_FS_8000 1 +#define LVDBE_CAP_FS_11025 2 +#define LVDBE_CAP_FS_12000 4 +#define LVDBE_CAP_FS_16000 8 +#define LVDBE_CAP_FS_22050 16 +#define LVDBE_CAP_FS_24000 32 +#define LVDBE_CAP_FS_32000 64 +#define LVDBE_CAP_FS_44100 128 +#define LVDBE_CAP_FS_48000 256 + +typedef enum +{ + LVDBE_FS_8000 = 0, + LVDBE_FS_11025 = 1, + LVDBE_FS_12000 = 2, + LVDBE_FS_16000 = 3, + LVDBE_FS_22050 = 4, + LVDBE_FS_24000 = 5, + LVDBE_FS_32000 = 6, + LVDBE_FS_44100 = 7, + LVDBE_FS_48000 = 8, + LVDBE_FS_MAX = LVM_MAXINT_32 +} LVDBE_Fs_en; + + +/****************************************************************************************/ +/* */ +/* Structures */ +/* */ +/****************************************************************************************/ + +/* 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 +{ + LVDBE_Mode_en OperatingMode; + LVDBE_Fs_en SampleRate; + LVM_INT16 EffectLevel; + LVDBE_CentreFreq_en CentreFrequency; + LVDBE_FilterSelect_en HPFSelect; + LVDBE_Volume_en VolumeControl; + LVM_INT16 VolumedB; + LVM_INT16 HeadroomdB; + +} LVDBE_Params_t; + + +/* Capability structure */ +typedef struct +{ + LVM_UINT16 SampleRate; /* Sampling rate capabilities */ + LVM_UINT16 CentreFrequency; /* Centre frequency capabilities */ + LVM_UINT16 MaxBlockSize; /* Maximum block size in sample pairs */ +} LVDBE_Capabilities_t; + + +/****************************************************************************************/ +/* */ +/* Function Prototypes */ +/* */ +/****************************************************************************************/ + +/****************************************************************************************/ +/* */ +/* 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 default capabilites */ +/* */ +/* 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); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVDBE_Init */ +/* */ +/* 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. */ +/* */ +/* 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 */ +/* */ +/****************************************************************************************/ + +LVDBE_ReturnStatus_en LVDBE_Init(LVDBE_Handle_t *phInstance, + LVDBE_MemTab_t *pMemoryTable, + LVDBE_Capabilities_t *pCapabilities); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVDBE_GetParameters */ +/* */ +/* DESCRIPTION: */ +/* Request the Bass Enhancement parameters. The current parameter set is returned */ +/* via the parameter pointer. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to an empty parameter structure */ +/* */ +/* RETURNS: */ +/* LVDBE_SUCCESS Always succeeds */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVDBE_Process function */ +/* */ +/****************************************************************************************/ + +LVDBE_ReturnStatus_en LVDBE_GetParameters(LVDBE_Handle_t hInstance, + LVDBE_Params_t *pParams); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVDBE_GetCapabilities */ +/* */ +/* DESCRIPTION: */ +/* Request the Dynamic Bass Enhancement capabilities. The initial capabilities are */ +/* returned via the pointer. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pCapabilities Pointer to an empty capabilitiy structure */ +/* */ +/* RETURNS: */ +/* LVDBE_Success Always succeeds */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVDBE_Process function */ +/* */ +/****************************************************************************************/ + +LVDBE_ReturnStatus_en LVDBE_GetCapabilities(LVDBE_Handle_t hInstance, + LVDBE_Capabilities_t *pCapabilities); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVDBE_Control */ +/* */ +/* DESCRIPTION: */ +/* Sets or changes the Bass Enhancement parameters. Changing the parameters while the */ +/* module is processing signals may have the following side effects: */ +/* */ +/* General parameters: */ +/* =================== */ +/* OperatingMode: Changing the mode of operation may cause a change in volume */ +/* level. */ +/* */ +/* SampleRate: Changing the sample rate may cause pops and clicks. */ +/* */ +/* EffectLevel: Changing the effect level setting will have no side effects */ +/* */ +/* CentreFrequency: Changing the centre frequency may cause pops and clicks */ +/* */ +/* HPFSelect: Selecting/de-selecting the high pass filter may cause pops and */ +/* clicks */ +/* */ +/* VolumedB Changing the volume setting will have no side effects */ +/* */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to a parameter structure */ +/* */ +/* RETURNS: */ +/* LVDBE_SUCCESS Always succeeds */ +/* */ +/* NOTES: */ +/* 1. This function must not be interrupted by the LVDBE_Process function */ +/* */ +/****************************************************************************************/ + +LVDBE_ReturnStatus_en LVDBE_Control(LVDBE_Handle_t hInstance, + LVDBE_Params_t *pParams); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVDBE_Process */ +/* */ +/* DESCRIPTION: */ +/* Process function for the Bass Enhancement module. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pInData Pointer to the input data */ +/* pOutData Pointer to the output data */ +/* NumSamples Number of samples in the input buffer */ +/* */ +/* RETURNS: */ +/* LVDBE_SUCCESS Succeeded */ +/* LVDBE_TOOMANYSAMPLES NumSamples was larger than the maximum block size */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +LVDBE_ReturnStatus_en LVDBE_Process(LVDBE_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 *pOutData, + LVM_UINT16 NumSamples); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LVDBE_H__ */ diff --git a/media/libeffects/lvm/lib/Bass/src/LVDBE_Coeffs.h b/media/libeffects/lvm/lib/Bass/src/LVDBE_Coeffs.h new file mode 100755 index 0000000..94a7869 --- /dev/null +++ b/media/libeffects/lvm/lib/Bass/src/LVDBE_Coeffs.h @@ -0,0 +1,518 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LVDBE_COEFFS_H__ +#define __LVDBE_COEFFS_H__ + + +/************************************************************************************/ +/* */ +/* General */ +/* */ +/************************************************************************************/ + +#define LVDBE_SCALESHIFT 10 /* As a power of 2 */ + + +/************************************************************************************/ +/* */ +/* High Pass Filter coefficients */ +/* */ +/************************************************************************************/ + + /* Coefficients for centre frequency 55Hz */ +#define HPF_Fs8000_Fc55_A0 1029556328 /* Floating point value 0.958849 */ +#define HPF_Fs8000_Fc55_A1 -2059112655 /* Floating point value -1.917698 */ +#define HPF_Fs8000_Fc55_A2 1029556328 /* Floating point value 0.958849 */ +#define HPF_Fs8000_Fc55_B1 -2081986375 /* Floating point value -1.939001 */ +#define HPF_Fs8000_Fc55_B2 1010183914 /* Floating point value 0.940807 */ +#define HPF_Fs11025_Fc55_A0 1038210831 /* Floating point value 0.966909 */ +#define HPF_Fs11025_Fc55_A1 -2076421662 /* Floating point value -1.933818 */ +#define HPF_Fs11025_Fc55_A2 1038210831 /* Floating point value 0.966909 */ +#define HPF_Fs11025_Fc55_B1 -2099950710 /* Floating point value -1.955732 */ +#define HPF_Fs11025_Fc55_B2 1027238450 /* Floating point value 0.956690 */ +#define HPF_Fs12000_Fc55_A0 1040079943 /* Floating point value 0.968650 */ +#define HPF_Fs12000_Fc55_A1 -2080159885 /* Floating point value -1.937300 */ +#define HPF_Fs12000_Fc55_A2 1040079943 /* Floating point value 0.968650 */ +#define HPF_Fs12000_Fc55_B1 -2103811702 /* Floating point value -1.959327 */ +#define HPF_Fs12000_Fc55_B2 1030940477 /* Floating point value 0.960138 */ +#define HPF_Fs16000_Fc55_A0 1045381988 /* Floating point value 0.973588 */ +#define HPF_Fs16000_Fc55_A1 -2090763976 /* Floating point value -1.947176 */ +#define HPF_Fs16000_Fc55_A2 1045381988 /* Floating point value 0.973588 */ +#define HPF_Fs16000_Fc55_B1 -2114727793 /* Floating point value -1.969494 */ +#define HPF_Fs16000_Fc55_B2 1041478147 /* Floating point value 0.969952 */ +#define HPF_Fs22050_Fc55_A0 1049766523 /* Floating point value 0.977671 */ +#define HPF_Fs22050_Fc55_A1 -2099533046 /* Floating point value -1.955343 */ +#define HPF_Fs22050_Fc55_A2 1049766523 /* Floating point value 0.977671 */ +#define HPF_Fs22050_Fc55_B1 -2123714381 /* Floating point value -1.977863 */ +#define HPF_Fs22050_Fc55_B2 1050232780 /* Floating point value 0.978105 */ +#define HPF_Fs24000_Fc55_A0 1050711051 /* Floating point value 0.978551 */ +#define HPF_Fs24000_Fc55_A1 -2101422103 /* Floating point value -1.957102 */ +#define HPF_Fs24000_Fc55_A2 1050711051 /* Floating point value 0.978551 */ +#define HPF_Fs24000_Fc55_B1 -2125645498 /* Floating point value -1.979662 */ +#define HPF_Fs24000_Fc55_B2 1052123526 /* Floating point value 0.979866 */ +#define HPF_Fs32000_Fc55_A0 1053385759 /* Floating point value 0.981042 */ +#define HPF_Fs32000_Fc55_A1 -2106771519 /* Floating point value -1.962084 */ +#define HPF_Fs32000_Fc55_A2 1053385759 /* Floating point value 0.981042 */ +#define HPF_Fs32000_Fc55_B1 -2131104794 /* Floating point value -1.984746 */ +#define HPF_Fs32000_Fc55_B2 1057486949 /* Floating point value 0.984861 */ +#define HPF_Fs44100_Fc55_A0 1055592498 /* Floating point value 0.983097 */ +#define HPF_Fs44100_Fc55_A1 -2111184995 /* Floating point value -1.966194 */ +#define HPF_Fs44100_Fc55_A2 1055592498 /* Floating point value 0.983097 */ +#define HPF_Fs44100_Fc55_B1 -2135598658 /* Floating point value -1.988931 */ +#define HPF_Fs44100_Fc55_B2 1061922249 /* Floating point value 0.988992 */ +#define HPF_Fs48000_Fc55_A0 1056067276 /* Floating point value 0.983539 */ +#define HPF_Fs48000_Fc55_A1 -2112134551 /* Floating point value -1.967079 */ +#define HPF_Fs48000_Fc55_A2 1056067276 /* Floating point value 0.983539 */ +#define HPF_Fs48000_Fc55_B1 -2136564296 /* Floating point value -1.989831 */ +#define HPF_Fs48000_Fc55_B2 1062877714 /* Floating point value 0.989882 */ + + /* Coefficients for centre frequency 66Hz */ +#define HPF_Fs8000_Fc66_A0 1023293271 /* Floating point value 0.953016 */ +#define HPF_Fs8000_Fc66_A1 -2046586542 /* Floating point value -1.906032 */ +#define HPF_Fs8000_Fc66_A2 1023293271 /* Floating point value 0.953016 */ +#define HPF_Fs8000_Fc66_B1 -2068896860 /* Floating point value -1.926810 */ +#define HPF_Fs8000_Fc66_B2 997931110 /* Floating point value 0.929396 */ +#define HPF_Fs11025_Fc66_A0 1033624228 /* Floating point value 0.962638 */ +#define HPF_Fs11025_Fc66_A1 -2067248455 /* Floating point value -1.925275 */ +#define HPF_Fs11025_Fc66_A2 1033624228 /* Floating point value 0.962638 */ +#define HPF_Fs11025_Fc66_B1 -2090448000 /* Floating point value -1.946881 */ +#define HPF_Fs11025_Fc66_B2 1018182305 /* Floating point value 0.948256 */ +#define HPF_Fs12000_Fc66_A0 1035857662 /* Floating point value 0.964718 */ +#define HPF_Fs12000_Fc66_A1 -2071715325 /* Floating point value -1.929435 */ +#define HPF_Fs12000_Fc66_A2 1035857662 /* Floating point value 0.964718 */ +#define HPF_Fs12000_Fc66_B1 -2095080333 /* Floating point value -1.951196 */ +#define HPF_Fs12000_Fc66_B2 1022587158 /* Floating point value 0.952359 */ +#define HPF_Fs16000_Fc66_A0 1042197528 /* Floating point value 0.970622 */ +#define HPF_Fs16000_Fc66_A1 -2084395056 /* Floating point value -1.941244 */ +#define HPF_Fs16000_Fc66_A2 1042197528 /* Floating point value 0.970622 */ +#define HPF_Fs16000_Fc66_B1 -2108177912 /* Floating point value -1.963394 */ +#define HPF_Fs16000_Fc66_B2 1035142690 /* Floating point value 0.964052 */ +#define HPF_Fs22050_Fc66_A0 1047445145 /* Floating point value 0.975509 */ +#define HPF_Fs22050_Fc66_A1 -2094890289 /* Floating point value -1.951019 */ +#define HPF_Fs22050_Fc66_A2 1047445145 /* Floating point value 0.975509 */ +#define HPF_Fs22050_Fc66_B1 -2118961025 /* Floating point value -1.973436 */ +#define HPF_Fs22050_Fc66_B2 1045593102 /* Floating point value 0.973784 */ +#define HPF_Fs24000_Fc66_A0 1048576175 /* Floating point value 0.976563 */ +#define HPF_Fs24000_Fc66_A1 -2097152349 /* Floating point value -1.953125 */ +#define HPF_Fs24000_Fc66_A2 1048576175 /* Floating point value 0.976563 */ +#define HPF_Fs24000_Fc66_B1 -2121278255 /* Floating point value -1.975594 */ +#define HPF_Fs24000_Fc66_B2 1047852379 /* Floating point value 0.975889 */ +#define HPF_Fs32000_Fc66_A0 1051780119 /* Floating point value 0.979547 */ +#define HPF_Fs32000_Fc66_A1 -2103560237 /* Floating point value -1.959093 */ +#define HPF_Fs32000_Fc66_A2 1051780119 /* Floating point value 0.979547 */ +#define HPF_Fs32000_Fc66_B1 -2127829187 /* Floating point value -1.981695 */ +#define HPF_Fs32000_Fc66_B2 1054265623 /* Floating point value 0.981861 */ +#define HPF_Fs44100_Fc66_A0 1054424722 /* Floating point value 0.982010 */ +#define HPF_Fs44100_Fc66_A1 -2108849444 /* Floating point value -1.964019 */ +#define HPF_Fs44100_Fc66_A2 1054424722 /* Floating point value 0.982010 */ +#define HPF_Fs44100_Fc66_B1 -2133221723 /* Floating point value -1.986718 */ +#define HPF_Fs44100_Fc66_B2 1059573993 /* Floating point value 0.986805 */ +#define HPF_Fs48000_Fc66_A0 1054993851 /* Floating point value 0.982540 */ +#define HPF_Fs48000_Fc66_A1 -2109987702 /* Floating point value -1.965079 */ +#define HPF_Fs48000_Fc66_A2 1054993851 /* Floating point value 0.982540 */ +#define HPF_Fs48000_Fc66_B1 -2134380475 /* Floating point value -1.987797 */ +#define HPF_Fs48000_Fc66_B2 1060718118 /* Floating point value 0.987871 */ + + /* Coefficients for centre frequency 78Hz */ +#define HPF_Fs8000_Fc78_A0 1016504203 /* Floating point value 0.946693 */ +#define HPF_Fs8000_Fc78_A1 -2033008405 /* Floating point value -1.893387 */ +#define HPF_Fs8000_Fc78_A2 1016504203 /* Floating point value 0.946693 */ +#define HPF_Fs8000_Fc78_B1 -2054623390 /* Floating point value -1.913517 */ +#define HPF_Fs8000_Fc78_B2 984733853 /* Floating point value 0.917105 */ +#define HPF_Fs11025_Fc78_A0 1028643741 /* Floating point value 0.957999 */ +#define HPF_Fs11025_Fc78_A1 -2057287482 /* Floating point value -1.915998 */ +#define HPF_Fs11025_Fc78_A2 1028643741 /* Floating point value 0.957999 */ +#define HPF_Fs11025_Fc78_B1 -2080083769 /* Floating point value -1.937229 */ +#define HPF_Fs11025_Fc78_B2 1008393904 /* Floating point value 0.939140 */ +#define HPF_Fs12000_Fc78_A0 1031271067 /* Floating point value 0.960446 */ +#define HPF_Fs12000_Fc78_A1 -2062542133 /* Floating point value -1.920892 */ +#define HPF_Fs12000_Fc78_A2 1031271067 /* Floating point value 0.960446 */ +#define HPF_Fs12000_Fc78_B1 -2085557048 /* Floating point value -1.942326 */ +#define HPF_Fs12000_Fc78_B2 1013551620 /* Floating point value 0.943944 */ +#define HPF_Fs16000_Fc78_A0 1038734628 /* Floating point value 0.967397 */ +#define HPF_Fs16000_Fc78_A1 -2077469256 /* Floating point value -1.934794 */ +#define HPF_Fs16000_Fc78_A2 1038734628 /* Floating point value 0.967397 */ +#define HPF_Fs16000_Fc78_B1 -2101033380 /* Floating point value -1.956740 */ +#define HPF_Fs16000_Fc78_B2 1028275228 /* Floating point value 0.957656 */ +#define HPF_Fs22050_Fc78_A0 1044918584 /* Floating point value 0.973156 */ +#define HPF_Fs22050_Fc78_A1 -2089837169 /* Floating point value -1.946313 */ +#define HPF_Fs22050_Fc78_A2 1044918584 /* Floating point value 0.973156 */ +#define HPF_Fs22050_Fc78_B1 -2113775854 /* Floating point value -1.968607 */ +#define HPF_Fs22050_Fc78_B2 1040555007 /* Floating point value 0.969092 */ +#define HPF_Fs24000_Fc78_A0 1046252164 /* Floating point value 0.974398 */ +#define HPF_Fs24000_Fc78_A1 -2092504328 /* Floating point value -1.948797 */ +#define HPF_Fs24000_Fc78_A2 1046252164 /* Floating point value 0.974398 */ +#define HPF_Fs24000_Fc78_B1 -2116514229 /* Floating point value -1.971157 */ +#define HPF_Fs24000_Fc78_B2 1043212719 /* Floating point value 0.971568 */ +#define HPF_Fs32000_Fc78_A0 1050031301 /* Floating point value 0.977918 */ +#define HPF_Fs32000_Fc78_A1 -2100062603 /* Floating point value -1.955836 */ +#define HPF_Fs32000_Fc78_A2 1050031301 /* Floating point value 0.977918 */ +#define HPF_Fs32000_Fc78_B1 -2124255900 /* Floating point value -1.978367 */ +#define HPF_Fs32000_Fc78_B2 1050762639 /* Floating point value 0.978599 */ +#define HPF_Fs44100_Fc78_A0 1053152258 /* Floating point value 0.980824 */ +#define HPF_Fs44100_Fc78_A1 -2106304516 /* Floating point value -1.961649 */ +#define HPF_Fs44100_Fc78_A2 1053152258 /* Floating point value 0.980824 */ +#define HPF_Fs44100_Fc78_B1 -2130628742 /* Floating point value -1.984303 */ +#define HPF_Fs44100_Fc78_B2 1057018180 /* Floating point value 0.984425 */ +#define HPF_Fs48000_Fc78_A0 1053824087 /* Floating point value 0.981450 */ +#define HPF_Fs48000_Fc78_A1 -2107648173 /* Floating point value -1.962900 */ +#define HPF_Fs48000_Fc78_A2 1053824087 /* Floating point value 0.981450 */ +#define HPF_Fs48000_Fc78_B1 -2131998154 /* Floating point value -1.985578 */ +#define HPF_Fs48000_Fc78_B2 1058367200 /* Floating point value 0.985681 */ + + /* Coefficients for centre frequency 90Hz */ +#define HPF_Fs8000_Fc90_A0 1009760053 /* Floating point value 0.940412 */ +#define HPF_Fs8000_Fc90_A1 -2019520105 /* Floating point value -1.880825 */ +#define HPF_Fs8000_Fc90_A2 1009760053 /* Floating point value 0.940412 */ +#define HPF_Fs8000_Fc90_B1 -2040357139 /* Floating point value -1.900231 */ +#define HPF_Fs8000_Fc90_B2 971711129 /* Floating point value 0.904977 */ +#define HPF_Fs11025_Fc90_A0 1023687217 /* Floating point value 0.953383 */ +#define HPF_Fs11025_Fc90_A1 -2047374434 /* Floating point value -1.906766 */ +#define HPF_Fs11025_Fc90_A2 1023687217 /* Floating point value 0.953383 */ +#define HPF_Fs11025_Fc90_B1 -2069722397 /* Floating point value -1.927579 */ +#define HPF_Fs11025_Fc90_B2 998699604 /* Floating point value 0.930111 */ +#define HPF_Fs12000_Fc90_A0 1026704754 /* Floating point value 0.956193 */ +#define HPF_Fs12000_Fc90_A1 -2053409508 /* Floating point value -1.912387 */ +#define HPF_Fs12000_Fc90_A2 1026704754 /* Floating point value 0.956193 */ +#define HPF_Fs12000_Fc90_B1 -2076035996 /* Floating point value -1.933459 */ +#define HPF_Fs12000_Fc90_B2 1004595918 /* Floating point value 0.935603 */ +#define HPF_Fs16000_Fc90_A0 1035283225 /* Floating point value 0.964183 */ +#define HPF_Fs16000_Fc90_A1 -2070566451 /* Floating point value -1.928365 */ +#define HPF_Fs16000_Fc90_A2 1035283225 /* Floating point value 0.964183 */ +#define HPF_Fs16000_Fc90_B1 -2093889811 /* Floating point value -1.950087 */ +#define HPF_Fs16000_Fc90_B2 1021453326 /* Floating point value 0.951303 */ +#define HPF_Fs22050_Fc90_A0 1042398116 /* Floating point value 0.970809 */ +#define HPF_Fs22050_Fc90_A1 -2084796232 /* Floating point value -1.941618 */ +#define HPF_Fs22050_Fc90_A2 1042398116 /* Floating point value 0.970809 */ +#define HPF_Fs22050_Fc90_B1 -2108591057 /* Floating point value -1.963778 */ +#define HPF_Fs22050_Fc90_B2 1035541188 /* Floating point value 0.964423 */ +#define HPF_Fs24000_Fc90_A0 1043933302 /* Floating point value 0.972239 */ +#define HPF_Fs24000_Fc90_A1 -2087866604 /* Floating point value -1.944477 */ +#define HPF_Fs24000_Fc90_A2 1043933302 /* Floating point value 0.972239 */ +#define HPF_Fs24000_Fc90_B1 -2111750495 /* Floating point value -1.966721 */ +#define HPF_Fs24000_Fc90_B2 1038593601 /* Floating point value 0.967266 */ +#define HPF_Fs32000_Fc90_A0 1048285391 /* Floating point value 0.976292 */ +#define HPF_Fs32000_Fc90_A1 -2096570783 /* Floating point value -1.952584 */ +#define HPF_Fs32000_Fc90_A2 1048285391 /* Floating point value 0.976292 */ +#define HPF_Fs32000_Fc90_B1 -2120682737 /* Floating point value -1.975040 */ +#define HPF_Fs32000_Fc90_B2 1047271295 /* Floating point value 0.975347 */ +#define HPF_Fs44100_Fc90_A0 1051881330 /* Floating point value 0.979641 */ +#define HPF_Fs44100_Fc90_A1 -2103762660 /* Floating point value -1.959282 */ +#define HPF_Fs44100_Fc90_A2 1051881330 /* Floating point value 0.979641 */ +#define HPF_Fs44100_Fc90_B1 -2128035809 /* Floating point value -1.981888 */ +#define HPF_Fs44100_Fc90_B2 1054468533 /* Floating point value 0.982050 */ +#define HPF_Fs48000_Fc90_A0 1052655619 /* Floating point value 0.980362 */ +#define HPF_Fs48000_Fc90_A1 -2105311238 /* Floating point value -1.960724 */ +#define HPF_Fs48000_Fc90_A2 1052655619 /* Floating point value 0.980362 */ +#define HPF_Fs48000_Fc90_B1 -2129615871 /* Floating point value -1.983359 */ +#define HPF_Fs48000_Fc90_B2 1056021492 /* Floating point value 0.983497 */ + + +/************************************************************************************/ +/* */ +/* Band Pass Filter coefficients */ +/* */ +/************************************************************************************/ + + /* Coefficients for centre frequency 55Hz */ +#define BPF_Fs8000_Fc55_A0 9875247 /* Floating point value 0.009197 */ +#define BPF_Fs8000_Fc55_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs8000_Fc55_A2 -9875247 /* Floating point value -0.009197 */ +#define BPF_Fs8000_Fc55_B1 -2125519830 /* Floating point value -1.979545 */ +#define BPF_Fs8000_Fc55_B2 1053762629 /* Floating point value 0.981393 */ +#define BPF_Fs11025_Fc55_A0 7183952 /* Floating point value 0.006691 */ +#define BPF_Fs11025_Fc55_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs11025_Fc55_A2 -7183952 /* Floating point value -0.006691 */ +#define BPF_Fs11025_Fc55_B1 -2131901658 /* Floating point value -1.985488 */ +#define BPF_Fs11025_Fc55_B2 1059207548 /* Floating point value 0.986464 */ +#define BPF_Fs12000_Fc55_A0 6603871 /* Floating point value 0.006150 */ +#define BPF_Fs12000_Fc55_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs12000_Fc55_A2 -6603871 /* Floating point value -0.006150 */ +#define BPF_Fs12000_Fc55_B1 -2133238092 /* Floating point value -1.986733 */ +#define BPF_Fs12000_Fc55_B2 1060381143 /* Floating point value 0.987557 */ +#define BPF_Fs16000_Fc55_A0 4960591 /* Floating point value 0.004620 */ +#define BPF_Fs16000_Fc55_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs16000_Fc55_A2 -4960591 /* Floating point value -0.004620 */ +#define BPF_Fs16000_Fc55_B1 -2136949052 /* Floating point value -1.990189 */ +#define BPF_Fs16000_Fc55_B2 1063705760 /* Floating point value 0.990653 */ +#define BPF_Fs22050_Fc55_A0 3604131 /* Floating point value 0.003357 */ +#define BPF_Fs22050_Fc55_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs22050_Fc55_A2 -3604131 /* Floating point value -0.003357 */ +#define BPF_Fs22050_Fc55_B1 -2139929085 /* Floating point value -1.992964 */ +#define BPF_Fs22050_Fc55_B2 1066450095 /* Floating point value 0.993209 */ +#define BPF_Fs24000_Fc55_A0 3312207 /* Floating point value 0.003085 */ +#define BPF_Fs24000_Fc55_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs24000_Fc55_A2 -3312207 /* Floating point value -0.003085 */ +#define BPF_Fs24000_Fc55_B1 -2140560606 /* Floating point value -1.993552 */ +#define BPF_Fs24000_Fc55_B2 1067040703 /* Floating point value 0.993759 */ +#define BPF_Fs32000_Fc55_A0 2486091 /* Floating point value 0.002315 */ +#define BPF_Fs32000_Fc55_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs32000_Fc55_A2 -2486091 /* Floating point value -0.002315 */ +#define BPF_Fs32000_Fc55_B1 -2142328962 /* Floating point value -1.995199 */ +#define BPF_Fs32000_Fc55_B2 1068712067 /* Floating point value 0.995316 */ +#define BPF_Fs44100_Fc55_A0 1805125 /* Floating point value 0.001681 */ +#define BPF_Fs44100_Fc55_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs44100_Fc55_A2 -1805125 /* Floating point value -0.001681 */ +#define BPF_Fs44100_Fc55_B1 -2143765772 /* Floating point value -1.996537 */ +#define BPF_Fs44100_Fc55_B2 1070089770 /* Floating point value 0.996599 */ +#define BPF_Fs48000_Fc55_A0 1658687 /* Floating point value 0.001545 */ +#define BPF_Fs48000_Fc55_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs48000_Fc55_A2 -1658687 /* Floating point value -0.001545 */ +#define BPF_Fs48000_Fc55_B1 -2144072292 /* Floating point value -1.996823 */ +#define BPF_Fs48000_Fc55_B2 1070386036 /* Floating point value 0.996875 */ + + /* Coefficients for centre frequency 66Hz */ +#define BPF_Fs8000_Fc66_A0 13580189 /* Floating point value 0.012648 */ +#define BPF_Fs8000_Fc66_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs8000_Fc66_A2 -13580189 /* Floating point value -0.012648 */ +#define BPF_Fs8000_Fc66_B1 -2117161175 /* Floating point value -1.971760 */ +#define BPF_Fs8000_Fc66_B2 1046266945 /* Floating point value 0.974412 */ +#define BPF_Fs11025_Fc66_A0 9888559 /* Floating point value 0.009209 */ +#define BPF_Fs11025_Fc66_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs11025_Fc66_A2 -9888559 /* Floating point value -0.009209 */ +#define BPF_Fs11025_Fc66_B1 -2125972738 /* Floating point value -1.979966 */ +#define BPF_Fs11025_Fc66_B2 1053735698 /* Floating point value 0.981368 */ +#define BPF_Fs12000_Fc66_A0 9091954 /* Floating point value 0.008468 */ +#define BPF_Fs12000_Fc66_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs12000_Fc66_A2 -9091954 /* Floating point value -0.008468 */ +#define BPF_Fs12000_Fc66_B1 -2127818004 /* Floating point value -1.981685 */ +#define BPF_Fs12000_Fc66_B2 1055347356 /* Floating point value 0.982869 */ +#define BPF_Fs16000_Fc66_A0 6833525 /* Floating point value 0.006364 */ +#define BPF_Fs16000_Fc66_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs16000_Fc66_A2 -6833525 /* Floating point value -0.006364 */ +#define BPF_Fs16000_Fc66_B1 -2132941739 /* Floating point value -1.986457 */ +#define BPF_Fs16000_Fc66_B2 1059916517 /* Floating point value 0.987124 */ +#define BPF_Fs22050_Fc66_A0 4967309 /* Floating point value 0.004626 */ +#define BPF_Fs22050_Fc66_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs22050_Fc66_A2 -4967309 /* Floating point value -0.004626 */ +#define BPF_Fs22050_Fc66_B1 -2137056003 /* Floating point value -1.990288 */ +#define BPF_Fs22050_Fc66_B2 1063692170 /* Floating point value 0.990641 */ +#define BPF_Fs24000_Fc66_A0 4565445 /* Floating point value 0.004252 */ +#define BPF_Fs24000_Fc66_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs24000_Fc66_A2 -4565445 /* Floating point value -0.004252 */ +#define BPF_Fs24000_Fc66_B1 -2137927842 /* Floating point value -1.991100 */ +#define BPF_Fs24000_Fc66_B2 1064505202 /* Floating point value 0.991398 */ +#define BPF_Fs32000_Fc66_A0 3427761 /* Floating point value 0.003192 */ +#define BPF_Fs32000_Fc66_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs32000_Fc66_A2 -3427761 /* Floating point value -0.003192 */ +#define BPF_Fs32000_Fc66_B1 -2140369007 /* Floating point value -1.993374 */ +#define BPF_Fs32000_Fc66_B2 1066806920 /* Floating point value 0.993541 */ +#define BPF_Fs44100_Fc66_A0 2489466 /* Floating point value 0.002318 */ +#define BPF_Fs44100_Fc66_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs44100_Fc66_A2 -2489466 /* Floating point value -0.002318 */ +#define BPF_Fs44100_Fc66_B1 -2142352342 /* Floating point value -1.995221 */ +#define BPF_Fs44100_Fc66_B2 1068705240 /* Floating point value 0.995309 */ +#define BPF_Fs48000_Fc66_A0 2287632 /* Floating point value 0.002131 */ +#define BPF_Fs48000_Fc66_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs48000_Fc66_A2 -2287632 /* Floating point value -0.002131 */ +#define BPF_Fs48000_Fc66_B1 -2142775436 /* Floating point value -1.995615 */ +#define BPF_Fs48000_Fc66_B2 1069113581 /* Floating point value 0.995690 */ + + /* Coefficients for centre frequency 78Hz */ +#define BPF_Fs8000_Fc78_A0 19941180 /* Floating point value 0.018572 */ +#define BPF_Fs8000_Fc78_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs8000_Fc78_A2 -19941180 /* Floating point value -0.018572 */ +#define BPF_Fs8000_Fc78_B1 -2103186749 /* Floating point value -1.958745 */ +#define BPF_Fs8000_Fc78_B2 1033397648 /* Floating point value 0.962427 */ +#define BPF_Fs11025_Fc78_A0 14543934 /* Floating point value 0.013545 */ +#define BPF_Fs11025_Fc78_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs11025_Fc78_A2 -14543934 /* Floating point value -0.013545 */ +#define BPF_Fs11025_Fc78_B1 -2115966638 /* Floating point value -1.970647 */ +#define BPF_Fs11025_Fc78_B2 1044317135 /* Floating point value 0.972596 */ +#define BPF_Fs12000_Fc78_A0 13376999 /* Floating point value 0.012458 */ +#define BPF_Fs12000_Fc78_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs12000_Fc78_A2 -13376999 /* Floating point value -0.012458 */ +#define BPF_Fs12000_Fc78_B1 -2118651708 /* Floating point value -1.973148 */ +#define BPF_Fs12000_Fc78_B2 1046678029 /* Floating point value 0.974795 */ +#define BPF_Fs16000_Fc78_A0 10064222 /* Floating point value 0.009373 */ +#define BPF_Fs16000_Fc78_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs16000_Fc78_A2 -10064222 /* Floating point value -0.009373 */ +#define BPF_Fs16000_Fc78_B1 -2126124342 /* Floating point value -1.980108 */ +#define BPF_Fs16000_Fc78_B2 1053380304 /* Floating point value 0.981037 */ +#define BPF_Fs22050_Fc78_A0 7321780 /* Floating point value 0.006819 */ +#define BPF_Fs22050_Fc78_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs22050_Fc78_A2 -7321780 /* Floating point value -0.006819 */ +#define BPF_Fs22050_Fc78_B1 -2132143771 /* Floating point value -1.985714 */ +#define BPF_Fs22050_Fc78_B2 1058928700 /* Floating point value 0.986204 */ +#define BPF_Fs24000_Fc78_A0 6730640 /* Floating point value 0.006268 */ +#define BPF_Fs24000_Fc78_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs24000_Fc78_A2 -6730640 /* Floating point value -0.006268 */ +#define BPF_Fs24000_Fc78_B1 -2133421607 /* Floating point value -1.986904 */ +#define BPF_Fs24000_Fc78_B2 1060124669 /* Floating point value 0.987318 */ +#define BPF_Fs32000_Fc78_A0 5055965 /* Floating point value 0.004709 */ +#define BPF_Fs32000_Fc78_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs32000_Fc78_A2 -5055965 /* Floating point value -0.004709 */ +#define BPF_Fs32000_Fc78_B1 -2137003977 /* Floating point value -1.990240 */ +#define BPF_Fs32000_Fc78_B2 1063512802 /* Floating point value 0.990473 */ +#define BPF_Fs44100_Fc78_A0 3673516 /* Floating point value 0.003421 */ +#define BPF_Fs44100_Fc78_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs44100_Fc78_A2 -3673516 /* Floating point value -0.003421 */ +#define BPF_Fs44100_Fc78_B1 -2139919394 /* Floating point value -1.992955 */ +#define BPF_Fs44100_Fc78_B2 1066309718 /* Floating point value 0.993078 */ +#define BPF_Fs48000_Fc78_A0 3375990 /* Floating point value 0.003144 */ +#define BPF_Fs48000_Fc78_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs48000_Fc78_A2 -3375990 /* Floating point value -0.003144 */ +#define BPF_Fs48000_Fc78_B1 -2140541906 /* Floating point value -1.993535 */ +#define BPF_Fs48000_Fc78_B2 1066911660 /* Floating point value 0.993639 */ + + /* Coefficients for centre frequency 90Hz */ +#define BPF_Fs8000_Fc90_A0 24438548 /* Floating point value 0.022760 */ +#define BPF_Fs8000_Fc90_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs8000_Fc90_A2 -24438548 /* Floating point value -0.022760 */ +#define BPF_Fs8000_Fc90_B1 -2092801347 /* Floating point value -1.949073 */ +#define BPF_Fs8000_Fc90_B2 1024298757 /* Floating point value 0.953953 */ +#define BPF_Fs11025_Fc90_A0 17844385 /* Floating point value 0.016619 */ +#define BPF_Fs11025_Fc90_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs11025_Fc90_A2 -17844385 /* Floating point value -0.016619 */ +#define BPF_Fs11025_Fc90_B1 -2108604921 /* Floating point value -1.963791 */ +#define BPF_Fs11025_Fc90_B2 1037639797 /* Floating point value 0.966377 */ +#define BPF_Fs12000_Fc90_A0 16416707 /* Floating point value 0.015289 */ +#define BPF_Fs12000_Fc90_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs12000_Fc90_A2 -16416707 /* Floating point value -0.015289 */ +#define BPF_Fs12000_Fc90_B1 -2111922936 /* Floating point value -1.966882 */ +#define BPF_Fs12000_Fc90_B2 1040528216 /* Floating point value 0.969067 */ +#define BPF_Fs16000_Fc90_A0 12359883 /* Floating point value 0.011511 */ +#define BPF_Fs16000_Fc90_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs16000_Fc90_A2 -12359883 /* Floating point value -0.011511 */ +#define BPF_Fs16000_Fc90_B1 -2121152162 /* Floating point value -1.975477 */ +#define BPF_Fs16000_Fc90_B2 1048735817 /* Floating point value 0.976711 */ +#define BPF_Fs22050_Fc90_A0 8997173 /* Floating point value 0.008379 */ +#define BPF_Fs22050_Fc90_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs22050_Fc90_A2 -8997173 /* Floating point value -0.008379 */ +#define BPF_Fs22050_Fc90_B1 -2128580762 /* Floating point value -1.982395 */ +#define BPF_Fs22050_Fc90_B2 1055539113 /* Floating point value 0.983047 */ +#define BPF_Fs24000_Fc90_A0 8271818 /* Floating point value 0.007704 */ +#define BPF_Fs24000_Fc90_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs24000_Fc90_A2 -8271818 /* Floating point value -0.007704 */ +#define BPF_Fs24000_Fc90_B1 -2130157013 /* Floating point value -1.983863 */ +#define BPF_Fs24000_Fc90_B2 1057006621 /* Floating point value 0.984414 */ +#define BPF_Fs32000_Fc90_A0 6215918 /* Floating point value 0.005789 */ +#define BPF_Fs32000_Fc90_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs32000_Fc90_A2 -6215918 /* Floating point value -0.005789 */ +#define BPF_Fs32000_Fc90_B1 -2134574521 /* Floating point value -1.987977 */ +#define BPF_Fs32000_Fc90_B2 1061166033 /* Floating point value 0.988288 */ +#define BPF_Fs44100_Fc90_A0 4517651 /* Floating point value 0.004207 */ +#define BPF_Fs44100_Fc90_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs44100_Fc90_A2 -4517651 /* Floating point value -0.004207 */ +#define BPF_Fs44100_Fc90_B1 -2138167926 /* Floating point value -1.991324 */ +#define BPF_Fs44100_Fc90_B2 1064601898 /* Floating point value 0.991488 */ +#define BPF_Fs48000_Fc90_A0 4152024 /* Floating point value 0.003867 */ +#define BPF_Fs48000_Fc90_A1 0 /* Floating point value 0.000000 */ +#define BPF_Fs48000_Fc90_A2 -4152024 /* Floating point value -0.003867 */ +#define BPF_Fs48000_Fc90_B1 -2138935002 /* Floating point value -1.992038 */ +#define BPF_Fs48000_Fc90_B2 1065341620 /* Floating point value 0.992177 */ + + +/************************************************************************************/ +/* */ +/* Automatic Gain Control time constants and gain settings */ +/* */ +/************************************************************************************/ + +/* AGC Time constants */ +#define AGC_ATTACK_Fs8000 27571 /* Floating point value 0.841395 */ +#define AGC_ATTACK_Fs11025 28909 /* Floating point value 0.882223 */ +#define AGC_ATTACK_Fs12000 29205 /* Floating point value 0.891251 */ +#define AGC_ATTACK_Fs16000 30057 /* Floating point value 0.917276 */ +#define AGC_ATTACK_Fs22050 30778 /* Floating point value 0.939267 */ +#define AGC_ATTACK_Fs24000 30935 /* Floating point value 0.944061 */ +#define AGC_ATTACK_Fs32000 31383 /* Floating point value 0.957745 */ +#define AGC_ATTACK_Fs44100 31757 /* Floating point value 0.969158 */ +#define AGC_ATTACK_Fs48000 31838 /* Floating point value 0.971628 */ +#define DECAY_SHIFT 10 /* As a power of 2 */ +#define AGC_DECAY_Fs8000 44 /* Floating point value 0.000042 */ +#define AGC_DECAY_Fs11025 32 /* Floating point value 0.000030 */ +#define AGC_DECAY_Fs12000 29 /* Floating point value 0.000028 */ +#define AGC_DECAY_Fs16000 22 /* Floating point value 0.000021 */ +#define AGC_DECAY_Fs22050 16 /* Floating point value 0.000015 */ +#define AGC_DECAY_Fs24000 15 /* Floating point value 0.000014 */ +#define AGC_DECAY_Fs32000 11 /* Floating point value 0.000010 */ +#define AGC_DECAY_Fs44100 8 /* Floating point value 0.000008 */ +#define AGC_DECAY_Fs48000 7 /* Floating point value 0.000007 */ + +/* AGC Gain settings */ +#define AGC_GAIN_SCALE 31 /* As a power of 2 */ +#define AGC_GAIN_SHIFT 4 /* As a power of 2 */ +#define AGC_TARGETLEVEL 33170337 /* Floating point value -0.100000dB */ +#define AGC_HPFGAIN_0dB 110739704 /* Floating point value 0.412538 */ +#define AGC_GAIN_0dB 0 /* Floating point value 0.000000 */ +#define AGC_HPFGAIN_1dB 157006071 /* Floating point value 0.584893 */ +#define AGC_GAIN_1dB 32754079 /* Floating point value 0.122018 */ +#define AGC_HPFGAIN_2dB 208917788 /* Floating point value 0.778279 */ +#define AGC_GAIN_2dB 69504761 /* Floating point value 0.258925 */ +#define AGC_HPFGAIN_3dB 267163693 /* Floating point value 0.995262 */ +#define AGC_GAIN_3dB 110739704 /* Floating point value 0.412538 */ +#define AGC_HPFGAIN_4dB 332516674 /* Floating point value 1.238721 */ +#define AGC_GAIN_4dB 157006071 /* Floating point value 0.584893 */ +#define AGC_HPFGAIN_5dB 405843924 /* Floating point value 1.511886 */ +#define AGC_GAIN_5dB 208917788 /* Floating point value 0.778279 */ +#define AGC_HPFGAIN_6dB 488118451 /* Floating point value 1.818383 */ +#define AGC_GAIN_6dB 267163693 /* Floating point value 0.995262 */ +#define AGC_HPFGAIN_7dB 580431990 /* Floating point value 2.162278 */ +#define AGC_GAIN_7dB 332516674 /* Floating point value 1.238721 */ +#define AGC_HPFGAIN_8dB 684009483 /* Floating point value 2.548134 */ +#define AGC_GAIN_8dB 405843924 /* Floating point value 1.511886 */ +#define AGC_HPFGAIN_9dB 800225343 /* Floating point value 2.981072 */ +#define AGC_GAIN_9dB 488118451 /* Floating point value 1.818383 */ +#define AGC_HPFGAIN_10dB 930621681 /* Floating point value 3.466836 */ +#define AGC_GAIN_10dB 580431990 /* Floating point value 2.162278 */ +#define AGC_HPFGAIN_11dB 1076928780 /* Floating point value 4.011872 */ +#define AGC_GAIN_11dB 684009483 /* Floating point value 2.548134 */ +#define AGC_HPFGAIN_12dB 1241088045 /* Floating point value 4.623413 */ +#define AGC_GAIN_12dB 800225343 /* Floating point value 2.981072 */ +#define AGC_HPFGAIN_13dB 1425277769 /* Floating point value 5.309573 */ +#define AGC_GAIN_13dB 930621681 /* Floating point value 3.466836 */ +#define AGC_HPFGAIN_14dB 1631942039 /* Floating point value 6.079458 */ +#define AGC_GAIN_14dB 1076928780 /* Floating point value 4.011872 */ +#define AGC_HPFGAIN_15dB 1863823163 /* Floating point value 6.943282 */ +#define AGC_GAIN_15dB 1241088045 /* Floating point value 4.623413 */ + + +/************************************************************************************/ +/* */ +/* Volume control */ +/* */ +/************************************************************************************/ + +/* Volume control gain */ +#define VOLUME_MAX 0 /* In dBs */ +#define VOLUME_SHIFT 0 /* In dBs */ + +/* Volume control time constants */ +#define VOL_TC_SHIFT 21 /* As a power of 2 */ +#define VOL_TC_Fs8000 25889 /* Floating point value 0.024690 */ +#define VOL_TC_Fs11025 18850 /* Floating point value 0.017977 */ +#define VOL_TC_Fs12000 17331 /* Floating point value 0.016529 */ +#define VOL_TC_Fs16000 13026 /* Floating point value 0.012422 */ +#define VOL_TC_Fs22050 9468 /* Floating point value 0.009029 */ +#define VOL_TC_Fs24000 8702 /* Floating point value 0.008299 */ +#define VOL_TC_Fs32000 6533 /* Floating point value 0.006231 */ +#define VOL_TC_Fs44100 4745 /* Floating point value 0.004525 */ +#define VOL_TC_Fs48000 4360 /* Floating point value 0.004158 */ +#define MIX_TC_Fs8000 29365 /* Floating point value 0.896151 */ +#define MIX_TC_Fs11025 30230 /* Floating point value 0.922548 */ +#define MIX_TC_Fs12000 30422 /* Floating point value 0.928415 */ +#define MIX_TC_Fs16000 30978 /* Floating point value 0.945387 */ +#define MIX_TC_Fs22050 31451 /* Floating point value 0.959804 */ +#define MIX_TC_Fs24000 31554 /* Floating point value 0.962956 */ +#define MIX_TC_Fs32000 31850 /* Floating point value 0.971973 */ +#define MIX_TC_Fs44100 32097 /* Floating point value 0.979515 */ +#define MIX_TC_Fs48000 32150 /* Floating point value 0.981150 */ + + +#endif diff --git a/media/libeffects/lvm/lib/Bass/src/LVDBE_Control.c b/media/libeffects/lvm/lib/Bass/src/LVDBE_Control.c new file mode 100755 index 0000000..e66513f --- /dev/null +++ b/media/libeffects/lvm/lib/Bass/src/LVDBE_Control.c @@ -0,0 +1,377 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************************** + + $Author: nxp007753 $ + $Revision: 1223 $ + $Date: 2010-07-15 14:27:01 +0200 (Thu, 15 Jul 2010) $ + +*****************************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVDBE.h" +#include "LVDBE_Private.h" +#include "VectorArithmetic.h" +#include "LVDBE_Coeffs.h" +#include "LVDBE_Tables.h" + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVDBE_GetParameters */ +/* */ +/* DESCRIPTION: */ +/* Request the Dynamic Bass Enhancement parameters. The current parameter set is */ +/* returned via the parameter pointer. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to an empty parameter structure */ +/* */ +/* RETURNS: */ +/* LVDBE_SUCCESS Always succeeds */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVDBE_Process function */ +/* */ +/****************************************************************************************/ + +LVDBE_ReturnStatus_en LVDBE_GetParameters(LVDBE_Handle_t hInstance, + LVDBE_Params_t *pParams) +{ + + LVDBE_Instance_t *pInstance =(LVDBE_Instance_t *)hInstance; + + *pParams = pInstance->Params; + + return(LVDBE_SUCCESS); +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVDBE_GetCapabilities */ +/* */ +/* DESCRIPTION: Dynamic Bass Enhnacement capabilities. The current capabilities are */ +/* returned via the pointer. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pCapabilities Pointer to an empty capability structure */ +/* */ +/* RETURNS: */ +/* LVDBE_Success Always succeeds */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVDBE_Process function */ +/* */ +/************************************************************************************/ + +LVDBE_ReturnStatus_en LVDBE_GetCapabilities(LVDBE_Handle_t hInstance, + LVDBE_Capabilities_t *pCapabilities) +{ + + LVDBE_Instance_t *pInstance =(LVDBE_Instance_t *)hInstance; + + *pCapabilities = pInstance->Capabilities; + + return(LVDBE_SUCCESS); +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVDBE_SetFilters */ +/* */ +/* DESCRIPTION: */ +/* Sets the filter coefficients and clears the data history */ +/* */ +/* PARAMETERS: */ +/* pInstance Pointer to the instance */ +/* pParams Initialisation parameters */ +/* */ +/************************************************************************************/ + +void LVDBE_SetFilters(LVDBE_Instance_t *pInstance, + LVDBE_Params_t *pParams) +{ + + /* + * Calculate the table offsets + */ + LVM_UINT16 Offset = (LVM_UINT16)((LVM_UINT16)pParams->SampleRate + (LVM_UINT16)(pParams->CentreFrequency * (1+LVDBE_FS_48000))); + + + /* + * Setup the high pass filter + */ + LoadConst_16(0, /* Clear the history, value 0 */ + (LVM_INT16 *)&pInstance->pData->HPFTaps, /* Destination */ + sizeof(pInstance->pData->HPFTaps)/sizeof(LVM_INT16)); /* Number of words */ + BQ_2I_D32F32Cll_TRC_WRA_01_Init(&pInstance->pCoef->HPFInstance, /* Initialise the filter */ + &pInstance->pData->HPFTaps, + (BQ_C32_Coefs_t *)&LVDBE_HPF_Table[Offset]); + + + /* + * Setup the band pass filter + */ + LoadConst_16(0, /* Clear the history, value 0 */ + (LVM_INT16 *)&pInstance->pData->BPFTaps, /* Destination */ + sizeof(pInstance->pData->BPFTaps)/sizeof(LVM_INT16)); /* Number of words */ + BP_1I_D32F32Cll_TRC_WRA_02_Init(&pInstance->pCoef->BPFInstance, /* Initialise the filter */ + &pInstance->pData->BPFTaps, + (BP_C32_Coefs_t *)&LVDBE_BPF_Table[Offset]); + +} + + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVDBE_SetAGC */ +/* */ +/* DESCRIPTION: */ +/* Sets the AGC gain level and attack and decay times constants. */ +/* */ +/* PARAMETERS: */ +/* pInstance Pointer to the instance */ +/* pParams Initialisation parameters */ +/* */ +/************************************************************************************/ + +void LVDBE_SetAGC(LVDBE_Instance_t *pInstance, + LVDBE_Params_t *pParams) +{ + + /* + * Get the attack and decay time constants + */ + pInstance->pData->AGCInstance.AGC_Attack = LVDBE_AGC_ATTACK_Table[(LVM_UINT16)pParams->SampleRate]; /* Attack multiplier */ + pInstance->pData->AGCInstance.AGC_Decay = LVDBE_AGC_DECAY_Table[(LVM_UINT16)pParams->SampleRate]; /* Decay multipler */ + + + /* + * Get the boost gain + */ + if (pParams->HPFSelect == LVDBE_HPF_ON) + { + pInstance->pData->AGCInstance.AGC_MaxGain = LVDBE_AGC_HPFGAIN_Table[(LVM_UINT16)pParams->EffectLevel]; /* High pass filter on */ + } + else + { + pInstance->pData->AGCInstance.AGC_MaxGain = LVDBE_AGC_GAIN_Table[(LVM_UINT16)pParams->EffectLevel]; /* High pass filter off */ + } + pInstance->pData->AGCInstance.AGC_GainShift = AGC_GAIN_SHIFT; + pInstance->pData->AGCInstance.AGC_Target = AGC_TARGETLEVEL; + +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVDBE_SetVolume */ +/* */ +/* DESCRIPTION: */ +/* Converts the input volume demand from dBs to linear. */ +/* */ +/* PARAMETERS: */ +/* pInstance Pointer to the instance */ +/* pParams Initialisation parameters */ +/* */ +/* NOTES: */ +/* 1. The volume should have the following settings: */ +/* */ +/* DBE Vol Control Volume setting */ +/* === =========== =================== */ +/* Off Off HeadroomdB */ +/* Off On VolumedB+HeadroomdB */ +/* On Off HeadroomdB */ +/* On On VolumedB+HeadroomdB */ +/* */ +/************************************************************************************/ + +void LVDBE_SetVolume(LVDBE_Instance_t *pInstance, + LVDBE_Params_t *pParams) +{ + + LVM_UINT16 dBShifts; /* 6dB shifts */ + LVM_UINT16 dBOffset; /* Table offset */ + LVM_INT16 Volume = 0; /* Required volume in dBs */ + + /* + * Apply the volume if enabled + */ + if (pParams->VolumeControl == LVDBE_VOLUME_ON) + { + /* + * Limit the gain to the maximum allowed + */ + if (pParams->VolumedB > VOLUME_MAX) + { + Volume = VOLUME_MAX; + } + else + { + Volume = pParams->VolumedB; + } + } + + + /* + * Calculate the required gain and shifts + */ + dBOffset = (LVM_UINT16)(6 + Volume % 6); /* Get the dBs 0-5 */ + dBShifts = (LVM_UINT16)(Volume / -6); /* Get the 6dB shifts */ + + + /* + * When DBE is enabled use AGC volume + */ + pInstance->pData->AGCInstance.Target = ((LVM_INT32)LVDBE_VolumeTable[dBOffset] << 16); + pInstance->pData->AGCInstance.Target = pInstance->pData->AGCInstance.Target >> dBShifts; + + pInstance->pData->AGCInstance.VolumeTC = LVDBE_VolumeTCTable[(LVM_UINT16)pParams->SampleRate]; /* Volume update time constant */ + pInstance->pData->AGCInstance.VolumeShift = VOLUME_SHIFT+1; + + /* + * When DBE is disabled use the bypass volume control + */ + if(dBShifts > 0) + { + LVC_Mixer_SetTarget(&pInstance->pData->BypassVolume.MixerStream[0],(((LVM_INT32)LVDBE_VolumeTable[dBOffset]) >> dBShifts)); + } + else + { + LVC_Mixer_SetTarget(&pInstance->pData->BypassVolume.MixerStream[0],(LVM_INT32)LVDBE_VolumeTable[dBOffset]); + } + + pInstance->pData->BypassVolume.MixerStream[0].CallbackSet = 1; + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->pData->BypassVolume.MixerStream[0], + LVDBE_MIXER_TC, + (LVM_Fs_en)pInstance->Params.SampleRate, + 2); +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVDBE_Control */ +/* */ +/* DESCRIPTION: */ +/* Sets or changes the Bass Enhancement parameters. Changing the parameters while the */ +/* module is processing signals may have the following side effects: */ +/* */ +/* General parameters: */ +/* =================== */ +/* OperatingMode: Changing the mode of operation may cause a change in volume */ +/* level or cause pops and clicks. */ +/* */ +/* SampleRate: Changing the sample rate may cause pops and clicks. */ +/* */ +/* EffectLevel: Changing the effect level may cause pops and clicks */ +/* */ +/* CentreFrequency: Changing the centre frequency may cause pops and clicks */ +/* */ +/* HPFSelect: Selecting/de-selecting the high pass filter may cause pops and */ +/* clicks */ +/* */ +/* VolumedB Changing the volume setting will have no side effects */ +/* */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to a parameter structure */ +/* */ +/* RETURNS: */ +/* LVDBE_SUCCESS Always succeeds */ +/* */ +/* NOTES: */ +/* 1. This function must not be interrupted by the LVDBE_Process function */ +/* */ +/****************************************************************************************/ + +LVDBE_ReturnStatus_en LVDBE_Control(LVDBE_Handle_t hInstance, + LVDBE_Params_t *pParams) +{ + + LVDBE_Instance_t *pInstance =(LVDBE_Instance_t *)hInstance; + + + /* + * Update the filters + */ + if ((pInstance->Params.SampleRate != pParams->SampleRate) || + (pInstance->Params.CentreFrequency != pParams->CentreFrequency)) + { + LVDBE_SetFilters(pInstance, /* Instance pointer */ + pParams); /* New parameters */ + } + + + /* + * Update the AGC is the effect level has changed + */ + if ((pInstance->Params.SampleRate != pParams->SampleRate) || + (pInstance->Params.EffectLevel != pParams->EffectLevel) || + (pInstance->Params.HPFSelect != pParams->HPFSelect)) + { + LVDBE_SetAGC(pInstance, /* Instance pointer */ + pParams); /* New parameters */ + } + + + /* + * Update the Volume if the volume demand has changed + */ + if ((pInstance->Params.VolumedB != pParams->VolumedB) || + (pInstance->Params.SampleRate != pParams->SampleRate) || + (pInstance->Params.HeadroomdB != pParams->HeadroomdB) || + (pInstance->Params.VolumeControl != pParams->VolumeControl)) + { + LVDBE_SetVolume(pInstance, /* Instance pointer */ + pParams); /* New parameters */ + } + + if (pInstance->Params.OperatingMode==LVDBE_ON && pParams->OperatingMode==LVDBE_OFF) + { + LVDBE_Params_t Params = *pParams; /* make local copy of params */ + Params.EffectLevel = 0; /* zero effect level before switching off module*/ + pInstance->bTransitionOnToOff = LVM_TRUE; /* Set the CallBack */ + LVDBE_SetAGC(pInstance, /* Instance pointer */ + &Params); /* New parameters */ + } + if (pInstance->Params.OperatingMode==LVDBE_OFF && pParams->OperatingMode==LVDBE_ON) + { + pInstance->bTransitionOnToOff = LVM_FALSE; /* Set the CallBack */ + LVDBE_SetAGC(pInstance, /* Instance pointer */ + pParams); /* New parameters */ + } + + /* + * Update the instance parameters + */ + pInstance->Params = *pParams; + + + return(LVDBE_SUCCESS); +} diff --git a/media/libeffects/lvm/lib/Bass/src/LVDBE_Init.c b/media/libeffects/lvm/lib/Bass/src/LVDBE_Init.c new file mode 100755 index 0000000..75869c7 --- /dev/null +++ b/media/libeffects/lvm/lib/Bass/src/LVDBE_Init.c @@ -0,0 +1,267 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************************** + + $Author: nxp007753 $ + $Revision: 1081 $ + $Date: 2010-07-05 11:48:44 +0200 (Mon, 05 Jul 2010) $ + +*****************************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#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_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_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_INT16)*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. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pMemoryTable Pointer to the memory definition table */ +/* pCapabilities Pointer to the instance capabilities */ +/* */ +/* RETURNS: */ +/* LVDBE_SUCCESS Initialisation succeeded */ +/* LVDBE_ALIGNMENTERROR Instance or scratch memory on incorrect alignment */ +/* LVDBE_NULLADDRESS Instance or scratch 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 */ +/* */ +/****************************************************************************************/ + +LVDBE_ReturnStatus_en LVDBE_Init(LVDBE_Handle_t *phInstance, + LVDBE_MemTab_t *pMemoryTable, + LVDBE_Capabilities_t *pCapabilities) +{ + + LVDBE_Instance_t *pInstance; + LVMixer3_1St_st *pMixer_Instance; + LVM_INT16 i; + LVM_INT32 MixGain; + + + /* + * Set the instance handle if not already initialised + */ + if (*phInstance == LVM_NULL) + { + *phInstance = (LVDBE_Handle_t)pMemoryTable->Region[LVDBE_MEMREGION_INSTANCE].pBaseAddress; + } + pInstance =(LVDBE_Instance_t *)*phInstance; + + + /* + * Check the memory table for NULL pointers and incorrectly aligned data + */ + for (i=0; iRegion[i].Size!=0) + { + if (pMemoryTable->Region[i].pBaseAddress==LVM_NULL) + { + return(LVDBE_NULLADDRESS); + } + if (((LVM_UINT32)pMemoryTable->Region[i].pBaseAddress % pMemoryTable->Region[i].Alignment)!=0){ + return(LVDBE_ALIGNMENTERROR); + } + } + } + + + /* + * Save the memory table in the instance structure + */ + pInstance->Capabilities = *pCapabilities; + + + /* + * Save the memory table in the instance structure + */ + pInstance->MemoryTable = *pMemoryTable; + + + /* + * Set the default instance parameters + */ + pInstance->Params.CentreFrequency = LVDBE_CENTRE_55HZ; + pInstance->Params.EffectLevel = 0; + pInstance->Params.HeadroomdB = 0; + pInstance->Params.HPFSelect = LVDBE_HPF_OFF; + pInstance->Params.OperatingMode = LVDBE_OFF; + pInstance->Params.SampleRate = LVDBE_FS_8000; + pInstance->Params.VolumeControl = LVDBE_VOLUME_OFF; + pInstance->Params.VolumedB = 0; + + + /* + * Set pointer to data and coef memory + */ + pInstance->pData = pMemoryTable->Region[LVDBE_MEMREGION_PERSISTENT_DATA].pBaseAddress; + pInstance->pCoef = pMemoryTable->Region[LVDBE_MEMREGION_PERSISTENT_COEF].pBaseAddress; + + + /* + * Initialise the filters + */ + LVDBE_SetFilters(pInstance, /* Set the filter taps and coefficients */ + &pInstance->Params); + + + /* + * Initialise the AGC + */ + LVDBE_SetAGC(pInstance, /* Set the AGC gain */ + &pInstance->Params); + pInstance->pData->AGCInstance.AGC_Gain = pInstance->pData->AGCInstance.AGC_MaxGain; /* Default to the bass boost setting */ + + + /* + * Initialise the volume + */ + LVDBE_SetVolume(pInstance, /* Set the Volume */ + &pInstance->Params); + + pInstance->pData->AGCInstance.Volume = pInstance->pData->AGCInstance.Target; /* Initialise as the target */ + + pMixer_Instance = &pInstance->pData->BypassVolume; + MixGain = LVC_Mixer_GetTarget(&pMixer_Instance->MixerStream[0]); + LVC_Mixer_Init(&pMixer_Instance->MixerStream[0],MixGain,MixGain); + + /* Configure the mixer process path */ + pMixer_Instance->MixerStream[0].CallbackParam = 0; + pMixer_Instance->MixerStream[0].pCallbackHandle = LVM_NULL; + pMixer_Instance->MixerStream[0].pCallBack = LVM_NULL; + pMixer_Instance->MixerStream[0].CallbackSet = 0; + + /* + * Initialise the clicks minimisation variable + */ + pInstance->bTransitionOnToOff = LVM_FALSE; + + return(LVDBE_SUCCESS); +} + diff --git a/media/libeffects/lvm/lib/Bass/src/LVDBE_Private.h b/media/libeffects/lvm/lib/Bass/src/LVDBE_Private.h new file mode 100755 index 0000000..3e09cf4 --- /dev/null +++ b/media/libeffects/lvm/lib/Bass/src/LVDBE_Private.h @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************************** + + $Author: nxp007753 $ + $Revision: 1081 $ + $Date: 2010-07-05 11:48:44 +0200 (Mon, 05 Jul 2010) $ + +*****************************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Header file for the private layer interface of Dynamic Bass Enhancement module */ +/* */ +/* This files includes all definitions, types, structures and function */ +/* prototypes required by the execution layer. */ +/* */ +/****************************************************************************************/ + +#ifndef __LVDBE_PRIVATE_H__ +#define __LVDBE_PRIVATE_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVDBE.h" /* Calling or Application layer definitions */ +#include "BIQUAD.h" +#include "LVC_Mixer.h" +#include "AGC.h" + + +/****************************************************************************************/ +/* */ +/* Defines */ +/* */ +/****************************************************************************************/ + +/* 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 */ + +#define LVDBE_SCRATCHBUFFERS_INPLACE 4 /* Number of buffers required for inplace processing */ + +#define LVDBE_MIXER_TC 5 /* Mixer time */ + +/****************************************************************************************/ +/* */ +/* Structures */ +/* */ +/****************************************************************************************/ + +/* Data structure */ +typedef struct +{ + /* AGC parameters */ + AGC_MIX_VOL_2St1Mon_D32_t AGCInstance; /* AGC instance parameters */ + + /* Process variables */ + Biquad_2I_Order2_Taps_t HPFTaps; /* High pass filter taps */ + Biquad_1I_Order2_Taps_t BPFTaps; /* Band pass filter taps */ + LVMixer3_1St_st BypassVolume; /* Bypass volume scaler */ + +} LVDBE_Data_t; + +/* Coefs structure */ +typedef struct +{ + /* Process variables */ + Biquad_Instance_t HPFInstance; /* High pass filter instance */ + Biquad_Instance_t BPFInstance; /* Band pass filter instance */ + +} LVDBE_Coef_t; + +/* Instance structure */ +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_t *pData; /* Instance data */ + LVDBE_Coef_t *pCoef; /* Instance coefficients */ + + LVM_INT32 bTransitionOnToOff; + +} LVDBE_Instance_t; + + +/****************************************************************************************/ +/* */ +/* Function prototypes */ +/* */ +/****************************************************************************************/ + +void LVDBE_SetAGC(LVDBE_Instance_t *pInstance, + LVDBE_Params_t *pParams); + + +void LVDBE_SetVolume(LVDBE_Instance_t *pInstance, + LVDBE_Params_t *pParams); + + +void LVDBE_SetFilters(LVDBE_Instance_t *pInstance, + LVDBE_Params_t *pParams); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LVDBE_PRIVATE_H__ */ + + diff --git a/media/libeffects/lvm/lib/Bass/src/LVDBE_Process.c b/media/libeffects/lvm/lib/Bass/src/LVDBE_Process.c new file mode 100755 index 0000000..35eec07 --- /dev/null +++ b/media/libeffects/lvm/lib/Bass/src/LVDBE_Process.c @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************************** + + $Author: nxp007753 $ + $Revision: 1081 $ + $Date: 2010-07-05 11:48:44 +0200 (Mon, 05 Jul 2010) $ + +*****************************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVDBE.h" +#include "LVDBE_Private.h" +#include "VectorArithmetic.h" +#include "AGC.h" +#include "LVDBE_Coeffs.h" /* Filter coefficients */ + + +/********************************************************************************************/ +/* */ +/* FUNCTION: LVDBE_Process */ +/* */ +/* DESCRIPTION: */ +/* Process function for the Bass Enhancement module. */ +/* */ +/* Data can be processed in two formats, stereo or mono-in-stereo. Data in mono */ +/* format is not supported, the calling routine must convert the mono stream to */ +/* mono-in-stereo. */ +/* ___________ */ +/* ________ | | ________ */ +/* | | _____ |------------------------->| | | | */ +/* | 16-bit | | | | ________ | | | 32-bit | */ +/* -+-->| to |-->| HPF |--| | | _____ | AGC Mixer |-->| to |--| */ +/* | | 32-bit | |_____| | | Stereo | | | | | | 16-bit | | */ +/* | |________| |-->| to |-->| BPF |-->| | |________| 0 */ +/* | | Mono | |_____| |___________| \--> */ +/* | |________| */ +/* | _________ 0 */ +/* | | | | */ +/* |----------------------------------------------------| Volume |-----------------| */ +/* | Control | */ +/* |_________| */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pInData Pointer to the input data */ +/* pOutData Pointer to the output data */ +/* NumSamples Number of samples in the input buffer */ +/* */ +/* RETURNS: */ +/* LVDBE_SUCCESS Succeeded */ +/* LVDBE_TOOMANYSAMPLES NumSamples was larger than the maximum block size */ +/* */ +/* NOTES: */ +/* 1. The input and output data must be 32-bit format. The input is scaled by a shift */ +/* when converting from 16-bit format, this scaling allows for internal headroom in the */ +/* bass enhancement algorithm. */ +/* 2. For a 16-bit implementation the converstion to 32-bit is removed and replaced with */ +/* the headroom loss. This headroom loss is compensated in the volume control so the */ +/* overall end to end gain is odB. */ +/* */ +/********************************************************************************************/ + +LVDBE_ReturnStatus_en LVDBE_Process(LVDBE_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 *pOutData, + LVM_UINT16 NumSamples) +{ + + LVDBE_Instance_t *pInstance =(LVDBE_Instance_t *)hInstance; + LVM_INT32 *pScratch = (LVM_INT32 *)pInstance->MemoryTable.Region[LVDBE_MEMREGION_SCRATCH].pBaseAddress; + LVM_INT32 *pMono = (LVM_INT32 *)pOutData; + LVM_INT16 *pInput = (LVM_INT16 *)pInData; + + + /* + * Check the number of samples is not too large + */ + if (NumSamples > pInstance->Capabilities.MaxBlockSize) + { + return(LVDBE_TOOMANYSAMPLES); + } + + /* + * Check if the algorithm is enabled + */ + if ((pInstance->Params.OperatingMode != LVDBE_OFF) || + (pInstance->bTransitionOnToOff == LVM_TRUE)) + { + + /* + * Convert 16-bit samples to 32-bit and scale + * (For a 16-bit implementation apply headroom loss here) + */ + Int16LShiftToInt32_16x32(pInput, /* Source 16-bit data */ + pScratch, /* Destination 32-bit data */ + (LVM_INT16)(2*NumSamples), /* Left and right */ + LVDBE_SCALESHIFT); /* Shift scale */ + + + /* + * Apply the high pass filter if selected + */ + if (pInstance->Params.HPFSelect == LVDBE_HPF_ON) + { + BQ_2I_D32F32C30_TRC_WRA_01(&pInstance->pCoef->HPFInstance, /* Filter instance */ + (LVM_INT32 *)pScratch, /* Source */ + (LVM_INT32 *)pScratch, /* Destination */ + (LVM_INT16)NumSamples); /* Number of samples */ + } + + + /* + * Create the mono stream + */ + From2iToMono_32(pScratch, /* Stereo source */ + pMono, /* Mono destination */ + (LVM_INT16)NumSamples); /* Number of samples */ + + + /* + * Apply the band pass filter + */ + BP_1I_D32F32C30_TRC_WRA_02(&pInstance->pCoef->BPFInstance, /* Filter instance */ + (LVM_INT32 *)pMono, /* Source */ + (LVM_INT32 *)pMono, /* Destination */ + (LVM_INT16)NumSamples); /* Number of samples */ + + + /* + * Apply the AGC and mix + */ + AGC_MIX_VOL_2St1Mon_D32_WRA(&pInstance->pData->AGCInstance, /* Instance pointer */ + pScratch, /* Stereo source */ + pMono, /* Mono band pass source */ + pScratch, /* Stereo destination */ + NumSamples); /* Number of samples */ + + if(pInstance->bTransitionOnToOff == LVM_TRUE) + { + if ((pInstance->pData->AGCInstance.AGC_Gain == pInstance->pData->AGCInstance.AGC_Target)&& + (pInstance->pData->AGCInstance.AGC_Gain == 0)) + { + pInstance->bTransitionOnToOff = LVM_FALSE; + } + } + + + + /* + * Convert 32-bit samples to 16-bit and saturate + * (Not required for 16-bit implemenations) + */ + Int32RShiftToInt16_Sat_32x16(pScratch, /* Source 32-bit data */ + pOutData, /* Destination 16-bit data */ + (LVM_INT16)(2*NumSamples), /* Left and right */ + LVDBE_SCALESHIFT); /* Shift scale */ + + } + else + { + + /* + * The algorithm is disabled but volume management is required to compensate for + * headroom and volume (if enabled) + */ + LVC_MixSoft_1St_D16C31_SAT(&pInstance->pData->BypassVolume, + pInData, + pOutData, + (LVM_INT16)(2*NumSamples)); /* Left and right */ + + } + + return(LVDBE_SUCCESS); +} + + + + + + + + + + diff --git a/media/libeffects/lvm/lib/Bass/src/LVDBE_Tables.c b/media/libeffects/lvm/lib/Bass/src/LVDBE_Tables.c new file mode 100755 index 0000000..da8ca5a --- /dev/null +++ b/media/libeffects/lvm/lib/Bass/src/LVDBE_Tables.c @@ -0,0 +1,463 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1009 $ + $Date: 2010-06-28 14:14:15 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVDBE.h" +#include "LVDBE_Coeffs.h" /* Filter coefficients */ +#include "BIQUAD.h" + + +/************************************************************************************/ +/* */ +/* Coefficients constant table */ +/* */ +/************************************************************************************/ + +/* + * High Pass Filter Coefficient table + */ +const BQ_C32_Coefs_t LVDBE_HPF_Table[] = { + /* Coefficients for 55Hz centre frequency */ + {HPF_Fs8000_Fc55_A2, /* 8kS/s coefficients */ + HPF_Fs8000_Fc55_A1, + HPF_Fs8000_Fc55_A0, + -HPF_Fs8000_Fc55_B2, + -HPF_Fs8000_Fc55_B1}, + {HPF_Fs11025_Fc55_A2, /* 11kS/s coefficients */ + HPF_Fs11025_Fc55_A1, + HPF_Fs11025_Fc55_A0, + -HPF_Fs11025_Fc55_B2, + -HPF_Fs11025_Fc55_B1}, + {HPF_Fs12000_Fc55_A2, /* 12kS/s coefficients */ + HPF_Fs12000_Fc55_A1, + HPF_Fs12000_Fc55_A0, + -HPF_Fs12000_Fc55_B2, + -HPF_Fs12000_Fc55_B1}, + {HPF_Fs16000_Fc55_A2, /* 16kS/s coefficients */ + HPF_Fs16000_Fc55_A1, + HPF_Fs16000_Fc55_A0, + -HPF_Fs16000_Fc55_B2, + -HPF_Fs16000_Fc55_B1}, + {HPF_Fs22050_Fc55_A2, /* 22kS/s coefficients */ + HPF_Fs22050_Fc55_A1, + HPF_Fs22050_Fc55_A0, + -HPF_Fs22050_Fc55_B2, + -HPF_Fs22050_Fc55_B1}, + {HPF_Fs24000_Fc55_A2, /* 24kS/s coefficients */ + HPF_Fs24000_Fc55_A1, + HPF_Fs24000_Fc55_A0, + -HPF_Fs24000_Fc55_B2, + -HPF_Fs24000_Fc55_B1}, + {HPF_Fs32000_Fc55_A2, /* 32kS/s coefficients */ + HPF_Fs32000_Fc55_A1, + HPF_Fs32000_Fc55_A0, + -HPF_Fs32000_Fc55_B2, + -HPF_Fs32000_Fc55_B1}, + {HPF_Fs44100_Fc55_A2, /* 44kS/s coefficients */ + HPF_Fs44100_Fc55_A1, + HPF_Fs44100_Fc55_A0, + -HPF_Fs44100_Fc55_B2, + -HPF_Fs44100_Fc55_B1}, + {HPF_Fs48000_Fc55_A2, /* 48kS/s coefficients */ + HPF_Fs48000_Fc55_A1, + HPF_Fs48000_Fc55_A0, + -HPF_Fs48000_Fc55_B2, + -HPF_Fs48000_Fc55_B1}, + + /* Coefficients for 66Hz centre frequency */ + {HPF_Fs8000_Fc66_A2, /* 8kS/s coefficients */ + HPF_Fs8000_Fc66_A1, + HPF_Fs8000_Fc66_A0, + -HPF_Fs8000_Fc66_B2, + -HPF_Fs8000_Fc66_B1}, + {HPF_Fs11025_Fc66_A2, /* 11kS/s coefficients */ + HPF_Fs11025_Fc66_A1, + HPF_Fs11025_Fc66_A0, + -HPF_Fs11025_Fc66_B2, + -HPF_Fs11025_Fc66_B1}, + {HPF_Fs12000_Fc66_A2, /* 12kS/s coefficients */ + HPF_Fs12000_Fc66_A1, + HPF_Fs12000_Fc66_A0, + -HPF_Fs12000_Fc66_B2, + -HPF_Fs12000_Fc66_B1}, + {HPF_Fs16000_Fc66_A2, /* 16kS/s coefficients */ + HPF_Fs16000_Fc66_A1, + HPF_Fs16000_Fc66_A0, + -HPF_Fs16000_Fc66_B2, + -HPF_Fs16000_Fc66_B1}, + {HPF_Fs22050_Fc66_A2, /* 22kS/s coefficients */ + HPF_Fs22050_Fc66_A1, + HPF_Fs22050_Fc66_A0, + -HPF_Fs22050_Fc66_B2, + -HPF_Fs22050_Fc66_B1}, + {HPF_Fs24000_Fc66_A2, /* 24kS/s coefficients */ + HPF_Fs24000_Fc66_A1, + HPF_Fs24000_Fc66_A0, + -HPF_Fs24000_Fc66_B2, + -HPF_Fs24000_Fc66_B1}, + {HPF_Fs32000_Fc66_A2, /* 32kS/s coefficients */ + HPF_Fs32000_Fc66_A1, + HPF_Fs32000_Fc66_A0, + -HPF_Fs32000_Fc66_B2, + -HPF_Fs32000_Fc66_B1}, + {HPF_Fs44100_Fc66_A2, /* 44kS/s coefficients */ + HPF_Fs44100_Fc66_A1, + HPF_Fs44100_Fc66_A0, + -HPF_Fs44100_Fc66_B2, + -HPF_Fs44100_Fc66_B1}, + {HPF_Fs48000_Fc66_A2, /* 48kS/s coefficients */ + HPF_Fs48000_Fc66_A1, + HPF_Fs48000_Fc66_A0, + -HPF_Fs48000_Fc66_B2, + -HPF_Fs48000_Fc66_B1}, + + /* Coefficients for 78Hz centre frequency */ + {HPF_Fs8000_Fc78_A2, /* 8kS/s coefficients */ + HPF_Fs8000_Fc78_A1, + HPF_Fs8000_Fc78_A0, + -HPF_Fs8000_Fc78_B2, + -HPF_Fs8000_Fc78_B1}, + {HPF_Fs11025_Fc78_A2, /* 11kS/s coefficients */ + HPF_Fs11025_Fc78_A1, + HPF_Fs11025_Fc78_A0, + -HPF_Fs11025_Fc78_B2, + -HPF_Fs11025_Fc78_B1}, + {HPF_Fs12000_Fc78_A2, /* 12kS/s coefficients */ + HPF_Fs12000_Fc78_A1, + HPF_Fs12000_Fc78_A0, + -HPF_Fs12000_Fc78_B2, + -HPF_Fs12000_Fc78_B1}, + {HPF_Fs16000_Fc78_A2, /* 16kS/s coefficients */ + HPF_Fs16000_Fc78_A1, + HPF_Fs16000_Fc78_A0, + -HPF_Fs16000_Fc78_B2, + -HPF_Fs16000_Fc78_B1}, + {HPF_Fs22050_Fc78_A2, /* 22kS/s coefficients */ + HPF_Fs22050_Fc78_A1, + HPF_Fs22050_Fc78_A0, + -HPF_Fs22050_Fc78_B2, + -HPF_Fs22050_Fc78_B1}, + {HPF_Fs24000_Fc78_A2, /* 24kS/s coefficients */ + HPF_Fs24000_Fc78_A1, + HPF_Fs24000_Fc78_A0, + -HPF_Fs24000_Fc78_B2, + -HPF_Fs24000_Fc78_B1}, + {HPF_Fs32000_Fc78_A2, /* 32kS/s coefficients */ + HPF_Fs32000_Fc78_A1, + HPF_Fs32000_Fc78_A0, + -HPF_Fs32000_Fc78_B2, + -HPF_Fs32000_Fc78_B1}, + {HPF_Fs44100_Fc78_A2, /* 44kS/s coefficients */ + HPF_Fs44100_Fc78_A1, + HPF_Fs44100_Fc78_A0, + -HPF_Fs44100_Fc78_B2, + -HPF_Fs44100_Fc78_B1}, + {HPF_Fs48000_Fc78_A2, /* 48kS/s coefficients */ + HPF_Fs48000_Fc78_A1, + HPF_Fs48000_Fc78_A0, + -HPF_Fs48000_Fc78_B2, + -HPF_Fs48000_Fc78_B1}, + + /* Coefficients for 90Hz centre frequency */ + {HPF_Fs8000_Fc90_A2, /* 8kS/s coefficients */ + HPF_Fs8000_Fc90_A1, + HPF_Fs8000_Fc90_A0, + -HPF_Fs8000_Fc90_B2, + -HPF_Fs8000_Fc90_B1}, + {HPF_Fs11025_Fc90_A2, /* 11kS/s coefficients */ + HPF_Fs11025_Fc90_A1, + HPF_Fs11025_Fc90_A0, + -HPF_Fs11025_Fc90_B2, + -HPF_Fs11025_Fc90_B1}, + {HPF_Fs12000_Fc90_A2, /* 12kS/s coefficients */ + HPF_Fs12000_Fc90_A1, + HPF_Fs12000_Fc90_A0, + -HPF_Fs12000_Fc90_B2, + -HPF_Fs12000_Fc90_B1}, + {HPF_Fs16000_Fc90_A2, /* 16kS/s coefficients */ + HPF_Fs16000_Fc90_A1, + HPF_Fs16000_Fc90_A0, + -HPF_Fs16000_Fc90_B2, + -HPF_Fs16000_Fc90_B1}, + {HPF_Fs22050_Fc90_A2, /* 22kS/s coefficients */ + HPF_Fs22050_Fc90_A1, + HPF_Fs22050_Fc90_A0, + -HPF_Fs22050_Fc90_B2, + -HPF_Fs22050_Fc90_B1}, + {HPF_Fs24000_Fc90_A2, /* 24kS/s coefficients */ + HPF_Fs24000_Fc90_A1, + HPF_Fs24000_Fc90_A0, + -HPF_Fs24000_Fc90_B2, + -HPF_Fs24000_Fc90_B1}, + {HPF_Fs32000_Fc90_A2, /* 32kS/s coefficients */ + HPF_Fs32000_Fc90_A1, + HPF_Fs32000_Fc90_A0, + -HPF_Fs32000_Fc90_B2, + -HPF_Fs32000_Fc90_B1}, + {HPF_Fs44100_Fc90_A2, /* 44kS/s coefficients */ + HPF_Fs44100_Fc90_A1, + HPF_Fs44100_Fc90_A0, + -HPF_Fs44100_Fc90_B2, + -HPF_Fs44100_Fc90_B1}, + {HPF_Fs48000_Fc90_A2, /* 48kS/s coefficients */ + HPF_Fs48000_Fc90_A1, + HPF_Fs48000_Fc90_A0, + -HPF_Fs48000_Fc90_B2, + -HPF_Fs48000_Fc90_B1}}; + +/* + * Band Pass Filter coefficient table + */ +const BP_C32_Coefs_t LVDBE_BPF_Table[] = { + /* Coefficients for 55Hz centre frequency */ + {BPF_Fs8000_Fc55_A0, /* 8kS/s coefficients */ + -BPF_Fs8000_Fc55_B2, + -BPF_Fs8000_Fc55_B1}, + {BPF_Fs11025_Fc55_A0, /* 11kS/s coefficients */ + -BPF_Fs11025_Fc55_B2, + -BPF_Fs11025_Fc55_B1}, + {BPF_Fs12000_Fc55_A0, /* 12kS/s coefficients */ + -BPF_Fs12000_Fc55_B2, + -BPF_Fs12000_Fc55_B1}, + {BPF_Fs16000_Fc55_A0, /* 16kS/s coefficients */ + -BPF_Fs16000_Fc55_B2, + -BPF_Fs16000_Fc55_B1}, + {BPF_Fs22050_Fc55_A0, /* 22kS/s coefficients */ + -BPF_Fs22050_Fc55_B2, + -BPF_Fs22050_Fc55_B1}, + {BPF_Fs24000_Fc55_A0, /* 24kS/s coefficients */ + -BPF_Fs24000_Fc55_B2, + -BPF_Fs24000_Fc55_B1}, + {BPF_Fs32000_Fc55_A0, /* 32kS/s coefficients */ + -BPF_Fs32000_Fc55_B2, + -BPF_Fs32000_Fc55_B1}, + {BPF_Fs44100_Fc55_A0, /* 44kS/s coefficients */ + -BPF_Fs44100_Fc55_B2, + -BPF_Fs44100_Fc55_B1}, + {BPF_Fs48000_Fc55_A0, /* 48kS/s coefficients */ + -BPF_Fs48000_Fc55_B2, + -BPF_Fs48000_Fc55_B1}, + + /* Coefficients for 66Hz centre frequency */ + {BPF_Fs8000_Fc66_A0, /* 8kS/s coefficients */ + -BPF_Fs8000_Fc66_B2, + -BPF_Fs8000_Fc66_B1}, + {BPF_Fs11025_Fc66_A0, /* 11kS/s coefficients */ + -BPF_Fs11025_Fc66_B2, + -BPF_Fs11025_Fc66_B1}, + {BPF_Fs12000_Fc66_A0, /* 12kS/s coefficients */ + -BPF_Fs12000_Fc66_B2, + -BPF_Fs12000_Fc66_B1}, + {BPF_Fs16000_Fc66_A0, /* 16kS/s coefficients */ + -BPF_Fs16000_Fc66_B2, + -BPF_Fs16000_Fc66_B1}, + {BPF_Fs22050_Fc66_A0, /* 22kS/s coefficients */ + -BPF_Fs22050_Fc66_B2, + -BPF_Fs22050_Fc66_B1}, + {BPF_Fs24000_Fc66_A0, /* 24kS/s coefficients */ + -BPF_Fs24000_Fc66_B2, + -BPF_Fs24000_Fc66_B1}, + {BPF_Fs32000_Fc66_A0, /* 32kS/s coefficients */ + -BPF_Fs32000_Fc66_B2, + -BPF_Fs32000_Fc66_B1}, + {BPF_Fs44100_Fc66_A0, /* 44kS/s coefficients */ + -BPF_Fs44100_Fc66_B2, + -BPF_Fs44100_Fc66_B1}, + {BPF_Fs48000_Fc66_A0, /* 48kS/s coefficients */ + -BPF_Fs48000_Fc66_B2, + -BPF_Fs48000_Fc66_B1}, + + /* Coefficients for 78Hz centre frequency */ + {BPF_Fs8000_Fc78_A0, /* 8kS/s coefficients */ + -BPF_Fs8000_Fc78_B2, + -BPF_Fs8000_Fc78_B1}, + {BPF_Fs11025_Fc78_A0, /* 11kS/s coefficients */ + -BPF_Fs11025_Fc78_B2, + -BPF_Fs11025_Fc78_B1}, + {BPF_Fs12000_Fc78_A0, /* 12kS/s coefficients */ + -BPF_Fs12000_Fc78_B2, + -BPF_Fs12000_Fc78_B1}, + {BPF_Fs16000_Fc78_A0, /* 16kS/s coefficients */ + -BPF_Fs16000_Fc78_B2, + -BPF_Fs16000_Fc78_B1}, + {BPF_Fs22050_Fc78_A0, /* 22kS/s coefficients */ + -BPF_Fs22050_Fc78_B2, + -BPF_Fs22050_Fc78_B1}, + {BPF_Fs24000_Fc78_A0, /* 24kS/s coefficients */ + -BPF_Fs24000_Fc78_B2, + -BPF_Fs24000_Fc78_B1}, + {BPF_Fs32000_Fc78_A0, /* 32kS/s coefficients */ + -BPF_Fs32000_Fc78_B2, + -BPF_Fs32000_Fc78_B1}, + {BPF_Fs44100_Fc78_A0, /* 44kS/s coefficients */ + -BPF_Fs44100_Fc78_B2, + -BPF_Fs44100_Fc78_B1}, + {BPF_Fs48000_Fc78_A0, /* 48kS/s coefficients */ + -BPF_Fs48000_Fc78_B2, + -BPF_Fs48000_Fc78_B1}, + + /* Coefficients for 90Hz centre frequency */ + {BPF_Fs8000_Fc90_A0, /* 8kS/s coefficients */ + -BPF_Fs8000_Fc90_B2, + -BPF_Fs8000_Fc90_B1}, + {BPF_Fs11025_Fc90_A0, /* 11kS/s coefficients */ + -BPF_Fs11025_Fc90_B2, + -BPF_Fs11025_Fc90_B1}, + {BPF_Fs12000_Fc90_A0, /* 12kS/s coefficients */ + -BPF_Fs12000_Fc90_B2, + -BPF_Fs12000_Fc90_B1}, + {BPF_Fs16000_Fc90_A0, /* 16kS/s coefficients */ + -BPF_Fs16000_Fc90_B2, + -BPF_Fs16000_Fc90_B1}, + {BPF_Fs22050_Fc90_A0, /* 22kS/s coefficients */ + -BPF_Fs22050_Fc90_B2, + -BPF_Fs22050_Fc90_B1}, + {BPF_Fs24000_Fc90_A0, /* 24kS/s coefficients */ + -BPF_Fs24000_Fc90_B2, + -BPF_Fs24000_Fc90_B1}, + {BPF_Fs32000_Fc90_A0, /* 32kS/s coefficients */ + -BPF_Fs32000_Fc90_B2, + -BPF_Fs32000_Fc90_B1}, + {BPF_Fs44100_Fc90_A0, /* 44kS/s coefficients */ + -BPF_Fs44100_Fc90_B2, + -BPF_Fs44100_Fc90_B1}, + {BPF_Fs48000_Fc90_A0, /* 48kS/s coefficients */ + -BPF_Fs48000_Fc90_B2, + -BPF_Fs48000_Fc90_B1}}; + + +/************************************************************************************/ +/* */ +/* AGC constant tables */ +/* */ +/************************************************************************************/ + +/* Attack time (signal too large) */ +const LVM_INT16 LVDBE_AGC_ATTACK_Table[] = { + AGC_ATTACK_Fs8000, + AGC_ATTACK_Fs11025, + AGC_ATTACK_Fs12000, + AGC_ATTACK_Fs16000, + AGC_ATTACK_Fs22050, + AGC_ATTACK_Fs24000, + AGC_ATTACK_Fs32000, + AGC_ATTACK_Fs44100, + AGC_ATTACK_Fs48000}; + +/* Decay time (signal too small) */ +const LVM_INT16 LVDBE_AGC_DECAY_Table[] = { + AGC_DECAY_Fs8000, + AGC_DECAY_Fs11025, + AGC_DECAY_Fs12000, + AGC_DECAY_Fs16000, + AGC_DECAY_Fs22050, + AGC_DECAY_Fs24000, + AGC_DECAY_Fs32000, + AGC_DECAY_Fs44100, + AGC_DECAY_Fs48000}; + +/* Gain for use without the high pass filter */ +const LVM_INT32 LVDBE_AGC_GAIN_Table[] = { + AGC_GAIN_0dB, + AGC_GAIN_1dB, + AGC_GAIN_2dB, + AGC_GAIN_3dB, + AGC_GAIN_4dB, + AGC_GAIN_5dB, + AGC_GAIN_6dB, + AGC_GAIN_7dB, + AGC_GAIN_8dB, + AGC_GAIN_9dB, + AGC_GAIN_10dB, + AGC_GAIN_11dB, + AGC_GAIN_12dB, + AGC_GAIN_13dB, + AGC_GAIN_14dB, + AGC_GAIN_15dB}; + +/* Gain for use with the high pass filter */ +const LVM_INT32 LVDBE_AGC_HPFGAIN_Table[] = { + AGC_HPFGAIN_0dB, + AGC_HPFGAIN_1dB, + AGC_HPFGAIN_2dB, + AGC_HPFGAIN_3dB, + AGC_HPFGAIN_4dB, + AGC_HPFGAIN_5dB, + AGC_HPFGAIN_6dB, + AGC_HPFGAIN_7dB, + AGC_HPFGAIN_8dB, + AGC_HPFGAIN_9dB, + AGC_HPFGAIN_10dB, + AGC_HPFGAIN_11dB, + AGC_HPFGAIN_12dB, + AGC_HPFGAIN_13dB, + AGC_HPFGAIN_14dB, + AGC_HPFGAIN_15dB}; + + +/************************************************************************************/ +/* */ +/* Volume control gain and time constant tables */ +/* */ +/************************************************************************************/ + +/* dB to linear conversion table */ +const LVM_INT16 LVDBE_VolumeTable[] = { + 0x4000, /* -6dB */ + 0x47FB, /* -5dB */ + 0x50C3, /* -4dB */ + 0x5A9E, /* -3dB */ + 0x65AD, /* -2dB */ + 0x7215, /* -1dB */ + 0x7FFF}; /* 0dB */ + +const LVM_INT16 LVDBE_VolumeTCTable[] = { + VOL_TC_Fs8000, + VOL_TC_Fs11025, + VOL_TC_Fs12000, + VOL_TC_Fs16000, + VOL_TC_Fs22050, + VOL_TC_Fs24000, + VOL_TC_Fs32000, + VOL_TC_Fs44100, + VOL_TC_Fs48000}; + +const LVM_INT16 LVDBE_MixerTCTable[] = { + MIX_TC_Fs8000, + MIX_TC_Fs11025, + MIX_TC_Fs12000, + MIX_TC_Fs16000, + MIX_TC_Fs22050, + MIX_TC_Fs24000, + MIX_TC_Fs32000, + MIX_TC_Fs44100, + MIX_TC_Fs48000}; + + diff --git a/media/libeffects/lvm/lib/Bass/src/LVDBE_Tables.h b/media/libeffects/lvm/lib/Bass/src/LVDBE_Tables.h new file mode 100755 index 0000000..4cb6d21 --- /dev/null +++ b/media/libeffects/lvm/lib/Bass/src/LVDBE_Tables.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1009 $ + $Date: 2010-06-28 14:14:15 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ +#ifndef __LVBDE_TABLES_H__ +#define __LVBDE_TABLES_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include "BIQUAD.h" +#include "LVM_Types.h" + +/************************************************************************************/ +/* */ +/* Coefficients constant table */ +/* */ +/************************************************************************************/ + +/* + * High Pass Filter Coefficient table + */ +extern const BQ_C32_Coefs_t LVDBE_HPF_Table[]; + +/* + * Band Pass Filter coefficient table + */ +extern const BP_C32_Coefs_t LVDBE_BPF_Table[]; + +/************************************************************************************/ +/* */ +/* AGC constant tables */ +/* */ +/************************************************************************************/ + +/* Attack time (signal too large) */ +extern const LVM_INT16 LVDBE_AGC_ATTACK_Table[]; + +/* Decay time (signal too small) */ +extern const LVM_INT16 LVDBE_AGC_DECAY_Table[]; + +/* Gain for use without the high pass filter */ +extern const LVM_INT32 LVDBE_AGC_GAIN_Table[]; + +/* Gain for use with the high pass filter */ +extern const LVM_INT32 LVDBE_AGC_HPFGAIN_Table[]; + +/************************************************************************************/ +/* */ +/* Volume control gain and time constant tables */ +/* */ +/************************************************************************************/ + +/* dB to linear conversion table */ +extern const LVM_INT16 LVDBE_VolumeTable[]; + +extern const LVM_INT16 LVDBE_VolumeTCTable[]; + +extern const LVM_INT16 LVDBE_MixerTCTable[]; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LVBDE_TABLES_H__ */ diff --git a/media/libeffects/lvm/lib/Bundle/lib/LVM.h b/media/libeffects/lvm/lib/Bundle/lib/LVM.h new file mode 100755 index 0000000..d472182 --- /dev/null +++ b/media/libeffects/lvm/lib/Bundle/lib/LVM.h @@ -0,0 +1,637 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/***************************************************************************************** + + $Author: beq07716 $ + $Revision: 1002 $ + $Date: 2010-06-28 13:40:09 +0200 (Mon, 28 Jun 2010) $ + +*****************************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Header file for the application layer interface of Concert Sound, Bass Enhancement, */ +/* Equalizer, Power Spectrum Analyzer, Trebble Enhancement and volume management */ +/* bundle. */ +/* */ +/* This files includes all definitions, types, structures and function */ +/* prototypes required by the calling layer. All other types, structures and */ +/* functions are private. */ +/* */ +/****************************************************************************************/ +/* */ +/* Note: 1 */ +/* ======= */ +/* The algorithm can execute either with separate input and output buffers or with */ +/* a common buffer, i.e. the data is processed in-place. */ +/* */ +/****************************************************************************************/ +/* */ +/* Note: 2 */ +/* ======= */ +/* Three data formats are support Stereo,Mono-In-Stereo and Mono. The data is */ +/* interleaved as follows: */ +/* */ +/* Byte Offset Stereo Input Mono-In-Stereo Input Mono Input */ +/* =========== ============ ==================== ============== */ +/* 0 Left Sample #1 Mono Sample #1 Mono Sample #1 */ +/* 2 Right Sample #1 Mono Sample #1 Mono Sample #2 */ +/* 4 Left Sample #2 Mono Sample #2 Mono Sample #3 */ +/* 6 Right Sample #2 Mono Sample #2 Mono Sample #4 */ +/* . . . . */ +/* . . . . */ +/* */ +/****************************************************************************************/ + +#ifndef __LVM_H__ +#define __LVM_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVM_Types.h" + + +/****************************************************************************************/ +/* */ +/* Definitions */ +/* */ +/****************************************************************************************/ + +/* Memory table*/ +#define LVM_NR_MEMORY_REGIONS 4 /* Number of memory regions */ + +/* Concert Sound effect level presets */ +#define LVM_CS_EFFECT_NONE 0 /* 0% effect, minimum value */ +#define LVM_CS_EFFECT_LOW 16384 /* 50% effect */ +#define LVM_CS_EFFECT_MED 24576 /* 75% effect */ +#define LVM_CS_EFFECT_HIGH 32767 /* 100% effect, maximum value */ + +/* Treble enhancement */ +#define LVM_TE_LOW_MIPS 32767 + +/* Bass enhancement effect level presets */ +#define LVM_BE_0DB 0 /* 0dB boost, no effect */ +#define LVM_BE_3DB 3 /* +3dB boost */ +#define LVM_BE_6DB 6 /* +6dB boost */ +#define LVM_BE_9DB 9 /* +9dB boost */ +#define LVM_BE_12DB 12 /* +12dB boost */ +#define LVM_BE_15DB 15 /* +15dB boost */ + +/* N-Band Equalizer */ +#define LVM_EQ_NBANDS 5 /* Number of bands for equalizer */ + +/* Headroom management */ +#define LVM_HEADROOM_MAX_NBANDS 5 + +/****************************************************************************************/ +/* */ +/* Types */ +/* */ +/****************************************************************************************/ + +/* Instance handle */ +typedef void *LVM_Handle_t; + + +/* Status return values */ +typedef enum +{ + LVM_SUCCESS = 0, /* Successful return from a routine */ + LVM_ALIGNMENTERROR = 1, /* Memory alignment error */ + LVM_NULLADDRESS = 2, /* NULL allocation address */ + LVM_OUTOFRANGE = 3, /* Out of range control parameter */ + LVM_INVALIDNUMSAMPLES = 4, /* Invalid number of samples */ + LVM_WRONGAUDIOTIME = 5, /* Wrong time value for audio time*/ + LVM_ALGORITHMDISABLED = 6, /* Algorithm is disabled*/ + LVM_ALGORITHMPSA = 7, /* Algorithm PSA returns an error */ + LVM_RETURNSTATUS_DUMMY = LVM_MAXENUM +} LVM_ReturnStatus_en; + + +/* Buffer Management mode */ +typedef enum +{ + LVM_MANAGED_BUFFERS = 0, + LVM_UNMANAGED_BUFFERS = 1, + LVM_BUFFERS_DUMMY = LVM_MAXENUM +} LVM_BufferMode_en; + +/* Output device type */ +typedef enum +{ + LVM_HEADPHONES = 0, + LVM_EX_HEADPHONES = 1, + LVM_SPEAKERTYPE_MAX = LVM_MAXENUM +} LVM_OutputDeviceType_en; + +/* Virtualizer mode selection*/ +typedef enum +{ + LVM_CONCERTSOUND = 0, + LVM_VIRTUALIZERTYPE_DUMMY = LVM_MAXENUM +} LVM_VirtualizerType_en; + +/* N-Band Equaliser operating mode */ +typedef enum +{ + LVM_EQNB_OFF = 0, + LVM_EQNB_ON = 1, + LVM_EQNB_DUMMY = LVM_MAXENUM +} LVM_EQNB_Mode_en; + +/* Bass Enhancement operating mode */ +typedef enum +{ + LVM_BE_OFF = 0, + LVM_BE_ON = 1, + LVM_BE_DUMMY = LVM_MAXENUM +} LVM_BE_Mode_en; + +/* Bass Enhancement centre frequency selection control */ +typedef enum +{ + LVM_BE_CENTRE_55Hz = 0, + LVM_BE_CENTRE_66Hz = 1, + LVM_BE_CENTRE_78Hz = 2, + LVM_BE_CENTRE_90Hz = 3, + LVM_BE_CENTRE_DUMMY = LVM_MAXENUM +} LVM_BE_CentreFreq_en; + +/* Bass Enhancement HPF selection control */ +typedef enum +{ + LVM_BE_HPF_OFF = 0, + LVM_BE_HPF_ON = 1, + LVM_BE_HPF_DUMMY = LVM_MAXENUM +} LVM_BE_FilterSelect_en; + +/* Volume Control operating mode */ +typedef enum +{ + LVM_VC_OFF = 0, + LVM_VC_ON = 1, + LVM_VC_DUMMY = LVM_MAXENUM +} LVM_VC_Mode_en; + +/* Treble Enhancement operating mode */ +typedef enum +{ + LVM_TE_OFF = 0, + LVM_TE_ON = 1, + LVM_TE_DUMMY = LVM_MAXENUM +} LVM_TE_Mode_en; + +/* Headroom management operating mode */ +typedef enum +{ + LVM_HEADROOM_OFF = 0, + LVM_HEADROOM_ON = 1, + LVM_Headroom_DUMMY = LVM_MAXENUM +} LVM_Headroom_Mode_en; + +typedef enum +{ + LVM_PSA_SPEED_SLOW, /* Peak decaying at slow speed */ + LVM_PSA_SPEED_MEDIUM, /* Peak decaying at medium speed */ + LVM_PSA_SPEED_FAST, /* Peak decaying at fast speed */ + LVM_PSA_SPEED_DUMMY = LVM_MAXENUM +} LVM_PSA_DecaySpeed_en; + +typedef enum +{ + LVM_PSA_OFF = 0, + LVM_PSA_ON = 1, + LVM_PSA_DUMMY = LVM_MAXENUM +} LVM_PSA_Mode_en; + +/* Version information */ +typedef struct +{ + LVM_CHAR *pVersionNumber; /* Pointer to the version number in the format X.YY.ZZ */ + LVM_CHAR *pPlatform; /* Pointer to the library platform type */ +} LVM_VersionInfo_st; + + +/****************************************************************************************/ +/* */ +/* Structures */ +/* */ +/****************************************************************************************/ + +/* Memory table containing the region definitions */ +typedef struct +{ + LVM_MemoryRegion_st Region[LVM_NR_MEMORY_REGIONS]; /* One definition for each region */ +} LVM_MemTab_t; + +/* N-Band equaliser band definition */ +typedef struct +{ + LVM_INT16 Gain; /* Band gain in dB */ + LVM_UINT16 Frequency; /* Band centre frequency in Hz */ + LVM_UINT16 QFactor; /* Band quality factor (x100) */ +} LVM_EQNB_BandDef_t; + + +/* Headroom band definition */ +typedef struct +{ + LVM_UINT16 Limit_Low; /* Low frequency limit of the band in Hertz */ + LVM_UINT16 Limit_High; /* High frequency limit of the band in Hertz */ + LVM_INT16 Headroom_Offset; /* Headroom = biggest band gain - Headroom_Offset */ +} LVM_HeadroomBandDef_t; + + +/* Control Parameter structure */ +typedef struct +{ + /* General parameters */ + LVM_Mode_en OperatingMode; /* Bundle operating mode On/Bypass */ + LVM_Fs_en SampleRate; /* Sample rate */ + LVM_Format_en SourceFormat; /* Input data format */ + LVM_OutputDeviceType_en SpeakerType; /* Output device type */ + + /* Concert Sound Virtualizer parameters*/ + LVM_Mode_en VirtualizerOperatingMode; /* Virtualizer operating mode On/Off */ + LVM_VirtualizerType_en VirtualizerType; /* Virtualizer type: ConcertSound */ + LVM_UINT16 VirtualizerReverbLevel; /* Virtualizer reverb level in % */ + LVM_INT16 CS_EffectLevel; /* Concert Sound effect level */ + + /* N-Band Equaliser parameters */ + LVM_EQNB_Mode_en EQNB_OperatingMode; /* N-Band Equaliser operating mode */ + LVM_UINT16 EQNB_NBands; /* Number of bands */ + LVM_EQNB_BandDef_t *pEQNB_BandDefinition; /* Pointer to equaliser definitions */ + + /* Bass Enhancement parameters */ + LVM_BE_Mode_en BE_OperatingMode; /* Bass Enhancement operating mode */ + LVM_INT16 BE_EffectLevel; /* Bass Enhancement effect level */ + LVM_BE_CentreFreq_en BE_CentreFreq; /* Bass Enhancement centre frequency */ + LVM_BE_FilterSelect_en BE_HPF; /* Bass Enhancement high pass filter selector */ + + /* Volume Control parameters */ + LVM_INT16 VC_EffectLevel; /* Volume Control setting in dBs */ + LVM_INT16 VC_Balance; /* Left Right Balance control in dB (-96 to 96 dB), -ve values reduce + Right channel while +ve value reduces Left channel*/ + + /* Treble Enhancement parameters */ + LVM_TE_Mode_en TE_OperatingMode; /* Treble Enhancement On/Off */ + LVM_INT16 TE_EffectLevel; /* Treble Enhancement gain dBs */ + + /* Spectrum Analyzer parameters Control */ + LVM_PSA_Mode_en PSA_Enable; + LVM_PSA_DecaySpeed_en PSA_PeakDecayRate; /* Peak value decay rate*/ + +} LVM_ControlParams_t; + + +/* Instance Parameter structure */ +typedef struct +{ + /* General */ + LVM_BufferMode_en BufferMode; /* Buffer management mode */ + LVM_UINT16 MaxBlockSize; /* Maximum processing block size */ + + /* N-Band Equaliser */ + LVM_UINT16 EQNB_NumBands; /* Maximum number of equaliser bands */ + + /* PSA */ + LVM_PSA_Mode_en PSA_Included; /* Controls the instance memory allocation for PSA: ON/OFF */ +} LVM_InstParams_t; + +/* Headroom management parameter structure */ +typedef struct +{ + LVM_Headroom_Mode_en Headroom_OperatingMode; /* Headroom Control On/Off */ + LVM_HeadroomBandDef_t *pHeadroomDefinition; /* Pointer to headroom bands definition */ + LVM_UINT16 NHeadroomBands; /* Number of headroom bands */ + +} LVM_HeadroomParams_t; + +/****************************************************************************************/ +/* */ +/* Function Prototypes */ +/* */ +/****************************************************************************************/ + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_GetVersionInfo */ +/* */ +/* DESCRIPTION: */ +/* This function is used to retrieve information about the library's version. */ +/* */ +/* PARAMETERS: */ +/* pVersion Pointer to an empty version info structure */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_NULLADDRESS when pVersion is NULL */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ +LVM_ReturnStatus_en LVM_GetVersionInfo(LVM_VersionInfo_st *pVersion); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_GetMemoryTable */ +/* */ +/* 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 */ +/* pInstParams Pointer to the instance parameters */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_NULLADDRESS When one of pMemoryTable or pInstParams is NULL */ +/* LVM_OUTOFRANGE When any of the Instance parameters are out of range */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ +LVM_ReturnStatus_en LVM_GetMemoryTable(LVM_Handle_t hInstance, + LVM_MemTab_t *pMemoryTable, + LVM_InstParams_t *pInstParams); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_GetInstanceHandle */ +/* */ +/* DESCRIPTION: */ +/* This function is used to create a bundle instance. It returns the created instance */ +/* handle through phInstance. All parameters are set to their default, inactive state. */ +/* */ +/* PARAMETERS: */ +/* phInstance pointer to the instance handle */ +/* pMemoryTable Pointer to the memory definition table */ +/* pInstParams Pointer to the instance parameters */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Initialisation succeeded */ +/* LVM_NULLADDRESS One or more memory has a NULL pointer */ +/* LVM_OUTOFRANGE When any of the Instance parameters are out of range */ +/* */ +/* NOTES: */ +/* 1. This function must not be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ +LVM_ReturnStatus_en LVM_GetInstanceHandle(LVM_Handle_t *phInstance, + LVM_MemTab_t *pMemoryTable, + LVM_InstParams_t *pInstParams); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_ClearAudioBuffers */ +/* */ +/* DESCRIPTION: */ +/* This function is used to clear the internal audio buffers of the bundle. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Initialisation succeeded */ +/* LVM_NULLADDRESS Instance memory has a NULL pointer */ +/* */ +/* NOTES: */ +/* 1. This function must not be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ +LVM_ReturnStatus_en LVM_ClearAudioBuffers(LVM_Handle_t hInstance); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_GetControlParameters */ +/* */ +/* DESCRIPTION: */ +/* Request the LifeVibes module parameters. The current parameter set is returned */ +/* via the parameter pointer. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to an empty parameter structure */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_NULLADDRESS when any of hInstance or pParams is NULL */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ +LVM_ReturnStatus_en LVM_GetControlParameters(LVM_Handle_t hInstance, + LVM_ControlParams_t *pParams); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_SetControlParameters */ +/* */ +/* DESCRIPTION: */ +/* Sets or changes the LifeVibes module parameters. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to a parameter structure */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_NULLADDRESS When hInstance, pParams or any control pointers are NULL */ +/* LVM_OUTOFRANGE When any of the control parameters are out of range */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ +LVM_ReturnStatus_en LVM_SetControlParameters(LVM_Handle_t hInstance, + LVM_ControlParams_t *pParams); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_Process */ +/* */ +/* DESCRIPTION: */ +/* Process function for the LifeVibes module. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pInData Pointer to the input data */ +/* pOutData Pointer to the output data */ +/* NumSamples Number of samples in the input buffer */ +/* AudioTime Audio Time of the current input data in milli-seconds */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_INVALIDNUMSAMPLES When the NumSamples is not a valied multiple in unmanaged */ +/* buffer mode */ +/* LVM_ALIGNMENTERROR When either the input our output buffers are not 32-bit */ +/* aligned in unmanaged mode */ +/* LVM_NULLADDRESS When one of hInstance, pInData or pOutData is NULL */ +/* */ +/* NOTES: */ +/* 1. The input and output buffers must be 32-bit aligned */ +/* 2. Number of samples is defined as follows: */ +/* MONO the number of samples in the block */ +/* MONOINSTEREO the number of sample pairs in the block */ +/* STEREO the number of sample pairs in the block */ +/* */ +/****************************************************************************************/ +LVM_ReturnStatus_en LVM_Process(LVM_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 *pOutData, + LVM_UINT16 NumSamples, + LVM_UINT32 AudioTime); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_SetHeadroomParams */ +/* */ +/* DESCRIPTION: */ +/* This function is used to set the automatic headroom management parameters. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pHeadroomParams Pointer to headroom parameter structure */ +/* */ +/* RETURNS: */ +/* LVM_NULLADDRESS When hInstance or pHeadroomParams is NULL */ +/* LVM_SUCCESS Succeeded */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ +LVM_ReturnStatus_en LVM_SetHeadroomParams( LVM_Handle_t hInstance, + LVM_HeadroomParams_t *pHeadroomParams); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_GetHeadroomParams */ +/* */ +/* DESCRIPTION: */ +/* This function is used to get the automatic headroom management parameters. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pHeadroomParams Pointer to headroom parameter structure (output) */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_NULLADDRESS When hInstance or pHeadroomParams are NULL */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ +LVM_ReturnStatus_en LVM_GetHeadroomParams( LVM_Handle_t hInstance, + LVM_HeadroomParams_t *pHeadroomParams); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_GetSpectrum */ +/* */ +/* DESCRIPTION: */ +/* This function is used to retrieve Spectral information at a given Audio time */ +/* for display usage */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pCurrentPeaks Pointer to location where currents peaks are to be saved */ +/* pPastPeaks Pointer to location where past peaks are to be saved */ +/* pCentreFreqs Pointer to location where centre frequency of each band is */ +/* to be saved */ +/* AudioTime Audio time at which the spectral information is needed */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_NULLADDRESS If any of input addresses are NULL */ +/* LVM_WRONGAUDIOTIME Failure due to audio time error */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ +LVM_ReturnStatus_en LVM_GetSpectrum( LVM_Handle_t hInstance, + LVM_UINT8 *pCurrentPeaks, + LVM_UINT8 *pPastPeaks, + LVM_INT32 AudioTime); + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_SetVolumeNoSmoothing */ +/* */ +/* DESCRIPTION: */ +/* This function is used to set output volume without any smoothing */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pParams Control Parameters, only volume value is used here */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_NULLADDRESS If any of input addresses are NULL */ +/* LVM_OUTOFRANGE When any of the control parameters are out of range */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ +LVM_ReturnStatus_en LVM_SetVolumeNoSmoothing( LVM_Handle_t hInstance, + LVM_ControlParams_t *pParams); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LVM_H__ */ + diff --git a/media/libeffects/lvm/lib/Bundle/src/LVM_API_Specials.c b/media/libeffects/lvm/lib/Bundle/src/LVM_API_Specials.c new file mode 100755 index 0000000..2f6fa4c --- /dev/null +++ b/media/libeffects/lvm/lib/Bundle/src/LVM_API_Specials.c @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************************** + + $Author: beq07716 $ + $Revision: 1002 $ + $Date: 2010-06-28 13:40:09 +0200 (Mon, 28 Jun 2010) $ + +*****************************************************************************************/ + + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVM_Private.h" +#include "LVM_Tables.h" + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_GetSpectrum */ +/* */ +/* DESCRIPTION: */ +/* This function is used to retrieve Spectral information at a given Audio time */ +/* for display usage */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pCurrentPeaks Pointer to location where currents peaks are to be saved */ +/* pPastPeaks Pointer to location where past peaks are to be saved */ +/* AudioTime Audio time at which the spectral information is needed */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_NULLADDRESS If any of input addresses are NULL */ +/* LVM_WRONGAUDIOTIME Failure due to audio time error */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ +LVM_ReturnStatus_en LVM_GetSpectrum( + LVM_Handle_t hInstance, + LVM_UINT8 *pCurrentPeaks, + LVM_UINT8 *pPastPeaks, + LVM_INT32 AudioTime + ) +{ + LVM_Instance_t *pInstance = (LVM_Instance_t *)hInstance; + + pLVPSA_Handle_t *hPSAInstance; + LVPSA_RETURN LVPSA_Status; + + + if(pInstance == LVM_NULL) + { + return LVM_NULLADDRESS; + } + + /*If PSA is not included at the time of instance creation, return without any processing*/ + if(pInstance->InstParams.PSA_Included!=LVM_PSA_ON) + { + return LVM_SUCCESS; + } + + hPSAInstance = pInstance->hPSAInstance; + + if((pCurrentPeaks == LVM_NULL) || + (pPastPeaks == LVM_NULL)) + { + return LVM_NULLADDRESS; + } + + + /* + * Update new parameters if necessary + */ + if (pInstance->ControlPending == LVM_TRUE) + { + LVM_ApplyNewSettings(hInstance); + } + + /* If PSA module is disabled, do nothing */ + if(pInstance->Params.PSA_Enable==LVM_PSA_OFF) + { + return LVM_ALGORITHMDISABLED; + } + + LVPSA_Status = LVPSA_GetSpectrum(hPSAInstance, + (LVPSA_Time) (AudioTime), + (LVM_UINT8*) pCurrentPeaks, + (LVM_UINT8*) pPastPeaks ); + + if(LVPSA_Status != LVPSA_OK) + { + if(LVPSA_Status == LVPSA_ERROR_WRONGTIME) + { + return (LVM_ReturnStatus_en) LVM_WRONGAUDIOTIME; + } + else + { + return (LVM_ReturnStatus_en) LVM_NULLADDRESS; + } + } + + return(LVM_SUCCESS); +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_SetVolumeNoSmoothing */ +/* */ +/* DESCRIPTION: */ +/* This function is used to set output volume without any smoothing */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pParams Control Parameters, only volume value is used here */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_NULLADDRESS If any of input addresses are NULL */ +/* LVM_OUTOFRANGE When any of the control parameters are out of range */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ +LVM_ReturnStatus_en LVM_SetVolumeNoSmoothing( LVM_Handle_t hInstance, + LVM_ControlParams_t *pParams) +{ + LVM_Instance_t *pInstance =(LVM_Instance_t *)hInstance; + LVM_ReturnStatus_en Error; + + /*Apply new controls*/ + Error = LVM_SetControlParameters(hInstance,pParams); + pInstance->NoSmoothVolume = LVM_TRUE; + return Error; +} + diff --git a/media/libeffects/lvm/lib/Bundle/src/LVM_Buffers.c b/media/libeffects/lvm/lib/Bundle/src/LVM_Buffers.c new file mode 100755 index 0000000..41785a3 --- /dev/null +++ b/media/libeffects/lvm/lib/Bundle/src/LVM_Buffers.c @@ -0,0 +1,878 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/**************************************************************************************** + + $Author: nxp007753 $ + $Revision: 1082 $ + $Date: 2010-07-05 12:44:39 +0200 (Mon, 05 Jul 2010) $ + +*****************************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVM_Private.h" +#include "VectorArithmetic.h" + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_BufferManagedIn */ +/* */ +/* DESCRIPTION: */ +/* Full buffer management allowing the user to provide input and output buffers on */ +/* any alignment and with any number of samples. The alignment is corrected within */ +/* the buffer management and the samples are grouped in to blocks of the correct size */ +/* before processing. */ +/* */ +/* PARAMETERS: */ +/* hInstance - Instance handle */ +/* pInData - Pointer to the input data stream */ +/* *pToProcess - Pointer to pointer to the start of data processing */ +/* *pProcessed - Pointer to pointer to the destination of the processed data */ +/* pNumSamples - Pointer to the number of samples to process */ +/* */ +/* RETURNS: */ +/* None */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +void LVM_BufferManagedIn(LVM_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 **pToProcess, + LVM_INT16 **pProcessed, + LVM_UINT16 *pNumSamples) +{ + + LVM_INT16 SampleCount; /* Number of samples to be processed this call */ + LVM_INT16 NumSamples; /* Number of samples in scratch buffer */ + LVM_INT16 *pStart; + LVM_Instance_t *pInstance = (LVM_Instance_t *)hInstance; + LVM_Buffer_t *pBuffer; + LVM_INT16 *pDest; + LVM_INT16 NumChannels =2; + + + /* + * Set the processing address pointers + */ + pBuffer = pInstance->pBufferManagement; + pDest = pBuffer->pScratch; + *pToProcess = pBuffer->pScratch; + *pProcessed = pBuffer->pScratch; + + /* + * Check if it is the first call of a block + */ + if (pInstance->SamplesToProcess == 0) + { + /* + * First call for a new block of samples + */ + pInstance->SamplesToProcess = (LVM_INT16)(*pNumSamples + pBuffer->InDelaySamples); + pInstance->pInputSamples = (LVM_INT16 *)pInData; + pBuffer->BufferState = LVM_FIRSTCALL; + } + pStart = pInstance->pInputSamples; /* Pointer to the input samples */ + pBuffer->SamplesToOutput = 0; /* Samples to output is same as number read for inplace processing */ + + + /* + * Calculate the number of samples to process this call and update the buffer state + */ + if (pInstance->SamplesToProcess > pInstance->InternalBlockSize) + { + /* + * Process the maximum bock size of samples. + */ + SampleCount = pInstance->InternalBlockSize; + NumSamples = pInstance->InternalBlockSize; + } + else + { + /* + * Last call for the block, so calculate how many frames and samples to process + */ + LVM_INT16 NumFrames; + + NumSamples = pInstance->SamplesToProcess; + NumFrames = (LVM_INT16)(NumSamples >> MIN_INTERNAL_BLOCKSHIFT); + SampleCount = (LVM_INT16)(NumFrames << MIN_INTERNAL_BLOCKSHIFT); + + /* + * Update the buffer state + */ + if (pBuffer->BufferState == LVM_FIRSTCALL) + { + pBuffer->BufferState = LVM_FIRSTLASTCALL; + } + else + { + pBuffer->BufferState = LVM_LASTCALL; + } + } + *pNumSamples = (LVM_UINT16)SampleCount; /* Set the number of samples to process this call */ + + + /* + * Copy samples from the delay buffer as required + */ + if (((pBuffer->BufferState == LVM_FIRSTCALL) || + (pBuffer->BufferState == LVM_FIRSTLASTCALL)) && + (pBuffer->InDelaySamples != 0)) + { + Copy_16(&pBuffer->InDelayBuffer[0], /* Source */ + pDest, /* Destination */ + (LVM_INT16)(NumChannels*pBuffer->InDelaySamples)); /* Number of delay samples, left and right */ + NumSamples = (LVM_INT16)(NumSamples - pBuffer->InDelaySamples); /* Update sample count */ + pDest += NumChannels * pBuffer->InDelaySamples; /* Update the destination pointer */ + } + + + /* + * Copy the rest of the samples for this call from the input buffer + */ + if (NumSamples > 0) + { + Copy_16(pStart, /* Source */ + pDest, /* Destination */ + (LVM_INT16)(NumChannels*NumSamples)); /* Number of input samples */ + pStart += NumChannels * NumSamples; /* Update the input pointer */ + + /* + * Update the input data pointer and samples to output + */ + pBuffer->SamplesToOutput = (LVM_INT16)(pBuffer->SamplesToOutput + NumSamples); /* Update samples to output */ + } + + + /* + * Update the sample count and input pointer + */ + pInstance->SamplesToProcess = (LVM_INT16)(pInstance->SamplesToProcess - SampleCount); /* Update the count of samples */ + pInstance->pInputSamples = pStart; /* Update input sample pointer */ + + + /* + * Save samples to the delay buffer if any left unprocessed + */ + if ((pBuffer->BufferState == LVM_FIRSTLASTCALL) || + (pBuffer->BufferState == LVM_LASTCALL)) + { + NumSamples = pInstance->SamplesToProcess; + pStart = pBuffer->pScratch; /* Start of the buffer */ + pStart += NumChannels*SampleCount; /* Offset by the number of processed samples */ + if (NumSamples != 0) + { + Copy_16(pStart, /* Source */ + &pBuffer->InDelayBuffer[0], /* Destination */ + (LVM_INT16)(NumChannels*NumSamples)); /* Number of input samples */ + } + + + /* + * Update the delay sample count + */ + pBuffer->InDelaySamples = NumSamples; /* Number of delay sample pairs */ + pInstance->SamplesToProcess = 0; /* All Samples used */ + } +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_BufferUnmanagedIn */ +/* */ +/* DESCRIPTION: */ +/* This mode is selected by the user code and disables the buffer management with the */ +/* exception of the maximum block size processing. The user must ensure that the */ +/* input and output buffers are 32-bit aligned and also that the number of samples to */ +/* process is a correct multiple of samples. */ +/* */ +/* PARAMETERS: */ +/* hInstance - Instance handle */ +/* *pToProcess - Pointer to the start of data processing */ +/* *pProcessed - Pointer to the destination of the processed data */ +/* pNumSamples - Pointer to the number of samples to process */ +/* */ +/* RETURNS: */ +/* None */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +void LVM_BufferUnmanagedIn(LVM_Handle_t hInstance, + LVM_INT16 **pToProcess, + LVM_INT16 **pProcessed, + LVM_UINT16 *pNumSamples) +{ + + LVM_Instance_t *pInstance = (LVM_Instance_t *)hInstance; + + + /* + * Check if this is the first call of a block + */ + if (pInstance->SamplesToProcess == 0) + { + pInstance->SamplesToProcess = (LVM_INT16)*pNumSamples; /* Get the number of samples on first call */ + pInstance->pInputSamples = *pToProcess; /* Get the I/O pointers */ + pInstance->pOutputSamples = *pProcessed; + + + /* + * Set te block size to process + */ + if (pInstance->SamplesToProcess > pInstance->InternalBlockSize) + { + *pNumSamples = (LVM_UINT16)pInstance->InternalBlockSize; + } + else + { + *pNumSamples = (LVM_UINT16)pInstance->SamplesToProcess; + } + } + + /* + * Set the process pointers + */ + *pToProcess = pInstance->pInputSamples; + *pProcessed = pInstance->pOutputSamples; +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_BufferOptimisedIn */ +/* */ +/* DESCRIPTION: */ +/* Optimised buffer management for the case where the data is outplace processing, */ +/* the output data is 32-bit aligned and there are sufficient samples to allow some */ +/* processing directly in the output buffer. This saves one data copy per sample */ +/* compared with the unoptimsed version. */ +/* */ +/* PARAMETERS: */ +/* hInstance - Instance handle */ +/* pInData - Pointer to the input data stream */ +/* *pToProcess - Pointer to the start of data processing */ +/* *pProcessed - Pointer to the destination of the processed data */ +/* pNumSamples - Pointer to the number of samples to process */ +/* */ +/* RETURNS: */ +/* None */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +void LVM_BufferOptimisedIn(LVM_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 **pToProcess, + LVM_INT16 **pProcessed, + LVM_UINT16 *pNumSamples) +{ + + LVM_Instance_t *pInstance = (LVM_Instance_t *)hInstance; + LVM_Buffer_t *pBuffer = pInstance->pBufferManagement; + LVM_INT16 *pDest; + LVM_INT16 SampleCount; + LVM_INT16 NumSamples; + LVM_INT16 NumFrames; + + /* + * Check if it is the first call for this block + */ + if (pInstance->SamplesToProcess == 0) + { + /* + * First call for a new block of samples + */ + pBuffer->BufferState = LVM_FIRSTCALL; + pInstance->pInputSamples = (LVM_INT16 *)pInData; + pInstance->SamplesToProcess = (LVM_INT16)*pNumSamples; + pBuffer->SamplesToOutput = (LVM_INT16)*pNumSamples; + pDest = *pProcessed; /* The start of the output buffer */ + + + /* + * Copy the already processed samples to the output buffer + */ + if (pBuffer->OutDelaySamples != 0) + { + Copy_16(&pBuffer->OutDelayBuffer[0], /* Source */ + pDest, /* Detsination */ + (LVM_INT16)(2*pBuffer->OutDelaySamples)); /* Number of delay samples */ + pDest += 2 * pBuffer->OutDelaySamples; /* Update the output pointer */ + pBuffer->SamplesToOutput = (LVM_INT16)(pBuffer->SamplesToOutput - pBuffer->OutDelaySamples); /* Update the numbr of samples to output */ + } + *pToProcess = pDest; /* Set the address to start processing */ + *pProcessed = pDest; /* Process in the output buffer, now inplace */ + + /* + * Copy the input delay buffer (unprocessed) samples to the output buffer + */ + if (pBuffer->InDelaySamples != 0) + { + Copy_16(&pBuffer->InDelayBuffer[0], /* Source */ + pDest, /* Destination */ + (LVM_INT16)(2*pBuffer->InDelaySamples)); /* Number of delay samples */ + pDest += 2 * pBuffer->InDelaySamples; /* Update the output pointer */ + } + + + /* + * Calculate how many input samples to process and copy + */ + NumSamples = (LVM_INT16)(*pNumSamples - pBuffer->OutDelaySamples); /* Number that will fit in the output buffer */ + if (NumSamples >= pInstance->InternalBlockSize) + { + NumSamples = pInstance->InternalBlockSize; + } + NumFrames = (LVM_INT16)(NumSamples >> MIN_INTERNAL_BLOCKSHIFT); + SampleCount = (LVM_INT16)(NumFrames << MIN_INTERNAL_BLOCKSHIFT); + *pNumSamples = (LVM_UINT16)SampleCount; /* The number of samples to process */ + pBuffer->SamplesToOutput = (LVM_INT16)(pBuffer->SamplesToOutput - SampleCount); /* Update the number of samples to output */ + SampleCount = (LVM_INT16)(SampleCount - pBuffer->InDelaySamples); /* The number of samples to copy from the input */ + + + /* + * Copy samples from the input buffer and update counts and pointers + */ + Copy_16(pInstance->pInputSamples, /* Source */ + pDest, /* Destination */ + (LVM_INT16)(2*SampleCount)); /* Number of input samples */ + pInstance->pInputSamples += 2 * SampleCount; /* Update the input pointer */ + pInstance->pOutputSamples = pDest + (2 * SampleCount); /* Update the output pointer */ + pInstance->SamplesToProcess = (LVM_INT16)(pInstance->SamplesToProcess - SampleCount); /* Samples left in the input buffer */ + } + else + { + /* + * Second or subsequent call in optimised mode + */ + if (pBuffer->SamplesToOutput >= MIN_INTERNAL_BLOCKSIZE) + { + /* + * More samples can be processed directly in the output buffer + */ + *pToProcess = pInstance->pOutputSamples; /* Set the address to start processing */ + *pProcessed = pInstance->pOutputSamples; /* Process in the output buffer, now inplace */ + NumSamples = pBuffer->SamplesToOutput; /* Number that will fit in the output buffer */ + if (NumSamples >= pInstance->InternalBlockSize) + { + NumSamples = pInstance->InternalBlockSize; + } + NumFrames = (LVM_INT16)(NumSamples >> MIN_INTERNAL_BLOCKSHIFT); + SampleCount = (LVM_INT16)(NumFrames << MIN_INTERNAL_BLOCKSHIFT); + *pNumSamples = (LVM_UINT16)SampleCount; /* The number of samples to process */ + + + /* + * Copy samples from the input buffer and update counts and pointers + */ + Copy_16(pInstance->pInputSamples, /* Source */ + pInstance->pOutputSamples, /* Destination */ + (LVM_INT16)(2*SampleCount)); /* Number of input samples */ + pInstance->pInputSamples += 2 * SampleCount; /* Update the input pointer */ + pInstance->pOutputSamples += 2 * SampleCount; /* Update the output pointer */ + pInstance->SamplesToProcess = (LVM_INT16)(pInstance->SamplesToProcess - SampleCount); /* Samples left in the input buffer */ + pBuffer->SamplesToOutput = (LVM_INT16)(pBuffer->SamplesToOutput - SampleCount); /* Number that will fit in the output buffer */ + } + else + { + /* + * The remaining samples can not be processed in the output buffer + */ + pBuffer->BufferState = LVM_LASTCALL; /* Indicate this is the last bock to process */ + *pToProcess = pBuffer->pScratch; /* Set the address to start processing */ + *pProcessed = pBuffer->pScratch; /* Process in the output buffer, now inplace */ + NumSamples = pInstance->SamplesToProcess; /* Number left to be processed */ + NumFrames = (LVM_INT16)(NumSamples >> MIN_INTERNAL_BLOCKSHIFT); + SampleCount = (LVM_INT16)(NumFrames << MIN_INTERNAL_BLOCKSHIFT); + *pNumSamples = (LVM_UINT16)SampleCount; /* The number of samples to process */ + + + /* + * Copy samples from the input buffer and update counts and pointers + */ + Copy_16(pInstance->pInputSamples, /* Source */ + pBuffer->pScratch, /* Destination */ + (LVM_INT16)(2*SampleCount)); /* Number of input samples */ + pInstance->pInputSamples += 2 * SampleCount; /* Update the input pointer */ + pInstance->SamplesToProcess = (LVM_INT16)(pInstance->SamplesToProcess - SampleCount); /* Samples left in the input buffer */ + } + } +} + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_BufferIn */ +/* */ +/* DESCRIPTION: */ +/* This function manages the data input, it has the following features: */ +/* - Accepts data in 16-bit aligned memory */ +/* - Copies the data to 32-bit aligned memory */ +/* - Converts Mono inputs to Mono-in-Stereo */ +/* - Accepts any number of samples as input, except 0 */ +/* - Breaks the input sample stream in to blocks of the configured frame size or */ +/* multiples of the frame size */ +/* - Limits the processing block size to the maximum block size. */ +/* - Works with inplace or outplace processing automatically */ +/* */ +/* To manage the data the function has a number of operating states: */ +/* LVM_FIRSTCALL - The first call for this block of input samples */ +/* LVM_MAXBLOCKCALL - The current block is the maximum size. Only used for the */ +/* second and subsequent blocks. */ +/* LVM_LASTCALL - The last call for this block of input samples */ +/* LVM_FIRSTLASTCALL - This is the first and last call for this block of input*/ +/* samples, this occurs when the number of samples to */ +/* process is less than the maximum block size. */ +/* */ +/* The function uses an internal delay buffer the size of the minimum frame, this is */ +/* used to temporarily hold samples when the number of samples to process is not a */ +/* multiple of the frame size. */ +/* */ +/* To ensure correct operation with inplace buffering the number of samples to output*/ +/* per call is calculated in this function and is set to the number of samples read */ +/* from the input buffer. */ +/* */ +/* The total number of samples to process is stored when the function is called for */ +/* the first time. The value is overwritten by the size of the block to be processed */ +/* in each call so the size of the processing blocks can be controlled. The number of */ +/* samples actually processed for each block of input samples is always a multiple of*/ +/* the frame size so for any particular block of input samples the actual number of */ +/* processed samples may not match the number of input samples, sometime it will be */ +/* sometimes less. The average is the same and the difference is never more than the */ +/* frame size. */ +/* */ +/* PARAMETERS: */ +/* hInstance - Instance handle */ +/* pInData - Pointer to the input data stream */ +/* *pToProcess - Pointer to the start of data processing */ +/* *pProcessed - Pointer to the destination of the processed data */ +/* pNumSamples - Pointer to the number of samples to process */ +/* */ +/* RETURNS: */ +/* None */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +void LVM_BufferIn(LVM_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 **pToProcess, + LVM_INT16 **pProcessed, + LVM_UINT16 *pNumSamples) +{ + + LVM_Instance_t *pInstance = (LVM_Instance_t *)hInstance; + + + /* + * Check which mode, managed or unmanaged + */ + if (pInstance->InstParams.BufferMode == LVM_MANAGED_BUFFERS) + { + LVM_BufferManagedIn(hInstance, + pInData, + pToProcess, + pProcessed, + pNumSamples); + } + else + { + LVM_BufferUnmanagedIn(hInstance, + pToProcess, + pProcessed, + pNumSamples); + } +} + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_BufferManagedOut */ +/* */ +/* DESCRIPTION: */ +/* Full buffer management output. This works in conjunction with the managed input */ +/* routine and ensures the correct number of samples are always output to the output */ +/* buffer. */ +/* */ +/* PARAMETERS: */ +/* hInstance - Instance handle */ +/* pOutData - Pointer to the output data stream */ +/* pNumSamples - Pointer to the number of samples to process */ +/* */ +/* RETURNS: */ +/* None */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +void LVM_BufferManagedOut(LVM_Handle_t hInstance, + LVM_INT16 *pOutData, + LVM_UINT16 *pNumSamples) +{ + + LVM_Instance_t *pInstance = (LVM_Instance_t *)hInstance; + LVM_Buffer_t *pBuffer = pInstance->pBufferManagement; + LVM_INT16 SampleCount = (LVM_INT16)*pNumSamples; + LVM_INT16 NumSamples; + LVM_INT16 *pStart; + LVM_INT16 *pDest; + + + /* + * Set the pointers + */ + NumSamples = pBuffer->SamplesToOutput; + pStart = pBuffer->pScratch; + + + /* + * check if it is the first call of a block + */ + if ((pBuffer->BufferState == LVM_FIRSTCALL) || + (pBuffer->BufferState == LVM_FIRSTLASTCALL)) + { + /* First call for a new block */ + pInstance->pOutputSamples = pOutData; /* Initialise the destination */ + } + pDest = pInstance->pOutputSamples; /* Set the output address */ + + + /* + * If the number of samples is non-zero then there are still samples to send to + * the output buffer + */ + if ((NumSamples != 0) && + (pBuffer->OutDelaySamples != 0)) + { + /* + * Copy the delayed output buffer samples to the output + */ + if (pBuffer->OutDelaySamples <= NumSamples) + { + /* + * Copy all output delay samples to the output + */ + Copy_16(&pBuffer->OutDelayBuffer[0], /* Source */ + pDest, /* Detsination */ + (LVM_INT16)(2*pBuffer->OutDelaySamples)); /* Number of delay samples */ + + /* + * Update the pointer and sample counts + */ + pDest += 2*pBuffer->OutDelaySamples; /* Output sample pointer */ + NumSamples = (LVM_INT16)(NumSamples - pBuffer->OutDelaySamples); /* Samples left to send */ + pBuffer->OutDelaySamples = 0; /* No samples left in the buffer */ + + } + else + { + /* + * Copy only some of the ouput delay samples to the output + */ + Copy_16(&pBuffer->OutDelayBuffer[0], /* Source */ + pDest, /* Detsination */ + (LVM_INT16)(2*NumSamples)); /* Number of delay samples */ + + /* + * Update the pointer and sample counts + */ + pDest += 2*NumSamples; /* Output sample pointer */ + pBuffer->OutDelaySamples = (LVM_INT16)(pBuffer->OutDelaySamples - NumSamples); /* No samples left in the buffer */ + + + /* + * Realign the delay buffer data to avoid using circular buffer management + */ + Copy_16(&pBuffer->OutDelayBuffer[2*NumSamples], /* Source */ + &pBuffer->OutDelayBuffer[0], /* Destination */ + (LVM_INT16)(2*pBuffer->OutDelaySamples)); /* Number of samples to move */ + NumSamples = 0; /* Samples left to send */ + } + } + + + /* + * Copy the processed results to the output + */ + if ((NumSamples != 0) && + (SampleCount != 0)) + { + if (SampleCount <= NumSamples) + { + /* + * Copy all processed samples to the output + */ + Copy_16(pStart, /* Source */ + pDest, /* Detsination */ + (LVM_INT16)(2*SampleCount)); /* Number of processed samples */ + + /* + * Update the pointer and sample counts + */ + pDest += 2 * SampleCount; /* Output sample pointer */ + NumSamples = (LVM_INT16)(NumSamples - SampleCount); /* Samples left to send */ + SampleCount = 0; /* No samples left in the buffer */ + } + else + { + /* + * Copy only some processed samples to the output + */ + Copy_16(pStart, /* Source */ + pDest, /* Destination */ + (LVM_INT16)(2*NumSamples)); /* Number of processed samples */ + + + /* + * Update the pointers and sample counts + */ + pStart += 2 * NumSamples; /* Processed sample pointer */ + pDest += 2 * NumSamples; /* Output sample pointer */ + SampleCount = (LVM_INT16)(SampleCount - NumSamples); /* Processed samples left */ + NumSamples = 0; /* Clear the sample count */ + } + } + + + /* + * Copy the remaining processed data to the output delay buffer + */ + if (SampleCount != 0) + { + Copy_16(pStart, /* Source */ + &pBuffer->OutDelayBuffer[2*pBuffer->OutDelaySamples], /* Destination */ + (LVM_INT16)(2*SampleCount)); /* Number of processed samples */ + pBuffer->OutDelaySamples = (LVM_INT16)(pBuffer->OutDelaySamples + SampleCount); /* Update the buffer count */ + } + + + /* + * pointers, counts and set default buffer processing + */ + pBuffer->SamplesToOutput = NumSamples; /* Samples left to send */ + pInstance->pOutputSamples = pDest; /* Output sample pointer */ + pBuffer->BufferState = LVM_MAXBLOCKCALL; /* Set for the default call block size */ + *pNumSamples = (LVM_UINT16)pInstance->SamplesToProcess; /* This will terminate the loop when all samples processed */ +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_BufferUnmanagedOut */ +/* */ +/* DESCRIPTION: */ +/* This works in conjunction with the unmanaged input routine and updates the number */ +/* of samples left to be processed and adjusts the buffer pointers. */ +/* */ +/* PARAMETERS: */ +/* hInstance - Instance handle */ +/* pNumSamples - Pointer to the number of samples to process */ +/* */ +/* RETURNS: */ +/* None */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +void LVM_BufferUnmanagedOut(LVM_Handle_t hInstance, + LVM_UINT16 *pNumSamples) +{ + + LVM_Instance_t *pInstance = (LVM_Instance_t *)hInstance; + LVM_INT16 NumChannels =2; + + + /* + * Update sample counts + */ + pInstance->pInputSamples += (LVM_INT16)(*pNumSamples * NumChannels); /* Update the I/O pointers */ + pInstance->pOutputSamples += (LVM_INT16)(*pNumSamples * 2); + pInstance->SamplesToProcess = (LVM_INT16)(pInstance->SamplesToProcess - *pNumSamples); /* Update the sample count */ + + /* + * Set te block size to process + */ + if (pInstance->SamplesToProcess > pInstance->InternalBlockSize) + { + *pNumSamples = (LVM_UINT16)pInstance->InternalBlockSize; + } + else + { + *pNumSamples = (LVM_UINT16)pInstance->SamplesToProcess; + } +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_BufferOptimisedOut */ +/* */ +/* DESCRIPTION: */ +/* This works in conjunction with the optimised input routine and copies the last few */ +/* processed and unprocessed samples to their respective buffers. */ +/* */ +/* PARAMETERS: */ +/* hInstance - Instance handle */ +/* pNumSamples - Pointer to the number of samples to process */ +/* */ +/* RETURNS: */ +/* None */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +void LVM_BufferOptimisedOut(LVM_Handle_t hInstance, + LVM_UINT16 *pNumSamples) +{ + + LVM_Instance_t *pInstance = (LVM_Instance_t *)hInstance; + LVM_Buffer_t *pBuffer = pInstance->pBufferManagement; + + /* + * Check if it is the last block to process + */ + if (pBuffer->BufferState == LVM_LASTCALL) + { + LVM_INT16 *pSrc = pBuffer->pScratch; + + /* + * Copy the unprocessed samples to the input delay buffer + */ + if (pInstance->SamplesToProcess != 0) + { + Copy_16(pInstance->pInputSamples, /* Source */ + &pBuffer->InDelayBuffer[0], /* Destination */ + (LVM_INT16)(2*pInstance->SamplesToProcess)); /* Number of input samples */ + pBuffer->InDelaySamples = pInstance->SamplesToProcess; + pInstance->SamplesToProcess = 0; + } + else + { + pBuffer->InDelaySamples = 0; + } + + + /* + * Fill the last empty spaces in the output buffer + */ + if (pBuffer->SamplesToOutput != 0) + { + Copy_16(pSrc, /* Source */ + pInstance->pOutputSamples, /* Destination */ + (LVM_INT16)(2*pBuffer->SamplesToOutput)); /* Number of input samples */ + *pNumSamples = (LVM_UINT16)(*pNumSamples - pBuffer->SamplesToOutput); + pSrc += 2 * pBuffer->SamplesToOutput; /* Update scratch pointer */ + pBuffer->SamplesToOutput = 0; /* No more samples in this block */ + } + + + /* + * Save any remaining processed samples in the output delay buffer + */ + if (*pNumSamples != 0) + { + Copy_16(pSrc, /* Source */ + &pBuffer->OutDelayBuffer[0], /* Destination */ + (LVM_INT16)(2**pNumSamples)); /* Number of input samples */ + + pBuffer->OutDelaySamples = (LVM_INT16)*pNumSamples; + + *pNumSamples = 0; /* No more samples in this block */ + } + else + { + pBuffer->OutDelaySamples = 0; + } + } +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_BufferOut */ +/* */ +/* DESCRIPTION: */ +/* This function manages the data output, it has the following features: */ +/* - Output data to 16-bit aligned memory */ +/* - Reads data from 32-bit aligned memory */ +/* - Reads data only in blocks of frame size or multiples of frame size */ +/* - Writes the same number of samples as the LVM_BufferIn function reads */ +/* - Works with inplace or outplace processing automatically */ +/* */ +/* To manage the data the function has a number of operating states: */ +/* LVM_FIRSTCALL - The first call for this block of input samples */ +/* LVM_FIRSTLASTCALL - This is the first and last call for this block of input*/ +/* samples, this occurs when the number of samples to */ +/* process is less than the maximum block size. */ +/* */ +/* The function uses an internal delay buffer the size of the minimum frame, this is */ +/* used to temporarily hold samples when the number of samples to write is not a */ +/* multiple of the frame size. */ +/* */ +/* To ensure correct operation with inplace buffering the number of samples to output*/ +/* per call is always the same as the number of samples read from the input buffer. */ +/* */ +/* PARAMETERS: */ +/* hInstance - Instance handle */ +/* pOutData - Pointer to the output data stream */ +/* pNumSamples - Pointer to the number of samples to process */ +/* */ +/* RETURNS: */ +/* None */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +void LVM_BufferOut(LVM_Handle_t hInstance, + LVM_INT16 *pOutData, + LVM_UINT16 *pNumSamples) +{ + + LVM_Instance_t *pInstance = (LVM_Instance_t *)hInstance; + + + /* + * Check which mode, managed or unmanaged + */ + if (pInstance->InstParams.BufferMode == LVM_MANAGED_BUFFERS) + { + LVM_BufferManagedOut(hInstance, + pOutData, + pNumSamples); + } + else + { + LVM_BufferUnmanagedOut(hInstance, + pNumSamples); + } +} + diff --git a/media/libeffects/lvm/lib/Bundle/src/LVM_Coeffs.h b/media/libeffects/lvm/lib/Bundle/src/LVM_Coeffs.h new file mode 100755 index 0000000..f578db9 --- /dev/null +++ b/media/libeffects/lvm/lib/Bundle/src/LVM_Coeffs.h @@ -0,0 +1,573 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LVM_COEFFS_H__ +#define __LVM_COEFFS_H__ + + +/************************************************************************************/ +/* */ +/* High Pass Shelving Filter coefficients */ +/* */ +/************************************************************************************/ + +#define TrebleBoostCorner 8000 +#define TrebleBoostMinRate 4 +#define TrebleBoostSteps 15 + + +/* Coefficients for sample rate 22050Hz */ + /* Gain = 1.000000 dB */ +#define HPF_Fs22050_Gain1_A0 5383 /* Floating point value 0.164291 */ +#define HPF_Fs22050_Gain1_A1 16859 /* Floating point value 0.514492 */ +#define HPF_Fs22050_Gain1_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain1_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain1_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain1_Shift 1 /* Shift value */ + /* Gain = 2.000000 dB */ +#define HPF_Fs22050_Gain2_A0 4683 /* Floating point value 0.142925 */ +#define HPF_Fs22050_Gain2_A1 17559 /* Floating point value 0.535858 */ +#define HPF_Fs22050_Gain2_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain2_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain2_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain2_Shift 1 /* Shift value */ + /* Gain = 3.000000 dB */ +#define HPF_Fs22050_Gain3_A0 3898 /* Floating point value 0.118953 */ +#define HPF_Fs22050_Gain3_A1 18345 /* Floating point value 0.559830 */ +#define HPF_Fs22050_Gain3_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain3_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain3_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain3_Shift 1 /* Shift value */ + /* Gain = 4.000000 dB */ +#define HPF_Fs22050_Gain4_A0 3016 /* Floating point value 0.092055 */ +#define HPF_Fs22050_Gain4_A1 19226 /* Floating point value 0.586728 */ +#define HPF_Fs22050_Gain4_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain4_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain4_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain4_Shift 1 /* Shift value */ + /* Gain = 5.000000 dB */ +#define HPF_Fs22050_Gain5_A0 2028 /* Floating point value 0.061876 */ +#define HPF_Fs22050_Gain5_A1 20215 /* Floating point value 0.616907 */ +#define HPF_Fs22050_Gain5_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain5_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain5_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain5_Shift 1 /* Shift value */ + /* Gain = 6.000000 dB */ +#define HPF_Fs22050_Gain6_A0 918 /* Floating point value 0.028013 */ +#define HPF_Fs22050_Gain6_A1 21324 /* Floating point value 0.650770 */ +#define HPF_Fs22050_Gain6_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain6_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain6_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain6_Shift 1 /* Shift value */ + /* Gain = 7.000000 dB */ +#define HPF_Fs22050_Gain7_A0 -164 /* Floating point value -0.005002 */ +#define HPF_Fs22050_Gain7_A1 11311 /* Floating point value 0.345199 */ +#define HPF_Fs22050_Gain7_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain7_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain7_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain7_Shift 2 /* Shift value */ + /* Gain = 8.000000 dB */ +#define HPF_Fs22050_Gain8_A0 -864 /* Floating point value -0.026368 */ +#define HPF_Fs22050_Gain8_A1 12012 /* Floating point value 0.366565 */ +#define HPF_Fs22050_Gain8_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain8_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain8_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain8_Shift 2 /* Shift value */ + /* Gain = 9.000000 dB */ +#define HPF_Fs22050_Gain9_A0 -1650 /* Floating point value -0.050340 */ +#define HPF_Fs22050_Gain9_A1 12797 /* Floating point value 0.390537 */ +#define HPF_Fs22050_Gain9_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain9_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain9_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain9_Shift 2 /* Shift value */ + /* Gain = 10.000000 dB */ +#define HPF_Fs22050_Gain10_A0 -2531 /* Floating point value -0.077238 */ +#define HPF_Fs22050_Gain10_A1 13679 /* Floating point value 0.417435 */ +#define HPF_Fs22050_Gain10_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain10_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain10_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain10_Shift 2 /* Shift value */ + /* Gain = 11.000000 dB */ +#define HPF_Fs22050_Gain11_A0 -3520 /* Floating point value -0.107417 */ +#define HPF_Fs22050_Gain11_A1 14667 /* Floating point value 0.447615 */ +#define HPF_Fs22050_Gain11_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain11_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain11_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain11_Shift 2 /* Shift value */ + /* Gain = 12.000000 dB */ +#define HPF_Fs22050_Gain12_A0 -4629 /* Floating point value -0.141279 */ +#define HPF_Fs22050_Gain12_A1 15777 /* Floating point value 0.481477 */ +#define HPF_Fs22050_Gain12_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain12_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain12_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain12_Shift 2 /* Shift value */ + /* Gain = 13.000000 dB */ +#define HPF_Fs22050_Gain13_A0 -2944 /* Floating point value -0.089849 */ +#define HPF_Fs22050_Gain13_A1 8531 /* Floating point value 0.260352 */ +#define HPF_Fs22050_Gain13_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain13_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain13_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain13_Shift 3 /* Shift value */ + /* Gain = 14.000000 dB */ +#define HPF_Fs22050_Gain14_A0 -3644 /* Floating point value -0.111215 */ +#define HPF_Fs22050_Gain14_A1 9231 /* Floating point value 0.281718 */ +#define HPF_Fs22050_Gain14_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain14_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain14_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain14_Shift 3 /* Shift value */ + /* Gain = 15.000000 dB */ +#define HPF_Fs22050_Gain15_A0 -4430 /* Floating point value -0.135187 */ +#define HPF_Fs22050_Gain15_A1 10017 /* Floating point value 0.305690 */ +#define HPF_Fs22050_Gain15_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain15_B1 12125 /* Floating point value 0.370033 */ +#define HPF_Fs22050_Gain15_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs22050_Gain15_Shift 3 /* Shift value */ + + +/* Coefficients for sample rate 24000Hz */ + /* Gain = 1.000000 dB */ +#define HPF_Fs24000_Gain1_A0 3625 /* Floating point value 0.110628 */ +#define HPF_Fs24000_Gain1_A1 16960 /* Floating point value 0.517578 */ +#define HPF_Fs24000_Gain1_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain1_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain1_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain1_Shift 1 /* Shift value */ + /* Gain = 2.000000 dB */ +#define HPF_Fs24000_Gain2_A0 2811 /* Floating point value 0.085800 */ +#define HPF_Fs24000_Gain2_A1 17774 /* Floating point value 0.542406 */ +#define HPF_Fs24000_Gain2_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain2_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain2_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain2_Shift 1 /* Shift value */ + /* Gain = 3.000000 dB */ +#define HPF_Fs24000_Gain3_A0 1899 /* Floating point value 0.057943 */ +#define HPF_Fs24000_Gain3_A1 18686 /* Floating point value 0.570263 */ +#define HPF_Fs24000_Gain3_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain3_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain3_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain3_Shift 1 /* Shift value */ + /* Gain = 4.000000 dB */ +#define HPF_Fs24000_Gain4_A0 874 /* Floating point value 0.026687 */ +#define HPF_Fs24000_Gain4_A1 19711 /* Floating point value 0.601519 */ +#define HPF_Fs24000_Gain4_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain4_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain4_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain4_Shift 1 /* Shift value */ + /* Gain = 5.000000 dB */ +#define HPF_Fs24000_Gain5_A0 -275 /* Floating point value -0.008383 */ +#define HPF_Fs24000_Gain5_A1 20860 /* Floating point value 0.636589 */ +#define HPF_Fs24000_Gain5_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain5_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain5_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain5_Shift 1 /* Shift value */ + /* Gain = 6.000000 dB */ +#define HPF_Fs24000_Gain6_A0 -1564 /* Floating point value -0.047733 */ +#define HPF_Fs24000_Gain6_A1 22149 /* Floating point value 0.675938 */ +#define HPF_Fs24000_Gain6_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain6_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain6_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain6_Shift 1 /* Shift value */ + /* Gain = 7.000000 dB */ +#define HPF_Fs24000_Gain7_A0 -1509 /* Floating point value -0.046051 */ +#define HPF_Fs24000_Gain7_A1 11826 /* Floating point value 0.360899 */ +#define HPF_Fs24000_Gain7_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain7_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain7_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain7_Shift 2 /* Shift value */ + /* Gain = 8.000000 dB */ +#define HPF_Fs24000_Gain8_A0 -2323 /* Floating point value -0.070878 */ +#define HPF_Fs24000_Gain8_A1 12640 /* Floating point value 0.385727 */ +#define HPF_Fs24000_Gain8_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain8_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain8_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain8_Shift 2 /* Shift value */ + /* Gain = 9.000000 dB */ +#define HPF_Fs24000_Gain9_A0 -3235 /* Floating point value -0.098736 */ +#define HPF_Fs24000_Gain9_A1 13552 /* Floating point value 0.413584 */ +#define HPF_Fs24000_Gain9_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain9_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain9_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain9_Shift 2 /* Shift value */ + /* Gain = 10.000000 dB */ +#define HPF_Fs24000_Gain10_A0 -4260 /* Floating point value -0.129992 */ +#define HPF_Fs24000_Gain10_A1 14577 /* Floating point value 0.444841 */ +#define HPF_Fs24000_Gain10_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain10_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain10_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain10_Shift 2 /* Shift value */ + /* Gain = 11.000000 dB */ +#define HPF_Fs24000_Gain11_A0 -5409 /* Floating point value -0.165062 */ +#define HPF_Fs24000_Gain11_A1 15726 /* Floating point value 0.479911 */ +#define HPF_Fs24000_Gain11_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain11_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain11_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain11_Shift 2 /* Shift value */ + /* Gain = 12.000000 dB */ +#define HPF_Fs24000_Gain12_A0 -6698 /* Floating point value -0.204411 */ +#define HPF_Fs24000_Gain12_A1 17015 /* Floating point value 0.519260 */ +#define HPF_Fs24000_Gain12_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain12_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain12_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain12_Shift 2 /* Shift value */ + /* Gain = 13.000000 dB */ +#define HPF_Fs24000_Gain13_A0 -4082 /* Floating point value -0.124576 */ +#define HPF_Fs24000_Gain13_A1 9253 /* Floating point value 0.282374 */ +#define HPF_Fs24000_Gain13_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain13_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain13_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain13_Shift 3 /* Shift value */ + /* Gain = 14.000000 dB */ +#define HPF_Fs24000_Gain14_A0 -4896 /* Floating point value -0.149404 */ +#define HPF_Fs24000_Gain14_A1 10066 /* Floating point value 0.307202 */ +#define HPF_Fs24000_Gain14_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain14_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain14_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain14_Shift 3 /* Shift value */ + /* Gain = 15.000000 dB */ +#define HPF_Fs24000_Gain15_A0 -5808 /* Floating point value -0.177261 */ +#define HPF_Fs24000_Gain15_A1 10979 /* Floating point value 0.335059 */ +#define HPF_Fs24000_Gain15_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain15_B1 8780 /* Floating point value 0.267949 */ +#define HPF_Fs24000_Gain15_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs24000_Gain15_Shift 3 /* Shift value */ + + +/* Coefficients for sample rate 32000Hz */ + /* Gain = 1.000000 dB */ +#define HPF_Fs32000_Gain1_A0 17225 /* Floating point value 0.525677 */ +#define HPF_Fs32000_Gain1_A1 -990 /* Floating point value -0.030227 */ +#define HPF_Fs32000_Gain1_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain1_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain1_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain1_Shift 1 /* Shift value */ + /* Gain = 2.000000 dB */ +#define HPF_Fs32000_Gain2_A0 18337 /* Floating point value 0.559593 */ +#define HPF_Fs32000_Gain2_A1 -2102 /* Floating point value -0.064142 */ +#define HPF_Fs32000_Gain2_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain2_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain2_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain2_Shift 1 /* Shift value */ + /* Gain = 3.000000 dB */ +#define HPF_Fs32000_Gain3_A0 19584 /* Floating point value 0.597646 */ +#define HPF_Fs32000_Gain3_A1 -3349 /* Floating point value -0.102196 */ +#define HPF_Fs32000_Gain3_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain3_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain3_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain3_Shift 1 /* Shift value */ + /* Gain = 4.000000 dB */ +#define HPF_Fs32000_Gain4_A0 20983 /* Floating point value 0.640343 */ +#define HPF_Fs32000_Gain4_A1 -4748 /* Floating point value -0.144893 */ +#define HPF_Fs32000_Gain4_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain4_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain4_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain4_Shift 1 /* Shift value */ + /* Gain = 5.000000 dB */ +#define HPF_Fs32000_Gain5_A0 22553 /* Floating point value 0.688250 */ +#define HPF_Fs32000_Gain5_A1 -6318 /* Floating point value -0.192799 */ +#define HPF_Fs32000_Gain5_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain5_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain5_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain5_Shift 1 /* Shift value */ + /* Gain = 6.000000 dB */ +#define HPF_Fs32000_Gain6_A0 24314 /* Floating point value 0.742002 */ +#define HPF_Fs32000_Gain6_A1 -8079 /* Floating point value -0.246551 */ +#define HPF_Fs32000_Gain6_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain6_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain6_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain6_Shift 1 /* Shift value */ + /* Gain = 7.000000 dB */ +#define HPF_Fs32000_Gain7_A0 13176 /* Floating point value 0.402109 */ +#define HPF_Fs32000_Gain7_A1 -5040 /* Floating point value -0.153795 */ +#define HPF_Fs32000_Gain7_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain7_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain7_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain7_Shift 2 /* Shift value */ + /* Gain = 8.000000 dB */ +#define HPF_Fs32000_Gain8_A0 14288 /* Floating point value 0.436024 */ +#define HPF_Fs32000_Gain8_A1 -6151 /* Floating point value -0.187711 */ +#define HPF_Fs32000_Gain8_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain8_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain8_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain8_Shift 2 /* Shift value */ + /* Gain = 9.000000 dB */ +#define HPF_Fs32000_Gain9_A0 15535 /* Floating point value 0.474078 */ +#define HPF_Fs32000_Gain9_A1 -7398 /* Floating point value -0.225764 */ +#define HPF_Fs32000_Gain9_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain9_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain9_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain9_Shift 2 /* Shift value */ + /* Gain = 10.000000 dB */ +#define HPF_Fs32000_Gain10_A0 16934 /* Floating point value 0.516774 */ +#define HPF_Fs32000_Gain10_A1 -8797 /* Floating point value -0.268461 */ +#define HPF_Fs32000_Gain10_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain10_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain10_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain10_Shift 2 /* Shift value */ + /* Gain = 11.000000 dB */ +#define HPF_Fs32000_Gain11_A0 18503 /* Floating point value 0.564681 */ +#define HPF_Fs32000_Gain11_A1 -10367 /* Floating point value -0.316368 */ +#define HPF_Fs32000_Gain11_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain11_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain11_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain11_Shift 2 /* Shift value */ + /* Gain = 12.000000 dB */ +#define HPF_Fs32000_Gain12_A0 20265 /* Floating point value 0.618433 */ +#define HPF_Fs32000_Gain12_A1 -12128 /* Floating point value -0.370120 */ +#define HPF_Fs32000_Gain12_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain12_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain12_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain12_Shift 2 /* Shift value */ + /* Gain = 13.000000 dB */ +#define HPF_Fs32000_Gain13_A0 11147 /* Floating point value 0.340178 */ +#define HPF_Fs32000_Gain13_A1 -7069 /* Floating point value -0.215726 */ +#define HPF_Fs32000_Gain13_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain13_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain13_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain13_Shift 3 /* Shift value */ + /* Gain = 14.000000 dB */ +#define HPF_Fs32000_Gain14_A0 12258 /* Floating point value 0.374093 */ +#define HPF_Fs32000_Gain14_A1 -8180 /* Floating point value -0.249642 */ +#define HPF_Fs32000_Gain14_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain14_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain14_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain14_Shift 3 /* Shift value */ + /* Gain = 15.000000 dB */ +#define HPF_Fs32000_Gain15_A0 13505 /* Floating point value 0.412147 */ +#define HPF_Fs32000_Gain15_A1 -9427 /* Floating point value -0.287695 */ +#define HPF_Fs32000_Gain15_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain15_B1 0 /* Floating point value -0.000000 */ +#define HPF_Fs32000_Gain15_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs32000_Gain15_Shift 3 /* Shift value */ + + +/* Coefficients for sample rate 44100Hz */ + /* Gain = 1.000000 dB */ +#define HPF_Fs44100_Gain1_A0 17442 /* Floating point value 0.532294 */ +#define HPF_Fs44100_Gain1_A1 -4761 /* Floating point value -0.145294 */ +#define HPF_Fs44100_Gain1_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain1_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain1_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain1_Shift 1 /* Shift value */ + /* Gain = 2.000000 dB */ +#define HPF_Fs44100_Gain2_A0 18797 /* Floating point value 0.573633 */ +#define HPF_Fs44100_Gain2_A1 -6116 /* Floating point value -0.186634 */ +#define HPF_Fs44100_Gain2_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain2_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain2_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain2_Shift 1 /* Shift value */ + /* Gain = 3.000000 dB */ +#define HPF_Fs44100_Gain3_A0 20317 /* Floating point value 0.620016 */ +#define HPF_Fs44100_Gain3_A1 -7635 /* Floating point value -0.233017 */ +#define HPF_Fs44100_Gain3_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain3_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain3_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain3_Shift 1 /* Shift value */ + /* Gain = 4.000000 dB */ +#define HPF_Fs44100_Gain4_A0 22022 /* Floating point value 0.672059 */ +#define HPF_Fs44100_Gain4_A1 -9341 /* Floating point value -0.285060 */ +#define HPF_Fs44100_Gain4_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain4_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain4_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain4_Shift 1 /* Shift value */ + /* Gain = 5.000000 dB */ +#define HPF_Fs44100_Gain5_A0 23935 /* Floating point value 0.730452 */ +#define HPF_Fs44100_Gain5_A1 -11254 /* Floating point value -0.343453 */ +#define HPF_Fs44100_Gain5_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain5_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain5_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain5_Shift 1 /* Shift value */ + /* Gain = 6.000000 dB */ +#define HPF_Fs44100_Gain6_A0 26082 /* Floating point value 0.795970 */ +#define HPF_Fs44100_Gain6_A1 -13401 /* Floating point value -0.408971 */ +#define HPF_Fs44100_Gain6_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain6_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain6_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain6_Shift 1 /* Shift value */ + /* Gain = 7.000000 dB */ +#define HPF_Fs44100_Gain7_A0 14279 /* Floating point value 0.435774 */ +#define HPF_Fs44100_Gain7_A1 -7924 /* Floating point value -0.241815 */ +#define HPF_Fs44100_Gain7_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain7_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain7_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain7_Shift 2 /* Shift value */ + /* Gain = 8.000000 dB */ +#define HPF_Fs44100_Gain8_A0 15634 /* Floating point value 0.477113 */ +#define HPF_Fs44100_Gain8_A1 -9278 /* Floating point value -0.283154 */ +#define HPF_Fs44100_Gain8_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain8_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain8_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain8_Shift 2 /* Shift value */ + /* Gain = 9.000000 dB */ +#define HPF_Fs44100_Gain9_A0 17154 /* Floating point value 0.523496 */ +#define HPF_Fs44100_Gain9_A1 -10798 /* Floating point value -0.329537 */ +#define HPF_Fs44100_Gain9_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain9_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain9_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain9_Shift 2 /* Shift value */ + /* Gain = 10.000000 dB */ +#define HPF_Fs44100_Gain10_A0 18859 /* Floating point value 0.575539 */ +#define HPF_Fs44100_Gain10_A1 -12504 /* Floating point value -0.381580 */ +#define HPF_Fs44100_Gain10_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain10_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain10_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain10_Shift 2 /* Shift value */ + /* Gain = 11.000000 dB */ +#define HPF_Fs44100_Gain11_A0 20773 /* Floating point value 0.633932 */ +#define HPF_Fs44100_Gain11_A1 -14417 /* Floating point value -0.439973 */ +#define HPF_Fs44100_Gain11_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain11_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain11_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain11_Shift 2 /* Shift value */ + /* Gain = 12.000000 dB */ +#define HPF_Fs44100_Gain12_A0 22920 /* Floating point value 0.699450 */ +#define HPF_Fs44100_Gain12_A1 -16564 /* Floating point value -0.505491 */ +#define HPF_Fs44100_Gain12_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain12_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain12_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain12_Shift 2 /* Shift value */ + /* Gain = 13.000000 dB */ +#define HPF_Fs44100_Gain13_A0 12694 /* Floating point value 0.387399 */ +#define HPF_Fs44100_Gain13_A1 -9509 /* Floating point value -0.290189 */ +#define HPF_Fs44100_Gain13_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain13_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain13_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain13_Shift 3 /* Shift value */ + /* Gain = 14.000000 dB */ +#define HPF_Fs44100_Gain14_A0 14049 /* Floating point value 0.428738 */ +#define HPF_Fs44100_Gain14_A1 -10864 /* Floating point value -0.331528 */ +#define HPF_Fs44100_Gain14_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain14_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain14_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain14_Shift 3 /* Shift value */ + /* Gain = 15.000000 dB */ +#define HPF_Fs44100_Gain15_A0 15569 /* Floating point value 0.475121 */ +#define HPF_Fs44100_Gain15_A1 -12383 /* Floating point value -0.377912 */ +#define HPF_Fs44100_Gain15_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain15_B1 -7173 /* Floating point value -0.218894 */ +#define HPF_Fs44100_Gain15_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs44100_Gain15_Shift 3 /* Shift value */ + + +/* Coefficients for sample rate 48000Hz */ + /* Gain = 1.000000 dB */ +#define HPF_Fs48000_Gain1_A0 17491 /* Floating point value 0.533777 */ +#define HPF_Fs48000_Gain1_A1 -5606 /* Floating point value -0.171082 */ +#define HPF_Fs48000_Gain1_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain1_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain1_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain1_Shift 1 /* Shift value */ + /* Gain = 2.000000 dB */ +#define HPF_Fs48000_Gain2_A0 18900 /* Floating point value 0.576779 */ +#define HPF_Fs48000_Gain2_A1 -7015 /* Floating point value -0.214085 */ +#define HPF_Fs48000_Gain2_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain2_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain2_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain2_Shift 1 /* Shift value */ + /* Gain = 3.000000 dB */ +#define HPF_Fs48000_Gain3_A0 20481 /* Floating point value 0.625029 */ +#define HPF_Fs48000_Gain3_A1 -8596 /* Floating point value -0.262335 */ +#define HPF_Fs48000_Gain3_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain3_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain3_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain3_Shift 1 /* Shift value */ + /* Gain = 4.000000 dB */ +#define HPF_Fs48000_Gain4_A0 22255 /* Floating point value 0.679167 */ +#define HPF_Fs48000_Gain4_A1 -10370 /* Floating point value -0.316472 */ +#define HPF_Fs48000_Gain4_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain4_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain4_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain4_Shift 1 /* Shift value */ + /* Gain = 5.000000 dB */ +#define HPF_Fs48000_Gain5_A0 24245 /* Floating point value 0.739910 */ +#define HPF_Fs48000_Gain5_A1 -12361 /* Floating point value -0.377215 */ +#define HPF_Fs48000_Gain5_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain5_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain5_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain5_Shift 1 /* Shift value */ + /* Gain = 6.000000 dB */ +#define HPF_Fs48000_Gain6_A0 26479 /* Floating point value 0.808065 */ +#define HPF_Fs48000_Gain6_A1 -14594 /* Floating point value -0.445370 */ +#define HPF_Fs48000_Gain6_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain6_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain6_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain6_Shift 1 /* Shift value */ + /* Gain = 7.000000 dB */ +#define HPF_Fs48000_Gain7_A0 14527 /* Floating point value 0.443318 */ +#define HPF_Fs48000_Gain7_A1 -8570 /* Floating point value -0.261540 */ +#define HPF_Fs48000_Gain7_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain7_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain7_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain7_Shift 2 /* Shift value */ + /* Gain = 8.000000 dB */ +#define HPF_Fs48000_Gain8_A0 15936 /* Floating point value 0.486321 */ +#define HPF_Fs48000_Gain8_A1 -9979 /* Floating point value -0.304543 */ +#define HPF_Fs48000_Gain8_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain8_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain8_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain8_Shift 2 /* Shift value */ + /* Gain = 9.000000 dB */ +#define HPF_Fs48000_Gain9_A0 17517 /* Floating point value 0.534571 */ +#define HPF_Fs48000_Gain9_A1 -11560 /* Floating point value -0.352793 */ +#define HPF_Fs48000_Gain9_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain9_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain9_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain9_Shift 2 /* Shift value */ + /* Gain = 10.000000 dB */ +#define HPF_Fs48000_Gain10_A0 19291 /* Floating point value 0.588708 */ +#define HPF_Fs48000_Gain10_A1 -13334 /* Floating point value -0.406930 */ +#define HPF_Fs48000_Gain10_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain10_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain10_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain10_Shift 2 /* Shift value */ + /* Gain = 11.000000 dB */ +#define HPF_Fs48000_Gain11_A0 21281 /* Floating point value 0.649452 */ +#define HPF_Fs48000_Gain11_A1 -15325 /* Floating point value -0.467674 */ +#define HPF_Fs48000_Gain11_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain11_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain11_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain11_Shift 2 /* Shift value */ + /* Gain = 12.000000 dB */ +#define HPF_Fs48000_Gain12_A0 23515 /* Floating point value 0.717607 */ +#define HPF_Fs48000_Gain12_A1 -17558 /* Floating point value -0.535829 */ +#define HPF_Fs48000_Gain12_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain12_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain12_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain12_Shift 2 /* Shift value */ + /* Gain = 13.000000 dB */ +#define HPF_Fs48000_Gain13_A0 13041 /* Floating point value 0.397982 */ +#define HPF_Fs48000_Gain13_A1 -10056 /* Floating point value -0.306877 */ +#define HPF_Fs48000_Gain13_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain13_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain13_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain13_Shift 3 /* Shift value */ + /* Gain = 14.000000 dB */ +#define HPF_Fs48000_Gain14_A0 14450 /* Floating point value 0.440984 */ +#define HPF_Fs48000_Gain14_A1 -11465 /* Floating point value -0.349880 */ +#define HPF_Fs48000_Gain14_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain14_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain14_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain14_Shift 3 /* Shift value */ + /* Gain = 15.000000 dB */ +#define HPF_Fs48000_Gain15_A0 16031 /* Floating point value 0.489234 */ +#define HPF_Fs48000_Gain15_A1 -13046 /* Floating point value -0.398130 */ +#define HPF_Fs48000_Gain15_A2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain15_B1 -8780 /* Floating point value -0.267949 */ +#define HPF_Fs48000_Gain15_B2 0 /* Floating point value 0.000000 */ +#define HPF_Fs48000_Gain15_Shift 3 /* Shift value */ + + +#endif diff --git a/media/libeffects/lvm/lib/Bundle/src/LVM_Control.c b/media/libeffects/lvm/lib/Bundle/src/LVM_Control.c new file mode 100755 index 0000000..4667feb --- /dev/null +++ b/media/libeffects/lvm/lib/Bundle/src/LVM_Control.c @@ -0,0 +1,1032 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************************** + + $Author: nxp007753 $ + $Revision: 1255 $ + $Date: 2010-07-16 17:07:29 +0200 (Fri, 16 Jul 2010) $ + +*****************************************************************************************/ + + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "VectorArithmetic.h" +#include "ScalarArithmetic.h" +#include "LVM_Coeffs.h" +#include "LVM_Tables.h" +#include "LVM_Private.h" + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_SetControlParameters */ +/* */ +/* DESCRIPTION: */ +/* Sets or changes the LifeVibes module parameters. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to a parameter structure */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_NULLADDRESS When hInstance, pParams or any control pointers are NULL */ +/* LVM_OUTOFRANGE When any of the control parameters are out of range */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ + +LVM_ReturnStatus_en LVM_SetControlParameters(LVM_Handle_t hInstance, + LVM_ControlParams_t *pParams) +{ + LVM_Instance_t *pInstance =(LVM_Instance_t *)hInstance; + + + if ((pParams == LVM_NULL) || (hInstance == LVM_NULL)) + { + return (LVM_NULLADDRESS); + } + + pInstance->NewParams = *pParams; + + if( + /* General parameters */ + ((pParams->OperatingMode != LVM_MODE_OFF) && (pParams->OperatingMode != LVM_MODE_ON)) || + ((pParams->SampleRate != LVM_FS_8000) && (pParams->SampleRate != LVM_FS_11025) && (pParams->SampleRate != LVM_FS_12000) && + (pParams->SampleRate != LVM_FS_16000) && (pParams->SampleRate != LVM_FS_22050) && (pParams->SampleRate != LVM_FS_24000) && + (pParams->SampleRate != LVM_FS_32000) && (pParams->SampleRate != LVM_FS_44100) && (pParams->SampleRate != LVM_FS_48000)) || + ((pParams->SourceFormat != LVM_STEREO) && (pParams->SourceFormat != LVM_MONOINSTEREO) && (pParams->SourceFormat != LVM_MONO)) || + (pParams->SpeakerType > LVM_EX_HEADPHONES)) + { + return (LVM_OUTOFRANGE); + } + + /* + * Cinema Sound parameters + */ + if((pParams->VirtualizerOperatingMode != LVM_MODE_OFF) && (pParams->VirtualizerOperatingMode != LVM_MODE_ON)) + { + return (LVM_OUTOFRANGE); + } + + if(pParams->VirtualizerType != LVM_CONCERTSOUND) + { + return (LVM_OUTOFRANGE); + } + + if(pParams->VirtualizerReverbLevel > LVM_VIRTUALIZER_MAX_REVERB_LEVEL) + { + return (LVM_OUTOFRANGE); + } + + if(pParams->CS_EffectLevel < LVM_CS_MIN_EFFECT_LEVEL) + { + return (LVM_OUTOFRANGE); + } + + /* + * N-Band Equalizer + */ + if(pParams->EQNB_NBands > pInstance->InstParams.EQNB_NumBands) + { + return (LVM_OUTOFRANGE); + } + + /* Definition pointer */ + if ((pParams->pEQNB_BandDefinition == LVM_NULL) && + (pParams->EQNB_NBands != 0)) + { + return (LVM_NULLADDRESS); + } + + /* + * Copy the filter definitions for the Equaliser + */ + { + LVM_INT16 i; + + if (pParams->EQNB_NBands != 0) + { + for (i=0; iEQNB_NBands; i++) + { + pInstance->pEQNB_BandDefs[i] = pParams->pEQNB_BandDefinition[i]; + } + pInstance->NewParams.pEQNB_BandDefinition = pInstance->pEQNB_BandDefs; + } + } + if( /* N-Band Equaliser parameters */ + ((pParams->EQNB_OperatingMode != LVM_EQNB_OFF) && (pParams->EQNB_OperatingMode != LVM_EQNB_ON)) || + (pParams->EQNB_NBands > pInstance->InstParams.EQNB_NumBands)) + { + return (LVM_OUTOFRANGE); + } + /* Band parameters*/ + { + LVM_INT16 i; + for(i = 0; i < pParams->EQNB_NBands; i++) + { + if(((pParams->pEQNB_BandDefinition[i].Frequency < LVM_EQNB_MIN_BAND_FREQ) || + (pParams->pEQNB_BandDefinition[i].Frequency > LVM_EQNB_MAX_BAND_FREQ)) || + ((pParams->pEQNB_BandDefinition[i].Gain < LVM_EQNB_MIN_BAND_GAIN) || + (pParams->pEQNB_BandDefinition[i].Gain > LVM_EQNB_MAX_BAND_GAIN)) || + ((pParams->pEQNB_BandDefinition[i].QFactor < LVM_EQNB_MIN_QFACTOR) || + (pParams->pEQNB_BandDefinition[i].QFactor > LVM_EQNB_MAX_QFACTOR))) + { + return (LVM_OUTOFRANGE); + } + } + } + + /* + * Bass Enhancement parameters + */ + if(((pParams->BE_OperatingMode != LVM_BE_OFF) && (pParams->BE_OperatingMode != LVM_BE_ON)) || + ((pParams->BE_EffectLevel < LVM_BE_MIN_EFFECTLEVEL ) || (pParams->BE_EffectLevel > LVM_BE_MAX_EFFECTLEVEL ))|| + ((pParams->BE_CentreFreq != LVM_BE_CENTRE_55Hz) && (pParams->BE_CentreFreq != LVM_BE_CENTRE_66Hz) && + (pParams->BE_CentreFreq != LVM_BE_CENTRE_78Hz) && (pParams->BE_CentreFreq != LVM_BE_CENTRE_90Hz)) || + ((pParams->BE_HPF != LVM_BE_HPF_OFF) && (pParams->BE_HPF != LVM_BE_HPF_ON))) + { + return (LVM_OUTOFRANGE); + } + + /* + * Volume Control parameters + */ + if((pParams->VC_EffectLevel < LVM_VC_MIN_EFFECTLEVEL ) || (pParams->VC_EffectLevel > LVM_VC_MAX_EFFECTLEVEL )) + { + return (LVM_OUTOFRANGE); + } + if((pParams->VC_Balance < LVM_VC_BALANCE_MIN ) || (pParams->VC_Balance > LVM_VC_BALANCE_MAX )) + { + return (LVM_OUTOFRANGE); + } + + /* + * PSA parameters + */ + if( (pParams->PSA_PeakDecayRate > LVPSA_SPEED_HIGH) || + (pParams->PSA_Enable > LVM_PSA_ON)) + { + return (LVM_OUTOFRANGE); + } + + + /* + * Set the flag to indicate there are new parameters to use + * + * Protect the copy of the new parameters from interrupts to avoid possible problems + * with loss control parameters. This problem can occur if this control function is called more + * than once before a call to the process function. If the process function interrupts + * the copy to NewParams then one frame may have mixed parameters, some old and some new. + */ + pInstance->ControlPending = LVM_TRUE; + pInstance->NoSmoothVolume = LVM_FALSE; + + return(LVM_SUCCESS); +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_GetControlParameters */ +/* */ +/* DESCRIPTION: */ +/* Request the LifeVibes module parameters. The current parameter set is returned */ +/* via the parameter pointer. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to an empty parameter structure */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_NULLADDRESS when any of hInstance or pParams is NULL */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ + +LVM_ReturnStatus_en LVM_GetControlParameters(LVM_Handle_t hInstance, + LVM_ControlParams_t *pParams) +{ + LVM_Instance_t *pInstance =(LVM_Instance_t *)hInstance; + + + /* + * Check pointer + */ + if ((pParams == LVM_NULL) || (hInstance == LVM_NULL)) + { + return (LVM_NULLADDRESS); + } + *pParams = pInstance->NewParams; + + /* + * Copy the filter definitions for the Equaliser + */ + { + LVM_INT16 i; + + if (pInstance->NewParams.EQNB_NBands != 0) + for (i=0; iNewParams.EQNB_NBands; i++) + { + pInstance->pEQNB_UserDefs[i] = pInstance->pEQNB_BandDefs[i]; + } + pParams->pEQNB_BandDefinition = pInstance->pEQNB_UserDefs; + } + + return(LVM_SUCCESS); +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_SetTrebleBoost */ +/* */ +/* DESCRIPTION: */ +/* Enable the treble boost when the settings are appropriate, i.e. non-zero gain */ +/* and the sample rate is high enough for the effect to be heard. */ +/* */ +/* PARAMETERS: */ +/* pInstance Pointer to the instance structure */ +/* pParams Pointer to the parameters to use */ +/* */ +/****************************************************************************************/ +void LVM_SetTrebleBoost(LVM_Instance_t *pInstance, + LVM_ControlParams_t *pParams) +{ + extern FO_C16_LShx_Coefs_t LVM_TrebleBoostCoefs[]; + LVM_INT16 Offset; + LVM_INT16 EffectLevel = 0; + + /* + * Load the coefficients + */ + if ((pParams->TE_OperatingMode == LVM_TE_ON) && + (pParams->SampleRate >= TrebleBoostMinRate) && + (pParams->OperatingMode == LVM_MODE_ON) && + (pParams->TE_EffectLevel > 0)) + { + if((pParams->TE_EffectLevel == LVM_TE_LOW_MIPS) && + ((pParams->SpeakerType == LVM_HEADPHONES)|| + (pParams->SpeakerType == LVM_EX_HEADPHONES))) + { + pInstance->TE_Active = LVM_FALSE; + } + else + { + EffectLevel = pParams->TE_EffectLevel; + pInstance->TE_Active = LVM_TRUE; + } + + if(pInstance->TE_Active == LVM_TRUE) + { + /* + * Load the coefficients and enabled the treble boost + */ + Offset = (LVM_INT16)(EffectLevel - 1 + TrebleBoostSteps * (pParams->SampleRate - TrebleBoostMinRate)); + FO_2I_D16F32Css_LShx_TRC_WRA_01_Init(&pInstance->pTE_State->TrebleBoost_State, + &pInstance->pTE_Taps->TrebleBoost_Taps, + &LVM_TrebleBoostCoefs[Offset]); + + /* + * Clear the taps + */ + LoadConst_16((LVM_INT16)0, /* Value */ + (LVM_INT16 *)&pInstance->pTE_Taps->TrebleBoost_Taps, /* Destination */ + (LVM_UINT16)(sizeof(pInstance->pTE_Taps->TrebleBoost_Taps)/sizeof(LVM_INT16))); /* Number of words */ + } + } + else + { + /* + * Disable the treble boost + */ + pInstance->TE_Active = LVM_FALSE; + } + + return; +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVM_SetVolume */ +/* */ +/* DESCRIPTION: */ +/* Converts the input volume demand from dBs to linear. */ +/* */ +/* PARAMETERS: */ +/* pInstance Pointer to the instance */ +/* pParams Initialisation parameters */ +/* */ +/************************************************************************************/ +void LVM_SetVolume(LVM_Instance_t *pInstance, + LVM_ControlParams_t *pParams) +{ + + LVM_UINT16 dBShifts; /* 6dB shifts */ + LVM_UINT16 dBOffset; /* Table offset */ + LVM_INT16 Volume = 0; /* Required volume in dBs */ + + /* + * Limit the gain to the maximum allowed + */ + if (pParams->VC_EffectLevel > 0) + { + Volume = 0; + } + else + { + Volume = pParams->VC_EffectLevel; + } + + /* Compensate this volume in PSA plot */ + if(Volume > -60) /* Limit volume loss to PSA Limits*/ + pInstance->PSA_GainOffset=(LVM_INT16)(-Volume);/* Loss is compensated by Gain*/ + else + pInstance->PSA_GainOffset=(LVM_INT16)60;/* Loss is compensated by Gain*/ + + pInstance->VC_AVLFixedVolume = 0; + + /* + * Set volume control and AVL volumes according to headroom and volume user setting + */ + if(pParams->OperatingMode == LVM_MODE_ON) + { + /* Default Situation with no AVL and no RS */ + if(pParams->EQNB_OperatingMode == LVM_EQNB_ON) + { + if(Volume > -pInstance->Headroom) + Volume = (LVM_INT16)-pInstance->Headroom; + } + } + + /* + * Activate volume control if necessary + */ + pInstance->VC_Active = LVM_TRUE; + if (Volume != 0) + { + pInstance->VC_VolumedB = Volume; + } + else + { + pInstance->VC_VolumedB = 0; + } + + /* + * Calculate the required gain and shifts + */ + dBOffset = (LVM_UINT16)((-Volume) % 6); /* Get the dBs 0-5 */ + dBShifts = (LVM_UINT16)(Volume / -6); /* Get the 6dB shifts */ + + + /* + * Set the parameters + */ + if(dBShifts == 0) + { + LVC_Mixer_SetTarget(&pInstance->VC_Volume.MixerStream[0], + (LVM_INT32)LVM_VolumeTable[dBOffset]); + } + else + { + LVC_Mixer_SetTarget(&pInstance->VC_Volume.MixerStream[0], + (((LVM_INT32)LVM_VolumeTable[dBOffset])>>dBShifts)); + } + pInstance->VC_Volume.MixerStream[0].CallbackSet = 1; + if(pInstance->NoSmoothVolume == LVM_TRUE) + { + LVC_Mixer_SetTimeConstant(&pInstance->VC_Volume.MixerStream[0],0,pInstance->Params.SampleRate,2); + } + else + { + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->VC_Volume.MixerStream[0],LVM_VC_MIXER_TIME,pInstance->Params.SampleRate,2); + } +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVM_SetHeadroom */ +/* */ +/* DESCRIPTION: */ +/* Find suitable headroom based on EQ settings. */ +/* */ +/* PARAMETERS: */ +/* pInstance Pointer to the instance */ +/* pParams Initialisation parameters */ +/* */ +/* RETURNS: */ +/* void Nothing */ +/* */ +/* NOTES: */ +/* */ +/************************************************************************************/ +void LVM_SetHeadroom(LVM_Instance_t *pInstance, + LVM_ControlParams_t *pParams) +{ + LVM_INT16 ii, jj; + LVM_INT16 Headroom = 0; + LVM_INT16 MaxGain = 0; + + + if ((pParams->EQNB_OperatingMode == LVEQNB_ON) && (pInstance->HeadroomParams.Headroom_OperatingMode == LVM_HEADROOM_ON)) + { + /* Find typical headroom value */ + for(jj = 0; jj < pInstance->HeadroomParams.NHeadroomBands; jj++) + { + MaxGain = 0; + for( ii = 0; ii < pParams->EQNB_NBands; ii++) + { + if((pParams->pEQNB_BandDefinition[ii].Frequency >= pInstance->HeadroomParams.pHeadroomDefinition[jj].Limit_Low) && + (pParams->pEQNB_BandDefinition[ii].Frequency <= pInstance->HeadroomParams.pHeadroomDefinition[jj].Limit_High)) + { + if(pParams->pEQNB_BandDefinition[ii].Gain > MaxGain) + { + MaxGain = pParams->pEQNB_BandDefinition[ii].Gain; + } + } + } + + if((MaxGain - pInstance->HeadroomParams.pHeadroomDefinition[jj].Headroom_Offset) > Headroom){ + Headroom = (LVM_INT16)(MaxGain - pInstance->HeadroomParams.pHeadroomDefinition[jj].Headroom_Offset); + } + } + + /* Saturate */ + if(Headroom < 0) + Headroom = 0; + } + pInstance->Headroom = (LVM_UINT16)Headroom ; + +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_ApplyNewSettings */ +/* */ +/* DESCRIPTION: */ +/* Applies changes to parametres. This function makes no assumptions about what */ +/* each module needs for initialisation and hence passes all parameters to all the */ +/* the modules in turn. */ +/* */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* */ +/* RETURNS: */ +/* LVM_Success Succeeded */ +/* */ +/****************************************************************************************/ + +LVM_ReturnStatus_en LVM_ApplyNewSettings(LVM_Handle_t hInstance) +{ + LVM_Instance_t *pInstance =(LVM_Instance_t *)hInstance; + LVM_ControlParams_t LocalParams; + LVM_INT16 Count = 5; + + + /* + * Copy the new parameters but make sure they didn't change while copying + */ + do + { + pInstance->ControlPending = LVM_FALSE; + LocalParams = pInstance->NewParams; + pInstance->HeadroomParams = pInstance->NewHeadroomParams; + Count--; + } while ((pInstance->ControlPending != LVM_FALSE) && + (Count > 0)); + + /* Clear all internal data if format change*/ + if(LocalParams.SourceFormat != pInstance->Params.SourceFormat) + { + LVM_ClearAudioBuffers(pInstance); + pInstance->ControlPending = LVM_FALSE; + } + + /* + * Update the treble boost if required + */ + if ((pInstance->Params.SampleRate != LocalParams.SampleRate) || + (pInstance->Params.TE_EffectLevel != LocalParams.TE_EffectLevel) || + (pInstance->Params.TE_OperatingMode != LocalParams.TE_OperatingMode) || + (pInstance->Params.OperatingMode != LocalParams.OperatingMode) || + (pInstance->Params.SpeakerType != LocalParams.SpeakerType)) + { + LVM_SetTrebleBoost(pInstance, + &LocalParams); + } + + /* + * Update the headroom if required + */ + LVM_SetHeadroom(pInstance, /* Instance pointer */ + &LocalParams); /* New parameters */ + + /* + * Update the volume if required + */ + { + LVM_SetVolume(pInstance, /* Instance pointer */ + &LocalParams); /* New parameters */ + } + /* Apply balance changes*/ + if(pInstance->Params.VC_Balance != LocalParams.VC_Balance) + { + /* Configure Mixer module for gradual changes to volume*/ + if(LocalParams.VC_Balance < 0) + { + LVM_INT32 Target; + /* Drop in right channel volume*/ + Target = LVM_MAXINT_16; + LVC_Mixer_SetTarget(&pInstance->VC_BalanceMix.MixerStream[0],Target); + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->VC_BalanceMix.MixerStream[0],LVM_VC_MIXER_TIME,LocalParams.SampleRate,1); + + Target = dB_to_Lin32((LVM_INT16)(LocalParams.VC_Balance<<4)); + LVC_Mixer_SetTarget(&pInstance->VC_BalanceMix.MixerStream[1],Target); + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->VC_BalanceMix.MixerStream[1],LVM_VC_MIXER_TIME,LocalParams.SampleRate,1); + } + else if(LocalParams.VC_Balance >0) + { + LVM_INT32 Target; + /* Drop in left channel volume*/ + Target = dB_to_Lin32((LVM_INT16)((-LocalParams.VC_Balance)<<4)); + LVC_Mixer_SetTarget(&pInstance->VC_BalanceMix.MixerStream[0],Target); + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->VC_BalanceMix.MixerStream[0],LVM_VC_MIXER_TIME,LocalParams.SampleRate,1); + + Target = LVM_MAXINT_16; + LVC_Mixer_SetTarget(&pInstance->VC_BalanceMix.MixerStream[1],Target); + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->VC_BalanceMix.MixerStream[1],LVM_VC_MIXER_TIME,LocalParams.SampleRate,1); + } + else + { + LVM_INT32 Target; + /* No drop*/ + Target = LVM_MAXINT_16; + LVC_Mixer_SetTarget(&pInstance->VC_BalanceMix.MixerStream[0],Target); + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->VC_BalanceMix.MixerStream[0],LVM_VC_MIXER_TIME,LocalParams.SampleRate,1); + + LVC_Mixer_SetTarget(&pInstance->VC_BalanceMix.MixerStream[1],Target); + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->VC_BalanceMix.MixerStream[1],LVM_VC_MIXER_TIME,LocalParams.SampleRate,1); + } + } + /* + * Update the bass enhancement + */ + { + LVDBE_ReturnStatus_en DBE_Status; + LVDBE_Params_t DBE_Params; + LVDBE_Handle_t *hDBEInstance = pInstance->hDBEInstance; + + + /* + * Set the new parameters + */ + if(LocalParams.OperatingMode == LVM_MODE_OFF) + { + DBE_Params.OperatingMode = LVDBE_OFF; + } + else + { + DBE_Params.OperatingMode = (LVDBE_Mode_en)LocalParams.BE_OperatingMode; + } + DBE_Params.SampleRate = (LVDBE_Fs_en)LocalParams.SampleRate; + DBE_Params.EffectLevel = LocalParams.BE_EffectLevel; + DBE_Params.CentreFrequency = (LVDBE_CentreFreq_en)LocalParams.BE_CentreFreq; + DBE_Params.HPFSelect = (LVDBE_FilterSelect_en)LocalParams.BE_HPF; + DBE_Params.HeadroomdB = 0; + DBE_Params.VolumeControl = LVDBE_VOLUME_OFF; + DBE_Params.VolumedB = 0; + + /* + * Make the changes + */ + DBE_Status = LVDBE_Control(hDBEInstance, + &DBE_Params); + + + /* + * Quit if the changes were not accepted + */ + if (DBE_Status != LVDBE_SUCCESS) + { + return((LVM_ReturnStatus_en)DBE_Status); + } + + + /* + * Set the control flag + */ + pInstance->DBE_Active = LVM_TRUE; + } + + /* + * Update the N-Band Equaliser + */ + { + LVEQNB_ReturnStatus_en EQNB_Status; + LVEQNB_Params_t EQNB_Params; + LVEQNB_Handle_t *hEQNBInstance = pInstance->hEQNBInstance; + + + /* + * Set the new parameters + */ + + if(LocalParams.OperatingMode == LVM_MODE_OFF) + { + EQNB_Params.OperatingMode = LVEQNB_BYPASS; + } + else + { + EQNB_Params.OperatingMode = (LVEQNB_Mode_en)LocalParams.EQNB_OperatingMode; + } + + EQNB_Params.SampleRate = (LVEQNB_Fs_en)LocalParams.SampleRate; + EQNB_Params.NBands = LocalParams.EQNB_NBands; + EQNB_Params.pBandDefinition = (LVEQNB_BandDef_t *)LocalParams.pEQNB_BandDefinition; + if (LocalParams.SourceFormat == LVM_STEREO) /* Mono format not supported */ + { + EQNB_Params.SourceFormat = LVEQNB_STEREO; + } + else + { + EQNB_Params.SourceFormat = LVEQNB_MONOINSTEREO; /* Force to Mono-in-Stereo mode */ + } + + + /* + * Set the control flag + */ + if ((LocalParams.OperatingMode == LVM_MODE_ON) && + (LocalParams.EQNB_OperatingMode == LVM_EQNB_ON)) + { + pInstance->EQNB_Active = LVM_TRUE; + } + else + { + EQNB_Params.OperatingMode = LVEQNB_BYPASS; + } + + /* + * Make the changes + */ + EQNB_Status = LVEQNB_Control(hEQNBInstance, + &EQNB_Params); + + + /* + * Quit if the changes were not accepted + */ + if (EQNB_Status != LVEQNB_SUCCESS) + { + return((LVM_ReturnStatus_en)EQNB_Status); + } + + } + + + /* + * Update concert sound + */ + { + LVCS_ReturnStatus_en CS_Status; + LVCS_Params_t CS_Params; + LVCS_Handle_t *hCSInstance = pInstance->hCSInstance; + LVM_Mode_en CompressorMode=LVM_MODE_ON; + + /* + * Set the new parameters + */ + if(LocalParams.VirtualizerOperatingMode == LVM_MODE_ON) + { + CS_Params.OperatingMode = LVCS_ON; + } + else + { + CS_Params.OperatingMode = LVCS_OFF; + } + + if((LocalParams.TE_OperatingMode == LVM_TE_ON) && (LocalParams.TE_EffectLevel == LVM_TE_LOW_MIPS)) + { + CS_Params.SpeakerType = LVCS_EX_HEADPHONES; + } + else + { + CS_Params.SpeakerType = LVCS_HEADPHONES; + } + + if (LocalParams.SourceFormat == LVM_STEREO) /* Mono format not supported */ + { + CS_Params.SourceFormat = LVCS_STEREO; + } + else + { + CS_Params.SourceFormat = LVCS_MONOINSTEREO; /* Force to Mono-in-Stereo mode */ + } + CS_Params.SampleRate = LocalParams.SampleRate; + CS_Params.ReverbLevel = LocalParams.VirtualizerReverbLevel; + CS_Params.EffectLevel = LocalParams.CS_EffectLevel; + + + /* + * Set the control flag + */ + if ((LocalParams.OperatingMode == LVM_MODE_ON) && + (LocalParams.VirtualizerOperatingMode != LVCS_OFF)) + { + pInstance->CS_Active = LVM_TRUE; + } + else + { + CS_Params.OperatingMode = LVCS_OFF; + } + + CS_Params.CompressorMode=CompressorMode; + + /* + * Make the changes + */ + CS_Status = LVCS_Control(hCSInstance, + &CS_Params); + + + /* + * Quit if the changes were not accepted + */ + if (CS_Status != LVCS_SUCCESS) + { + return((LVM_ReturnStatus_en)CS_Status); + } + + } + + /* + * Update the Power Spectrum Analyser + */ + { + LVPSA_RETURN PSA_Status; + LVPSA_ControlParams_t PSA_Params; + pLVPSA_Handle_t *hPSAInstance = pInstance->hPSAInstance; + + + /* + * Set the new parameters + */ + PSA_Params.Fs = LocalParams.SampleRate; + PSA_Params.LevelDetectionSpeed = (LVPSA_LevelDetectSpeed_en)LocalParams.PSA_PeakDecayRate; + + /* + * Make the changes + */ + if(pInstance->InstParams.PSA_Included==LVM_PSA_ON) + { + PSA_Status = LVPSA_Control(hPSAInstance, + &PSA_Params); + + if (PSA_Status != LVPSA_OK) + { + return((LVM_ReturnStatus_en)PSA_Status); + } + + /* + * Apply new settings + */ + PSA_Status = LVPSA_ApplyNewSettings ((LVPSA_InstancePr_t*)hPSAInstance); + if(PSA_Status != LVPSA_OK) + { + return((LVM_ReturnStatus_en)PSA_Status); + } + } + } + + /* + * Update the parameters and clear the flag + */ + pInstance->Params = LocalParams; + + + return(LVM_SUCCESS); +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_SetHeadroomParams */ +/* */ +/* DESCRIPTION: */ +/* This function is used to set the automatiuc headroom management parameters. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pHeadroomParams Pointer to headroom parameter structure */ +/* */ +/* RETURNS: */ +/* LVM_Success Succeeded */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ + +LVM_ReturnStatus_en LVM_SetHeadroomParams(LVM_Handle_t hInstance, + LVM_HeadroomParams_t *pHeadroomParams) +{ + LVM_Instance_t *pInstance =(LVM_Instance_t *)hInstance; + LVM_UINT16 ii, NBands; + + /* Check for NULL pointers */ + if ((hInstance == LVM_NULL) || (pHeadroomParams == LVM_NULL)) + { + return (LVM_NULLADDRESS); + } + if ((pHeadroomParams->NHeadroomBands != 0) && (pHeadroomParams->pHeadroomDefinition == LVM_NULL)) + { + return (LVM_NULLADDRESS); + } + + /* Consider only the LVM_HEADROOM_MAX_NBANDS first bands*/ + if (pHeadroomParams->NHeadroomBands > LVM_HEADROOM_MAX_NBANDS) + { + NBands = LVM_HEADROOM_MAX_NBANDS; + } + else + { + NBands = pHeadroomParams->NHeadroomBands; + } + pInstance->NewHeadroomParams.NHeadroomBands = NBands; + + /* Copy settings in memory */ + for(ii = 0; ii < NBands; ii++) + { + pInstance->pHeadroom_BandDefs[ii] = pHeadroomParams->pHeadroomDefinition[ii]; + } + + pInstance->NewHeadroomParams.pHeadroomDefinition = pInstance->pHeadroom_BandDefs; + pInstance->NewHeadroomParams.Headroom_OperatingMode = pHeadroomParams->Headroom_OperatingMode; + pInstance->ControlPending = LVM_TRUE; + + return(LVM_SUCCESS); +} + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_GetHeadroomParams */ +/* */ +/* DESCRIPTION: */ +/* This function is used to get the automatic headroom management parameters. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pHeadroomParams Pointer to headroom parameter structure (output) */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_NULLADDRESS When hInstance or pHeadroomParams are NULL */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ + +LVM_ReturnStatus_en LVM_GetHeadroomParams(LVM_Handle_t hInstance, + LVM_HeadroomParams_t *pHeadroomParams) +{ + LVM_Instance_t *pInstance =(LVM_Instance_t *)hInstance; + LVM_UINT16 ii; + + /* Check for NULL pointers */ + if ((hInstance == LVM_NULL) || (pHeadroomParams == LVM_NULL)) + { + return (LVM_NULLADDRESS); + } + + pHeadroomParams->NHeadroomBands = pInstance->NewHeadroomParams.NHeadroomBands; + + + /* Copy settings in memory */ + for(ii = 0; ii < pInstance->NewHeadroomParams.NHeadroomBands; ii++) + { + pInstance->pHeadroom_UserDefs[ii] = pInstance->pHeadroom_BandDefs[ii]; + } + + + pHeadroomParams->pHeadroomDefinition = pInstance->pHeadroom_UserDefs; + pHeadroomParams->Headroom_OperatingMode = pInstance->NewHeadroomParams.Headroom_OperatingMode; + return(LVM_SUCCESS); +} + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_AlgoCallBack */ +/* */ +/* DESCRIPTION: */ +/* This is the callback function of the algorithm. */ +/* */ +/* PARAMETERS: */ +/* pBundleHandle Pointer to the Instance Handle */ +/* pData Pointer to the data */ +/* callbackId ID of the callback */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ +LVM_INT32 LVM_AlgoCallBack( void *pBundleHandle, + void *pData, + LVM_INT16 callbackId) +{ + LVM_Instance_t *pInstance =(LVM_Instance_t *)pBundleHandle; + + (void) pData; + + switch(callbackId & 0xFF00){ + case ALGORITHM_CS_ID: + switch(callbackId & 0x00FF) + { + case LVCS_EVENT_ALGOFF: + pInstance->CS_Active = LVM_FALSE; + break; + default: + break; + } + break; + case ALGORITHM_EQNB_ID: + switch(callbackId & 0x00FF) + { + case LVEQNB_EVENT_ALGOFF: + pInstance->EQNB_Active = LVM_FALSE; + break; + default: + break; + } + break; + default: + break; + } + + return 0; +} + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_VCCallBack */ +/* */ +/* DESCRIPTION: */ +/* This is the callback function of the Volume control. */ +/* */ +/* PARAMETERS: */ +/* pBundleHandle Pointer to the Instance Handle */ +/* pGeneralPurpose Pointer to the data */ +/* CallBackParam ID of the callback */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ +LVM_INT32 LVM_VCCallBack(void* pBundleHandle, + void* pGeneralPurpose, + short CallBackParam) +{ + LVM_Instance_t *pInstance =(LVM_Instance_t *)pBundleHandle; + LVM_INT32 Target; + + (void) pGeneralPurpose; + (void) CallBackParam; + + /* When volume mixer has reached 0 dB target then stop it to avoid + unnecessary processing. */ + Target = LVC_Mixer_GetTarget(&pInstance->VC_Volume.MixerStream[0]); + + if(Target == 0x7FFF) + { + pInstance->VC_Active = LVM_FALSE; + } + return 1; +} diff --git a/media/libeffects/lvm/lib/Bundle/src/LVM_Init.c b/media/libeffects/lvm/lib/Bundle/src/LVM_Init.c new file mode 100755 index 0000000..7ac5685 --- /dev/null +++ b/media/libeffects/lvm/lib/Bundle/src/LVM_Init.c @@ -0,0 +1,1003 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: nxp007753 $ + $Revision: 1255 $ + $Date: 2010-07-16 17:07:29 +0200 (Fri, 16 Jul 2010) $ + +*************************************************************************************/ + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVM_Private.h" +#include "LVM_Tables.h" +#include "VectorArithmetic.h" +#include "InstAlloc.h" + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_GetMemoryTable */ +/* */ +/* 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 default capabilities */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_NULLADDRESS When one of pMemoryTable or pInstParams is NULL */ +/* LVM_OUTOFRANGE When any of the Instance parameters are out of range */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVM_Process function */ +/* 2. The scratch memory is the largest required by any of the sub-modules plus any */ +/* additional scratch requirements of the bundle */ +/* */ +/****************************************************************************************/ + +LVM_ReturnStatus_en LVM_GetMemoryTable(LVM_Handle_t hInstance, + LVM_MemTab_t *pMemoryTable, + LVM_InstParams_t *pInstParams) +{ + + LVM_Instance_t *pInstance = (LVM_Instance_t *)hInstance; + LVM_UINT32 AlgScratchSize; + LVM_UINT32 BundleScratchSize; + LVM_UINT16 InternalBlockSize; + INST_ALLOC AllocMem[LVM_NR_MEMORY_REGIONS]; + LVM_INT16 i; + + + /* + * Check parameters + */ + if(pMemoryTable == LVM_NULL) + { + return LVM_NULLADDRESS; + } + + + /* + * Return memory table if the instance has already been created + */ + if (hInstance != LVM_NULL) + { + /* Read back memory allocation table */ + *pMemoryTable = pInstance->MemoryTable; + return(LVM_SUCCESS); + } + + if(pInstParams == LVM_NULL) + { + return LVM_NULLADDRESS; + } + + /* + * Power Spectrum Analyser + */ + if(pInstParams->PSA_Included > LVM_PSA_ON) + { + return (LVM_OUTOFRANGE); + } + + /* + * Check the instance parameters + */ + if( (pInstParams->BufferMode != LVM_MANAGED_BUFFERS) && (pInstParams->BufferMode != LVM_UNMANAGED_BUFFERS) ) + { + return (LVM_OUTOFRANGE); + } + + /* N-Band Equalizer */ + if( pInstParams->EQNB_NumBands > 32 ) + { + return (LVM_OUTOFRANGE); + } + + if(pInstParams->BufferMode == LVM_MANAGED_BUFFERS) + { + if( (pInstParams->MaxBlockSize < LVM_MIN_MAXBLOCKSIZE ) || (pInstParams->MaxBlockSize > LVM_MANAGED_MAX_MAXBLOCKSIZE ) ) + { + return (LVM_OUTOFRANGE); + } + } + else + { + if( (pInstParams->MaxBlockSize < LVM_MIN_MAXBLOCKSIZE ) || (pInstParams->MaxBlockSize > LVM_UNMANAGED_MAX_MAXBLOCKSIZE) ) + { + return (LVM_OUTOFRANGE); + } + } + + /* + * Initialise the AllocMem structures + */ + for (i=0; iMaxBlockSize) & MIN_INTERNAL_BLOCKMASK); /* Force to a multiple of MIN_INTERNAL_BLOCKSIZE */ + + if (InternalBlockSize < MIN_INTERNAL_BLOCKSIZE) + { + InternalBlockSize = MIN_INTERNAL_BLOCKSIZE; + } + + /* Maximum Internal Black Size should not be more than MAX_INTERNAL_BLOCKSIZE*/ + if(InternalBlockSize > MAX_INTERNAL_BLOCKSIZE) + { + InternalBlockSize = MAX_INTERNAL_BLOCKSIZE; + } + + /* + * Bundle requirements + */ + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_SLOW_DATA], + sizeof(LVM_Instance_t)); + + + /* + * Set the algorithm and bundle scratch requirements + */ + AlgScratchSize = 0; + if (pInstParams->BufferMode == LVM_MANAGED_BUFFERS) + { + BundleScratchSize = 6 * (MIN_INTERNAL_BLOCKSIZE + InternalBlockSize) * sizeof(LVM_INT16); + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST], /* Scratch buffer */ + BundleScratchSize); + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_SLOW_DATA], + sizeof(LVM_Buffer_t)); + } + + /* + * Treble Enhancement requirements + */ + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + sizeof(LVM_TE_Data_t)); + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF], + sizeof(LVM_TE_Coefs_t)); + + /* + * N-Band Equalizer requirements + */ + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], /* Local storage */ + (pInstParams->EQNB_NumBands * sizeof(LVM_EQNB_BandDef_t))); + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], /* User storage */ + (pInstParams->EQNB_NumBands * sizeof(LVM_EQNB_BandDef_t))); + + /* + * Concert Sound requirements + */ + { + LVCS_MemTab_t CS_MemTab; + LVCS_Capabilities_t CS_Capabilities; + + /* + * Set the capabilities + */ + CS_Capabilities.MaxBlockSize = InternalBlockSize; + + /* + * Get the memory requirements + */ + LVCS_Memory(LVM_NULL, + &CS_MemTab, + &CS_Capabilities); + + /* + * Update the memory allocation structures + */ + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + CS_MemTab.Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].Size); + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF], + CS_MemTab.Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].Size); + if (CS_MemTab.Region[LVM_MEMREGION_TEMPORARY_FAST].Size > AlgScratchSize) AlgScratchSize = CS_MemTab.Region[LVM_MEMREGION_TEMPORARY_FAST].Size; + + } + + + /* + * Dynamic Bass Enhancement requirements + */ + { + LVDBE_MemTab_t DBE_MemTab; + LVDBE_Capabilities_t DBE_Capabilities; + + /* + * Set the capabilities + */ + DBE_Capabilities.SampleRate = LVDBE_CAP_FS_8000 | LVDBE_CAP_FS_11025 | LVDBE_CAP_FS_12000 | LVDBE_CAP_FS_16000 | LVDBE_CAP_FS_22050 | LVDBE_CAP_FS_24000 | LVDBE_CAP_FS_32000 | LVDBE_CAP_FS_44100 | LVDBE_CAP_FS_48000; + DBE_Capabilities.CentreFrequency = LVDBE_CAP_CENTRE_55Hz | LVDBE_CAP_CENTRE_55Hz | LVDBE_CAP_CENTRE_66Hz | LVDBE_CAP_CENTRE_78Hz | LVDBE_CAP_CENTRE_90Hz; + DBE_Capabilities.MaxBlockSize = InternalBlockSize; + + /* + * Get the memory requirements + */ + LVDBE_Memory(LVM_NULL, + &DBE_MemTab, + + &DBE_Capabilities); + /* + * Update the bundle table + */ + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + DBE_MemTab.Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].Size); + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF], + DBE_MemTab.Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].Size); + if (DBE_MemTab.Region[LVM_MEMREGION_TEMPORARY_FAST].Size > AlgScratchSize) AlgScratchSize = DBE_MemTab.Region[LVM_MEMREGION_TEMPORARY_FAST].Size; + + } + + + /* + * N-Band equaliser requirements + */ + { + LVEQNB_MemTab_t EQNB_MemTab; /* For N-Band Equaliser */ + LVEQNB_Capabilities_t EQNB_Capabilities; + + /* + * Set the capabilities + */ + EQNB_Capabilities.SampleRate = LVEQNB_CAP_FS_8000 | LVEQNB_CAP_FS_11025 | LVEQNB_CAP_FS_12000 | LVEQNB_CAP_FS_16000 | LVEQNB_CAP_FS_22050 | LVEQNB_CAP_FS_24000 | LVEQNB_CAP_FS_32000 | LVEQNB_CAP_FS_44100 | LVEQNB_CAP_FS_48000; + EQNB_Capabilities.SourceFormat = LVEQNB_CAP_STEREO | LVEQNB_CAP_MONOINSTEREO; + EQNB_Capabilities.MaxBlockSize = InternalBlockSize; + EQNB_Capabilities.MaxBands = pInstParams->EQNB_NumBands; + + /* + * Get the memory requirements + */ + LVEQNB_Memory(LVM_NULL, + &EQNB_MemTab, + &EQNB_Capabilities); + + /* + * Update the bundle table + */ + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + EQNB_MemTab.Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].Size); + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF], + EQNB_MemTab.Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].Size); + if (EQNB_MemTab.Region[LVM_MEMREGION_TEMPORARY_FAST].Size > AlgScratchSize) AlgScratchSize = EQNB_MemTab.Region[LVM_MEMREGION_TEMPORARY_FAST].Size; + + } + + /* + * Headroom management memory allocation + */ + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + (LVM_HEADROOM_MAX_NBANDS * sizeof(LVM_HeadroomBandDef_t))); + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + (LVM_HEADROOM_MAX_NBANDS * sizeof(LVM_HeadroomBandDef_t))); + + + /* + * Spectrum Analyzer memory requirements + */ + { + pLVPSA_Handle_t hPSAInst = LVM_NULL; + LVPSA_MemTab_t PSA_MemTab; + LVPSA_InitParams_t PSA_InitParams; + LVPSA_FilterParam_t FiltersParams[9]; + LVPSA_RETURN PSA_Status; + + if(pInstParams->PSA_Included == LVM_PSA_ON) + { + PSA_InitParams.SpectralDataBufferDuration = (LVM_UINT16) 500; + PSA_InitParams.MaxInputBlockSize = (LVM_UINT16) 1000; + PSA_InitParams.nBands = (LVM_UINT16) 9; + + PSA_InitParams.pFiltersParams = &FiltersParams[0]; + for(i = 0; i < PSA_InitParams.nBands; i++) + { + FiltersParams[i].CenterFrequency = (LVM_UINT16) 1000; + FiltersParams[i].QFactor = (LVM_UINT16) 25; + FiltersParams[i].PostGain = (LVM_INT16) 0; + } + + /* + * Get the memory requirements + */ + PSA_Status = LVPSA_Memory (hPSAInst, + &PSA_MemTab, + &PSA_InitParams); + + if (PSA_Status != LVPSA_OK) + { + return((LVM_ReturnStatus_en) LVM_ALGORITHMPSA); + } + + /* + * Update the bundle table + */ + /* Slow Data */ + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_SLOW_DATA], + PSA_MemTab.Region[LVM_PERSISTENT_SLOW_DATA].Size); + + /* Fast Data */ + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + PSA_MemTab.Region[LVM_PERSISTENT_FAST_DATA].Size); + + /* Fast Coef */ + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF], + PSA_MemTab.Region[LVM_PERSISTENT_FAST_COEF].Size); + + /* Fast Temporary */ + InstAlloc_AddMember(&AllocMem[LVM_TEMPORARY_FAST], + MAX_INTERNAL_BLOCKSIZE * sizeof(LVM_INT16)); + + if (PSA_MemTab.Region[LVM_TEMPORARY_FAST].Size > AlgScratchSize) + { + AlgScratchSize = PSA_MemTab.Region[LVM_TEMPORARY_FAST].Size; + } + } + } + + /* + * Return the memory table + */ + pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_SLOW_DATA].Size = InstAlloc_GetTotal(&AllocMem[LVM_MEMREGION_PERSISTENT_SLOW_DATA]); + pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_SLOW_DATA].Type = LVM_PERSISTENT_SLOW_DATA; + pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_SLOW_DATA].pBaseAddress = LVM_NULL; + + pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].Size = InstAlloc_GetTotal(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA]); + pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].Type = LVM_PERSISTENT_FAST_DATA; + pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].pBaseAddress = LVM_NULL; + if (pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].Size < 4) + { + pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].Size = 0; + } + + pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].Size = InstAlloc_GetTotal(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF]); + pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].Type = LVM_PERSISTENT_FAST_COEF; + pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].pBaseAddress = LVM_NULL; + if (pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].Size < 4) + { + pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].Size = 0; + } + + InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST], + AlgScratchSize); + pMemoryTable->Region[LVM_MEMREGION_TEMPORARY_FAST].Size = InstAlloc_GetTotal(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST]); + pMemoryTable->Region[LVM_MEMREGION_TEMPORARY_FAST].Type = LVM_TEMPORARY_FAST; + pMemoryTable->Region[LVM_MEMREGION_TEMPORARY_FAST].pBaseAddress = LVM_NULL; + if (pMemoryTable->Region[LVM_MEMREGION_TEMPORARY_FAST].Size < 4) + { + pMemoryTable->Region[LVM_MEMREGION_TEMPORARY_FAST].Size = 0; + } + + return(LVM_SUCCESS); + +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_GetInstanceHandle */ +/* */ +/* DESCRIPTION: */ +/* This function is used to create a bundle instance. It returns the created instance */ +/* handle through phInstance. All parameters are set to their default, inactive state. */ +/* */ +/* PARAMETERS: */ +/* phInstance pointer to the instance handle */ +/* pMemoryTable Pointer to the memory definition table */ +/* pInstParams Pointer to the initialisation capabilities */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Initialisation succeeded */ +/* LVM_OUTOFRANGE When any of the Instance parameters are out of range */ +/* LVM_NULLADDRESS When one of phInstance, pMemoryTable or pInstParams are NULL*/ +/* */ +/* NOTES: */ +/* 1. This function must not be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ + +LVM_ReturnStatus_en LVM_GetInstanceHandle(LVM_Handle_t *phInstance, + LVM_MemTab_t *pMemoryTable, + LVM_InstParams_t *pInstParams) +{ + + LVM_ReturnStatus_en Status = LVM_SUCCESS; + LVM_Instance_t *pInstance; + INST_ALLOC AllocMem[LVM_NR_MEMORY_REGIONS]; + LVM_INT16 i; + LVM_UINT16 InternalBlockSize; + LVM_INT32 BundleScratchSize; + + + /* + * Check valid points have been given + */ + if ((phInstance == LVM_NULL) || (pMemoryTable == LVM_NULL) || (pInstParams == LVM_NULL)) + { + return (LVM_NULLADDRESS); + } + + /* + * Check the memory table for NULL pointers + */ + for (i=0; iRegion[i].Size != 0) && + (pMemoryTable->Region[i].pBaseAddress==LVM_NULL)) + { + return(LVM_NULLADDRESS); + } + } + + /* + * Check the instance parameters + */ + if( (pInstParams->BufferMode != LVM_MANAGED_BUFFERS) && (pInstParams->BufferMode != LVM_UNMANAGED_BUFFERS) ) + { + return (LVM_OUTOFRANGE); + } + + if( pInstParams->EQNB_NumBands > 32 ) + { + return (LVM_OUTOFRANGE); + } + + if(pInstParams->BufferMode == LVM_MANAGED_BUFFERS) + { + if( (pInstParams->MaxBlockSize < LVM_MIN_MAXBLOCKSIZE ) || (pInstParams->MaxBlockSize > LVM_MANAGED_MAX_MAXBLOCKSIZE ) ) + { + return (LVM_OUTOFRANGE); + } + } + else + { + if( (pInstParams->MaxBlockSize < LVM_MIN_MAXBLOCKSIZE ) || (pInstParams->MaxBlockSize > LVM_UNMANAGED_MAX_MAXBLOCKSIZE) ) + { + return (LVM_OUTOFRANGE); + } + } + + if(pInstParams->PSA_Included > LVM_PSA_ON) + { + return (LVM_OUTOFRANGE); + } + + /* + * Initialise the AllocMem structures + */ + for (i=0; iRegion[i].pBaseAddress); + } + + + /* + * Set the instance handle + */ + *phInstance = (LVM_Handle_t)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_SLOW_DATA], + sizeof(LVM_Instance_t)); + pInstance =(LVM_Instance_t *)*phInstance; + + + /* + * Save the memory table, parameters and capabilities + */ + pInstance->MemoryTable = *pMemoryTable; + pInstance->InstParams = *pInstParams; + + + /* + * Set the bundle scratch memory and initialse the buffer management + */ + InternalBlockSize = (LVM_UINT16)((pInstParams->MaxBlockSize) & MIN_INTERNAL_BLOCKMASK); /* Force to a multiple of MIN_INTERNAL_BLOCKSIZE */ + if (InternalBlockSize < MIN_INTERNAL_BLOCKSIZE) + { + InternalBlockSize = MIN_INTERNAL_BLOCKSIZE; + } + + /* Maximum Internal Black Size should not be more than MAX_INTERNAL_BLOCKSIZE*/ + if(InternalBlockSize > MAX_INTERNAL_BLOCKSIZE) + { + InternalBlockSize = MAX_INTERNAL_BLOCKSIZE; + } + pInstance->InternalBlockSize = (LVM_INT16)InternalBlockSize; + + + /* + * Common settings for managed and unmanaged buffers + */ + pInstance->SamplesToProcess = 0; /* No samples left to process */ + if (pInstParams->BufferMode == LVM_MANAGED_BUFFERS) + { + /* + * Managed buffers required + */ + pInstance->pBufferManagement = InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_SLOW_DATA], + sizeof(LVM_Buffer_t)); + BundleScratchSize = (LVM_INT32)(6 * (MIN_INTERNAL_BLOCKSIZE + InternalBlockSize) * sizeof(LVM_INT16)); + pInstance->pBufferManagement->pScratch = InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST], /* Scratch 1 buffer */ + (LVM_UINT32)BundleScratchSize); + + LoadConst_16(0, /* Clear the input delay buffer */ + (LVM_INT16 *)&pInstance->pBufferManagement->InDelayBuffer, + (LVM_INT16)(2 * MIN_INTERNAL_BLOCKSIZE)); + pInstance->pBufferManagement->InDelaySamples = MIN_INTERNAL_BLOCKSIZE; /* Set the number of delay samples */ + pInstance->pBufferManagement->OutDelaySamples = 0; /* No samples in the output buffer */ + pInstance->pBufferManagement->BufferState = LVM_FIRSTCALL; /* Set the state ready for the first call */ + } + + + /* + * Set default parameters + */ + pInstance->Params.OperatingMode = LVM_MODE_OFF; + pInstance->Params.SampleRate = LVM_FS_8000; + pInstance->Params.SourceFormat = LVM_MONO; + pInstance->Params.SpeakerType = LVM_HEADPHONES; + pInstance->Params.VC_EffectLevel = 0; + pInstance->Params.VC_Balance = 0; + + /* + * Set callback + */ + pInstance->CallBack = LVM_AlgoCallBack; + + + /* + * DC removal filter + */ + DC_2I_D16_TRC_WRA_01_Init(&pInstance->DC_RemovalInstance); + + + /* + * Treble Enhancement + */ + pInstance->pTE_Taps = (LVM_TE_Data_t *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + sizeof(LVM_TE_Data_t)); + + pInstance->pTE_State = (LVM_TE_Coefs_t *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF], + sizeof(LVM_TE_Coefs_t)); + pInstance->Params.TE_OperatingMode = LVM_TE_OFF; + pInstance->Params.TE_EffectLevel = 0; + pInstance->TE_Active = LVM_FALSE; + + + /* + * Set the volume control and initialise Current to Target + */ + pInstance->VC_Volume.MixerStream[0].CallbackParam = 0; + pInstance->VC_Volume.MixerStream[0].CallbackSet = 0; + pInstance->VC_Volume.MixerStream[0].pCallbackHandle = pInstance; + pInstance->VC_Volume.MixerStream[0].pCallBack = LVM_VCCallBack; + + /* In managed buffering, start with low signal level as delay in buffer management causes a click*/ + if (pInstParams->BufferMode == LVM_MANAGED_BUFFERS) + { + LVC_Mixer_Init(&pInstance->VC_Volume.MixerStream[0],0,0); + } + else + { + LVC_Mixer_Init(&pInstance->VC_Volume.MixerStream[0],LVM_MAXINT_16,LVM_MAXINT_16); + } + + LVC_Mixer_SetTimeConstant(&pInstance->VC_Volume.MixerStream[0],0,LVM_FS_8000,2); + + pInstance->VC_VolumedB = 0; + pInstance->VC_AVLFixedVolume = 0; + pInstance->VC_Active = LVM_FALSE; + + pInstance->VC_BalanceMix.MixerStream[0].CallbackParam = 0; + pInstance->VC_BalanceMix.MixerStream[0].CallbackSet = 0; + pInstance->VC_BalanceMix.MixerStream[0].pCallbackHandle = pInstance; + pInstance->VC_BalanceMix.MixerStream[0].pCallBack = LVM_VCCallBack; + LVC_Mixer_Init(&pInstance->VC_BalanceMix.MixerStream[0],LVM_MAXINT_16,LVM_MAXINT_16); + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->VC_BalanceMix.MixerStream[0],LVM_VC_MIXER_TIME,LVM_FS_8000,2); + + pInstance->VC_BalanceMix.MixerStream[1].CallbackParam = 0; + pInstance->VC_BalanceMix.MixerStream[1].CallbackSet = 0; + pInstance->VC_BalanceMix.MixerStream[1].pCallbackHandle = pInstance; + pInstance->VC_BalanceMix.MixerStream[1].pCallBack = LVM_VCCallBack; + LVC_Mixer_Init(&pInstance->VC_BalanceMix.MixerStream[1],LVM_MAXINT_16,LVM_MAXINT_16); + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->VC_BalanceMix.MixerStream[1],LVM_VC_MIXER_TIME,LVM_FS_8000,2); + /* + * Set the default EQNB pre-gain and pointer to the band definitions + */ + pInstance->pEQNB_BandDefs = InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + (pInstParams->EQNB_NumBands * sizeof(LVM_EQNB_BandDef_t))); + pInstance->pEQNB_UserDefs = InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + (pInstParams->EQNB_NumBands * sizeof(LVM_EQNB_BandDef_t))); + + + /* + * Initialise the Concert Sound module + */ + { + LVCS_Handle_t hCSInstance; /* Instance handle */ + LVCS_MemTab_t CS_MemTab; /* Memory table */ + LVCS_Capabilities_t CS_Capabilities; /* Initial capabilities */ + LVCS_ReturnStatus_en LVCS_Status; /* Function call status */ + + /* + * Set default parameters + */ + pInstance->Params.VirtualizerReverbLevel = 100; + pInstance->Params.VirtualizerType = LVM_CONCERTSOUND; + pInstance->Params.VirtualizerOperatingMode = LVM_MODE_OFF; + pInstance->CS_Active = LVM_FALSE; + + /* + * Set the initialisation capabilities + */ + CS_Capabilities.MaxBlockSize = (LVM_UINT16)InternalBlockSize; + CS_Capabilities.CallBack = pInstance->CallBack; + CS_Capabilities.pBundleInstance = (void*)pInstance; + + + /* + * Get the memory requirements and then set the address pointers, forcing alignment + */ + LVCS_Status = LVCS_Memory(LVM_NULL, /* Get the memory requirements */ + &CS_MemTab, + &CS_Capabilities); + CS_MemTab.Region[LVCS_MEMREGION_PERSISTENT_SLOW_DATA].pBaseAddress = &pInstance->CS_Instance; + CS_MemTab.Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + CS_MemTab.Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].Size); + CS_MemTab.Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF], + CS_MemTab.Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].Size); + CS_MemTab.Region[LVCS_MEMREGION_TEMPORARY_FAST].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST], + 0); + + /* + * Initialise the Concert Sound instance and save the instance handle + */ + hCSInstance = LVM_NULL; /* Set to NULL to return handle */ + LVCS_Status = LVCS_Init(&hCSInstance, /* Initiailse */ + &CS_MemTab, + &CS_Capabilities); + if (LVCS_Status != LVCS_SUCCESS) return((LVM_ReturnStatus_en)LVCS_Status); + pInstance->hCSInstance = hCSInstance; /* Save the instance handle */ + + } + + /* + * Initialise the Bass Enhancement module + */ + { + LVDBE_Handle_t hDBEInstance; /* Instance handle */ + LVDBE_MemTab_t DBE_MemTab; /* Memory table */ + LVDBE_Capabilities_t DBE_Capabilities; /* Initial capabilities */ + LVDBE_ReturnStatus_en LVDBE_Status; /* Function call status */ + + + /* + * Set the initialisation parameters + */ + pInstance->Params.BE_OperatingMode = LVM_BE_OFF; + pInstance->Params.BE_CentreFreq = LVM_BE_CENTRE_55Hz; + pInstance->Params.BE_EffectLevel = 0; + pInstance->Params.BE_HPF = LVM_BE_HPF_OFF; + + pInstance->DBE_Active = LVM_FALSE; + + + + /* + * Set the initialisation capabilities + */ + DBE_Capabilities.SampleRate = LVDBE_CAP_FS_8000 | LVDBE_CAP_FS_11025 | LVDBE_CAP_FS_12000 | LVDBE_CAP_FS_16000 | LVDBE_CAP_FS_22050 | LVDBE_CAP_FS_24000 | LVDBE_CAP_FS_32000 | LVDBE_CAP_FS_44100 | LVDBE_CAP_FS_48000; + DBE_Capabilities.CentreFrequency = LVDBE_CAP_CENTRE_55Hz | LVDBE_CAP_CENTRE_55Hz | LVDBE_CAP_CENTRE_66Hz | LVDBE_CAP_CENTRE_78Hz | LVDBE_CAP_CENTRE_90Hz; + DBE_Capabilities.MaxBlockSize = (LVM_UINT16)InternalBlockSize; + + + /* + * Get the memory requirements and then set the address pointers + */ + LVDBE_Status = LVDBE_Memory(LVM_NULL, /* Get the memory requirements */ + &DBE_MemTab, + &DBE_Capabilities); + DBE_MemTab.Region[LVDBE_MEMREGION_INSTANCE].pBaseAddress = &pInstance->DBE_Instance; + DBE_MemTab.Region[LVDBE_MEMREGION_PERSISTENT_DATA].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + DBE_MemTab.Region[LVDBE_MEMREGION_PERSISTENT_DATA].Size); + DBE_MemTab.Region[LVDBE_MEMREGION_PERSISTENT_COEF].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF], + DBE_MemTab.Region[LVDBE_MEMREGION_PERSISTENT_COEF].Size); + DBE_MemTab.Region[LVDBE_MEMREGION_SCRATCH].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST], + 0); + + + /* + * Initialise the Dynamic Bass Enhancement instance and save the instance handle + */ + hDBEInstance = LVM_NULL; /* Set to NULL to return handle */ + LVDBE_Status = LVDBE_Init(&hDBEInstance, /* Initiailse */ + &DBE_MemTab, + &DBE_Capabilities); + if (LVDBE_Status != LVDBE_SUCCESS) return((LVM_ReturnStatus_en)LVDBE_Status); + pInstance->hDBEInstance = hDBEInstance; /* Save the instance handle */ + } + + + /* + * Initialise the N-Band Equaliser module + */ + { + LVEQNB_Handle_t hEQNBInstance; /* Instance handle */ + LVEQNB_MemTab_t EQNB_MemTab; /* Memory table */ + LVEQNB_Capabilities_t EQNB_Capabilities; /* Initial capabilities */ + LVEQNB_ReturnStatus_en LVEQNB_Status; /* Function call status */ + + + /* + * Set the initialisation parameters + */ + pInstance->Params.EQNB_OperatingMode = LVM_EQNB_OFF; + pInstance->Params.EQNB_NBands = 0; + pInstance->Params.pEQNB_BandDefinition = LVM_NULL; + pInstance->EQNB_Active = LVM_FALSE; + + + /* + * Set the initialisation capabilities + */ + EQNB_Capabilities.SampleRate = LVEQNB_CAP_FS_8000 | LVEQNB_CAP_FS_11025 | LVEQNB_CAP_FS_12000 | LVEQNB_CAP_FS_16000 | LVEQNB_CAP_FS_22050 | LVEQNB_CAP_FS_24000 | LVEQNB_CAP_FS_32000 | LVEQNB_CAP_FS_44100 | LVEQNB_CAP_FS_48000; + EQNB_Capabilities.MaxBlockSize = (LVM_UINT16)InternalBlockSize; + EQNB_Capabilities.MaxBands = pInstParams->EQNB_NumBands; + EQNB_Capabilities.SourceFormat = LVEQNB_CAP_STEREO | LVEQNB_CAP_MONOINSTEREO; + EQNB_Capabilities.CallBack = pInstance->CallBack; + EQNB_Capabilities.pBundleInstance = (void*)pInstance; + + + /* + * Get the memory requirements and then set the address pointers, forcing alignment + */ + LVEQNB_Status = LVEQNB_Memory(LVM_NULL, /* Get the memory requirements */ + &EQNB_MemTab, + &EQNB_Capabilities); + EQNB_MemTab.Region[LVEQNB_MEMREGION_INSTANCE].pBaseAddress = &pInstance->EQNB_Instance; + EQNB_MemTab.Region[LVEQNB_MEMREGION_PERSISTENT_DATA].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + EQNB_MemTab.Region[LVEQNB_MEMREGION_PERSISTENT_DATA].Size); + EQNB_MemTab.Region[LVEQNB_MEMREGION_PERSISTENT_COEF].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF], + EQNB_MemTab.Region[LVEQNB_MEMREGION_PERSISTENT_COEF].Size); + EQNB_MemTab.Region[LVEQNB_MEMREGION_SCRATCH].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST], + 0); + + + /* + * Initialise the Dynamic Bass Enhancement instance and save the instance handle + */ + hEQNBInstance = LVM_NULL; /* Set to NULL to return handle */ + LVEQNB_Status = LVEQNB_Init(&hEQNBInstance, /* Initiailse */ + &EQNB_MemTab, + &EQNB_Capabilities); + if (LVEQNB_Status != LVEQNB_SUCCESS) return((LVM_ReturnStatus_en)LVEQNB_Status); + pInstance->hEQNBInstance = hEQNBInstance; /* Save the instance handle */ + } + + /* + * Headroom management memory allocation + */ + { + pInstance->pHeadroom_BandDefs = InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + (LVM_HEADROOM_MAX_NBANDS * sizeof(LVM_HeadroomBandDef_t))); + pInstance->pHeadroom_UserDefs = InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + (LVM_HEADROOM_MAX_NBANDS * sizeof(LVM_HeadroomBandDef_t))); + + /* Headroom management parameters initialisation */ + pInstance->NewHeadroomParams.NHeadroomBands = 2; + pInstance->NewHeadroomParams.pHeadroomDefinition = pInstance->pHeadroom_BandDefs; + pInstance->NewHeadroomParams.pHeadroomDefinition[0].Limit_Low = 20; + pInstance->NewHeadroomParams.pHeadroomDefinition[0].Limit_High = 4999; + pInstance->NewHeadroomParams.pHeadroomDefinition[0].Headroom_Offset = 3; + pInstance->NewHeadroomParams.pHeadroomDefinition[1].Limit_Low = 5000; + pInstance->NewHeadroomParams.pHeadroomDefinition[1].Limit_High = 24000; + pInstance->NewHeadroomParams.pHeadroomDefinition[1].Headroom_Offset = 4; + pInstance->NewHeadroomParams.Headroom_OperatingMode = LVM_HEADROOM_ON; + + pInstance->Headroom =0; + } + + + /* + * Initialise the PSA module + */ + { + pLVPSA_Handle_t hPSAInstance = LVM_NULL; /* Instance handle */ + LVPSA_MemTab_t PSA_MemTab; + LVPSA_RETURN PSA_Status; /* Function call status */ + LVPSA_FilterParam_t FiltersParams[9]; + + if(pInstParams->PSA_Included==LVM_PSA_ON) + { + pInstance->PSA_InitParams.SpectralDataBufferDuration = (LVM_UINT16) 500; + pInstance->PSA_InitParams.MaxInputBlockSize = (LVM_UINT16) 2048; + pInstance->PSA_InitParams.nBands = (LVM_UINT16) 9; + pInstance->PSA_InitParams.pFiltersParams = &FiltersParams[0]; + for(i = 0; i < pInstance->PSA_InitParams.nBands; i++) + { + FiltersParams[i].CenterFrequency = (LVM_UINT16) 1000; + FiltersParams[i].QFactor = (LVM_UINT16) 100; + FiltersParams[i].PostGain = (LVM_INT16) 0; + } + + /*Get the memory requirements and then set the address pointers*/ + PSA_Status = LVPSA_Memory (hPSAInstance, + &PSA_MemTab, + &pInstance->PSA_InitParams); + + if (PSA_Status != LVPSA_OK) + { + return((LVM_ReturnStatus_en) LVM_ALGORITHMPSA); + } + + /* Slow Data */ + PSA_MemTab.Region[LVM_PERSISTENT_SLOW_DATA].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_SLOW_DATA], + PSA_MemTab.Region[LVM_PERSISTENT_SLOW_DATA].Size); + + + /* Fast Data */ + PSA_MemTab.Region[LVM_PERSISTENT_FAST_DATA].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA], + PSA_MemTab.Region[LVM_PERSISTENT_FAST_DATA].Size); + + + /* Fast Coef */ + PSA_MemTab.Region[LVM_PERSISTENT_FAST_COEF].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF], + PSA_MemTab.Region[LVM_PERSISTENT_FAST_COEF].Size); + + /* Fast Temporary */ + pInstance->pPSAInput = InstAlloc_AddMember(&AllocMem[LVM_TEMPORARY_FAST], + (LVM_UINT32) MAX_INTERNAL_BLOCKSIZE * sizeof(LVM_INT16)); + + PSA_MemTab.Region[LVM_TEMPORARY_FAST].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST],0); + + + /*Initialise PSA instance and save the instance handle*/ + pInstance->PSA_ControlParams.Fs = LVM_FS_48000; + pInstance->PSA_ControlParams.LevelDetectionSpeed = LVPSA_SPEED_MEDIUM; + PSA_Status = LVPSA_Init (&hPSAInstance, + &pInstance->PSA_InitParams, + &pInstance->PSA_ControlParams, + &PSA_MemTab); + + if (PSA_Status != LVPSA_OK) + { + return((LVM_ReturnStatus_en) LVM_ALGORITHMPSA); + } + + pInstance->hPSAInstance = hPSAInstance; /* Save the instance handle */ + pInstance->PSA_GainOffset = 0; + } + else + { + pInstance->hPSAInstance = LVM_NULL; + } + + /* + * Set the initialisation parameters. + */ + pInstance->Params.PSA_PeakDecayRate = LVM_PSA_SPEED_MEDIUM; + pInstance->Params.PSA_Enable = LVM_PSA_OFF; + } + + /* + * Copy the initial parameters to the new parameters for correct readback of + * the settings. + */ + pInstance->NewParams = pInstance->Params; + + + /* + * Create configuration number + */ + pInstance->ConfigurationNumber = 0x00000000; + pInstance->ConfigurationNumber += LVM_CS_MASK; + pInstance->ConfigurationNumber += LVM_EQNB_MASK; + pInstance->ConfigurationNumber += LVM_DBE_MASK; + pInstance->ConfigurationNumber += LVM_VC_MASK; + pInstance->ConfigurationNumber += LVM_PSA_MASK; + + if(((pInstance->ConfigurationNumber & LVM_CS_MASK)!=0) || + ((pInstance->ConfigurationNumber & LVM_DBE_MASK)!=0) || + ((pInstance->ConfigurationNumber & LVM_EQNB_MASK)!=0)|| + ((pInstance->ConfigurationNumber & LVM_TE_MASK)!=0) || + ((pInstance->ConfigurationNumber & LVM_VC_MASK)!=0)) + { + pInstance->BlickSizeMultiple = 4; + } + else + { + pInstance->BlickSizeMultiple = 1; + } + + return(Status); +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_ClearAudioBuffers */ +/* */ +/* DESCRIPTION: */ +/* This function is used to clear the internal audio buffers of the bundle. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Initialisation succeeded */ +/* LVM_NULLADDRESS Instance or scratch memory has a NULL pointer */ +/* */ +/* NOTES: */ +/* 1. This function must not be interrupted by the LVM_Process function */ +/* */ +/****************************************************************************************/ + +LVM_ReturnStatus_en LVM_ClearAudioBuffers(LVM_Handle_t hInstance) +{ + LVM_MemTab_t MemTab; /* Memory table */ + LVM_InstParams_t InstParams; /* Instance parameters */ + LVM_ControlParams_t Params; /* Control Parameters */ + LVM_Instance_t *pInstance = (LVM_Instance_t *)hInstance; /* Pointer to Instance */ + + + if(hInstance == LVM_NULL){ + return LVM_NULLADDRESS; + } + + /* Save the control parameters */ /* coverity[unchecked_value] */ /* Do not check return value internal function calls */ + LVM_GetControlParameters(hInstance, &Params); + + /* Retrieve allocated buffers in memtab */ + LVM_GetMemoryTable(hInstance, &MemTab, LVM_NULL); + + /* Save the instance parameters */ + InstParams = pInstance->InstParams; + + /* Call LVM_GetInstanceHandle to re-initialise the bundle */ + LVM_GetInstanceHandle( &hInstance, + &MemTab, + &InstParams); + + /* Restore control parameters */ /* coverity[unchecked_value] */ /* Do not check return value internal function calls */ + LVM_SetControlParameters(hInstance, &Params); + + /* DC removal filter */ + DC_2I_D16_TRC_WRA_01_Init(&pInstance->DC_RemovalInstance); + + + return LVM_SUCCESS; +} + + + diff --git a/media/libeffects/lvm/lib/Bundle/src/LVM_Private.h b/media/libeffects/lvm/lib/Bundle/src/LVM_Private.h new file mode 100755 index 0000000..f70e473 --- /dev/null +++ b/media/libeffects/lvm/lib/Bundle/src/LVM_Private.h @@ -0,0 +1,292 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: nxp007753 $ + $Revision: 1082 $ + $Date: 2010-07-05 12:44:39 +0200 (Mon, 05 Jul 2010) $ + +***********************************************************************************/ + +/************************************************************************************/ +/* */ +/* Header file for the private layer interface of concert sound bundle */ +/* */ +/* This files includes all definitions, types, structures and function */ +/* prototypes required by the execution layer. */ +/* */ +/************************************************************************************/ + +#ifndef __LVM_PRIVATE_H__ +#define __LVM_PRIVATE_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVM.h" /* LifeVibes */ +#include "LVM_Common.h" /* LifeVibes common */ +#include "BIQUAD.h" /* Biquad library */ +#include "LVC_Mixer.h" /* Mixer library */ +#include "LVCS_Private.h" /* Concert Sound */ +#include "LVDBE_Private.h" /* Dynamic Bass Enhancement */ +#include "LVEQNB_Private.h" /* N-Band equaliser */ +#include "LVPSA_Private.h" /* Parametric Spectrum Analyzer */ + + +/************************************************************************************/ +/* */ +/* Defines */ +/* */ +/************************************************************************************/ + +/* General */ +#define LVM_INVALID 0xFFFF /* Invalid init parameter */ + +/* Memory */ +#define LVM_INSTANCE_ALIGN 4 /* 32-bit for structures */ +#define LVM_FIRSTCALL 0 /* First call to the buffer */ +#define LVM_MAXBLOCKCALL 1 /* Maximum block size calls to the buffer */ +#define LVM_LASTCALL 2 /* Last call to the buffer */ +#define LVM_FIRSTLASTCALL 3 /* Single call for small number of samples */ + +/* Block Size */ +#define LVM_MIN_MAXBLOCKSIZE 16 /* Minimum MaxBlockSize Limit*/ +#define LVM_MANAGED_MAX_MAXBLOCKSIZE 8191 /* Maximum MaxBlockSzie Limit for Managed Buffer Mode*/ +#define LVM_UNMANAGED_MAX_MAXBLOCKSIZE 4096 /* Maximum MaxBlockSzie Limit for Unmanaged Buffer Mode */ + +#define MAX_INTERNAL_BLOCKSIZE 8128 /* Maximum multiple of 64 below 8191*/ + +#define MIN_INTERNAL_BLOCKSIZE 16 /* Minimum internal block size */ +#define MIN_INTERNAL_BLOCKSHIFT 4 /* Minimum internal block size as a power of 2 */ +#define MIN_INTERNAL_BLOCKMASK 0xFFF0 /* Minimum internal block size mask */ + +#define LVM_PSA_DYNAMICRANGE 60 /* Spectral Dynamic range: used for offseting output*/ +#define LVM_PSA_BARHEIGHT 127 /* Spectral Bar Height*/ + +#define LVM_TE_MIN_EFFECTLEVEL 0 /*TE Minimum EffectLevel*/ +#define LVM_TE_MAX_EFFECTLEVEL 15 /*TE Maximum Effect level*/ + +#define LVM_VC_MIN_EFFECTLEVEL -96 /*VC Minimum EffectLevel*/ +#define LVM_VC_MAX_EFFECTLEVEL 0 /*VC Maximum Effect level*/ + +#define LVM_BE_MIN_EFFECTLEVEL 0 /*BE Minimum EffectLevel*/ +#define LVM_BE_MAX_EFFECTLEVEL 15 /*BE Maximum Effect level*/ + +#define LVM_EQNB_MIN_BAND_FREQ 20 /*EQNB Minimum Band Frequency*/ +#define LVM_EQNB_MAX_BAND_FREQ 24000 /*EQNB Maximum Band Frequency*/ +#define LVM_EQNB_MIN_BAND_GAIN -15 /*EQNB Minimum Band Frequency*/ +#define LVM_EQNB_MAX_BAND_GAIN 15 /*EQNB Maximum Band Frequency*/ +#define LVM_EQNB_MIN_QFACTOR 25 /*EQNB Minimum Q Factor*/ +#define LVM_EQNB_MAX_QFACTOR 1200 /*EQNB Maximum Q Factor*/ +#define LVM_EQNB_MIN_LPF_FREQ 1000 /*EQNB Minimum Low Pass Corner frequency*/ +#define LVM_EQNB_MIN_HPF_FREQ 20 /*EQNB Minimum High Pass Corner frequency*/ +#define LVM_EQNB_MAX_HPF_FREQ 1000 /*EQNB Maximum High Pass Corner frequency*/ + +#define LVM_CS_MIN_EFFECT_LEVEL 0 /*CS Minimum Effect Level*/ +#define LVM_CS_MAX_REVERB_LEVEL 100 /*CS Maximum Reverb Level*/ +#define LVM_VIRTUALIZER_MAX_REVERB_LEVEL 100 /*Vitrualizer Maximum Reverb Level*/ + +#define LVM_VC_MIXER_TIME 100 /*VC mixer time*/ +#define LVM_VC_BALANCE_MAX 96 /*VC balance max value*/ +#define LVM_VC_BALANCE_MIN -96 /*VC balance min value*/ + +/* Algorithm masks */ +#define LVM_CS_MASK 1 +#define LVM_EQNB_MASK 2 +#define LVM_DBE_MASK 4 +#define LVM_VC_MASK 16 +#define LVM_TE_MASK 32 +#define LVM_PSA_MASK 2048 + + +/************************************************************************************/ +/* */ +/* Structures */ +/* */ +/************************************************************************************/ + +/* Memory region definition */ +typedef struct +{ + LVM_UINT32 Size; /* Region size in bytes */ + LVM_UINT16 Alignment; /* Byte alignment */ + LVM_MemoryTypes_en Type; /* Region type */ + void *pBaseAddress; /* Pointer to the region base address */ +} LVM_IntMemoryRegion_t; + + +/* Memory table containing the region definitions */ +typedef struct +{ + LVM_IntMemoryRegion_t Region[LVM_NR_MEMORY_REGIONS]; /* One definition for each region */ +} LVM_IntMemTab_t; + + +/* Buffer Management */ +typedef struct +{ + LVM_INT16 *pScratch; /* Bundle scratch buffer */ + + LVM_INT16 BufferState; /* Buffer status */ + LVM_INT16 InDelayBuffer[6*MIN_INTERNAL_BLOCKSIZE]; /* Input buffer delay line, left and right */ + LVM_INT16 InDelaySamples; /* Number of samples in the input delay buffer */ + + LVM_INT16 OutDelayBuffer[2*MIN_INTERNAL_BLOCKSIZE]; /* Output buffer delay line */ + LVM_INT16 OutDelaySamples; /* Number of samples in the output delay buffer, left and right */ + LVM_INT16 SamplesToOutput; /* Samples to write to the output */ +} LVM_Buffer_t; + + +/* Filter taps */ +typedef struct +{ + Biquad_2I_Order1_Taps_t TrebleBoost_Taps; /* Treble boost Taps */ +} LVM_TE_Data_t; + + +/* Coefficients */ +typedef struct +{ + Biquad_Instance_t TrebleBoost_State; /* State for the treble boost filter */ +} LVM_TE_Coefs_t; + + +typedef struct +{ + /* Public parameters */ + LVM_MemTab_t MemoryTable; /* Instance memory allocation table */ + LVM_ControlParams_t Params; /* Control parameters */ + LVM_InstParams_t InstParams; /* Instance parameters */ + + /* Private parameters */ + LVM_UINT16 ControlPending; /* Control flag to indicate update pending */ + LVM_ControlParams_t NewParams; /* New control parameters pending update */ + + /* Buffer control */ + LVM_INT16 InternalBlockSize; /* Maximum internal block size */ + LVM_Buffer_t *pBufferManagement; /* Buffer management variables */ + LVM_INT16 SamplesToProcess; /* Input samples left to process */ + LVM_INT16 *pInputSamples; /* External input sample pointer */ + LVM_INT16 *pOutputSamples; /* External output sample pointer */ + + /* Configuration number */ + LVM_INT32 ConfigurationNumber; + LVM_INT32 BlickSizeMultiple; + + /* DC removal */ + Biquad_Instance_t DC_RemovalInstance; /* DC removal filter instance */ + + /* Concert Sound */ + LVCS_Handle_t hCSInstance; /* Concert Sound instance handle */ + LVCS_Instance_t CS_Instance; /* Concert Sound instance */ + LVM_INT16 CS_Active; /* Control flag */ + + /* Equalizer */ + LVEQNB_Handle_t hEQNBInstance; /* N-Band Equaliser instance handle */ + LVEQNB_Instance_t EQNB_Instance; /* N-Band Equaliser instance */ + LVM_EQNB_BandDef_t *pEQNB_BandDefs; /* Local storage for new definitions */ + LVM_EQNB_BandDef_t *pEQNB_UserDefs; /* Local storage for the user's definitions */ + LVM_INT16 EQNB_Active; /* Control flag */ + + /* Dynamic Bass Enhancement */ + LVDBE_Handle_t hDBEInstance; /* Dynamic Bass Enhancement instance handle */ + LVDBE_Instance_t DBE_Instance; /* Dynamic Bass Enhancement instance */ + LVM_INT16 DBE_Active; /* Control flag */ + + /* Volume Control */ + LVMixer3_1St_st VC_Volume; /* Volume scaler */ + LVMixer3_2St_st VC_BalanceMix; /* VC balance mixer */ + LVM_INT16 VC_VolumedB; /* Gain in dB */ + LVM_INT16 VC_Active; /* Control flag */ + LVM_INT16 VC_AVLFixedVolume; /* AVL fixed volume */ + + /* Treble Enhancement */ + LVM_TE_Data_t *pTE_Taps; /* Treble boost Taps */ + LVM_TE_Coefs_t *pTE_State; /* State for the treble boost filter */ + LVM_INT16 TE_Active; /* Control flag */ + + /* Headroom */ + LVM_HeadroomParams_t NewHeadroomParams; /* New headroom parameters pending update */ + LVM_HeadroomParams_t HeadroomParams; /* Headroom parameters */ + LVM_HeadroomBandDef_t *pHeadroom_BandDefs; /* Local storage for new definitions */ + LVM_HeadroomBandDef_t *pHeadroom_UserDefs; /* Local storage for the user's definitions */ + LVM_UINT16 Headroom; /* Value of the current headroom */ + + /* Spectrum Analyzer */ + pLVPSA_Handle_t hPSAInstance; /* Spectrum Analyzer instance handle */ + LVPSA_InstancePr_t PSA_Instance; /* Spectrum Analyzer instance */ + LVPSA_InitParams_t PSA_InitParams; /* Spectrum Analyzer initialization parameters */ + LVPSA_ControlParams_t PSA_ControlParams; /* Spectrum Analyzer control parameters */ + LVM_INT16 PSA_GainOffset; /* Tone control flag */ + LVM_Callback CallBack; + LVM_INT16 *pPSAInput; /* PSA input pointer */ + + LVM_INT16 NoSmoothVolume; /* Enable or disable smooth volume changes*/ + +} LVM_Instance_t; + + +/************************************************************************************/ +/* */ +/* Function Prototypes */ +/* */ +/************************************************************************************/ + +LVM_ReturnStatus_en LVM_ApplyNewSettings(LVM_Handle_t hInstance); + +void LVM_SetTrebleBoost( LVM_Instance_t *pInstance, + LVM_ControlParams_t *pParams); + +void LVM_SetVolume( LVM_Instance_t *pInstance, + LVM_ControlParams_t *pParams); + +LVM_INT32 LVM_VCCallBack(void* pBundleHandle, + void* pGeneralPurpose, + short CallBackParam); + +void LVM_SetHeadroom( LVM_Instance_t *pInstance, + LVM_ControlParams_t *pParams); + +void LVM_BufferIn( LVM_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 **pToProcess, + LVM_INT16 **pProcessed, + LVM_UINT16 *pNumSamples); + +void LVM_BufferOut( LVM_Handle_t hInstance, + LVM_INT16 *pOutData, + LVM_UINT16 *pNumSamples); + +LVM_INT32 LVM_AlgoCallBack( void *pBundleHandle, + void *pData, + LVM_INT16 callbackId); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LVM_PRIVATE_H__ */ + diff --git a/media/libeffects/lvm/lib/Bundle/src/LVM_Process.c b/media/libeffects/lvm/lib/Bundle/src/LVM_Process.c new file mode 100755 index 0000000..bad9450 --- /dev/null +++ b/media/libeffects/lvm/lib/Bundle/src/LVM_Process.c @@ -0,0 +1,283 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************************** + + $Author: beq07716 $ + $Revision: 1002 $ + $Date: 2010-06-28 13:40:09 +0200 (Mon, 28 Jun 2010) $ + +*****************************************************************************************/ + + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVM_Private.h" +#include "VectorArithmetic.h" +#include "LVM_Coeffs.h" + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVM_Process */ +/* */ +/* DESCRIPTION: */ +/* Process function for the LifeVibes module. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pInData Pointer to the input data */ +/* pOutData Pointer to the output data */ +/* NumSamples Number of samples in the input buffer */ +/* AudioTime Audio Time of the current input buffer in ms */ +/* */ +/* RETURNS: */ +/* LVM_SUCCESS Succeeded */ +/* LVM_INVALIDNUMSAMPLES When the NumSamples is not a valied multiple in unmanaged */ +/* buffer mode */ +/* LVM_ALIGNMENTERROR When either the input our output buffers are not 32-bit */ +/* aligned in unmanaged mode */ +/* LVM_NULLADDRESS When one of hInstance, pInData or pOutData is NULL */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +LVM_ReturnStatus_en LVM_Process(LVM_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 *pOutData, + LVM_UINT16 NumSamples, + LVM_UINT32 AudioTime) +{ + + LVM_Instance_t *pInstance = (LVM_Instance_t *)hInstance; + LVM_UINT16 SampleCount = NumSamples; + LVM_INT16 *pInput = (LVM_INT16 *)pInData; + LVM_INT16 *pToProcess = (LVM_INT16 *)pInData; + LVM_INT16 *pProcessed = pOutData; + LVM_ReturnStatus_en Status; + + /* + * Check if the number of samples is zero + */ + if (NumSamples == 0) + { + return(LVM_SUCCESS); + } + + + /* + * Check valid points have been given + */ + if ((hInstance == LVM_NULL) || (pInData == LVM_NULL) || (pOutData == LVM_NULL)) + { + return (LVM_NULLADDRESS); + } + + /* + * For unmanaged mode only + */ + if(pInstance->InstParams.BufferMode == LVM_UNMANAGED_BUFFERS) + { + /* + * Check if the number of samples is a good multiple (unmanaged mode only) + */ + if((NumSamples % pInstance->BlickSizeMultiple) != 0) + { + return(LVM_INVALIDNUMSAMPLES); + } + + /* + * Check the buffer alignment + */ + if((((LVM_UINT32)pInData % 4) != 0) || (((LVM_UINT32)pOutData % 4) != 0)) + { + return(LVM_ALIGNMENTERROR); + } + } + + + /* + * Update new parameters if necessary + */ + if (pInstance->ControlPending == LVM_TRUE) + { + Status = LVM_ApplyNewSettings(hInstance); + + if(Status != LVM_SUCCESS) + { + return Status; + } + } + + + /* + * Convert from Mono if necessary + */ + if (pInstance->Params.SourceFormat == LVM_MONO) + { + MonoTo2I_16(pInData, /* Source */ + pOutData, /* Destination */ + (LVM_INT16)NumSamples); /* Number of input samples */ + pInput = pOutData; + pToProcess = pOutData; + } + + + /* + * Process the data with managed buffers + */ + while (SampleCount != 0) + { + /* + * Manage the input buffer and frame processing + */ + LVM_BufferIn(hInstance, + pInput, + &pToProcess, + &pProcessed, + &SampleCount); + + /* + * Only process data when SampleCount is none zero, a zero count can occur when + * the BufferIn routine is working in managed mode. + */ + if (SampleCount != 0) + { + + /* + * Apply ConcertSound if required + */ + if (pInstance->CS_Active == LVM_TRUE) + { + (void)LVCS_Process(pInstance->hCSInstance, /* Concert Sound instance handle */ + pToProcess, + pProcessed, + SampleCount); + pToProcess = pProcessed; + } + + /* + * Apply volume if required + */ + if (pInstance->VC_Active!=0) + { + LVC_MixSoft_1St_D16C31_SAT(&pInstance->VC_Volume, + pToProcess, + pProcessed, + (LVM_INT16)(2*SampleCount)); /* Left and right*/ + pToProcess = pProcessed; + } + + /* + * Call N-Band equaliser if enabled + */ + if (pInstance->EQNB_Active == LVM_TRUE) + { + LVEQNB_Process(pInstance->hEQNBInstance, /* N-Band equaliser instance handle */ + pToProcess, + pProcessed, + SampleCount); + pToProcess = pProcessed; + } + + /* + * Call bass enhancement if enabled + */ + if (pInstance->DBE_Active == LVM_TRUE) + { + LVDBE_Process(pInstance->hDBEInstance, /* Dynamic Bass Enhancement instance handle */ + pToProcess, + pProcessed, + SampleCount); + pToProcess = pProcessed; + } + + /* + * Bypass mode or everything off, so copy the input to the output + */ + if (pToProcess != pProcessed) + { + Copy_16(pToProcess, /* Source */ + pProcessed, /* Destination */ + (LVM_INT16)(2*SampleCount)); /* Left and right */ + } + + /* + * Apply treble boost if required + */ + if (pInstance->TE_Active == LVM_TRUE) + { + /* + * Apply the filter + */ + FO_2I_D16F32C15_LShx_TRC_WRA_01(&pInstance->pTE_State->TrebleBoost_State, + pProcessed, + pProcessed, + (LVM_INT16)SampleCount); + + } + + /* + * Volume balance + */ + LVC_MixSoft_1St_2i_D16C31_SAT(&pInstance->VC_BalanceMix, + pProcessed, + pProcessed, + SampleCount); + + /* + * Perform Parametric Spectum Analysis + */ + if ((pInstance->Params.PSA_Enable == LVM_PSA_ON)&&(pInstance->InstParams.PSA_Included==LVM_PSA_ON)) + { + From2iToMono_16(pProcessed, + pInstance->pPSAInput, + (LVM_INT16) (SampleCount)); + + LVPSA_Process(pInstance->hPSAInstance, + pInstance->pPSAInput, + (LVM_UINT16) (SampleCount), + AudioTime); + } + + + /* + * DC removal + */ + DC_2I_D16_TRC_WRA_01(&pInstance->DC_RemovalInstance, + pProcessed, + pProcessed, + (LVM_INT16)SampleCount); + + + } + + /* + * Manage the output buffer + */ + LVM_BufferOut(hInstance, + pOutData, + &SampleCount); + + } + + return(LVM_SUCCESS); +} diff --git a/media/libeffects/lvm/lib/Bundle/src/LVM_Tables.c b/media/libeffects/lvm/lib/Bundle/src/LVM_Tables.c new file mode 100755 index 0000000..cb33541 --- /dev/null +++ b/media/libeffects/lvm/lib/Bundle/src/LVM_Tables.c @@ -0,0 +1,397 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1002 $ + $Date: 2010-06-28 13:40:09 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVM_Tables.h" +#include "LVM_Coeffs.h" + +/************************************************************************************/ +/* */ +/* Treble Boost Filter Coefficients */ +/* */ +/************************************************************************************/ + +FO_C16_LShx_Coefs_t LVM_TrebleBoostCoefs[] = { + + /* 22kHz sampling rate */ + {HPF_Fs22050_Gain1_A1, /* Gain setting 1 */ + HPF_Fs22050_Gain1_A0, + -HPF_Fs22050_Gain1_B1, + HPF_Fs22050_Gain1_Shift}, + {HPF_Fs22050_Gain2_A1, /* Gain setting 2 */ + HPF_Fs22050_Gain2_A0, + -HPF_Fs22050_Gain2_B1, + HPF_Fs22050_Gain2_Shift}, + {HPF_Fs22050_Gain3_A1, /* Gain setting 3 */ + HPF_Fs22050_Gain3_A0, + -HPF_Fs22050_Gain3_B1, + HPF_Fs22050_Gain3_Shift}, + {HPF_Fs22050_Gain4_A1, /* Gain setting 4 */ + HPF_Fs22050_Gain4_A0, + -HPF_Fs22050_Gain4_B1, + HPF_Fs22050_Gain4_Shift}, + {HPF_Fs22050_Gain5_A1, /* Gain setting 5 */ + HPF_Fs22050_Gain5_A0, + -HPF_Fs22050_Gain5_B1, + HPF_Fs22050_Gain5_Shift}, + {HPF_Fs22050_Gain6_A1, /* Gain setting 6 */ + HPF_Fs22050_Gain6_A0, + -HPF_Fs22050_Gain6_B1, + HPF_Fs22050_Gain6_Shift}, + {HPF_Fs22050_Gain7_A1, /* Gain setting 7 */ + HPF_Fs22050_Gain7_A0, + -HPF_Fs22050_Gain7_B1, + HPF_Fs22050_Gain7_Shift}, + {HPF_Fs22050_Gain8_A1, /* Gain setting 8 */ + HPF_Fs22050_Gain8_A0, + -HPF_Fs22050_Gain8_B1, + HPF_Fs22050_Gain8_Shift}, + {HPF_Fs22050_Gain9_A1, /* Gain setting 9 */ + HPF_Fs22050_Gain9_A0, + -HPF_Fs22050_Gain9_B1, + HPF_Fs22050_Gain9_Shift}, + {HPF_Fs22050_Gain10_A1, /* Gain setting 10 */ + HPF_Fs22050_Gain10_A0, + -HPF_Fs22050_Gain10_B1, + HPF_Fs22050_Gain10_Shift}, + {HPF_Fs22050_Gain11_A1, /* Gain setting 11 */ + HPF_Fs22050_Gain11_A0, + -HPF_Fs22050_Gain11_B1, + HPF_Fs22050_Gain11_Shift}, + {HPF_Fs22050_Gain12_A1, /* Gain setting 12 */ + HPF_Fs22050_Gain12_A0, + -HPF_Fs22050_Gain12_B1, + HPF_Fs22050_Gain12_Shift}, + {HPF_Fs22050_Gain13_A1, /* Gain setting 13 */ + HPF_Fs22050_Gain13_A0, + -HPF_Fs22050_Gain13_B1, + HPF_Fs22050_Gain13_Shift}, + {HPF_Fs22050_Gain14_A1, /* Gain setting 14 */ + HPF_Fs22050_Gain14_A0, + -HPF_Fs22050_Gain14_B1, + HPF_Fs22050_Gain14_Shift}, + {HPF_Fs22050_Gain15_A1, /* Gain setting 15 */ + HPF_Fs22050_Gain15_A0, + -HPF_Fs22050_Gain15_B1, + HPF_Fs22050_Gain15_Shift}, + + /* 24kHz sampling rate */ + {HPF_Fs24000_Gain1_A1, /* Gain setting 1 */ + HPF_Fs24000_Gain1_A0, + -HPF_Fs24000_Gain1_B1, + HPF_Fs24000_Gain1_Shift}, + {HPF_Fs24000_Gain2_A1, /* Gain setting 2 */ + HPF_Fs24000_Gain2_A0, + -HPF_Fs24000_Gain2_B1, + HPF_Fs24000_Gain2_Shift}, + {HPF_Fs24000_Gain3_A1, /* Gain setting 3 */ + HPF_Fs24000_Gain3_A0, + -HPF_Fs24000_Gain3_B1, + HPF_Fs24000_Gain3_Shift}, + {HPF_Fs24000_Gain4_A1, /* Gain setting 4 */ + HPF_Fs24000_Gain4_A0, + -HPF_Fs24000_Gain4_B1, + HPF_Fs24000_Gain4_Shift}, + {HPF_Fs24000_Gain5_A1, /* Gain setting 5 */ + HPF_Fs24000_Gain5_A0, + -HPF_Fs24000_Gain5_B1, + HPF_Fs24000_Gain5_Shift}, + {HPF_Fs24000_Gain6_A1, /* Gain setting 6 */ + HPF_Fs24000_Gain6_A0, + -HPF_Fs24000_Gain6_B1, + HPF_Fs24000_Gain6_Shift}, + {HPF_Fs24000_Gain7_A1, /* Gain setting 7 */ + HPF_Fs24000_Gain7_A0, + -HPF_Fs24000_Gain7_B1, + HPF_Fs24000_Gain7_Shift}, + {HPF_Fs24000_Gain8_A1, /* Gain setting 8 */ + HPF_Fs24000_Gain8_A0, + -HPF_Fs24000_Gain8_B1, + HPF_Fs24000_Gain8_Shift}, + {HPF_Fs24000_Gain9_A1, /* Gain setting 9 */ + HPF_Fs24000_Gain9_A0, + -HPF_Fs24000_Gain9_B1, + HPF_Fs24000_Gain9_Shift}, + {HPF_Fs24000_Gain10_A1, /* Gain setting 10 */ + HPF_Fs24000_Gain10_A0, + -HPF_Fs24000_Gain10_B1, + HPF_Fs24000_Gain10_Shift}, + {HPF_Fs24000_Gain11_A1, /* Gain setting 11 */ + HPF_Fs24000_Gain11_A0, + -HPF_Fs24000_Gain11_B1, + HPF_Fs24000_Gain11_Shift}, + {HPF_Fs24000_Gain12_A1, /* Gain setting 12 */ + HPF_Fs24000_Gain12_A0, + -HPF_Fs24000_Gain12_B1, + HPF_Fs24000_Gain12_Shift}, + {HPF_Fs24000_Gain13_A1, /* Gain setting 13 */ + HPF_Fs24000_Gain13_A0, + -HPF_Fs24000_Gain13_B1, + HPF_Fs24000_Gain13_Shift}, + {HPF_Fs24000_Gain14_A1, /* Gain setting 14 */ + HPF_Fs24000_Gain14_A0, + -HPF_Fs24000_Gain14_B1, + HPF_Fs24000_Gain14_Shift}, + {HPF_Fs24000_Gain15_A1, /* Gain setting 15 */ + HPF_Fs24000_Gain15_A0, + -HPF_Fs24000_Gain15_B1, + HPF_Fs24000_Gain15_Shift}, + + /* 32kHz sampling rate */ + {HPF_Fs32000_Gain1_A1, /* Gain setting 1 */ + HPF_Fs32000_Gain1_A0, + -HPF_Fs32000_Gain1_B1, + HPF_Fs32000_Gain1_Shift}, + {HPF_Fs32000_Gain2_A1, /* Gain setting 2 */ + HPF_Fs32000_Gain2_A0, + -HPF_Fs32000_Gain2_B1, + HPF_Fs32000_Gain2_Shift}, + {HPF_Fs32000_Gain3_A1, /* Gain setting 3 */ + HPF_Fs32000_Gain3_A0, + -HPF_Fs32000_Gain3_B1, + HPF_Fs32000_Gain3_Shift}, + {HPF_Fs32000_Gain4_A1, /* Gain setting 4 */ + HPF_Fs32000_Gain4_A0, + -HPF_Fs32000_Gain4_B1, + HPF_Fs32000_Gain4_Shift}, + {HPF_Fs32000_Gain5_A1, /* Gain setting 5 */ + HPF_Fs32000_Gain5_A0, + -HPF_Fs32000_Gain5_B1, + HPF_Fs32000_Gain5_Shift}, + {HPF_Fs32000_Gain6_A1, /* Gain setting 6 */ + HPF_Fs32000_Gain6_A0, + -HPF_Fs32000_Gain6_B1, + HPF_Fs32000_Gain6_Shift}, + {HPF_Fs32000_Gain7_A1, /* Gain setting 7 */ + HPF_Fs32000_Gain7_A0, + -HPF_Fs32000_Gain7_B1, + HPF_Fs32000_Gain7_Shift}, + {HPF_Fs32000_Gain8_A1, /* Gain setting 8 */ + HPF_Fs32000_Gain8_A0, + -HPF_Fs32000_Gain8_B1, + HPF_Fs32000_Gain8_Shift}, + {HPF_Fs32000_Gain9_A1, /* Gain setting 9 */ + HPF_Fs32000_Gain9_A0, + -HPF_Fs32000_Gain9_B1, + HPF_Fs32000_Gain9_Shift}, + {HPF_Fs32000_Gain10_A1, /* Gain setting 10 */ + HPF_Fs32000_Gain10_A0, + -HPF_Fs32000_Gain10_B1, + HPF_Fs32000_Gain10_Shift}, + {HPF_Fs32000_Gain11_A1, /* Gain setting 11 */ + HPF_Fs32000_Gain11_A0, + -HPF_Fs32000_Gain11_B1, + HPF_Fs32000_Gain11_Shift}, + {HPF_Fs32000_Gain12_A1, /* Gain setting 12 */ + HPF_Fs32000_Gain12_A0, + -HPF_Fs32000_Gain12_B1, + HPF_Fs32000_Gain12_Shift}, + {HPF_Fs32000_Gain13_A1, /* Gain setting 13 */ + HPF_Fs32000_Gain13_A0, + -HPF_Fs32000_Gain13_B1, + HPF_Fs32000_Gain13_Shift}, + {HPF_Fs32000_Gain14_A1, /* Gain setting 14 */ + HPF_Fs32000_Gain14_A0, + -HPF_Fs32000_Gain14_B1, + HPF_Fs32000_Gain14_Shift}, + {HPF_Fs32000_Gain15_A1, /* Gain setting 15 */ + HPF_Fs32000_Gain15_A0, + -HPF_Fs32000_Gain15_B1, + HPF_Fs32000_Gain15_Shift}, + + /* 44kHz sampling rate */ + {HPF_Fs44100_Gain1_A1, /* Gain setting 1 */ + HPF_Fs44100_Gain1_A0, + -HPF_Fs44100_Gain1_B1, + HPF_Fs44100_Gain1_Shift}, + {HPF_Fs44100_Gain2_A1, /* Gain setting 2 */ + HPF_Fs44100_Gain2_A0, + -HPF_Fs44100_Gain2_B1, + HPF_Fs44100_Gain2_Shift}, + {HPF_Fs44100_Gain3_A1, /* Gain setting 3 */ + HPF_Fs44100_Gain3_A0, + -HPF_Fs44100_Gain3_B1, + HPF_Fs44100_Gain3_Shift}, + {HPF_Fs44100_Gain4_A1, /* Gain setting 4 */ + HPF_Fs44100_Gain4_A0, + -HPF_Fs44100_Gain4_B1, + HPF_Fs44100_Gain4_Shift}, + {HPF_Fs44100_Gain5_A1, /* Gain setting 5 */ + HPF_Fs44100_Gain5_A0, + -HPF_Fs44100_Gain5_B1, + HPF_Fs44100_Gain5_Shift}, + {HPF_Fs44100_Gain6_A1, /* Gain setting 6 */ + HPF_Fs44100_Gain6_A0, + -HPF_Fs44100_Gain6_B1, + HPF_Fs44100_Gain6_Shift}, + {HPF_Fs44100_Gain7_A1, /* Gain setting 7 */ + HPF_Fs44100_Gain7_A0, + -HPF_Fs44100_Gain7_B1, + HPF_Fs44100_Gain7_Shift}, + {HPF_Fs44100_Gain8_A1, /* Gain setting 8 */ + HPF_Fs44100_Gain8_A0, + -HPF_Fs44100_Gain8_B1, + HPF_Fs44100_Gain8_Shift}, + {HPF_Fs44100_Gain9_A1, /* Gain setting 9 */ + HPF_Fs44100_Gain9_A0, + -HPF_Fs44100_Gain9_B1, + HPF_Fs44100_Gain9_Shift}, + {HPF_Fs44100_Gain10_A1, /* Gain setting 10 */ + HPF_Fs44100_Gain10_A0, + -HPF_Fs44100_Gain10_B1, + HPF_Fs44100_Gain10_Shift}, + {HPF_Fs44100_Gain11_A1, /* Gain setting 11 */ + HPF_Fs44100_Gain11_A0, + -HPF_Fs44100_Gain11_B1, + HPF_Fs44100_Gain11_Shift}, + {HPF_Fs44100_Gain12_A1, /* Gain setting 12 */ + HPF_Fs44100_Gain12_A0, + -HPF_Fs44100_Gain12_B1, + HPF_Fs44100_Gain12_Shift}, + {HPF_Fs44100_Gain13_A1, /* Gain setting 13 */ + HPF_Fs44100_Gain13_A0, + -HPF_Fs44100_Gain13_B1, + HPF_Fs44100_Gain13_Shift}, + {HPF_Fs44100_Gain14_A1, /* Gain setting 14 */ + HPF_Fs44100_Gain14_A0, + -HPF_Fs44100_Gain14_B1, + HPF_Fs44100_Gain14_Shift}, + {HPF_Fs44100_Gain15_A1, /* Gain setting 15 */ + HPF_Fs44100_Gain15_A0, + -HPF_Fs44100_Gain15_B1, + HPF_Fs44100_Gain15_Shift}, + + /* 48kHz sampling rate */ + {HPF_Fs48000_Gain1_A1, /* Gain setting 1 */ + HPF_Fs48000_Gain1_A0, + -HPF_Fs48000_Gain1_B1, + HPF_Fs48000_Gain1_Shift}, + {HPF_Fs48000_Gain2_A1, /* Gain setting 2 */ + HPF_Fs48000_Gain2_A0, + -HPF_Fs48000_Gain2_B1, + HPF_Fs48000_Gain2_Shift}, + {HPF_Fs48000_Gain3_A1, /* Gain setting 3 */ + HPF_Fs48000_Gain3_A0, + -HPF_Fs48000_Gain3_B1, + HPF_Fs48000_Gain3_Shift}, + {HPF_Fs48000_Gain4_A1, /* Gain setting 4 */ + HPF_Fs48000_Gain4_A0, + -HPF_Fs48000_Gain4_B1, + HPF_Fs48000_Gain4_Shift}, + {HPF_Fs48000_Gain5_A1, /* Gain setting 5 */ + HPF_Fs48000_Gain5_A0, + -HPF_Fs48000_Gain5_B1, + HPF_Fs48000_Gain5_Shift}, + {HPF_Fs48000_Gain6_A1, /* Gain setting 6 */ + HPF_Fs48000_Gain6_A0, + -HPF_Fs48000_Gain6_B1, + HPF_Fs48000_Gain6_Shift}, + {HPF_Fs48000_Gain7_A1, /* Gain setting 7 */ + HPF_Fs48000_Gain7_A0, + -HPF_Fs48000_Gain7_B1, + HPF_Fs48000_Gain7_Shift}, + {HPF_Fs48000_Gain8_A1, /* Gain setting 8 */ + HPF_Fs48000_Gain8_A0, + -HPF_Fs48000_Gain8_B1, + HPF_Fs48000_Gain8_Shift}, + {HPF_Fs48000_Gain9_A1, /* Gain setting 9 */ + HPF_Fs48000_Gain9_A0, + -HPF_Fs48000_Gain9_B1, + HPF_Fs48000_Gain9_Shift}, + {HPF_Fs48000_Gain10_A1, /* Gain setting 10 */ + HPF_Fs48000_Gain10_A0, + -HPF_Fs48000_Gain10_B1, + HPF_Fs48000_Gain10_Shift}, + {HPF_Fs48000_Gain11_A1, /* Gain setting 11 */ + HPF_Fs48000_Gain11_A0, + -HPF_Fs48000_Gain11_B1, + HPF_Fs48000_Gain11_Shift}, + {HPF_Fs48000_Gain12_A1, /* Gain setting 12 */ + HPF_Fs48000_Gain12_A0, + -HPF_Fs48000_Gain12_B1, + HPF_Fs48000_Gain12_Shift}, + {HPF_Fs48000_Gain13_A1, /* Gain setting 13 */ + HPF_Fs48000_Gain13_A0, + -HPF_Fs48000_Gain13_B1, + HPF_Fs48000_Gain13_Shift}, + {HPF_Fs48000_Gain14_A1, /* Gain setting 14 */ + HPF_Fs48000_Gain14_A0, + -HPF_Fs48000_Gain14_B1, + HPF_Fs48000_Gain14_Shift}, + {HPF_Fs48000_Gain15_A1, /* Gain setting 15 */ + HPF_Fs48000_Gain15_A0, + -HPF_Fs48000_Gain15_B1, + HPF_Fs48000_Gain15_Shift}}; + + +/************************************************************************************/ +/* */ +/* Volume control gain and time constant tables */ +/* */ +/************************************************************************************/ + +/* dB to linear conversion table */ +const LVM_INT16 LVM_VolumeTable[] = { + 0x7FFF, /* 0dB */ + 0x7215, /* -1dB */ + 0x65AD, /* -2dB */ + 0x5A9E, /* -3dB */ + 0x50C3, /* -4dB */ + 0x47FB, /* -5dB */ + 0x4000}; /* -6dB */ + +/************************************************************************************/ +/* */ +/* Volume mixer time constants (100ms) */ +/* */ +/************************************************************************************/ + +#define LVM_MIX_TC_Fs8000 32580 /* Floating point value 0.994262695 */ +#define LVM_MIX_TC_Fs11025 32632 /* Floating point value 0.995849609 */ +#define LVM_MIX_TC_Fs12000 32643 /* Floating point value 0.996185303 */ +#define LVM_MIX_TC_Fs16000 32674 /* Floating point value 0.997131348 */ +#define LVM_MIX_TC_Fs22050 32700 /* Floating point value 0.997924805 */ +#define LVM_MIX_TC_Fs24000 32705 /* Floating point value 0.998077393 */ +#define LVM_MIX_TC_Fs32000 32721 /* Floating point value 0.998565674 */ +#define LVM_MIX_TC_Fs44100 32734 /* Floating point value 0.998962402 */ +#define LVM_MIX_TC_Fs48000 32737 /* Floating point value 0.999053955 */ + + +const LVM_INT16 LVM_MixerTCTable[] = { + LVM_MIX_TC_Fs8000, + LVM_MIX_TC_Fs11025, + LVM_MIX_TC_Fs12000, + LVM_MIX_TC_Fs16000, + LVM_MIX_TC_Fs22050, + LVM_MIX_TC_Fs24000, + LVM_MIX_TC_Fs32000, + LVM_MIX_TC_Fs44100, + LVM_MIX_TC_Fs48000}; + diff --git a/media/libeffects/lvm/lib/Bundle/src/LVM_Tables.h b/media/libeffects/lvm/lib/Bundle/src/LVM_Tables.h new file mode 100755 index 0000000..574f641 --- /dev/null +++ b/media/libeffects/lvm/lib/Bundle/src/LVM_Tables.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1002 $ + $Date: 2010-06-28 13:40:09 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + +#ifndef __LVM_TABLES_H__ +#define __LVM_TABLES_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "BIQUAD.h" +#include "LVM_Types.h" + +/************************************************************************************/ +/* */ +/* Treble Boost Filter Coefficients */ +/* */ +/************************************************************************************/ + +extern FO_C16_LShx_Coefs_t LVM_TrebleBoostCoefs[]; + + +/************************************************************************************/ +/* */ +/* Volume control gain and time constant tables */ +/* */ +/************************************************************************************/ + +extern const LVM_INT16 LVM_VolumeTable[]; +extern const LVM_INT16 LVM_MixerTCTable[]; + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LVM_TABLES_H__ */ + + diff --git a/media/libeffects/lvm/lib/Common/lib/AGC.h b/media/libeffects/lvm/lib/Common/lib/AGC.h new file mode 100755 index 0000000..980a8e3 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/lib/AGC.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +#ifndef __AGC_H__ +#define __AGC_H__ + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/**********************************************************************************/ +/* */ +/* Includes */ +/* */ +/**********************************************************************************/ + +#include "LVM_Types.h" + + +/**********************************************************************************/ +/* */ +/* Types */ +/* */ +/**********************************************************************************/ + +typedef struct +{ + LVM_INT32 AGC_Gain; /* The current AGC gain */ + LVM_INT32 AGC_MaxGain; /* The maximum AGC gain */ + LVM_INT32 Volume; /* The current volume setting */ + LVM_INT32 Target; /* The target volume setting */ + LVM_INT32 AGC_Target; /* AGC target level */ + LVM_INT16 AGC_Attack; /* AGC attack scaler */ + LVM_INT16 AGC_Decay; /* AGC decay scaler */ + LVM_INT16 AGC_GainShift; /* The gain shift */ + LVM_INT16 VolumeShift; /* Volume shift scaling */ + LVM_INT16 VolumeTC; /* Volume update time constant */ + +} AGC_MIX_VOL_2St1Mon_D32_t; + + +/**********************************************************************************/ +/* */ +/* Function Prototypes */ +/* */ +/**********************************************************************************/ + +void AGC_MIX_VOL_2St1Mon_D32_WRA(AGC_MIX_VOL_2St1Mon_D32_t *pInstance, /* Instance pointer */ + const LVM_INT32 *pStSrc, /* Stereo source */ + const LVM_INT32 *pMonoSrc, /* Mono source */ + LVM_INT32 *pDst, /* Stereo destination */ + LVM_UINT16 n); /* Number of samples */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __AGC_H__ */ + + + + + + + + + + diff --git a/media/libeffects/lvm/lib/Common/lib/BIQUAD.h b/media/libeffects/lvm/lib/Common/lib/BIQUAD.h new file mode 100755 index 0000000..08e5a6f --- /dev/null +++ b/media/libeffects/lvm/lib/Common/lib/BIQUAD.h @@ -0,0 +1,341 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 722 $ + $Date: 2010-06-10 15:12:34 +0200 (Thu, 10 Jun 2010) $ + +***********************************************************************************/ + +#ifndef _BIQUAD_H_ +#define _BIQUAD_H_ + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include "LVM_Types.h" +/********************************************************************************** + INSTANCE MEMORY TYPE DEFINITION +***********************************************************************************/ + +typedef struct +{ + LVM_INT32 Storage[6]; + +} Biquad_Instance_t; + + +/********************************************************************************** + COEFFICIENT TYPE DEFINITIONS +***********************************************************************************/ + +/*** Biquad coefficients **********************************************************/ +typedef struct +{ + LVM_INT16 A2; /* a2 */ + LVM_INT16 A1; /* a1 */ + LVM_INT16 A0; /* a0 */ + LVM_INT16 B2; /* -b2! */ + LVM_INT16 B1; /* -b1! */ +} BQ_C16_Coefs_t; + +typedef struct +{ + LVM_INT32 A2; /* a2 */ + LVM_INT32 A1; /* a1 */ + LVM_INT32 A0; /* a0 */ + LVM_INT32 B2; /* -b2! */ + LVM_INT32 B1; /* -b1! */ +} BQ_C32_Coefs_t; + +/*** First order coefficients *****************************************************/ +typedef struct +{ + LVM_INT16 A1; /* a1 */ + LVM_INT16 A0; /* a0 */ + LVM_INT16 B1; /* -b1! */ +} FO_C16_Coefs_t; + +typedef struct +{ + LVM_INT32 A1; /* a1 */ + LVM_INT32 A0; /* a0 */ + LVM_INT32 B1; /* -b1! */ +} FO_C32_Coefs_t; + +/*** First order coefficients with Shift*****************************************************/ +typedef struct +{ + LVM_INT16 A1; /* a1 */ + LVM_INT16 A0; /* a0 */ + LVM_INT16 B1; /* -b1! */ + LVM_INT16 Shift; /* Shift */ +} FO_C16_LShx_Coefs_t; + +/*** Band pass coefficients *******************************************************/ +typedef struct +{ + LVM_INT16 A0; /* a0 */ + LVM_INT16 B2; /* -b2! */ + LVM_INT16 B1; /* -b1! */ +} BP_C16_Coefs_t; + +typedef struct +{ + LVM_INT32 A0; /* a0 */ + LVM_INT32 B2; /* -b2! */ + LVM_INT32 B1; /* -b1! */ +} BP_C32_Coefs_t; + +/*** Peaking coefficients *********************************************************/ +typedef struct +{ + LVM_INT16 A0; /* a0 */ + LVM_INT16 B2; /* -b2! */ + LVM_INT16 B1; /* -b1! */ + LVM_INT16 G; /* Gain */ +} PK_C16_Coefs_t; + +typedef struct +{ + LVM_INT32 A0; /* a0 */ + LVM_INT32 B2; /* -b2! */ + LVM_INT32 B1; /* -b1! */ + LVM_INT16 G; /* Gain */ +} PK_C32_Coefs_t; + + +/********************************************************************************** + TAPS TYPE DEFINITIONS +***********************************************************************************/ + +/*** Types used for first order and shelving filter *******************************/ + +typedef struct +{ + LVM_INT32 Storage[ (1*2) ]; /* One channel, two taps of size LVM_INT32 */ +} Biquad_1I_Order1_Taps_t; + +typedef struct +{ + LVM_INT32 Storage[ (2*2) ]; /* Two channels, two taps of size LVM_INT32 */ +} Biquad_2I_Order1_Taps_t; + + +/*** Types used for biquad, band pass and peaking filter **************************/ + +typedef struct +{ + LVM_INT32 Storage[ (1*4) ]; /* One channel, four taps of size LVM_INT32 */ +} Biquad_1I_Order2_Taps_t; + +typedef struct +{ + LVM_INT32 Storage[ (2*4) ]; /* Two channels, four taps of size LVM_INT32 */ +} Biquad_2I_Order2_Taps_t; + +/* The names of the functions are changed to satisfy QAC rules: Name should be Unique withing 16 characters*/ +#define BQ_2I_D32F32Cll_TRC_WRA_01_Init Init_BQ_2I_D32F32Cll_TRC_WRA_01 +#define BP_1I_D32F32C30_TRC_WRA_02 TWO_BP_1I_D32F32C30_TRC_WRA_02 + +/********************************************************************************** + FUNCTION PROTOTYPES: BIQUAD FILTERS +***********************************************************************************/ + +/*** 16 bit data path *************************************************************/ + +void BQ_2I_D16F32Css_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_2I_Order2_Taps_t *pTaps, + BQ_C16_Coefs_t *pCoef); + +void BQ_2I_D16F32C15_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples); + +void BQ_2I_D16F32C14_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples); + +void BQ_2I_D16F32C13_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples); + +void BQ_2I_D16F16Css_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_2I_Order2_Taps_t *pTaps, + BQ_C16_Coefs_t *pCoef); + +void BQ_2I_D16F16C15_TRC_WRA_01( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples); + +void BQ_2I_D16F16C14_TRC_WRA_01( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples); + +void BQ_1I_D16F16Css_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_1I_Order2_Taps_t *pTaps, + BQ_C16_Coefs_t *pCoef); + +void BQ_1I_D16F16C15_TRC_WRA_01( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples); + +void BQ_1I_D16F32Css_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_1I_Order2_Taps_t *pTaps, + BQ_C16_Coefs_t *pCoef); + +void BQ_1I_D16F32C14_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples); + +/*** 32 bit data path *************************************************************/ + +void BQ_2I_D32F32Cll_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_2I_Order2_Taps_t *pTaps, + BQ_C32_Coefs_t *pCoef); + +void BQ_2I_D32F32C30_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT32 *pDataIn, + LVM_INT32 *pDataOut, + LVM_INT16 NrSamples); + +/********************************************************************************** + FUNCTION PROTOTYPES: FIRST ORDER FILTERS +***********************************************************************************/ + +/*** 16 bit data path *************************************************************/ + +void FO_1I_D16F16Css_TRC_WRA_01_Init( Biquad_Instance_t *pInstance, + Biquad_1I_Order1_Taps_t *pTaps, + FO_C16_Coefs_t *pCoef); + +void FO_1I_D16F16C15_TRC_WRA_01( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples); + +void FO_2I_D16F32Css_LShx_TRC_WRA_01_Init(Biquad_Instance_t *pInstance, + Biquad_2I_Order1_Taps_t *pTaps, + FO_C16_LShx_Coefs_t *pCoef); + +void FO_2I_D16F32C15_LShx_TRC_WRA_01(Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples); + +/*** 32 bit data path *************************************************************/ + +void FO_1I_D32F32Cll_TRC_WRA_01_Init( Biquad_Instance_t *pInstance, + Biquad_1I_Order1_Taps_t *pTaps, + FO_C32_Coefs_t *pCoef); + +void FO_1I_D32F32C31_TRC_WRA_01( Biquad_Instance_t *pInstance, + LVM_INT32 *pDataIn, + LVM_INT32 *pDataOut, + LVM_INT16 NrSamples); + +/********************************************************************************** + FUNCTION PROTOTYPES: BAND PASS FILTERS +***********************************************************************************/ + +/*** 16 bit data path *************************************************************/ + +void BP_1I_D16F16Css_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_1I_Order2_Taps_t *pTaps, + BP_C16_Coefs_t *pCoef); + +void BP_1I_D16F16C14_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples); + +void BP_1I_D16F32Cll_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_1I_Order2_Taps_t *pTaps, + BP_C32_Coefs_t *pCoef); + +void BP_1I_D16F32C30_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples); + + +/*** 32 bit data path *************************************************************/ + +void BP_1I_D32F32Cll_TRC_WRA_02_Init ( Biquad_Instance_t *pInstance, + Biquad_1I_Order2_Taps_t *pTaps, + BP_C32_Coefs_t *pCoef); + +void BP_1I_D32F32C30_TRC_WRA_02( Biquad_Instance_t *pInstance, + LVM_INT32 *pDataIn, + LVM_INT32 *pDataOut, + LVM_INT16 NrSamples); + + +/*** 32 bit data path STEREO ******************************************************/ + +void PK_2I_D32F32CllGss_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_2I_Order2_Taps_t *pTaps, + PK_C32_Coefs_t *pCoef); + +void PK_2I_D32F32C30G11_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT32 *pDataIn, + LVM_INT32 *pDataOut, + LVM_INT16 NrSamples); + +void PK_2I_D32F32CssGss_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_2I_Order2_Taps_t *pTaps, + PK_C16_Coefs_t *pCoef); + +void PK_2I_D32F32C14G11_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT32 *pDataIn, + LVM_INT32 *pDataOut, + LVM_INT16 NrSamples); + + +/********************************************************************************** + FUNCTION PROTOTYPES: DC REMOVAL FILTERS +***********************************************************************************/ + +/*** 16 bit data path STEREO ******************************************************/ + +void DC_2I_D16_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance); + +void DC_2I_D16_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +/**********************************************************************************/ + +#endif /** _BIQUAD_H_ **/ + diff --git a/media/libeffects/lvm/lib/Common/lib/CompLim.h b/media/libeffects/lvm/lib/Common/lib/CompLim.h new file mode 100755 index 0000000..df9b583 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/lib/CompLim.h @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: nxp27078 $ + $Revision: 672 $ + $Date: 2010-06-08 19:39:38 +0200 (Tue, 08 Jun 2010) $ + +***********************************************************************************/ + +#ifndef _COMP_LIM_H +#define _COMP_LIM_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVM_Types.h" + + +/************************************************************************************/ +/* */ +/* Structures */ +/* */ +/************************************************************************************/ + +typedef struct /* Compressor state */ +{ + /* Normaliser */ + LVM_INT16 Norm_Attack; /* Attack time constant of the Normaliser integrator */ + LVM_INT16 Norm_Decay; /* Decay time constant of the Normaliser integrator */ + LVM_INT32 NormInt; /* Normaliser integrator current value */ + LVM_INT16 Shift; /* Shift gain */ + LVM_INT16 Threshold; /* Target threshold */ + + /* Compressor */ + LVM_INT16 Comp_Atten; /* Attenuation applied before soft knee compressor */ + LVM_INT16 Comp_Attack_S; /* Attack time constant of the slow integrator */ + LVM_INT16 Comp_Decay_S; /* Decay time constant of slow the integrator */ + LVM_INT16 Comp_Attack_F; /* Attack time constant of fast the integrator */ + LVM_INT16 Comp_Decay_F; /* Decay time constant of fast the integrator */ + LVM_INT16 SoftClipGain; /* Soft clip gain control */ + LVM_INT32 CompIntSlow; /* Compressor slow integrator current value */ + LVM_INT32 CompIntFast; /* Compressor fast integrator current value */ + + +} CompLim_Instance_t; + + +/************************************************************************************/ +/* */ +/* Function Prototypes */ +/* */ +/************************************************************************************/ + +void NonLinComp_D16(LVM_INT16 Gain, + LVM_INT16 *pSterBfIn, + LVM_INT16 *pSterBfOut, + LVM_INT32 BlockLength); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* #ifndef _COMP_LIM_H */ + + + diff --git a/media/libeffects/lvm/lib/Common/lib/Filter.h b/media/libeffects/lvm/lib/Common/lib/Filter.h new file mode 100755 index 0000000..93ccbcb --- /dev/null +++ b/media/libeffects/lvm/lib/Common/lib/Filter.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 771 $*/ +/* $Date: 2010-06-14 10:41:36 +0200 (Mon, 14 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#ifndef _FILTER_H_ +#define _FILTER_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/********************************************************************************** + INCLUDES +***********************************************************************************/ +#include "LVM_Types.h" +#include "BIQUAD.h" + + +/********************************************************************************** + DEFINES +***********************************************************************************/ +#define FILTER_LOSS 32730 /* -0.01dB loss to avoid wrapping due to band ripple */ + +/********************************************************************************** + FUNCTION PROTOTYPES +***********************************************************************************/ + +LVM_INT32 LVM_Polynomial(LVM_UINT16 N, + LVM_INT32 *pCoefficients, + LVM_INT32 X); + +LVM_INT32 LVM_Power10( LVM_INT32 X); + +LVM_INT32 LVM_FO_LPF( LVM_INT32 w, + FO_C32_Coefs_t *pCoeffs); + +LVM_INT32 LVM_FO_HPF( LVM_INT32 w, + FO_C32_Coefs_t *pCoeffs); + +LVM_INT32 LVM_GetOmega(LVM_UINT16 Fc, + LVM_Fs_en SampleRate); + +/**********************************************************************************/ +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /** _FILTER_H_ **/ + diff --git a/media/libeffects/lvm/lib/Common/lib/InstAlloc.h b/media/libeffects/lvm/lib/Common/lib/InstAlloc.h new file mode 100755 index 0000000..31409bf --- /dev/null +++ b/media/libeffects/lvm/lib/Common/lib/InstAlloc.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ +#ifndef __INSTALLOC_H__ +#define __INSTALLOC_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include "LVM_Types.h" +/*######################################################################################*/ +/* Type declarations */ +/*######################################################################################*/ +typedef struct +{ + LVM_UINT32 TotalSize; /* Accumulative total memory size */ + LVM_UINT32 pNextMember; /* Pointer to the next instance member to be allocated */ +} INST_ALLOC; + + +/*######################################################################################*/ +/* Function prototypes */ +/*######################################################################################*/ + +/**************************************************************************************** + * Name : InstAlloc_Init() + * Input : pms - Pointer to the INST_ALLOC instance + StartAddr - Base address of the instance memory + * Returns : Error code + * Description : Initializes the instance distribution and memory size calculation function + * Remarks : + ****************************************************************************************/ + +void InstAlloc_Init( INST_ALLOC *pms, void *StartAddr ); + + +/**************************************************************************************** + * Name : InstAlloc_AddMember() + * Input : pms - Pointer to the INST_ALLOC instance + Size - The size in bytes of the new added member + * Returns : A pointer to the new added member + * Description : Allocates space for a new member in the instance memory and returns + a pointer to this new member. The start address of all members will + be 32 bit alligned. + * Remarks : + ****************************************************************************************/ + +void* InstAlloc_AddMember( INST_ALLOC *pms, LVM_UINT32 Size ); + +/**************************************************************************************** + * Name : InstAlloc_GetTotal() + * Input : pms - Pointer to the INST_ALLOC instance + * Returns : The instance memory size + * Description : This functions returns the calculated instance memory size + * Remarks : + ****************************************************************************************/ + +LVM_UINT32 InstAlloc_GetTotal( INST_ALLOC *pms); + +void* InstAlloc_AddMemberAllRet( INST_ALLOC *pms, + LVM_UINT32 Size[], + void **ptr); + +void* InstAlloc_AddMemberAll( INST_ALLOC *pms, + LVM_UINT32 Size[], + LVM_MemoryTable_st *pMemoryTable); + +void InstAlloc_InitAll( INST_ALLOC *pms, + LVM_MemoryTable_st *pMemoryTable); + +void InstAlloc_InitAll_NULL( INST_ALLOC *pms); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __JBS_INSTALLOC_H__ */ diff --git a/media/libeffects/lvm/lib/Common/lib/LVM_Common.h b/media/libeffects/lvm/lib/Common/lib/LVM_Common.h new file mode 100755 index 0000000..f0f893d --- /dev/null +++ b/media/libeffects/lvm/lib/Common/lib/LVM_Common.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/***************************************************************************************** + + $Author: nxp27078 $ + $Revision: 672 $ + $Date: 2010-06-08 19:39:38 +0200 (Tue, 08 Jun 2010) $ + +*****************************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Header file for the common definitions used within the bundle and its algorithms. */ +/* */ +/* This files includes all definitions, types, structures and function prototypes. */ +/* */ +/****************************************************************************************/ + + +#ifndef __LVM_COMMON_H__ +#define __LVM_COMMON_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ +#include "LVM_Types.h" + + +/****************************************************************************************/ +/* */ +/* Definitions */ +/* */ +/****************************************************************************************/ +/* Algorithm identification */ +#define ALGORITHM_NONE_ID 0x0000 +#define ALGORITHM_CS_ID 0x0100 +#define ALGORITHM_EQNB_ID 0x0200 +#define ALGORITHM_DBE_ID 0x0300 +#define ALGORITHM_VC_ID 0x0500 +#define ALGORITHM_TE_ID 0x0600 + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LVM_COMMON_H__ */ + diff --git a/media/libeffects/lvm/lib/Common/lib/LVM_Macros.h b/media/libeffects/lvm/lib/Common/lib/LVM_Macros.h new file mode 100755 index 0000000..8bd363d --- /dev/null +++ b/media/libeffects/lvm/lib/Common/lib/LVM_Macros.h @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +#ifndef _LVM_MACROS_H_ +#define _LVM_MACROS_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/********************************************************************************** + MUL32x32INTO32(A,B,C,ShiftR) + C = (A * B) >> ShiftR + + A, B and C are all 32 bit SIGNED numbers and ShiftR can vary from 0 to 64 + + The user has to take care that C does not overflow. The result in case + of overflow is undefined. + +***********************************************************************************/ +#ifndef MUL32x32INTO32 +#define MUL32x32INTO32(A,B,C,ShiftR) \ + {LVM_INT32 MUL32x32INTO32_temp,MUL32x32INTO32_temp2,MUL32x32INTO32_mask,MUL32x32INTO32_HH,MUL32x32INTO32_HL,MUL32x32INTO32_LH,MUL32x32INTO32_LL;\ + LVM_INT32 shiftValue;\ + shiftValue = (ShiftR);\ + MUL32x32INTO32_mask=0x0000FFFF;\ + MUL32x32INTO32_HH= ((LVM_INT32)((LVM_INT16)((A)>>16))*((LVM_INT16)((B)>>16)) );\ + MUL32x32INTO32_HL= ((LVM_INT32)((B)&MUL32x32INTO32_mask)*((LVM_INT16)((A)>>16))) ;\ + MUL32x32INTO32_LH= ((LVM_INT32)((A)&MUL32x32INTO32_mask)*((LVM_INT16)((B)>>16)));\ + MUL32x32INTO32_LL= (LVM_INT32)((A)&MUL32x32INTO32_mask)*(LVM_INT32)((B)&MUL32x32INTO32_mask);\ + MUL32x32INTO32_temp= (LVM_INT32)(MUL32x32INTO32_HL&MUL32x32INTO32_mask)+(LVM_INT32)(MUL32x32INTO32_LH&MUL32x32INTO32_mask)+(LVM_INT32)((MUL32x32INTO32_LL>>16)&MUL32x32INTO32_mask);\ + MUL32x32INTO32_HH= MUL32x32INTO32_HH+(LVM_INT32)(MUL32x32INTO32_HL>>16)+(LVM_INT32)(MUL32x32INTO32_LH>>16)+(LVM_INT32)(MUL32x32INTO32_temp>>16);\ + MUL32x32INTO32_LL=MUL32x32INTO32_LL+(LVM_INT32)(MUL32x32INTO32_HL<<16)+(LVM_INT32)(MUL32x32INTO32_LH<<16);\ + if(shiftValue<32)\ + {\ + MUL32x32INTO32_HH=MUL32x32INTO32_HH<<(32-shiftValue);\ + MUL32x32INTO32_mask=((LVM_INT32)1<<(32-shiftValue))-1;\ + MUL32x32INTO32_LL=(MUL32x32INTO32_LL>>shiftValue)&MUL32x32INTO32_mask;\ + MUL32x32INTO32_temp2=MUL32x32INTO32_HH|MUL32x32INTO32_LL;\ + }\ + else\ + {\ + MUL32x32INTO32_temp2=(LVM_INT32)MUL32x32INTO32_HH>>(shiftValue-32);\ + }\ + (C) = MUL32x32INTO32_temp2;\ + } +#endif + +/********************************************************************************** + MUL32x16INTO32(A,B,C,ShiftR) + C = (A * B) >> ShiftR + + A and C are 32 bit SIGNED numbers. B is a 16 bit SIGNED number. + ShiftR can vary from 0 to 48 + + The user has to take care that C does not overflow. The result in case + of overflow is undefined. + +***********************************************************************************/ +#ifndef MUL32x16INTO32 +#define MUL32x16INTO32(A,B,C,ShiftR) \ + {LVM_INT32 MUL32x16INTO32_mask,MUL32x16INTO32_HH,MUL32x16INTO32_LL;\ + LVM_INT32 shiftValue;\ + shiftValue = (ShiftR);\ + MUL32x16INTO32_mask=0x0000FFFF;\ + MUL32x16INTO32_HH= ((LVM_INT32)(B)*((LVM_INT16)((A)>>16)));\ + MUL32x16INTO32_LL= ((LVM_INT32)((A)&MUL32x16INTO32_mask)*(B));\ + if(shiftValue<16)\ + {\ + MUL32x16INTO32_HH=(LVM_INT32)((LVM_UINT32)MUL32x16INTO32_HH<<(16-shiftValue));\ + (C)=MUL32x16INTO32_HH+(LVM_INT32)(MUL32x16INTO32_LL>>shiftValue);\ + }\ + else if(shiftValue<32) {\ + MUL32x16INTO32_HH=(LVM_INT32)(MUL32x16INTO32_HH>>(shiftValue-16));\ + (C)=MUL32x16INTO32_HH+(LVM_INT32)(MUL32x16INTO32_LL>>shiftValue);\ + }\ + else {\ + (C)=MUL32x16INTO32_HH>>(shiftValue-16);}\ + } +#endif + +/********************************************************************************** + ADD2_SAT_32x32(A,B,C) + C = SAT(A + B) + + A,B and C are 32 bit SIGNED numbers. +***********************************************************************************/ +#ifndef ADD2_SAT_32x32 +#define ADD2_SAT_32x32(A,B,C) \ + {(C)=(A)+(B);\ + if ((((C) ^ (A)) & ((C) ^ (B))) >> 31)\ + {\ + if((A)<0)\ + (C)=0x80000000l;\ + else\ + (C)=0x7FFFFFFFl;\ + }\ + } +#endif + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _LVM_MACROS_H_ */ + +/*** End of file ******************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/lib/LVM_Timer.h b/media/libeffects/lvm/lib/Common/lib/LVM_Timer.h new file mode 100755 index 0000000..22a16d6 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/lib/LVM_Timer.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LVM_TIMER_H__ +#define __LVM_TIMER_H__ +/************************************************************************/ +/* */ +/* Project:: My Project */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ +#include "LVM_Types.h" + +/****************************************************************************************/ +/* */ +/* Header file for the LVM_Timer library */ +/* */ +/* Functionality: */ +/* The timer will count down a number of ms, based on the number of samples it */ +/* sees and the curent sampling rate. When the timer expires, a registered */ +/* callback function will be called. */ +/* The maximal number of sampless that can be called by the timer is 2^32, which */ +/* corresponds to 24.8 hours at a sampling rate of 48 kHz */ +/* The timer currently does not suport changes in sampling rate while timing. */ +/****************************************************************************************/ + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************************/ +/* TYPE DEFINITIONS */ +/****************************************************************************************/ + +typedef struct +{ + LVM_INT32 Storage[6]; + +} LVM_Timer_Instance_t; + +typedef struct +{ + LVM_INT32 SamplingRate; + LVM_INT16 TimeInMs; + LVM_INT32 CallBackParam; + void *pCallBackParams; + void *pCallbackInstance; + void (*pCallBack)(void*,void*,LVM_INT32); + +} LVM_Timer_Params_t; + +/****************************************************************************************/ +/* FUNCTION PROTOTYPES */ +/****************************************************************************************/ + +void LVM_Timer_Init ( LVM_Timer_Instance_t *pInstance, + LVM_Timer_Params_t *pParams ); + + +void LVM_Timer ( LVM_Timer_Instance_t *pInstance, + LVM_INT16 BlockSize ); + + +/****************************************************************************************/ +/* END OF HEADER */ +/****************************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LVM_TIMER_H__ */ diff --git a/media/libeffects/lvm/lib/Common/lib/LVM_Types.h b/media/libeffects/lvm/lib/Common/lib/LVM_Types.h new file mode 100755 index 0000000..e4649ba --- /dev/null +++ b/media/libeffects/lvm/lib/Common/lib/LVM_Types.h @@ -0,0 +1,195 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +*****************************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Header file defining the standard LifeVibes types for use in the application layer */ +/* interface of all LifeVibes modules */ +/* */ +/****************************************************************************************/ + +#ifndef LVM_TYPES_H +#define LVM_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/****************************************************************************************/ +/* */ +/* definitions */ +/* */ +/****************************************************************************************/ + +#define LVM_NULL 0 /* NULL pointer */ + +#define LVM_TRUE 1 /* Booleans */ +#define LVM_FALSE 0 + +#define LVM_MAXINT_8 127 /* Maximum positive integer size */ +#define LVM_MAXINT_16 32767 +#define LVM_MAXINT_32 2147483647 +#define LVM_MAXENUM 2147483647 + +#define LVM_MODULEID_MASK 0xFF00 /* Mask to extract the calling module ID from callbackId */ +#define LVM_EVENTID_MASK 0x00FF /* Mask to extract the callback event from callbackId */ + +/* Memory table*/ +#define LVM_MEMREGION_PERSISTENT_SLOW_DATA 0 /* Offset to the instance memory region */ +#define LVM_MEMREGION_PERSISTENT_FAST_DATA 1 /* Offset to the persistent data memory region */ +#define LVM_MEMREGION_PERSISTENT_FAST_COEF 2 /* Offset to the persistent coefficient memory region */ +#define LVM_MEMREGION_TEMPORARY_FAST 3 /* Offset to temporary memory region */ + +#define LVM_NR_MEMORY_REGIONS 4 /* Number of memory regions */ + +/* Memory partition type */ +#define LVM_MEM_PARTITION0 0 /* 1st memory partition */ +#define LVM_MEM_PARTITION1 1 /* 2nd memory partition */ +#define LVM_MEM_PARTITION2 2 /* 3rd memory partition */ +#define LVM_MEM_PARTITION3 3 /* 4th memory partition */ + +/* Use type */ +#define LVM_MEM_PERSISTENT 0 /* Persistent memory type */ +#define LVM_MEM_SCRATCH 4 /* Scratch memory type */ + +/* Access type */ +#define LVM_MEM_INTERNAL 0 /* Internal (fast) access memory */ +#define LVM_MEM_EXTERNAL 8 /* External (slow) access memory */ + +/* Platform specific */ +#define LVM_PERSISTENT LVM_MEM_PARTITION0+LVM_MEM_PERSISTENT+LVM_MEM_INTERNAL +#define LVM_PERSISTENT_DATA LVM_MEM_PARTITION1+LVM_MEM_PERSISTENT+LVM_MEM_INTERNAL +#define LVM_PERSISTENT_COEF LVM_MEM_PARTITION2+LVM_MEM_PERSISTENT+LVM_MEM_INTERNAL +#define LVM_SCRATCH LVM_MEM_PARTITION3+LVM_MEM_SCRATCH+LVM_MEM_INTERNAL + +/****************************************************************************************/ +/* */ +/* Basic types */ +/* */ +/****************************************************************************************/ + +typedef char LVM_CHAR; /* ASCII character */ + +typedef char LVM_INT8; /* Signed 8-bit word */ +typedef unsigned char LVM_UINT8; /* Unsigned 8-bit word */ + +typedef short LVM_INT16; /* Signed 16-bit word */ +typedef unsigned short LVM_UINT16; /* Unsigned 16-bit word */ + +typedef long LVM_INT32; /* Signed 32-bit word */ +typedef unsigned long LVM_UINT32; /* Unsigned 32-bit word */ + + +/****************************************************************************************/ +/* */ +/* Standard Enumerated types */ +/* */ +/****************************************************************************************/ + +/* Operating mode */ +typedef enum +{ + LVM_MODE_OFF = 0, + LVM_MODE_ON = 1, + LVM_MODE_DUMMY = LVM_MAXENUM +} LVM_Mode_en; + + +/* Format */ +typedef enum +{ + LVM_STEREO = 0, + LVM_MONOINSTEREO = 1, + LVM_MONO = 2, + LVM_SOURCE_DUMMY = LVM_MAXENUM +} LVM_Format_en; + + +/* LVM sampling rates */ +typedef enum +{ + LVM_FS_8000 = 0, + LVM_FS_11025 = 1, + LVM_FS_12000 = 2, + LVM_FS_16000 = 3, + LVM_FS_22050 = 4, + LVM_FS_24000 = 5, + LVM_FS_32000 = 6, + LVM_FS_44100 = 7, + LVM_FS_48000 = 8, + LVM_FS_INVALID = LVM_MAXENUM-1, + LVM_FS_DUMMY = LVM_MAXENUM +} LVM_Fs_en; + + +/* Memory Types */ +typedef enum +{ + LVM_PERSISTENT_SLOW_DATA = LVM_MEMREGION_PERSISTENT_SLOW_DATA, + LVM_PERSISTENT_FAST_DATA = LVM_MEMREGION_PERSISTENT_FAST_DATA, + LVM_PERSISTENT_FAST_COEF = LVM_MEMREGION_PERSISTENT_FAST_COEF, + LVM_TEMPORARY_FAST = LVM_MEMREGION_TEMPORARY_FAST, + LVM_MEMORYTYPE_DUMMY = LVM_MAXENUM +} LVM_MemoryTypes_en; + + +/* Memory region definition */ +typedef struct +{ + LVM_UINT32 Size; /* Region size in bytes */ + LVM_MemoryTypes_en Type; /* Region type */ + void *pBaseAddress; /* Pointer to the region base address */ +} LVM_MemoryRegion_st; + + +/* Memory table containing the region definitions */ +typedef struct +{ + LVM_MemoryRegion_st Region[LVM_NR_MEMORY_REGIONS]; /* One definition for each region */ +} LVM_MemoryTable_st; + + +/****************************************************************************************/ +/* */ +/* Standard Function Prototypes */ +/* */ +/****************************************************************************************/ +typedef LVM_INT32 (*LVM_Callback)(void *pCallbackData, /* Pointer to the callback data structure */ + void *pGeneralPurpose, /* General purpose pointer (e.g. to a data structure needed in the callback) */ + LVM_INT16 GeneralPurpose ); /* General purpose variable (e.g. to be used as callback ID) */ + + +/****************************************************************************************/ +/* */ +/* End of file */ +/* */ +/****************************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LVM_TYPES_H */ diff --git a/media/libeffects/lvm/lib/Common/lib/Mixer.h b/media/libeffects/lvm/lib/Common/lib/Mixer.h new file mode 100755 index 0000000..d741980 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/lib/Mixer.h @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +#ifndef __MIXER_H__ +#define __MIXER_H__ + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#include "LVM_Types.h" + +/********************************************************************************** + INSTANCE MEMORY TYPE DEFINITION +***********************************************************************************/ + +typedef struct +{ + LVM_INT32 Alpha; /* Time constant. Set by calling application. Can be changed at any time */ + LVM_INT32 Target; /* Target value. Set by calling application. Can be changed at any time */ + LVM_INT32 Current; /* Current value. Set by the mixer function. */ + LVM_INT16 CallbackSet; /* Boolean. Should be set by calling application each time the target value is updated */ + LVM_INT16 CallbackParam; /* Parameter that will be used in the calback function */ + void *pCallbackHandle; /* Pointer to the instance of the callback function */ + void *pGeneralPurpose; /* Pointer for general purpose usage */ + LVM_Callback pCallBack; /* Pointer to the callback function */ +} Mix_1St_Cll_t; + +typedef struct +{ + LVM_INT32 Alpha1; + LVM_INT32 Target1; + LVM_INT32 Current1; + LVM_INT16 CallbackSet1; + LVM_INT16 CallbackParam1; + void *pCallbackHandle1; + void *pGeneralPurpose1; + LVM_Callback pCallBack1; + + LVM_INT32 Alpha2; /* Warning the address of this location is passed as a pointer to Mix_1St_Cll_t in some functions */ + LVM_INT32 Target2; + LVM_INT32 Current2; + LVM_INT16 CallbackSet2; + LVM_INT16 CallbackParam2; + void *pCallbackHandle2; + void *pGeneralPurpose2; + LVM_Callback pCallBack2; + +} Mix_2St_Cll_t; + + +/*** General functions ************************************************************/ + +LVM_UINT32 LVM_Mixer_TimeConstant(LVM_UINT32 tc, + LVM_UINT16 Fs, + LVM_UINT16 NumChannels); + + +void MixSoft_1St_D32C31_WRA( Mix_1St_Cll_t *pInstance, + const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n); + +void MixSoft_2St_D32C31_SAT( Mix_2St_Cll_t *pInstance, + const LVM_INT32 *src1, + const LVM_INT32 *src2, + LVM_INT32 *dst, + LVM_INT16 n); + +void MixInSoft_D32C31_SAT( Mix_1St_Cll_t *pInstance, + const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n); + +/********************************************************************************** + FUNCTION PROTOTYPES (LOW LEVEL SUBFUNCTIONS) +***********************************************************************************/ + +void Core_MixSoft_1St_D32C31_WRA( Mix_1St_Cll_t *pInstance, + const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n); + +void Core_MixHard_2St_D32C31_SAT( Mix_2St_Cll_t *pInstance, + const LVM_INT32 *src1, + const LVM_INT32 *src2, + LVM_INT32 *dst, + LVM_INT16 n); + +void Core_MixInSoft_D32C31_SAT( Mix_1St_Cll_t *pInstance, + const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +/**********************************************************************************/ + +#endif /* __MIXER_H__ */ + + + + + + + + + + diff --git a/media/libeffects/lvm/lib/Common/lib/ScalarArithmetic.h b/media/libeffects/lvm/lib/Common/lib/ScalarArithmetic.h new file mode 100755 index 0000000..c66e201 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/lib/ScalarArithmetic.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#ifndef __SCALARARITHMETIC_H__ +#define __SCALARARITHMETIC_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/*######################################################################################*/ +/* Include files */ +/*######################################################################################*/ + +#include "LVM_Types.h" + +/*######################################################################################*/ +/* Extern function prototypes */ +/*######################################################################################*/ + +/* Absolute value including the corner case for the extreme negative value */ +LVM_INT32 Abs_32(LVM_INT32 input); + +/**************************************************************************************** + * Name : dB_to_Lin32() + * Input : Signed 16-bit integer + * MSB (16) = sign bit + * (15->05) = integer part + * (04->01) = decimal part + * Output : Signed 32-bit integer + * MSB (32) = sign bit + * (31->16) = integer part + * (15->01) = decimal part + * Returns : Lin value format 1.16.15 + ****************************************************************************************/ + +LVM_INT32 dB_to_Lin32(LVM_INT16 db_fix); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __SCALARARITHMETIC_H__ */ + + diff --git a/media/libeffects/lvm/lib/Common/lib/VectorArithmetic.h b/media/libeffects/lvm/lib/Common/lib/VectorArithmetic.h new file mode 100755 index 0000000..290a996 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/lib/VectorArithmetic.h @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 853 $ + $Date: 2010-06-16 15:10:28 +0200 (Wed, 16 Jun 2010) $ + +***********************************************************************************/ + +#ifndef _VECTOR_ARITHMETIC_H_ +#define _VECTOR_ARITHMETIC_H_ + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include "LVM_Types.h" + +/********************************************************************************** + VARIOUS FUNCTIONS +***********************************************************************************/ + +void LoadConst_16( const LVM_INT16 val, + LVM_INT16 *dst, + LVM_INT16 n ); + +void LoadConst_32( const LVM_INT32 val, + LVM_INT32 *dst, + LVM_INT16 n ); + +void Copy_16( const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n ); + +/********************************************************************************* + * note: In Mult3s_16x16() saturation of result is not taken care when * + * overflow occurs. * + * For example when *src = 0x8000, val = *0x8000 * + * The function gives the output as 0x8000 instead of 0x7fff * + * This is the only case which will give wrong result. * + * For more information refer to Vector_Arithmetic.doc in /doc folder * + *********************************************************************************/ +void Mult3s_16x16( const LVM_INT16 *src, + const LVM_INT16 val, + LVM_INT16 *dst, + LVM_INT16 n); + +/********************************************************************************* + * note: In Mult3s_32x16() saturation of result is not taken care when * + * overflow occurs. * + * For example when *src = 0x8000000, val = *0x8000 * + * The function gives the output as 0x8000000 instead of 0x7fffffff * + * This is the only extreme condition which is giving unexpected result * + * For more information refer to Vector_Arithmetic.doc in /doc folder * + *********************************************************************************/ +void Mult3s_32x16( const LVM_INT32 *src, + const LVM_INT16 val, + LVM_INT32 *dst, + LVM_INT16 n); + +void DelayMix_16x16( const LVM_INT16 *src, + LVM_INT16 *delay, + LVM_INT16 size, + LVM_INT16 *dst, + LVM_INT16 *pOffset, + LVM_INT16 n); + +void DelayWrite_32( const LVM_INT32 *src, /* Source 1, to be delayed */ + LVM_INT32 *delay, /* Delay buffer */ + LVM_UINT16 size, /* Delay size */ + LVM_UINT16 *pOffset, /* Delay offset */ + LVM_INT16 n); + +void Add2_Sat_16x16( const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n ); + +void Add2_Sat_32x32( const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n ); + +void Mac3s_Sat_16x16( const LVM_INT16 *src, + const LVM_INT16 val, + LVM_INT16 *dst, + LVM_INT16 n); + +void Mac3s_Sat_32x16( const LVM_INT32 *src, + const LVM_INT16 val, + LVM_INT32 *dst, + LVM_INT16 n); + +void DelayAllPass_Sat_32x16To32( LVM_INT32 *delay, /* Delay buffer */ + LVM_UINT16 size, /* Delay size */ + LVM_INT16 coeff, /* All pass filter coefficient */ + LVM_UINT16 DelayOffset, /* Simple delay offset */ + LVM_UINT16 *pAllPassOffset, /* All pass filter delay offset */ + LVM_INT32 *dst, /* Source/destination */ + LVM_INT16 n); + +/********************************************************************************** + SHIFT FUNCTIONS +***********************************************************************************/ + +void Shift_Sat_v16xv16 ( const LVM_INT16 val, + const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n); + +void Shift_Sat_v32xv32 ( const LVM_INT16 val, + const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n); + +/********************************************************************************** + AUDIO FORMAT CONVERSION FUNCTIONS +***********************************************************************************/ + +void MonoTo2I_16( const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n); + +void MonoTo2I_32( const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n); + +void From2iToMono_32( const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n); + +void MSTo2i_Sat_16x16( const LVM_INT16 *srcM, + const LVM_INT16 *srcS, + LVM_INT16 *dst, + LVM_INT16 n ); + +void From2iToMS_16x16( const LVM_INT16 *src, + LVM_INT16 *dstM, + LVM_INT16 *dstS, + LVM_INT16 n ); + +void From2iToMono_16( const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n); + +void JoinTo2i_32x32( const LVM_INT32 *srcL, + const LVM_INT32 *srcR, + LVM_INT32 *dst, + LVM_INT16 n ); + +/********************************************************************************** + DATA TYPE CONVERSION FUNCTIONS +***********************************************************************************/ + +void Int16LShiftToInt32_16x32(const LVM_INT16 *src, + LVM_INT32 *dst, + LVM_INT16 n, + LVM_INT16 shift ); + +void Int32RShiftToInt16_Sat_32x16(const LVM_INT32 *src, + LVM_INT16 *dst, + LVM_INT16 n, + LVM_INT16 shift ); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +/**********************************************************************************/ + +#endif /* _VECTOR_ARITHMETIC_H_ */ + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/AGC_MIX_VOL_2St1Mon_D32_WRA.c b/media/libeffects/lvm/lib/Common/src/AGC_MIX_VOL_2St1Mon_D32_WRA.c new file mode 100755 index 0000000..40e0dbf --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/AGC_MIX_VOL_2St1Mon_D32_WRA.c @@ -0,0 +1,204 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************************** + + $Author: beq07716 $ + $Revision: 1070 $ + $Date: 2010-07-02 11:22:18 +0200 (Fri, 02 Jul 2010) $ + +*****************************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "AGC.h" +#include "ScalarArithmetic.h" + + +/****************************************************************************************/ +/* */ +/* Defines */ +/* */ +/****************************************************************************************/ + +#define VOL_TC_SHIFT 21 /* As a power of 2 */ +#define DECAY_SHIFT 10 /* As a power of 2 */ + + +/****************************************************************************************/ +/* */ +/* FUNCTION: AGC_MIX_VOL_2St1Mon_D32_WRA */ +/* */ +/* DESCRIPTION: */ +/* Apply AGC and mix signals */ +/* */ +/* */ +/* StSrc ------------------| */ +/* | */ +/* ______ _|_ ________ */ +/* | | | | | | */ +/* MonoSrc -->| AGC |---->| + |----->| Volume |------------------------------+---> */ +/* | Gain | |___| | Gain | | */ +/* |______| |________| | */ +/* /|\ __________ ________ | */ +/* | | | | | | */ +/* |-------------------------------| AGC Gain |<--| Peak |<--| */ +/* | Update | | Detect | */ +/* |__________| |________| */ +/* */ +/* */ +/* PARAMETERS: */ +/* pInstance Instance pointer */ +/* pStereoIn Stereo source */ +/* pMonoIn Mono band pass source */ +/* pStereoOut Stereo destination */ +/* */ +/* RETURNS: */ +/* Void */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +void AGC_MIX_VOL_2St1Mon_D32_WRA(AGC_MIX_VOL_2St1Mon_D32_t *pInstance, /* Instance pointer */ + const LVM_INT32 *pStSrc, /* Stereo source */ + const LVM_INT32 *pMonoSrc, /* Mono source */ + LVM_INT32 *pDst, /* Stereo destination */ + LVM_UINT16 NumSamples) /* Number of samples */ +{ + + /* + * General variables + */ + LVM_UINT16 i; /* Sample index */ + LVM_INT32 Left; /* Left sample */ + LVM_INT32 Right; /* Right sample */ + LVM_INT32 Mono; /* Mono sample */ + LVM_INT32 AbsPeak; /* Absolute peak signal */ + LVM_INT32 HighWord; /* High word in intermediate calculations */ + LVM_INT32 LowWord; /* Low word in intermediate calculations */ + LVM_INT16 AGC_Mult; /* Short AGC gain */ + LVM_INT16 Vol_Mult; /* Short volume */ + + + /* + * Instance control variables + */ + LVM_INT32 AGC_Gain = pInstance->AGC_Gain; /* Get the current AGC gain */ + LVM_INT32 AGC_MaxGain = pInstance->AGC_MaxGain; /* Get maximum AGC gain */ + LVM_INT16 AGC_GainShift = pInstance->AGC_GainShift; /* Get the AGC shift */ + LVM_INT16 AGC_Attack = pInstance->AGC_Attack; /* Attack scaler */ + LVM_INT16 AGC_Decay = pInstance->AGC_Decay; /* Decay scaler */ + LVM_INT32 AGC_Target = pInstance->AGC_Target; /* Get the target level */ + LVM_INT32 Vol_Current = pInstance->Volume; /* Actual volume setting */ + LVM_INT32 Vol_Target = pInstance->Target; /* Target volume setting */ + LVM_INT16 Vol_Shift = pInstance->VolumeShift; /* Volume shift scaling */ + LVM_INT16 Vol_TC = pInstance->VolumeTC; /* Time constant */ + + + /* + * Process on a sample by sample basis + */ + for (i=0;i> 16); /* Get the short AGC gain */ + Vol_Mult = (LVM_INT16)(Vol_Current >> 16); /* Get the short volume gain */ + + + /* + * Get the input samples + */ + Left = *pStSrc++; /* Get the left sample */ + Right = *pStSrc++; /* Get the right sample */ + Mono = *pMonoSrc++; /* Get the mono sample */ + + + /* + * Apply the AGC gain to the mono input and mix with the stereo signal + */ + HighWord = (AGC_Mult * (Mono >> 16)); /* signed long (Mono) by unsigned short (AGC_Mult) multiply */ + LowWord = (AGC_Mult * (Mono & 0xffff)); + Mono = (HighWord + (LowWord >> 16)) << (AGC_GainShift); + Left += Mono; /* Mix in the mono signal */ + Right += Mono; + + + /* + * Apply the volume and write to the output stream + */ + HighWord = (Vol_Mult * (Left >> 16)); /* signed long (Left) by unsigned short (Vol_Mult) multiply */ + LowWord = (Vol_Mult * (Left & 0xffff)); + Left = (HighWord + (LowWord >> 16)) << (Vol_Shift); + HighWord = (Vol_Mult * (Right >> 16)); /* signed long (Right) by unsigned short (Vol_Mult) multiply */ + LowWord = (Vol_Mult * (Right & 0xffff)); + Right = (HighWord + (LowWord >> 16)) << (Vol_Shift); + *pDst++ = Left; /* Save the results */ + *pDst++ = Right; + + + /* + * Update the AGC gain + */ + AbsPeak = (Abs_32(Left)>Abs_32(Right)) ? Abs_32(Left) : Abs_32(Right); /* Get the absolute peak */ + if (AbsPeak > AGC_Target) + { + /* + * The signal is too large so decrease the gain + */ + HighWord = (AGC_Attack * (AGC_Gain >> 16)); /* signed long (AGC_Gain) by unsigned short (AGC_Attack) multiply */ + LowWord = (AGC_Attack * (AGC_Gain & 0xffff)); + AGC_Gain = (HighWord + (LowWord >> 16)) << 1; + } + else + { + /* + * The signal is too small so increase the gain + */ + if (AGC_Gain > AGC_MaxGain) + { + AGC_Gain -= (AGC_Decay << DECAY_SHIFT); + } + else + { + AGC_Gain += (AGC_Decay << DECAY_SHIFT); + } + } + + /* + * Update the gain + */ + Vol_Current += Vol_TC * ((Vol_Target - Vol_Current) >> VOL_TC_SHIFT); + } + + + /* + * Update the parameters + */ + pInstance->Volume = Vol_Current; /* Actual volume setting */ + pInstance->AGC_Gain = AGC_Gain; + + return; +} + diff --git a/media/libeffects/lvm/lib/Common/src/Abs_32.c b/media/libeffects/lvm/lib/Common/src/Abs_32.c new file mode 100755 index 0000000..635315d --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Abs_32.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/*######################################################################################*/ +/* Include files */ +/*######################################################################################*/ + +#include "ScalarArithmetic.h" + +/**************************************************************************************** + * Name : Abs_32() + * Input : Signed 32-bit integer + * Output : + * Returns : Absolute value + * Description : Absolute value with maximum negative value corner case + * Remarks : + ****************************************************************************************/ + +LVM_INT32 Abs_32(LVM_INT32 input) +{ + if(input < 0) + { + if (input == (LVM_INT32)(0x80000000U)) + { + /* The corner case, so set to the maximum positive value */ + input=(LVM_INT32) 0x7fffffff; + } + else + { + /* Negative input, so invert */ + input = (LVM_INT32)(-input); + } + } + return input; +} + diff --git a/media/libeffects/lvm/lib/Common/src/Add2_Sat_16x16.c b/media/libeffects/lvm/lib/Common/src/Add2_Sat_16x16.c new file mode 100755 index 0000000..18026c5 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Add2_Sat_16x16.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION ADD2_SAT_16X16 +***********************************************************************************/ + +void Add2_Sat_16x16( const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n ) +{ + LVM_INT32 Temp; + LVM_INT16 ii; + for (ii = n; ii != 0; ii--) + { + Temp = ((LVM_INT32) *src) + ((LVM_INT32) *dst); + src++; + + if (Temp > 0x00007FFF) + { + *dst = 0x7FFF; + } + else if (Temp < -0x00008000) + { + *dst = - 0x8000; + } + else + { + *dst = (LVM_INT16)Temp; + } + dst++; + } + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/Add2_Sat_32x32.c b/media/libeffects/lvm/lib/Common/src/Add2_Sat_32x32.c new file mode 100755 index 0000000..96fc7e6 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Add2_Sat_32x32.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + + +/********************************************************************************** + FUNCTION ADD2_SAT_32X32 +***********************************************************************************/ + +void Add2_Sat_32x32( const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n ) +{ + LVM_INT32 a,b,c; + LVM_INT16 ii; + for (ii = n; ii != 0; ii--) + { + a=*src; + src++; + + b=*dst; + c=a+b; + if ((((c ^ a) & (c ^ b)) >> 31)!=0) /* overflow / underflow */ + { + if(a<0) + { + c=0x80000000l; + } + else + { + c=0x7FFFFFFFl; + } + } + + *dst = c; + dst++; + } + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/BP_1I_D16F16C14_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/BP_1I_D16F16C14_TRC_WRA_01.c new file mode 100755 index 0000000..76d8e42 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BP_1I_D16F16C14_TRC_WRA_01.c @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "BP_1I_D16F16Css_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A0, + pBiquadState->coefs[1] is -B2, + pBiquadState->coefs[2] is -B1, these are in Q14 format + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is x(n-2)L in Q0 format + pBiquadState->pDelays[2] is y(n-1)L in Q0 format + pBiquadState->pDelays[3] is y(n-2)L in Q0 format +***************************************************************************/ + +void BP_1I_D16F16C14_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples) + + + { + LVM_INT32 ynL; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + // ynL= (A0 (Q14) * (x(n)L (Q0) - x(n-2)L (Q0) ) ) in Q14 + ynL=(LVM_INT32)pBiquadState->coefs[0]* ((*pDataIn)-pBiquadState->pDelays[1]); + + // ynL+= ((-B2 (Q14) * y(n-2)L (Q0) ) ) in Q14 + ynL+=(LVM_INT32)pBiquadState->coefs[1]*pBiquadState->pDelays[3]; + + // ynL+= ((-B1 (Q30) * y(n-1)L (Q0) ) ) in Q14 + ynL+=(LVM_INT32)pBiquadState->coefs[2]*pBiquadState->pDelays[2]; + + ynL=(LVM_INT16)(ynL>>14); // ynL in Q0 + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[3]=pBiquadState->pDelays[2]; // y(n-2)L=y(n-1)L + pBiquadState->pDelays[1]=pBiquadState->pDelays[0]; // x(n-2)L=x(n-1)L + pBiquadState->pDelays[2]=ynL; // Update y(n-1)L in Q0 + pBiquadState->pDelays[0]=(*pDataIn++); // Update x(n-1)L in Q0 + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut++=(LVM_INT16)ynL; // Write Left output in Q0 + + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/BP_1I_D16F16Css_TRC_WRA_01_Init.c b/media/libeffects/lvm/lib/Common/src/BP_1I_D16F16Css_TRC_WRA_01_Init.c new file mode 100755 index 0000000..9338eb2 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BP_1I_D16F16Css_TRC_WRA_01_Init.c @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/*-------------------------------------------------------------------------*/ +#include "BIQUAD.h" +#include "BP_1I_D16F16Css_TRC_WRA_01_Private.h" + + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* BP_1I_D16F16Css_TRC_WRA_01_Init */ +/* */ +/* DESCRIPTION: */ +/* These functions initializes a BIQUAD filter defined as a cascade of */ +/* biquadratic Filter Sections. */ +/* */ +/* PARAMETERS: */ +/* pInstance - output, returns the pointer to the State Variable */ +/* This state pointer must be passed to any subsequent */ +/* call to "Biquad" functions. */ +/* pTaps - input, pointer to the taps memory */ +/* pCoef - input, pointer to the coefficient structure */ +/* N - M coefficient factor of QM.N */ +/* RETURNS: */ +/* void return code */ +/*-------------------------------------------------------------------------*/ +void BP_1I_D16F16Css_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_1I_Order2_Taps_t *pTaps, + BP_C16_Coefs_t *pCoef) +{ + PFilter_State pBiquadState = (PFilter_State) pInstance; + pBiquadState->pDelays =(LVM_INT32 *) pTaps; + + pBiquadState->coefs[0]=pCoef->A0; + pBiquadState->coefs[1]=pCoef->B2; + pBiquadState->coefs[2]=pCoef->B1; + } +/*-------------------------------------------------------------------------*/ +/* End Of File: BP_1I_D16F16Css_TRC_WRA_01_Init.c */ + diff --git a/media/libeffects/lvm/lib/Common/src/BP_1I_D16F16Css_TRC_WRA_01_Private.h b/media/libeffects/lvm/lib/Common/src/BP_1I_D16F16Css_TRC_WRA_01_Private.h new file mode 100755 index 0000000..2a0d7d5 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BP_1I_D16F16Css_TRC_WRA_01_Private.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _BP_1I_D16F16CSS_TRC_WRA_01_PRIVATE_H_ +#define _BP_1I_D16F16CSS_TRC_WRA_01_PRIVATE_H_ +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/* The internal state variables are implemented in a (for the user) hidden structure */ +/* In this (private) file, the internal structure is declared fro private use. */ +typedef struct _Filter_State_ +{ + LVM_INT32 * pDelays; /* pointer to the delayed samples (data of 32 bits) */ + LVM_INT32 coefs[3]; /* pointer to the filter coefficients */ +}Filter_State; + +typedef Filter_State * PFilter_State ; + +#endif /*_BP_1I_D16F16CSS_TRC_WRA_01_PRIVATE_H_*/ diff --git a/media/libeffects/lvm/lib/Common/src/BP_1I_D16F32C30_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/BP_1I_D16F32C30_TRC_WRA_01.c new file mode 100755 index 0000000..f52d3db --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BP_1I_D16F32C30_TRC_WRA_01.c @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "BP_1I_D16F32Cll_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A0, + pBiquadState->coefs[1] is -B2, + pBiquadState->coefs[2] is -B1, these are in Q30 format + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is x(n-2)L in Q0 format + pBiquadState->pDelays[2] is y(n-1)L in Q16 format + pBiquadState->pDelays[3] is y(n-2)L in Q16 format +***************************************************************************/ + +void BP_1I_D16F32C30_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples) + + + { + LVM_INT32 ynL,templ; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + // ynL= (A0 (Q30) * (x(n)L (Q0) - x(n-2)L (Q0) ) >>14) in Q16 + templ= (LVM_INT32) *pDataIn-pBiquadState->pDelays[1]; + MUL32x32INTO32(pBiquadState->coefs[0],templ,ynL,14) + + // ynL+= ((-B2 (Q30) * y(n-2)L (Q16) ) >>30) in Q16 + MUL32x32INTO32(pBiquadState->coefs[1],pBiquadState->pDelays[3],templ,30) + ynL+=templ; + + // ynL+= ((-B1 (Q30) * y(n-1)L (Q16) ) >>30) in Q16 + MUL32x32INTO32(pBiquadState->coefs[2],pBiquadState->pDelays[2],templ,30) + ynL+=templ; + + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[3]=pBiquadState->pDelays[2]; // y(n-2)L=y(n-1)L + pBiquadState->pDelays[1]=pBiquadState->pDelays[0]; // x(n-2)L=x(n-1)L + pBiquadState->pDelays[2]=ynL; // Update y(n-1)L in Q16 + pBiquadState->pDelays[0]=(*pDataIn++); // Update x(n-1)L in Q0 + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut++=(LVM_INT16)(ynL>>16); // Write Left output in Q0 + + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/BP_1I_D16F32Cll_TRC_WRA_01_Init.c b/media/libeffects/lvm/lib/Common/src/BP_1I_D16F32Cll_TRC_WRA_01_Init.c new file mode 100755 index 0000000..c560085 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BP_1I_D16F32Cll_TRC_WRA_01_Init.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/*-------------------------------------------------------------------------*/ +#include "BIQUAD.h" +#include "BP_1I_D16F32Cll_TRC_WRA_01_Private.h" + + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* BP_1I_D16F32Cll_TRC_WRA_01_Init */ +/* */ +/* DESCRIPTION: */ +/* These functions initializes a Band pass filter (BIQUAD) */ +/* biquadratic Filter Sections. */ +/* */ +/* PARAMETERS: */ +/* pInstance - output, returns the pointer to the State Variable */ +/* This state pointer must be passed to any subsequent */ +/* call to "Biquad" functions. */ +/* pTaps - input, pointer to the taps memory */ +/* pCoef - input, pointer to the coefficient structure */ +/* N - M coefficient factor of QM.N */ +/* */ +/* The coefficients are modified in the init() function such that lower */ +/* half word is right shifted by one and most significant bit of the lower */ +/* word is made to be zero. */ +/* */ +/* Reason: For MIPS effciency,we are using DSP 32*16 multiplication */ +/* instruction. But we have 32*32 multiplication. This can be realized by two 32*16 */ +/* multiplication. But 16th bit in the 32 bit word is not a sign bit. So this is done */ +/* by putting 16th bit to zero and lossing one bit precision by division of lower */ +/* half word by 2. */ +/* RETURNS: */ +/* void return code */ +/*-------------------------------------------------------------------------*/ +void BP_1I_D16F32Cll_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_1I_Order2_Taps_t *pTaps, + BP_C32_Coefs_t *pCoef) +{ + PFilter_State pBiquadState = (PFilter_State) pInstance; + pBiquadState->pDelays =(LVM_INT32 *) pTaps; + + pBiquadState->coefs[0] = pCoef->A0; + pBiquadState->coefs[1] = pCoef->B2; + pBiquadState->coefs[2] = pCoef->B1; +} +/*-------------------------------------------------------------------------*/ +/* End Of File: BP_1I_D16F32Cll_TRC_WRA_01_Init.c */ + diff --git a/media/libeffects/lvm/lib/Common/src/BP_1I_D16F32Cll_TRC_WRA_01_Private.h b/media/libeffects/lvm/lib/Common/src/BP_1I_D16F32Cll_TRC_WRA_01_Private.h new file mode 100755 index 0000000..76777f6 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BP_1I_D16F32Cll_TRC_WRA_01_Private.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _BP_1I_D16F32CLL_TRC_WRA_01_PRIVATE_H_ +#define _BP_1I_D16F32CLL_TRC_WRA_01_PRIVATE_H_ +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/* The internal state variables are implemented in a (for the user) hidden structure */ +/* In this (private) file, the internal structure is declared fro private use. */ +typedef struct _Filter_State_ +{ + LVM_INT32 * pDelays; /* pointer to the delayed samples (data of 32 bits) */ + LVM_INT32 coefs[3]; /* pointer to the filter coefficients */ +}Filter_State; + +typedef Filter_State * PFilter_State ; + +#endif /*_BP_1I_D16F32CLL_TRC_WRA_01_PRIVATE_H_*/ diff --git a/media/libeffects/lvm/lib/Common/src/BP_1I_D32F32C30_TRC_WRA_02.c b/media/libeffects/lvm/lib/Common/src/BP_1I_D32F32C30_TRC_WRA_02.c new file mode 100755 index 0000000..2b3555f --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BP_1I_D32F32C30_TRC_WRA_02.c @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "BP_1I_D32F32Cll_TRC_WRA_02_Private.h" +#include "LVM_Macros.h" + + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A0, + pBiquadState->coefs[1] is -B2, + pBiquadState->coefs[2] is -B1, these are in Q30 format + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is x(n-2)L in Q0 format + pBiquadState->pDelays[2] is y(n-1)L in Q0 format + pBiquadState->pDelays[3] is y(n-2)L in Q0 format +***************************************************************************/ + +void BP_1I_D32F32C30_TRC_WRA_02 ( Biquad_Instance_t *pInstance, + LVM_INT32 *pDataIn, + LVM_INT32 *pDataOut, + LVM_INT16 NrSamples) + { + LVM_INT32 ynL,templ; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + // ynL= (A0 (Q30) * (x(n)L (Q0) - x(n-2)L (Q0) ) >>30) in Q0 + templ=(*pDataIn)-pBiquadState->pDelays[1]; + MUL32x32INTO32(pBiquadState->coefs[0],templ,ynL,30) + + // ynL+= ((-B2 (Q30) * y(n-2)L (Q0) ) >>30) in Q0 + MUL32x32INTO32(pBiquadState->coefs[1],pBiquadState->pDelays[3],templ,30) + ynL+=templ; + + // ynL+= ((-B1 (Q30) * y(n-1)L (Q0) ) >>30) in Q0 + MUL32x32INTO32(pBiquadState->coefs[2],pBiquadState->pDelays[2],templ,30) + ynL+=templ; + + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[3]=pBiquadState->pDelays[2]; // y(n-2)L=y(n-1)L + pBiquadState->pDelays[1]=pBiquadState->pDelays[0]; // x(n-2)L=x(n-1)L + pBiquadState->pDelays[2]=ynL; // Update y(n-1)L in Q0 + pBiquadState->pDelays[0]=(*pDataIn++); // Update x(n-1)L in Q0 + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut++=ynL; // Write Left output in Q0 + + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/BP_1I_D32F32Cll_TRC_WRA_02_Init.c b/media/libeffects/lvm/lib/Common/src/BP_1I_D32F32Cll_TRC_WRA_02_Init.c new file mode 100755 index 0000000..f3f4571 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BP_1I_D32F32Cll_TRC_WRA_02_Init.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/*-------------------------------------------------------------------------*/ +#include "BIQUAD.h" +#include "BP_1I_D32F32Cll_TRC_WRA_02_Private.h" + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* BP_1I_D32F32Cll_TRC_WRA_02_Init */ +/* */ +/* DESCRIPTION: */ +/* These functions initializes a BIQUAD filter defined as a cascade of */ +/* biquadratic Filter Sections. */ +/* */ +/* PARAMETERS: */ +/* pInstance - output, returns the pointer to the State Variable */ +/* This state pointer must be passed to any subsequent */ +/* call to "Biquad" functions. */ +/* pTaps - input, pointer to the taps memory */ +/* pCoef - input, pointer to the coefficient structure */ +/* N - M coefficient factor of QM.N */ +/* RETURNS: */ +/* void return code */ +/*-------------------------------------------------------------------------*/ +void BP_1I_D32F32Cll_TRC_WRA_02_Init ( Biquad_Instance_t *pInstance, + Biquad_1I_Order2_Taps_t *pTaps, + BP_C32_Coefs_t *pCoef) +{ + PFilter_State pBiquadState = (PFilter_State) pInstance; + pBiquadState->pDelays =(LVM_INT32 *) pTaps; + + pBiquadState->coefs[0]=pCoef->A0; + + pBiquadState->coefs[1]=pCoef->B2; + + pBiquadState->coefs[2]=pCoef->B1; +} +/*-------------------------------------------------------------------------*/ +/* End Of File: BP_1I_D32F32Cll_TRC_WRA_02_Init.c */ + diff --git a/media/libeffects/lvm/lib/Common/src/BP_1I_D32F32Cll_TRC_WRA_02_Private.h b/media/libeffects/lvm/lib/Common/src/BP_1I_D32F32Cll_TRC_WRA_02_Private.h new file mode 100755 index 0000000..8884537 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BP_1I_D32F32Cll_TRC_WRA_02_Private.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _BP_1I_D32F32CLL_TRC_WRA_02_PRIVATE_H_ +#define _BP_1I_D32F32CLL_TRC_WRA_02_PRIVATE_H_ +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/* The internal state variables are implemented in a (for the user) hidden structure */ +/* In this (private) file, the internal structure is declared fro private use. */ +typedef struct _Filter_State_ +{ + LVM_INT32 * pDelays; /* pointer to the delayed samples (data of 32 bits) */ + LVM_INT32 coefs[3]; /* pointer to the filter coefficients */ +}Filter_State; + +typedef Filter_State * PFilter_State ; + +#endif /*_BP_1I_D32F32CLL_TRC_WRA_02_PRIVATE_H_*/ diff --git a/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F16C15_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F16C15_TRC_WRA_01.c new file mode 100755 index 0000000..00e3b52 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F16C15_TRC_WRA_01.c @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "BQ_1I_D16F16Css_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A2, pBiquadState->coefs[1] is A1 + pBiquadState->coefs[2] is A0, pBiquadState->coefs[3] is -B2 + pBiquadState->coefs[4] is -B1, these are in Q15 format + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is x(n-2)L in Q0 format + pBiquadState->pDelays[2] is y(n-1)L in Q0 format + pBiquadState->pDelays[3] is y(n-2)L in Q0 format +***************************************************************************/ + +void BQ_1I_D16F16C15_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples) + { + LVM_INT32 ynL; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + // ynL=A2 (Q15) * x(n-2)L (Q0) in Q15 + ynL=(LVM_INT32)pBiquadState->coefs[0]* pBiquadState->pDelays[1]; + + // ynL+=A1 (Q15) * x(n-1)L (Q0) in Q15 + ynL+=(LVM_INT32)pBiquadState->coefs[1]* pBiquadState->pDelays[0]; + + // ynL+=A0 (Q15) * x(n)L (Q0) in Q15 + ynL+=(LVM_INT32)pBiquadState->coefs[2]* (*pDataIn); + + // ynL+= (-B2 (Q15) * y(n-2)L (Q0) ) in Q15 + ynL+=(LVM_INT32)pBiquadState->coefs[3]*pBiquadState->pDelays[3]; + + // ynL+= (-B1 (Q15) * y(n-1)L (Q0) ) in Q15 + ynL+=(LVM_INT32)pBiquadState->coefs[4]*pBiquadState->pDelays[2]; + + ynL=ynL>>15; // ynL in Q0 format + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[3]=pBiquadState->pDelays[2]; // y(n-2)L=y(n-1)L + pBiquadState->pDelays[1]=pBiquadState->pDelays[0]; // x(n-2)L=x(n-1)L + pBiquadState->pDelays[2]=ynL; // Update y(n-1)L in Q0 + pBiquadState->pDelays[0]=(*pDataIn++); // Update x(n-1)L in Q0 + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut++=(LVM_INT16)ynL; // Write Left output in Q0 + + + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F16Css_TRC_WRA_01_Init.c b/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F16Css_TRC_WRA_01_Init.c new file mode 100755 index 0000000..3fedc45 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F16Css_TRC_WRA_01_Init.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/*-------------------------------------------------------------------------*/ +#include "BIQUAD.h" +#include "BQ_1I_D16F16Css_TRC_WRA_01_Private.h" + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* BQ_1I_D16F16Css_TRC_WRA_01_Init */ +/* */ +/* DESCRIPTION: */ +/* These functions initializes a BIQUAD filter defined as a cascade of */ +/* biquadratic Filter Sections. */ +/* */ +/* PARAMETERS: */ +/* pInstance - output, returns the pointer to the State Variable */ +/* This state pointer must be passed to any subsequent */ +/* call to "Biquad" functions. */ +/* pTaps - input, pointer to the taps memory */ +/* pCoef - input, pointer to the coefficient structure */ +/* N - M coefficient factor of QM.N */ +/* RETURNS: */ +/* void return code */ +/*-------------------------------------------------------------------------*/ +void BQ_1I_D16F16Css_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_1I_Order2_Taps_t *pTaps, + BQ_C16_Coefs_t *pCoef) +{ + LVM_INT16 temp; + PFilter_State pBiquadState = (PFilter_State) pInstance; + pBiquadState->pDelays =(LVM_INT32 *) pTaps ; + + temp=pCoef->A2; + pBiquadState->coefs[0]=temp; + temp=pCoef->A1; + pBiquadState->coefs[1]=temp; + temp=pCoef->A0; + pBiquadState->coefs[2]=temp; + temp=pCoef->B2; + pBiquadState->coefs[3]=temp; + temp=pCoef->B1; + pBiquadState->coefs[4]=temp; +} +/*-------------------------------------------------------------------------*/ +/* End Of File: BQ_1I_D16F16Css_TRC_WRA_01_Init.c */ + diff --git a/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F16Css_TRC_WRA_01_Private.h b/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F16Css_TRC_WRA_01_Private.h new file mode 100755 index 0000000..18dacd3 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F16Css_TRC_WRA_01_Private.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _BQ_1I_D16F16CSS_TRC_WRA_01_PRIVATE_H_ +#define _BQ_1I_D16F16CSS_TRC_WRA_01_PRIVATE_H_ +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/* The internal state variables are implemented in a (for the user) hidden structure */ +/* In this (private) file, the internal structure is declared fro private use. */ +typedef struct _Filter_State_ +{ + LVM_INT32 * pDelays; /* pointer to the delayed samples (data of 32 bits) */ + LVM_INT16 coefs[5]; /* pointer to the filter coefficients */ +}Filter_State; + +typedef Filter_State * PFilter_State ; + +#endif /*_BQ_1I_D16F16CSS_TRC_WRA_01_PRIVATE_H_ */ diff --git a/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F32C14_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F32C14_TRC_WRA_01.c new file mode 100755 index 0000000..cdff1d9 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F32C14_TRC_WRA_01.c @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "BQ_1I_D16F32Css_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A2, pBiquadState->coefs[1] is A1 + pBiquadState->coefs[2] is A0, pBiquadState->coefs[3] is -B2 + pBiquadState->coefs[4] is -B1, these are in Q14 format + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is x(n-2)L in Q0 format + pBiquadState->pDelays[2] is y(n-1)L in Q16 format + pBiquadState->pDelays[3] is y(n-2)L in Q16 format +***************************************************************************/ + +void BQ_1I_D16F32C14_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples) + { + LVM_INT32 ynL,templ; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + // ynL=A2 (Q14) * x(n-2)L (Q0) in Q14 + ynL=(LVM_INT32)pBiquadState->coefs[0]* pBiquadState->pDelays[1]; + + // ynL+=A1 (Q14) * x(n-1)L (Q0) in Q14 + ynL+=(LVM_INT32)pBiquadState->coefs[1]* pBiquadState->pDelays[0]; + + // ynL+=A0 (Q14) * x(n)L (Q0) in Q14 + ynL+=(LVM_INT32)pBiquadState->coefs[2]* (*pDataIn); + + // ynL+= ( (-B2 (Q14) * y(n-2)L (Q16) )>>16) in Q14 + MUL32x16INTO32(pBiquadState->pDelays[3],pBiquadState->coefs[3],templ,16) + ynL+=templ; + + // ynL+= ( (-B1 (Q14) * y(n-1)L (Q16) )>>16) in Q14 + MUL32x16INTO32(pBiquadState->pDelays[2],pBiquadState->coefs[4],templ,16) + ynL+=templ; + + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[3]=pBiquadState->pDelays[2]; // y(n-2)L=y(n-1)L + pBiquadState->pDelays[1]=pBiquadState->pDelays[0]; // x(n-2)L=x(n-1)L + pBiquadState->pDelays[2]=ynL<<2; // Update y(n-1)L in Q16 + pBiquadState->pDelays[0]=(*pDataIn++); // Update x(n-1)L in Q0 + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut++=(LVM_INT16)(ynL>>14); // Write Left output in Q0 + + } + } + diff --git a/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F32Css_TRC_WRA_01_Private.h b/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F32Css_TRC_WRA_01_Private.h new file mode 100755 index 0000000..bc88847 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F32Css_TRC_WRA_01_Private.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _BQ_1I_D16F32CSS_TRC_WRA_01_PRIVATE_H_ +#define _BQ_1I_D16F32CSS_TRC_WRA_01_PRIVATE_H_ +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/* The internal state variables are implemented in a (for the user) hidden structure */ +/* In this (private) file, the internal structure is declared fro private use. */ +typedef struct _Filter_State_ +{ + LVM_INT32 * pDelays; /* pointer to the delayed samples (data of 32 bits) */ + LVM_INT16 coefs[5]; /* pointer to the filter coefficients */ +}Filter_State; + +typedef Filter_State * PFilter_State ; + +#endif /*_BQ_1I_D16F32CSS_TRC_WRA_01_PRIVATE_H_*/ diff --git a/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F32Css_TRC_WRA_01_init.c b/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F32Css_TRC_WRA_01_init.c new file mode 100755 index 0000000..520c969 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_1I_D16F32Css_TRC_WRA_01_init.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/*-------------------------------------------------------------------------*/ +#include "BIQUAD.h" +#include "BQ_1I_D16F32Css_TRC_WRA_01_Private.h" + + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* BQ_1I_D16F32Css_TRC_WRA_01_Init */ +/* */ +/* DESCRIPTION: */ +/* These functions initializes a BIQUAD filter defined as a cascade of */ +/* biquadratic Filter Sections. */ +/* */ +/* PARAMETERS: */ +/* pInstance - output, returns the pointer to the State Variable */ +/* This state pointer must be passed to any subsequent */ +/* call to "Biquad" functions. */ +/* pTaps - input, pointer to the taps memory */ +/* pCoef - input, pointer to the coefficient structure */ +/* N - M coefficient factor of QM.N */ +/* RETURNS: */ +/* void return code */ +/*-------------------------------------------------------------------------*/ +void BQ_1I_D16F32Css_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_1I_Order2_Taps_t *pTaps, + BQ_C16_Coefs_t *pCoef) +{ + LVM_INT16 temp; + PFilter_State pBiquadState = (PFilter_State) pInstance; + pBiquadState->pDelays =(LVM_INT32 *) pTaps ; + + temp=pCoef->A2; + pBiquadState->coefs[0]=temp; + temp=pCoef->A1; + pBiquadState->coefs[1]=temp; + temp=pCoef->A0; + pBiquadState->coefs[2]=temp; + temp=pCoef->B2; + pBiquadState->coefs[3]=temp; + temp=pCoef->B1; + pBiquadState->coefs[4]=temp; +} +/*-------------------------------------------------------------------------*/ +/* End Of File: BQ_1I_D16F32Css_TRC_WRA_01_Init */ + diff --git a/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16C14_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16C14_TRC_WRA_01.c new file mode 100755 index 0000000..c267a90 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16C14_TRC_WRA_01.c @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "BQ_2I_D16F16Css_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A2, pBiquadState->coefs[1] is A1 + pBiquadState->coefs[2] is A0, pBiquadState->coefs[3] is -B2 + pBiquadState->coefs[4] is -B1, these are in Q14 format + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is x(n-1)R in Q0 format + pBiquadState->pDelays[2] is x(n-2)L in Q0 format + pBiquadState->pDelays[3] is x(n-2)R in Q0 format + pBiquadState->pDelays[4] is y(n-1)L in Q0 format + pBiquadState->pDelays[5] is y(n-1)R in Q0 format + pBiquadState->pDelays[6] is y(n-2)L in Q0 format + pBiquadState->pDelays[7] is y(n-2)R in Q0 format +***************************************************************************/ + +void BQ_2I_D16F16C14_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples) + { + LVM_INT32 ynL,ynR; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + // ynL=A2 (Q14) * x(n-2)L (Q0) in Q14 + ynL=(LVM_INT32)pBiquadState->coefs[0]* pBiquadState->pDelays[2]; + + // ynL+=A1 (Q14) * x(n-1)L (Q0) in Q14 + ynL+=(LVM_INT32)pBiquadState->coefs[1]* pBiquadState->pDelays[0]; + + // ynL+=A0 (Q14) * x(n)L (Q0) in Q14 + ynL+=(LVM_INT32)pBiquadState->coefs[2]* (*pDataIn); + + // ynL+= ( -B2 (Q14) * y(n-2)L (Q0) ) in Q14 + ynL+=(LVM_INT32)pBiquadState->coefs[3]*pBiquadState->pDelays[6]; + + // ynL+=( -B1 (Q14) * y(n-1)L (Q0) ) in Q14 + ynL+=(LVM_INT32)pBiquadState->coefs[4]*pBiquadState->pDelays[4]; + + ynL=ynL>>14; // ynL in Q0 format + + /************************************************************************** + PROCESSING OF THE RIGHT CHANNEL + ***************************************************************************/ + // ynR=A2 (Q14) * x(n-2)R (Q0) in Q14 + ynR=(LVM_INT32)pBiquadState->coefs[0]*pBiquadState->pDelays[3]; + + // ynR+=A1 (Q14) * x(n-1)R (Q0) in Q14 + ynR+=(LVM_INT32)pBiquadState->coefs[1]*pBiquadState->pDelays[1]; + + // ynR+=A0 (Q14) * x(n)R (Q0) in Q14 + ynR+=(LVM_INT32)pBiquadState->coefs[2]*(*(pDataIn+1)); + + // ynR+= ( -B2 (Q14) * y(n-2)R (Q0) ) in Q14 + ynR+=(LVM_INT32)pBiquadState->coefs[3]*pBiquadState->pDelays[7]; + + // ynR+=( -B1 (Q14) * y(n-1)R (Q0) ) in Q14 + ynR+=(LVM_INT32)pBiquadState->coefs[4]*pBiquadState->pDelays[5]; + + ynR=ynR>>14; // ynL in Q0 format + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[7]=pBiquadState->pDelays[5]; // y(n-2)R=y(n-1)R + pBiquadState->pDelays[6]=pBiquadState->pDelays[4]; // y(n-2)L=y(n-1)L + pBiquadState->pDelays[3]=pBiquadState->pDelays[1]; // x(n-2)R=x(n-1)R + pBiquadState->pDelays[2]=pBiquadState->pDelays[0]; // x(n-2)L=x(n-1)L + pBiquadState->pDelays[5]=ynR; // Update y(n-1)R in Q0 + pBiquadState->pDelays[4]=ynL; // Update y(n-1)L in Q0 + pBiquadState->pDelays[0]=(*pDataIn++); // Update x(n-1)L in Q0 + pBiquadState->pDelays[1]=(*pDataIn++); // Update x(n-1)R in Q0 + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut++=(LVM_INT16)ynL; // Write Left output in Q0 + *pDataOut++=(LVM_INT16)ynR; // Write Right ouput in Q0 + + + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16C15_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16C15_TRC_WRA_01.c new file mode 100755 index 0000000..ded2bb3 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16C15_TRC_WRA_01.c @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "BQ_2I_D16F16Css_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A2, pBiquadState->coefs[1] is A1 + pBiquadState->coefs[2] is A0, pBiquadState->coefs[3] is -B2 + pBiquadState->coefs[4] is -B1, these are in Q15 format + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is x(n-1)R in Q0 format + pBiquadState->pDelays[2] is x(n-2)L in Q0 format + pBiquadState->pDelays[3] is x(n-2)R in Q0 format + pBiquadState->pDelays[4] is y(n-1)L in Q0 format + pBiquadState->pDelays[5] is y(n-1)R in Q0 format + pBiquadState->pDelays[6] is y(n-2)L in Q0 format + pBiquadState->pDelays[7] is y(n-2)R in Q0 format +***************************************************************************/ + +void BQ_2I_D16F16C15_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples) + { + LVM_INT32 ynL,ynR; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + // ynL=A2 (Q15) * x(n-2)L (Q0) in Q15 + ynL=(LVM_INT32)pBiquadState->coefs[0]* pBiquadState->pDelays[2]; + + // ynL+=A1 (Q15) * x(n-1)L (Q0) in Q15 + ynL+=(LVM_INT32)pBiquadState->coefs[1]* pBiquadState->pDelays[0]; + + // ynL+=A0 (Q15) * x(n)L (Q0) in Q15 + ynL+=(LVM_INT32)pBiquadState->coefs[2]* (*pDataIn); + + // ynL+= ( -B2 (Q15) * y(n-2)L (Q0) ) in Q15 + ynL+=(LVM_INT32)pBiquadState->coefs[3]*pBiquadState->pDelays[6]; + + // ynL+=( -B1 (Q15) * y(n-1)L (Q0) ) in Q15 + ynL+=(LVM_INT32)pBiquadState->coefs[4]*pBiquadState->pDelays[4]; + + ynL=ynL>>15; // ynL in Q0 format + + /************************************************************************** + PROCESSING OF THE RIGHT CHANNEL + ***************************************************************************/ + // ynR=A2 (Q15) * x(n-2)R (Q0) in Q15 + ynR=(LVM_INT32)pBiquadState->coefs[0]*pBiquadState->pDelays[3]; + + // ynR+=A1 (Q15) * x(n-1)R (Q0) in Q15 + ynR+=(LVM_INT32)pBiquadState->coefs[1]*pBiquadState->pDelays[1]; + + // ynR+=A0 (Q15) * x(n)R (Q0) in Q15 + ynR+=(LVM_INT32)pBiquadState->coefs[2]*(*(pDataIn+1)); + + // ynR+= ( -B2 (Q15) * y(n-2)R (Q0) ) in Q15 + ynR+=(LVM_INT32)pBiquadState->coefs[3]*pBiquadState->pDelays[7]; + + // ynR+=( -B1 (Q15) * y(n-1)R (Q0) ) in Q15 + ynR+=(LVM_INT32)pBiquadState->coefs[4]*pBiquadState->pDelays[5]; + + ynR=ynR>>15; // ynL in Q0 format + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[7]=pBiquadState->pDelays[5]; // y(n-2)R=y(n-1)R + pBiquadState->pDelays[6]=pBiquadState->pDelays[4]; // y(n-2)L=y(n-1)L + pBiquadState->pDelays[3]=pBiquadState->pDelays[1]; // x(n-2)R=x(n-1)R + pBiquadState->pDelays[2]=pBiquadState->pDelays[0]; // x(n-2)L=x(n-1)L + pBiquadState->pDelays[5]=ynR; // Update y(n-1)R in Q0 + pBiquadState->pDelays[4]=ynL; // Update y(n-1)L in Q0 + pBiquadState->pDelays[0]=(*pDataIn++); // Update x(n-1)L in Q0 + pBiquadState->pDelays[1]=(*pDataIn++); // Update x(n-1)R in Q0 + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut++=(LVM_INT16)ynL; // Write Left output in Q0 + *pDataOut++=(LVM_INT16)ynR; // Write Right ouput in Q0 + + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16Css_TRC_WRA_01_Init.c b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16Css_TRC_WRA_01_Init.c new file mode 100755 index 0000000..b0cd1b9 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16Css_TRC_WRA_01_Init.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/*-------------------------------------------------------------------------*/ +#include "BIQUAD.h" +#include "BQ_2I_D16F16Css_TRC_WRA_01_Private.h" + + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* BQ_2I_D16F16Css_TRC_WRA_01_Init */ +/* */ +/* DESCRIPTION: */ +/* These functions initializes a BIQUAD filter defined as a cascade of */ +/* biquadratic Filter Sections. */ +/* */ +/* PARAMETERS: */ +/* pInstance - output, returns the pointer to the State Variable */ +/* This state pointer must be passed to any subsequent */ +/* call to "Biquad" functions. */ +/* pTaps - input, pointer to the taps memory */ +/* pCoef - input, pointer to the coefficient structure */ +/* N - M coefficient factor of QM.N */ +/* RETURNS: */ +/* void return code */ +/*-------------------------------------------------------------------------*/ +void BQ_2I_D16F16Css_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_2I_Order2_Taps_t *pTaps, + BQ_C16_Coefs_t *pCoef) +{ + LVM_INT16 temp; + PFilter_State pBiquadState = (PFilter_State) pInstance; + pBiquadState->pDelays =(LVM_INT32 *) pTaps ; + + temp=pCoef->A2; + pBiquadState->coefs[0]=temp; + temp=pCoef->A1; + pBiquadState->coefs[1]=temp; + temp=pCoef->A0; + pBiquadState->coefs[2]=temp; + temp=pCoef->B2; + pBiquadState->coefs[3]=temp; + temp=pCoef->B1; + pBiquadState->coefs[4]=temp; +} +/*-------------------------------------------------------------------------*/ +/* End Of File: BQ_2I_D16F16Css_TRC_WRA_01_Init.c */ + diff --git a/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16Css_TRC_WRA_01_Private.h b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16Css_TRC_WRA_01_Private.h new file mode 100755 index 0000000..bcb0093 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F16Css_TRC_WRA_01_Private.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _BQ_2I_D16F16CSS_TRC_WRA_01_PRIVATE_H_ +#define _BQ_2I_D16F16CSS_TRC_WRA_01_PRIVATE_H_ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/* The internal state variables are implemented in a (for the user) hidden structure */ +/* In this (private) file, the internal structure is declared fro private use. */ +typedef struct _Filter_State_ +{ + LVM_INT32 * pDelays; /* pointer to the delayed samples (data of 32 bits) */ + LVM_INT16 coefs[5]; /* pointer to the filter coefficients */ +}Filter_State; + +typedef Filter_State * PFilter_State ; + +#endif /* _BQ_2I_D16F16CSS_TRC_WRA_01_PRIVATE_H_ */ diff --git a/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32C13_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32C13_TRC_WRA_01.c new file mode 100755 index 0000000..ae743f2 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32C13_TRC_WRA_01.c @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "BQ_2I_D16F32Css_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A2, pBiquadState->coefs[1] is A1 + pBiquadState->coefs[2] is A0, pBiquadState->coefs[3] is -B2 + pBiquadState->coefs[4] is -B1, these are in Q13 format + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is x(n-1)R in Q0 format + pBiquadState->pDelays[2] is x(n-2)L in Q0 format + pBiquadState->pDelays[3] is x(n-2)R in Q0 format + pBiquadState->pDelays[4] is y(n-1)L in Q16 format + pBiquadState->pDelays[5] is y(n-1)R in Q16 format + pBiquadState->pDelays[6] is y(n-2)L in Q16 format + pBiquadState->pDelays[7] is y(n-2)R in Q16 format +***************************************************************************/ + +void BQ_2I_D16F32C13_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples) + { + LVM_INT32 ynL,ynR,templ; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + /* ynL=A2 (Q13) * x(n-2)L (Q0) in Q13*/ + ynL=(LVM_INT32)pBiquadState->coefs[0]* pBiquadState->pDelays[2]; + + /* ynL+=A1 (Q13) * x(n-1)L (Q0) in Q13*/ + ynL+=(LVM_INT32)pBiquadState->coefs[1]* pBiquadState->pDelays[0]; + + /* ynL+=A0 (Q13) * x(n)L (Q0) in Q13*/ + ynL+=(LVM_INT32)pBiquadState->coefs[2]* (*pDataIn); + + /* ynL+= ( (-B2 (Q13) * y(n-2)L (Q16) )>>16) in Q13 */ + MUL32x16INTO32(pBiquadState->pDelays[6],pBiquadState->coefs[3],templ,16) + ynL+=templ; + + /* ynL+=( (-B1 (Q13) * y(n-1)L (Q16) )>>16) in Q13 */ + MUL32x16INTO32(pBiquadState->pDelays[4],pBiquadState->coefs[4],templ,16) + ynL+=templ; + + /************************************************************************** + PROCESSING OF THE RIGHT CHANNEL + ***************************************************************************/ + /* ynR=A2 (Q13) * x(n-2)R (Q0) in Q13*/ + ynR=(LVM_INT32)pBiquadState->coefs[0]*pBiquadState->pDelays[3]; + + /* ynR+=A1 (Q13) * x(n-1)R (Q0) in Q13*/ + ynR+=(LVM_INT32)pBiquadState->coefs[1]*pBiquadState->pDelays[1]; + + /* ynR+=A0 (Q13) * x(n)R (Q0) in Q13*/ + ynR+=(LVM_INT32)pBiquadState->coefs[2]*(*(pDataIn+1)); + + /* ynR+= ( (-B2 (Q13) * y(n-2)R (Q16) )>>16) in Q13*/ + MUL32x16INTO32(pBiquadState->pDelays[7],pBiquadState->coefs[3],templ,16) + ynR+=templ; + + /* ynR+=( (-B1 (Q13) * y(n-1)R (Q16) )>>16) in Q13 */ + MUL32x16INTO32(pBiquadState->pDelays[5],pBiquadState->coefs[4],templ,16) + ynR+=templ; + + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[7]=pBiquadState->pDelays[5]; /* y(n-2)R=y(n-1)R*/ + pBiquadState->pDelays[6]=pBiquadState->pDelays[4]; /* y(n-2)L=y(n-1)L*/ + pBiquadState->pDelays[3]=pBiquadState->pDelays[1]; /* x(n-2)R=x(n-1)R*/ + pBiquadState->pDelays[2]=pBiquadState->pDelays[0]; /* x(n-2)L=x(n-1)L*/ + pBiquadState->pDelays[5]=ynR<<3; /* Update y(n-1)R in Q16*/ + pBiquadState->pDelays[4]=ynL<<3; /* Update y(n-1)L in Q16*/ + pBiquadState->pDelays[0]=(*pDataIn); /* Update x(n-1)L in Q0*/ + pDataIn++; + pBiquadState->pDelays[1]=(*pDataIn); /* Update x(n-1)R in Q0*/ + pDataIn++; + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut=(LVM_INT16)(ynL>>13); /* Write Left output in Q0*/ + pDataOut++; + *pDataOut=(LVM_INT16)(ynR>>13); /* Write Right ouput in Q0*/ + pDataOut++; + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32C14_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32C14_TRC_WRA_01.c new file mode 100755 index 0000000..a0ca2cc --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32C14_TRC_WRA_01.c @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "BQ_2I_D16F32Css_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A2, pBiquadState->coefs[1] is A1 + pBiquadState->coefs[2] is A0, pBiquadState->coefs[3] is -B2 + pBiquadState->coefs[4] is -B1, these are in Q14 format + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is x(n-1)R in Q0 format + pBiquadState->pDelays[2] is x(n-2)L in Q0 format + pBiquadState->pDelays[3] is x(n-2)R in Q0 format + pBiquadState->pDelays[4] is y(n-1)L in Q16 format + pBiquadState->pDelays[5] is y(n-1)R in Q16 format + pBiquadState->pDelays[6] is y(n-2)L in Q16 format + pBiquadState->pDelays[7] is y(n-2)R in Q16 format +***************************************************************************/ + +void BQ_2I_D16F32C14_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples) + { + LVM_INT32 ynL,ynR,templ; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + /* ynL=A2 (Q14) * x(n-2)L (Q0) in Q14*/ + ynL=(LVM_INT32)pBiquadState->coefs[0]* pBiquadState->pDelays[2]; + + /* ynL+=A1 (Q14) * x(n-1)L (Q0) in Q14*/ + ynL+=(LVM_INT32)pBiquadState->coefs[1]* pBiquadState->pDelays[0]; + + /* ynL+=A0 (Q14) * x(n)L (Q0) in Q14*/ + ynL+=(LVM_INT32)pBiquadState->coefs[2]* (*pDataIn); + + /* ynL+= ( (-B2 (Q14) * y(n-2)L (Q16) )>>16) in Q14 */ + MUL32x16INTO32(pBiquadState->pDelays[6],pBiquadState->coefs[3],templ,16) + ynL+=templ; + + /* ynL+=( (-B1 (Q14) * y(n-1)L (Q16) )>>16) in Q14 */ + MUL32x16INTO32(pBiquadState->pDelays[4],pBiquadState->coefs[4],templ,16) + ynL+=templ; + + /************************************************************************** + PROCESSING OF THE RIGHT CHANNEL + ***************************************************************************/ + /* ynR=A2 (Q14) * x(n-2)R (Q0) in Q14*/ + ynR=(LVM_INT32)pBiquadState->coefs[0]*pBiquadState->pDelays[3]; + + /* ynR+=A1 (Q14) * x(n-1)R (Q0) in Q14*/ + ynR+=(LVM_INT32)pBiquadState->coefs[1]*pBiquadState->pDelays[1]; + + /* ynR+=A0 (Q14) * x(n)R (Q0) in Q14*/ + ynR+=(LVM_INT32)pBiquadState->coefs[2]*(*(pDataIn+1)); + + /* ynR+= ( (-B2 (Q14) * y(n-2)R (Q16) )>>16) in Q14*/ + MUL32x16INTO32(pBiquadState->pDelays[7],pBiquadState->coefs[3],templ,16) + ynR+=templ; + + /* ynR+=( (-B1 (Q14) * y(n-1)R (Q16) )>>16) in Q14 */ + MUL32x16INTO32(pBiquadState->pDelays[5],pBiquadState->coefs[4],templ,16) + ynR+=templ; + + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[7]=pBiquadState->pDelays[5]; /* y(n-2)R=y(n-1)R*/ + pBiquadState->pDelays[6]=pBiquadState->pDelays[4]; /* y(n-2)L=y(n-1)L*/ + pBiquadState->pDelays[3]=pBiquadState->pDelays[1]; /* x(n-2)R=x(n-1)R*/ + pBiquadState->pDelays[2]=pBiquadState->pDelays[0]; /* x(n-2)L=x(n-1)L*/ + pBiquadState->pDelays[5]=ynR<<2; /* Update y(n-1)R in Q16*/ + pBiquadState->pDelays[4]=ynL<<2; /* Update y(n-1)L in Q16*/ + pBiquadState->pDelays[0]=(*pDataIn); /* Update x(n-1)L in Q0*/ + pDataIn++; + pBiquadState->pDelays[1]=(*pDataIn); /* Update x(n-1)R in Q0*/ + pDataIn++; + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut=(LVM_INT16)(ynL>>14); /* Write Left output in Q0*/ + pDataOut++; + *pDataOut=(LVM_INT16)(ynR>>14); /* Write Right ouput in Q0*/ + pDataOut++; + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32C15_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32C15_TRC_WRA_01.c new file mode 100755 index 0000000..f1ab815 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32C15_TRC_WRA_01.c @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "BQ_2I_D16F32Css_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A2, pBiquadState->coefs[1] is A1 + pBiquadState->coefs[2] is A0, pBiquadState->coefs[3] is -B2 + pBiquadState->coefs[4] is -B1, these are in Q15 format + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is x(n-1)R in Q0 format + pBiquadState->pDelays[2] is x(n-2)L in Q0 format + pBiquadState->pDelays[3] is x(n-2)R in Q0 format + pBiquadState->pDelays[4] is y(n-1)L in Q16 format + pBiquadState->pDelays[5] is y(n-1)R in Q16 format + pBiquadState->pDelays[6] is y(n-2)L in Q16 format + pBiquadState->pDelays[7] is y(n-2)R in Q16 format +***************************************************************************/ + +void BQ_2I_D16F32C15_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples) + { + LVM_INT32 ynL,ynR,templ; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + /* ynL=A2 (Q15) * x(n-2)L (Q0) in Q15*/ + ynL=(LVM_INT32)pBiquadState->coefs[0]* pBiquadState->pDelays[2]; + + /* ynL+=A1 (Q15) * x(n-1)L (Q0) in Q15*/ + ynL+=(LVM_INT32)pBiquadState->coefs[1]* pBiquadState->pDelays[0]; + + /* ynL+=A0 (Q15) * x(n)L (Q0) in Q15*/ + ynL+=(LVM_INT32)pBiquadState->coefs[2]* (*pDataIn); + + /* ynL+= ( (-B2 (Q15) * y(n-2)L (Q16) )>>16) in Q15 */ + MUL32x16INTO32(pBiquadState->pDelays[6],pBiquadState->coefs[3],templ,16) + ynL+=templ; + + /* ynL+=( (-B1 (Q15) * y(n-1)L (Q16) )>>16) in Q15 */ + MUL32x16INTO32(pBiquadState->pDelays[4],pBiquadState->coefs[4],templ,16) + ynL+=templ; + + /************************************************************************** + PROCESSING OF THE RIGHT CHANNEL + ***************************************************************************/ + /* ynR=A2 (Q15) * x(n-2)R (Q0) in Q15*/ + ynR=(LVM_INT32)pBiquadState->coefs[0]*pBiquadState->pDelays[3]; + + /* ynR+=A1 (Q15) * x(n-1)R (Q0) in Q15*/ + ynR+=(LVM_INT32)pBiquadState->coefs[1]*pBiquadState->pDelays[1]; + + /* ynR+=A0 (Q15) * x(n)R (Q0) in Q15*/ + ynR+=(LVM_INT32)pBiquadState->coefs[2]*(*(pDataIn+1)); + + /* ynR+= ( (-B2 (Q15) * y(n-2)R (Q16) )>>16) in Q15 */ + MUL32x16INTO32(pBiquadState->pDelays[7],pBiquadState->coefs[3],templ,16) + ynR+=templ; + + /* ynR+=( (-B1 (Q15) * y(n-1)R (Q16) )>>16) in Q15 */ + MUL32x16INTO32(pBiquadState->pDelays[5],pBiquadState->coefs[4],templ,16) + ynR+=templ; + + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[7]=pBiquadState->pDelays[5]; /* y(n-2)R=y(n-1)R*/ + pBiquadState->pDelays[6]=pBiquadState->pDelays[4]; /* y(n-2)L=y(n-1)L*/ + pBiquadState->pDelays[3]=pBiquadState->pDelays[1]; /* x(n-2)R=x(n-1)R*/ + pBiquadState->pDelays[2]=pBiquadState->pDelays[0]; /* x(n-2)L=x(n-1)L*/ + pBiquadState->pDelays[5]=ynR<<1; /* Update y(n-1)R in Q16*/ + pBiquadState->pDelays[4]=ynL<<1; /* Update y(n-1)L in Q16*/ + pBiquadState->pDelays[0]=(*pDataIn); /* Update x(n-1)L in Q0*/ + pDataIn++; + pBiquadState->pDelays[1]=(*pDataIn); /* Update x(n-1)R in Q0*/ + pDataIn++; + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut=(LVM_INT16)(ynL>>15); /* Write Left output in Q0*/ + pDataOut++; + *pDataOut=(LVM_INT16)(ynR>>15); /* Write Right ouput in Q0*/ + pDataOut++; + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32Css_TRC_WRA_01_Private.h b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32Css_TRC_WRA_01_Private.h new file mode 100755 index 0000000..3cbb58b --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32Css_TRC_WRA_01_Private.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _BQ_2I_D16F32CSS_TRC_WRA_01_PRIVATE_H_ +#define _BQ_2I_D16F32CSS_TRC_WRA_01_PRIVATE_H_ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/* The internal state variables are implemented in a (for the user) hidden structure */ +/* In this (private) file, the internal structure is declared fro private use. */ +typedef struct _Filter_State_ +{ + LVM_INT32 * pDelays; /* pointer to the delayed samples (data of 32 bits) */ + LVM_INT16 coefs[5]; /* pointer to the filter coefficients */ +}Filter_State; + +typedef Filter_State * PFilter_State ; + +#endif /* _BQ_2I_D16F32CSS_TRC_WRA_01_PRIVATE_H_ */ diff --git a/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32Css_TRC_WRA_01_init.c b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32Css_TRC_WRA_01_init.c new file mode 100755 index 0000000..0c6b33e --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_2I_D16F32Css_TRC_WRA_01_init.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ +#include "BIQUAD.h" +#include "BQ_2I_D16F32Css_TRC_WRA_01_Private.h" + + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* BQ_2I_D16F32Css_TRC_WRA_01_Init */ +/* */ +/* DESCRIPTION: */ +/* These functions initializes a BIQUAD filter defined as a cascade of */ +/* biquadratic Filter Sections. */ +/* */ +/* PARAMETERS: */ +/* pInstance - output, returns the pointer to the State Variable */ +/* This state pointer must be passed to any subsequent */ +/* call to "Biquad" functions. */ +/* pTaps - input, pointer to the taps memory */ +/* pCoef - input, pointer to the coefficient structure */ +/* N - M coefficient factor of QM.N */ +/* RETURNS: */ +/* void return code */ +/*-------------------------------------------------------------------------*/ +void BQ_2I_D16F32Css_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_2I_Order2_Taps_t *pTaps, + BQ_C16_Coefs_t *pCoef) +{ + LVM_INT16 temp; + PFilter_State pBiquadState = (PFilter_State) pInstance; + pBiquadState->pDelays =(LVM_INT32 *) pTaps ; + + temp=pCoef->A2; + pBiquadState->coefs[0]=temp; + temp=pCoef->A1; + pBiquadState->coefs[1]=temp; + temp=pCoef->A0; + pBiquadState->coefs[2]=temp; + temp=pCoef->B2; + pBiquadState->coefs[3]=temp; + temp=pCoef->B1; + pBiquadState->coefs[4]=temp; +} +/*-------------------------------------------------------------------------*/ +/* End Of File: BQ_2I_D16F32Css_TRC_WRA_01_Init */ + diff --git a/media/libeffects/lvm/lib/Common/src/BQ_2I_D32F32C30_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/BQ_2I_D32F32C30_TRC_WRA_01.c new file mode 100755 index 0000000..51278cf --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_2I_D32F32C30_TRC_WRA_01.c @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "BQ_2I_D32F32Cll_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A2, pBiquadState->coefs[1] is A1 + pBiquadState->coefs[2] is A0, pBiquadState->coefs[3] is -B2 + pBiquadState->coefs[4] is -B1, these are in Q30 format + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is x(n-1)R in Q0 format + pBiquadState->pDelays[2] is x(n-2)L in Q0 format + pBiquadState->pDelays[3] is x(n-2)R in Q0 format + pBiquadState->pDelays[4] is y(n-1)L in Q0 format + pBiquadState->pDelays[5] is y(n-1)R in Q0 format + pBiquadState->pDelays[6] is y(n-2)L in Q0 format + pBiquadState->pDelays[7] is y(n-2)R in Q0 format +***************************************************************************/ + +void BQ_2I_D32F32C30_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT32 *pDataIn, + LVM_INT32 *pDataOut, + LVM_INT16 NrSamples) + + + { + LVM_INT32 ynL,ynR,templ,tempd; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + /* ynL= ( A2 (Q30) * x(n-2)L (Q0) ) >>30 in Q0*/ + MUL32x32INTO32(pBiquadState->coefs[0],pBiquadState->pDelays[2],ynL,30) + + /* ynL+= ( A1 (Q30) * x(n-1)L (Q0) ) >> 30 in Q0*/ + MUL32x32INTO32(pBiquadState->coefs[1],pBiquadState->pDelays[0],templ,30) + ynL+=templ; + + /* ynL+= ( A0 (Q30) * x(n)L (Q0) ) >> 30 in Q0*/ + MUL32x32INTO32(pBiquadState->coefs[2],*pDataIn,templ,30) + ynL+=templ; + + /* ynL+= (-B2 (Q30) * y(n-2)L (Q0) ) >> 30 in Q0*/ + MUL32x32INTO32(pBiquadState->coefs[3],pBiquadState->pDelays[6],templ,30) + ynL+=templ; + + /* ynL+= (-B1 (Q30) * y(n-1)L (Q0) ) >> 30 in Q0 */ + MUL32x32INTO32(pBiquadState->coefs[4],pBiquadState->pDelays[4],templ,30) + ynL+=templ; + + /************************************************************************** + PROCESSING OF THE RIGHT CHANNEL + ***************************************************************************/ + /* ynR= ( A2 (Q30) * x(n-2)R (Q0) ) >> 30 in Q0*/ + MUL32x32INTO32(pBiquadState->coefs[0],pBiquadState->pDelays[3],ynR,30) + + /* ynR+= ( A1 (Q30) * x(n-1)R (Q0) ) >> 30 in Q0*/ + MUL32x32INTO32(pBiquadState->coefs[1],pBiquadState->pDelays[1],templ,30) + ynR+=templ; + + /* ynR+= ( A0 (Q30) * x(n)R (Q0) ) >> 30 in Q0*/ + tempd=*(pDataIn+1); + MUL32x32INTO32(pBiquadState->coefs[2],tempd,templ,30) + ynR+=templ; + + /* ynR+= (-B2 (Q30) * y(n-2)R (Q0) ) >> 30 in Q0*/ + MUL32x32INTO32(pBiquadState->coefs[3],pBiquadState->pDelays[7],templ,30) + ynR+=templ; + + /* ynR+= (-B1 (Q30) * y(n-1)R (Q0) ) >> 30 in Q0 */ + MUL32x32INTO32(pBiquadState->coefs[4],pBiquadState->pDelays[5],templ,30) + ynR+=templ; + + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[7]=pBiquadState->pDelays[5]; /* y(n-2)R=y(n-1)R*/ + pBiquadState->pDelays[6]=pBiquadState->pDelays[4]; /* y(n-2)L=y(n-1)L*/ + pBiquadState->pDelays[3]=pBiquadState->pDelays[1]; /* x(n-2)R=x(n-1)R*/ + pBiquadState->pDelays[2]=pBiquadState->pDelays[0]; /* x(n-2)L=x(n-1)L*/ + pBiquadState->pDelays[5]=(LVM_INT32)ynR; /* Update y(n-1)R in Q0*/ + pBiquadState->pDelays[4]=(LVM_INT32)ynL; /* Update y(n-1)L in Q0*/ + pBiquadState->pDelays[0]=(*pDataIn); /* Update x(n-1)L in Q0*/ + pDataIn++; + pBiquadState->pDelays[1]=(*pDataIn); /* Update x(n-1)R in Q0*/ + pDataIn++; + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut=(LVM_INT32)ynL; /* Write Left output in Q0*/ + pDataOut++; + *pDataOut=(LVM_INT32)ynR; /* Write Right ouput in Q0*/ + pDataOut++; + + + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/BQ_2I_D32F32Cll_TRC_WRA_01_Init.c b/media/libeffects/lvm/lib/Common/src/BQ_2I_D32F32Cll_TRC_WRA_01_Init.c new file mode 100755 index 0000000..7c460d3 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_2I_D32F32Cll_TRC_WRA_01_Init.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/*-------------------------------------------------------------------------*/ +#include "BIQUAD.h" +#include "BQ_2I_D32F32Cll_TRC_WRA_01_Private.h" + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* BQ_2I_D32F32Cll_TRC_WRA_01_Init */ +/* */ +/* DESCRIPTION: */ +/* These functions initializes a BIQUAD filter defined as a cascade of */ +/* biquadratic Filter Sections. */ +/* */ +/* PARAMETERS: */ +/* pInstance - output, returns the pointer to the State Variable */ +/* This state pointer must be passed to any subsequent */ +/* call to "Biquad" functions. */ +/* pTaps - input, pointer to the taps memory */ +/* pCoef - input, pointer to the coefficient structure */ +/* N - M coefficient factor of QM.N */ +/* RETURNS: */ +/* void return code */ +/*-------------------------------------------------------------------------*/ +void BQ_2I_D32F32Cll_TRC_WRA_01_Init ( Biquad_Instance_t *pInstance, + Biquad_2I_Order2_Taps_t *pTaps, + BQ_C32_Coefs_t *pCoef) +{ + LVM_INT32 temp; + PFilter_State pBiquadState = (PFilter_State) pInstance; + pBiquadState->pDelays =(LVM_INT32 *) pTaps ; + + temp=pCoef->A2; + pBiquadState->coefs[0]=temp; + temp=pCoef->A1; + pBiquadState->coefs[1]=temp; + temp=pCoef->A0; + pBiquadState->coefs[2]=temp; + temp=pCoef->B2; + pBiquadState->coefs[3]=temp; + temp=pCoef->B1; + pBiquadState->coefs[4]=temp; +} +/*-------------------------------------------------------------------------*/ +/* End Of File: BQ_2I_D32F32C32_TRC_WRA_01_Init.c */ + diff --git a/media/libeffects/lvm/lib/Common/src/BQ_2I_D32F32Cll_TRC_WRA_01_Private.h b/media/libeffects/lvm/lib/Common/src/BQ_2I_D32F32Cll_TRC_WRA_01_Private.h new file mode 100755 index 0000000..fb4f2dd --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/BQ_2I_D32F32Cll_TRC_WRA_01_Private.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _BQ_2I_D32F32CLL_TRC_WRA_01_PRIVATE_H_ +#define _BQ_2I_D32F32CLL_TRC_WRA_01_PRIVATE_H_ + + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/* The internal state variables are implemented in a (for the user) hidden structure */ +/* In this (private) file, the internal structure is declared fro private use. */ +typedef struct _Filter_State_ +{ + LVM_INT32 * pDelays; /* pointer to the delayed samples (data of 32 bits) */ + LVM_INT32 coefs[5]; /* pointer to the filter coefficients */ +}Filter_State; + +typedef Filter_State * PFilter_State ; + +#endif /* _BQ_2I_D32F32CLL_TRC_WRA_01_PRIVATE_H_*/ diff --git a/media/libeffects/lvm/lib/Common/src/CompLim_private.h b/media/libeffects/lvm/lib/Common/src/CompLim_private.h new file mode 100755 index 0000000..07a8833 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/CompLim_private.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +#ifndef _COMP_LIM_PRIVATE_ +#define _COMP_LIM_PRIVATE_ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "CompLim.h" + +/********************************************************************************** + DEFINITIONS +***********************************************************************************/ + +#define FS_48K 48000 + +#define INTEGER_16 0xFFFF /* 65535*/ +#define INTEGER_15 0x7FFF /* 32767*/ + +#define GAIN_6DB 1 +#define GAIN_12DB 2 +#define GAIN_18DB 3 +#define GAIN_24DB 4 + +#endif /* #ifndef _COMP_LIM_PRIVATE_ */ + +/*** End of file ******************************************************************/ + diff --git a/media/libeffects/lvm/lib/Common/src/Copy_16.c b/media/libeffects/lvm/lib/Common/src/Copy_16.c new file mode 100755 index 0000000..6ee1ff6 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Copy_16.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION COPY_16 +***********************************************************************************/ + +void Copy_16( const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n ) +{ + LVM_INT16 ii; + + if (src > dst) + { + for (ii = n; ii != 0; ii--) + { + *dst = *src; + dst++; + src++; + } + } + else + { + src += n - 1; + dst += n - 1; + for (ii = n; ii != 0; ii--) + { + *dst = *src; + dst--; + src--; + } + } + + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/Core_MixHard_2St_D32C31_SAT.c b/media/libeffects/lvm/lib/Common/src/Core_MixHard_2St_D32C31_SAT.c new file mode 100755 index 0000000..adac24f --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Core_MixHard_2St_D32C31_SAT.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "Mixer_private.h" +#include "LVM_Macros.h" + +/********************************************************************************** + FUNCTION CORE_MIXHARD_2ST_D32C31_SAT +***********************************************************************************/ + +void Core_MixHard_2St_D32C31_SAT( Mix_2St_Cll_t *pInstance, + const LVM_INT32 *src1, + const LVM_INT32 *src2, + LVM_INT32 *dst, + LVM_INT16 n) +{ + LVM_INT32 Temp1,Temp2,Temp3; + LVM_INT16 ii; + LVM_INT16 Current1Short; + LVM_INT16 Current2Short; + + Current1Short = (LVM_INT16)(pInstance->Current1 >> 16); + Current2Short = (LVM_INT16)(pInstance->Current2 >> 16); + + for (ii = n; ii != 0; ii--){ + Temp1=*src1++; + MUL32x16INTO32(Temp1,Current1Short,Temp3,15) + Temp2=*src2++; + MUL32x16INTO32(Temp2,Current2Short,Temp1,15) + Temp2=(Temp1>>1)+(Temp3>>1); + if (Temp2 > 0x3FFFFFFF) + Temp2 = 0x7FFFFFFF; + else if (Temp2 < - 0x40000000) + Temp2 = 0x80000000; + else + Temp2=(Temp2<<1); + *dst++ = Temp2; + } +} + + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/Core_MixInSoft_D32C31_SAT.c b/media/libeffects/lvm/lib/Common/src/Core_MixInSoft_D32C31_SAT.c new file mode 100755 index 0000000..d557f6e --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Core_MixInSoft_D32C31_SAT.c @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "Mixer_private.h" +#include "LVM_Macros.h" + +/********************************************************************************** + FUNCTION CORE_MIXSOFT_1ST_D32C31_WRA +***********************************************************************************/ + +void Core_MixInSoft_D32C31_SAT( Mix_1St_Cll_t *pInstance, + const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n) +{ + LVM_INT32 Temp1,Temp2,Temp3; + LVM_INT16 OutLoop; + LVM_INT16 InLoop; + LVM_INT32 TargetTimesOneMinAlpha; + LVM_INT32 CurrentTimesAlpha; + LVM_INT16 ii,jj; + LVM_INT16 CurrentShort; + + InLoop = (LVM_INT16)(n >> 2); /* Process per 4 samples */ + OutLoop = (LVM_INT16)(n - (InLoop << 2)); + + MUL32x32INTO32((0x7FFFFFFF-pInstance->Alpha),pInstance->Target,TargetTimesOneMinAlpha,31); /* Q31 * Q0 in Q0 */ + if (pInstance->Target >= pInstance->Current){ + TargetTimesOneMinAlpha +=2; /* Ceil*/ + } + + if (OutLoop){ + MUL32x32INTO32(pInstance->Current,pInstance->Alpha,CurrentTimesAlpha,31); /* Q0 * Q31 in Q0 */ + pInstance->Current = TargetTimesOneMinAlpha + CurrentTimesAlpha; /* Q0 + Q0 into Q0*/ + CurrentShort = (LVM_INT16)(pInstance->Current>>16); /* From Q31 to Q15*/ + + for (ii = OutLoop; ii != 0; ii--){ + Temp1=*src++; + Temp2=*dst; + MUL32x16INTO32(Temp1,CurrentShort,Temp3,15) + Temp1=(Temp2>>1)+(Temp3>>1); + + if (Temp1 > 0x3FFFFFFF) + Temp1 = 0x7FFFFFFF; + else if (Temp1 < - 0x40000000) + Temp1 = 0x80000000; + else + Temp1=(Temp1<<1); + *dst++ = Temp1; + } + } + + for (ii = InLoop; ii != 0; ii--){ + MUL32x32INTO32(pInstance->Current,pInstance->Alpha,CurrentTimesAlpha,31); /* Q0 * Q31 in Q0 */ + pInstance->Current = TargetTimesOneMinAlpha + CurrentTimesAlpha; /* Q0 + Q0 into Q0*/ + CurrentShort = (LVM_INT16)(pInstance->Current>>16); /* From Q31 to Q15*/ + + for (jj = 4; jj!=0 ; jj--){ + Temp1=*src++; + Temp2=*dst; + MUL32x16INTO32(Temp1,CurrentShort,Temp3,15) + Temp1=(Temp2>>1)+(Temp3>>1); + + if (Temp1 > 0x3FFFFFFF) + Temp1 = 0x7FFFFFFF; + else if (Temp1 < - 0x40000000) + Temp1 = 0x80000000; + else + Temp1=(Temp1<<1); + *dst++ = Temp1; + } + } +} + + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/Core_MixSoft_1St_D32C31_WRA.c b/media/libeffects/lvm/lib/Common/src/Core_MixSoft_1St_D32C31_WRA.c new file mode 100755 index 0000000..7b4e66d --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Core_MixSoft_1St_D32C31_WRA.c @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "Mixer_private.h" +#include "LVM_Macros.h" + +/********************************************************************************** + FUNCTION CORE_MIXSOFT_1ST_D32C31_WRA +***********************************************************************************/ + +void Core_MixSoft_1St_D32C31_WRA( Mix_1St_Cll_t *pInstance, + const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n) +{ + LVM_INT32 Temp1,Temp2; + LVM_INT16 OutLoop; + LVM_INT16 InLoop; + LVM_INT32 TargetTimesOneMinAlpha; + LVM_INT32 CurrentTimesAlpha; + LVM_INT16 CurrentShort; + LVM_INT16 ii; + + InLoop = (LVM_INT16)(n >> 2); /* Process per 4 samples */ + OutLoop = (LVM_INT16)(n - (InLoop << 2)); + + MUL32x32INTO32((0x7FFFFFFF-pInstance->Alpha),pInstance->Target,TargetTimesOneMinAlpha,31) /* Q31 * Q31 in Q31 */ + if (pInstance->Target >= pInstance->Current) + { + TargetTimesOneMinAlpha +=2; /* Ceil*/ + } + + if (OutLoop!=0) + { + MUL32x32INTO32(pInstance->Current,pInstance->Alpha,CurrentTimesAlpha,31) /* Q31 * Q31 in Q31 */ + pInstance->Current = TargetTimesOneMinAlpha + CurrentTimesAlpha; /* Q31 + Q31 into Q31*/ + CurrentShort = (LVM_INT16)(pInstance->Current>>16); /* From Q31 to Q15*/ + + for (ii = OutLoop; ii != 0; ii--) + { + Temp1=*src; + src++; + + MUL32x16INTO32(Temp1,CurrentShort,Temp2,15) + *dst = Temp2; + dst++; + } + } + + for (ii = InLoop; ii != 0; ii--) + { + MUL32x32INTO32(pInstance->Current,pInstance->Alpha,CurrentTimesAlpha,31) /* Q31 * Q31 in Q31 */ + pInstance->Current = TargetTimesOneMinAlpha + CurrentTimesAlpha; /* Q31 + Q31 into Q31*/ + CurrentShort = (LVM_INT16)(pInstance->Current>>16); /* From Q31 to Q15*/ + Temp1=*src; + src++; + + MUL32x16INTO32(Temp1,CurrentShort,Temp2,15) + *dst = Temp2; + dst++; + + Temp1=*src; + src++; + + MUL32x16INTO32(Temp1,CurrentShort,Temp2,15) + *dst = Temp2; + dst++; + + Temp1=*src; + src++; + + MUL32x16INTO32(Temp1,CurrentShort,Temp2,15) + *dst = Temp2; + dst++; + + Temp1=*src; + src++; + MUL32x16INTO32(Temp1,CurrentShort,Temp2,15) + *dst = Temp2; + dst++; + } +} + + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/DC_2I_D16_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/DC_2I_D16_TRC_WRA_01.c new file mode 100755 index 0000000..187fe68 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/DC_2I_D16_TRC_WRA_01.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "DC_2I_D16_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + +void DC_2I_D16_TRC_WRA_01( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples) + { + LVM_INT32 LeftDC,RightDC; + LVM_INT32 Diff; + LVM_INT32 j; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + LeftDC = pBiquadState->LeftDC; + RightDC = pBiquadState->RightDC; + for(j=NrSamples-1;j>=0;j--) + { + /* Subtract DC an saturate */ + Diff=*(pDataIn++)-(LeftDC>>16); + if (Diff > 32767) { + Diff = 32767; } + else if (Diff < -32768) { + Diff = -32768; } + *(pDataOut++)=(LVM_INT16)Diff; + if (Diff < 0) { + LeftDC -= DC_D16_STEP; } + else { + LeftDC += DC_D16_STEP; } + + + /* Subtract DC an saturate */ + Diff=*(pDataIn++)-(RightDC>>16); + if (Diff > 32767) { + Diff = 32767; } + else if (Diff < -32768) { + Diff = -32768; } + *(pDataOut++)=(LVM_INT16)Diff; + if (Diff < 0) { + RightDC -= DC_D16_STEP; } + else { + RightDC += DC_D16_STEP; } + + } + pBiquadState->LeftDC = LeftDC; + pBiquadState->RightDC = RightDC; + + + } + diff --git a/media/libeffects/lvm/lib/Common/src/DC_2I_D16_TRC_WRA_01_Init.c b/media/libeffects/lvm/lib/Common/src/DC_2I_D16_TRC_WRA_01_Init.c new file mode 100755 index 0000000..292641b --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/DC_2I_D16_TRC_WRA_01_Init.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "DC_2I_D16_TRC_WRA_01_Private.h" + +void DC_2I_D16_TRC_WRA_01_Init(Biquad_Instance_t *pInstance) +{ + PFilter_State pBiquadState = (PFilter_State) pInstance; + pBiquadState->LeftDC = 0; + pBiquadState->RightDC = 0; +} + diff --git a/media/libeffects/lvm/lib/Common/src/DC_2I_D16_TRC_WRA_01_Private.h b/media/libeffects/lvm/lib/Common/src/DC_2I_D16_TRC_WRA_01_Private.h new file mode 100755 index 0000000..2514a77 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/DC_2I_D16_TRC_WRA_01_Private.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _DC_2I_D16_TRC_WRA_01_PRIVATE_H_ +#define _DC_2I_D16_TRC_WRA_01_PRIVATE_H_ + +#define DC_D16_STEP 0x200; + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + + +/* The internal state variables are implemented in a (for the user) hidden structure */ +/* In this (private) file, the internal structure is declared fro private use.*/ +typedef struct _Filter_State_ +{ + LVM_INT32 LeftDC; /* LeftDC */ + LVM_INT32 RightDC; /* RightDC */ +}Filter_State; + +typedef Filter_State * PFilter_State ; + +#endif /* _DC_2I_D16_TRC_WRA_01_PRIVATE_H_ */ diff --git a/media/libeffects/lvm/lib/Common/src/DelayAllPass_Sat_32x16To32.c b/media/libeffects/lvm/lib/Common/src/DelayAllPass_Sat_32x16To32.c new file mode 100755 index 0000000..cda72ac --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/DelayAllPass_Sat_32x16To32.c @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "LVM_Types.h" +#include "LVM_Macros.h" +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION DelayAllPass_32x32 +***********************************************************************************/ + +void DelayAllPass_Sat_32x16To32( LVM_INT32 *delay, /* Delay buffer */ + LVM_UINT16 size, /* Delay size */ + LVM_INT16 coeff, /* All pass filter coefficient */ + LVM_UINT16 DelayOffset, /* Simple delay offset */ + LVM_UINT16 *pAllPassOffset, /* All pass filter delay offset */ + LVM_INT32 *dst, /* Source/destination */ + LVM_INT16 n) /* Number of samples */ +{ + LVM_INT16 i; + LVM_UINT16 AllPassOffset = *pAllPassOffset; + LVM_INT32 temp; + LVM_INT32 a,b,c; + + for (i = 0; i < n; i++) + { + + MUL32x16INTO32(delay[AllPassOffset], coeff, temp, 15) + a = temp; + b = delay[DelayOffset]; + DelayOffset++; + + c = a + b; + if ((((c ^ a) & (c ^ b)) >> 31) != 0) /* overflow / underflow */ + { + if(a < 0) + { + c = 0x80000000l; + } + else + { + c = 0x7FFFFFFFl; + } + } + *dst = c; + dst++; + + + MUL32x16INTO32(c, -coeff, temp, 15) + a = temp; + b = delay[AllPassOffset]; + c = a + b; + if ((((c ^ a) & (c ^ b)) >> 31)!=0) /* overflow / underflow */ + { + if(a < 0) + { + c = 0x80000000l; + } + else + { + c = 0x7FFFFFFFl; + } + } + delay[AllPassOffset] = c; + AllPassOffset++; + + /* Make the delay buffer a circular buffer */ + if (DelayOffset >= size) + { + DelayOffset = 0; + } + + if (AllPassOffset >= size) + { + AllPassOffset = 0; + } + } + + /* Update the offset */ + *pAllPassOffset = AllPassOffset; + + return; +} + +/**********************************************************************************/ + diff --git a/media/libeffects/lvm/lib/Common/src/DelayMix_16x16.c b/media/libeffects/lvm/lib/Common/src/DelayMix_16x16.c new file mode 100755 index 0000000..ee41701 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/DelayMix_16x16.c @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION DelayMix_16x16 +***********************************************************************************/ + +void DelayMix_16x16(const LVM_INT16 *src, /* Source 1, to be delayed */ + LVM_INT16 *delay, /* Delay buffer */ + LVM_INT16 size, /* Delay size */ + LVM_INT16 *dst, /* Source/destination */ + LVM_INT16 *pOffset, /* Delay offset */ + LVM_INT16 n) /* Number of stereo samples */ +{ + LVM_INT16 i; + LVM_INT16 Offset = *pOffset; + LVM_INT16 temp; + + for (i=0; i> 1); + *dst = temp; + dst++; + + delay[Offset] = *src; + Offset++; + src++; + + + /* Right channel */ + temp = (LVM_INT16)((LVM_UINT32)((LVM_INT32)(*dst) - (LVM_INT32)delay[Offset]) >> 1); + *dst = temp; + dst++; + + delay[Offset] = *src; + Offset++; + src++; + + /* Make the reverb delay buffer a circular buffer */ + if (Offset >= size) + { + Offset = 0; + } + } + + /* Update the offset */ + *pOffset = Offset; + + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/DelayWrite_32.c b/media/libeffects/lvm/lib/Common/src/DelayWrite_32.c new file mode 100755 index 0000000..0ae4c42 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/DelayWrite_32.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION DelayMix_16x16 +***********************************************************************************/ + +void DelayWrite_32(const LVM_INT32 *src, /* Source 1, to be delayed */ + LVM_INT32 *delay, /* Delay buffer */ + LVM_UINT16 size, /* Delay size */ + LVM_UINT16 *pOffset, /* Delay offset */ + LVM_INT16 n) /* Number of samples */ +{ + LVM_INT16 i; + LVM_INT16 Offset = (LVM_INT16)*pOffset; + + for (i=0; i= size) + { + Offset = 0; + } + } + + /* Update the offset */ + *pOffset = (LVM_UINT16)Offset; + + return; +} + +/**********************************************************************************/ + diff --git a/media/libeffects/lvm/lib/Common/src/FO_1I_D16F16C15_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/FO_1I_D16F16C15_TRC_WRA_01.c new file mode 100755 index 0000000..831a115 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/FO_1I_D16F16C15_TRC_WRA_01.c @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "FO_1I_D16F16Css_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A1, + pBiquadState->coefs[1] is A0, + pBiquadState->coefs[2] is -B1, these are in Q15 format + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is y(n-1)L in Q0 format +***************************************************************************/ + +void FO_1I_D16F16C15_TRC_WRA_01( Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples) + { + LVM_INT32 ynL; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + // ynL=A1 (Q15) * x(n-1)L (Q0) in Q15 + ynL=(LVM_INT32)pBiquadState->coefs[0]* pBiquadState->pDelays[0]; + + // ynL+=A0 (Q15) * x(n)L (Q0) in Q15 + ynL+=(LVM_INT32)pBiquadState->coefs[1]* (*pDataIn); + + // ynL+= (-B1 (Q15) * y(n-1)L (Q0) ) in Q15 + ynL+=(LVM_INT32)pBiquadState->coefs[2]*pBiquadState->pDelays[1]; + + + ynL=(LVM_INT16)(ynL>>15); // ynL in Q0 format + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[1]=ynL; // Update y(n-1)L in Q0 + pBiquadState->pDelays[0]=(*pDataIn++); // Update x(n-1)L in Q0 + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut++=(LVM_INT16)ynL; // Write Left output in Q0 + + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/FO_1I_D16F16Css_TRC_WRA_01_Init.c b/media/libeffects/lvm/lib/Common/src/FO_1I_D16F16Css_TRC_WRA_01_Init.c new file mode 100755 index 0000000..4675084 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/FO_1I_D16F16Css_TRC_WRA_01_Init.c @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/*-------------------------------------------------------------------------*/ +#include "BIQUAD.h" +#include "FO_1I_D16F16Css_TRC_WRA_01_Private.h" + + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* FO_1I_D16F16Css_TRC_WRA_01_Init */ +/* */ +/* DESCRIPTION: */ +/* These functions initializes a BIQUAD filter defined as a cascade of */ +/* biquadratic Filter Sections. */ +/* */ +/* PARAMETERS: */ +/* pInstance - output, returns the pointer to the State Variable */ +/* This state pointer must be passed to any subsequent */ +/* call to "Biquad" functions. */ +/* pTaps - input, pointer to the taps memory */ +/* pCoef - input, pointer to the coefficient structure */ +/* N - M coefficient factor of QM.N */ +/* RETURNS: */ +/* void return code */ +/*-------------------------------------------------------------------------*/ +void FO_1I_D16F16Css_TRC_WRA_01_Init( Biquad_Instance_t *pInstance, + Biquad_1I_Order1_Taps_t *pTaps, + FO_C16_Coefs_t *pCoef) +{ + LVM_INT16 temp; + PFilter_State pBiquadState = (PFilter_State) pInstance; + pBiquadState->pDelays =(LVM_INT32 *) pTaps; + + temp=pCoef->A1; + pBiquadState->coefs[0]=temp; + temp=pCoef->A0; + pBiquadState->coefs[1]=temp; + temp=pCoef->B1; + pBiquadState->coefs[2]=temp; +} +/*------------------------------------------------*/ +/* End Of File: FO_1I_D16F16Css_TRC_WRA_01_Init.c */ + diff --git a/media/libeffects/lvm/lib/Common/src/FO_1I_D16F16Css_TRC_WRA_01_Private.h b/media/libeffects/lvm/lib/Common/src/FO_1I_D16F16Css_TRC_WRA_01_Private.h new file mode 100755 index 0000000..e1a818c --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/FO_1I_D16F16Css_TRC_WRA_01_Private.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _FO_1I_D16F16CSS_TRC_WRA_01_PRIVATE_H_ +#define _FO_1I_D16F16CSS_TRC_WRA_01_PRIVATE_H_ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ */ +/* */ +/************************************************************************/ + +/* The internal state variables are implemented in a (for the user) hidden structure */ +/* In this (private) file, the internal structure is declared fro private use. */ +typedef struct _Filter_State_ +{ + LVM_INT32* pDelays; /* pointer to the delayed samples (data of 32 bits) */ + LVM_INT16 coefs[3]; /* pointer to the filter coefficients */ +}Filter_State; + +typedef Filter_State * PFilter_State ; + +#endif /* _FO_1I_D16F16CSS_TRC_WRA_01_PRIVATE_H_ */ diff --git a/media/libeffects/lvm/lib/Common/src/FO_1I_D32F32C31_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/FO_1I_D32F32C31_TRC_WRA_01.c new file mode 100755 index 0000000..9bdc5b4 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/FO_1I_D32F32C31_TRC_WRA_01.c @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "FO_1I_D32F32Cll_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A1, + pBiquadState->coefs[1] is A0, + pBiquadState->coefs[2] is -B1, these are in Q31 format + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is y(n-1)L in Q0 format +***************************************************************************/ + +void FO_1I_D32F32C31_TRC_WRA_01( Biquad_Instance_t *pInstance, + LVM_INT32 *pDataIn, + LVM_INT32 *pDataOut, + LVM_INT16 NrSamples) + { + LVM_INT32 ynL,templ; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + // ynL=A1 (Q31) * x(n-1)L (Q0) >>31 in Q0 + MUL32x32INTO32(pBiquadState->coefs[0],pBiquadState->pDelays[0],ynL,31) + + // ynL+=A0 (Q31) * x(n)L (Q0) >> 31 in Q0 + MUL32x32INTO32(pBiquadState->coefs[1],*pDataIn,templ,31) + ynL+=templ; + + // ynL+= (-B1 (Q31) * y(n-1)L (Q0) ) >> 31 in Q0 + MUL32x32INTO32(pBiquadState->coefs[2],pBiquadState->pDelays[1],templ,31) + ynL+=templ; + + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[1]=ynL; // Update y(n-1)L in Q0 + pBiquadState->pDelays[0]=(*pDataIn++); // Update x(n-1)L in Q0 + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut++=(LVM_INT32)ynL; // Write Left output in Q0 + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/FO_1I_D32F32Cll_TRC_WRA_01_Init.c b/media/libeffects/lvm/lib/Common/src/FO_1I_D32F32Cll_TRC_WRA_01_Init.c new file mode 100755 index 0000000..eea0b64 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/FO_1I_D32F32Cll_TRC_WRA_01_Init.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "FO_1I_D32F32Cll_TRC_WRA_01_Private.h" + + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* FO_1I_D32F32Cll_TRC_WRA_01_Init */ +/* */ +/* DESCRIPTION: */ +/* These functions initializes a BIQUAD filter defined as a cascade of */ +/* biquadratic Filter Sections. */ +/* */ +/* PARAMETERS: */ +/* pInstance - output, returns the pointer to the State Variable */ +/* This state pointer must be passed to any subsequent */ +/* call to "Biquad" functions. */ +/* pTaps - input, pointer to the taps memory */ +/* pCoef - input, pointer to the coefficient structure */ +/* N - M coefficient factor of QM.N */ +/* RETURNS: */ +/* void return code */ +/*-------------------------------------------------------------------------*/ +void FO_1I_D32F32Cll_TRC_WRA_01_Init( Biquad_Instance_t *pInstance, + Biquad_1I_Order1_Taps_t *pTaps, + FO_C32_Coefs_t *pCoef) +{ + LVM_INT32 temp; + PFilter_State pBiquadState = (PFilter_State) pInstance; + pBiquadState->pDelays = (LVM_INT32 *) pTaps; + + temp=pCoef->A1; + pBiquadState->coefs[0]=temp; + temp=pCoef->A0; + pBiquadState->coefs[1]=temp; + temp=pCoef->B1; + pBiquadState->coefs[2]=temp; +} +/*------------------------------------------------*/ +/* End Of File: FO_1I_D32F32Cll_TRC_WRA_01_Init.c */ + diff --git a/media/libeffects/lvm/lib/Common/src/FO_1I_D32F32Cll_TRC_WRA_01_Private.h b/media/libeffects/lvm/lib/Common/src/FO_1I_D32F32Cll_TRC_WRA_01_Private.h new file mode 100755 index 0000000..9329150 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/FO_1I_D32F32Cll_TRC_WRA_01_Private.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#ifndef _FO_1I_D32F32CLL_TRC_WRA_01_PRIVATE_H_ +#define _FO_1I_D32F32CLL_TRC_WRA_01_PRIVATE_H_ + + +/* The internal state variables are implemented in a (for the user) hidden structure */ +/* In this (private) file, the internal structure is declared fro private use. */ +typedef struct _Filter_State_ +{ + LVM_INT32 * pDelays; /* pointer to the delayed samples (data of 32 bits) */ + LVM_INT32 coefs[3]; /* pointer to the filter coefficients */ +}Filter_State; + +typedef Filter_State * PFilter_State ; + +#endif /* _FO_1I_D32F32CLL_TRC_WRA_01_PRIVATE_H_ */ diff --git a/media/libeffects/lvm/lib/Common/src/FO_2I_D16F32C15_LShx_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/FO_2I_D16F32C15_LShx_TRC_WRA_01.c new file mode 100755 index 0000000..4b219a2 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/FO_2I_D16F32C15_LShx_TRC_WRA_01.c @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "FO_2I_D16F32Css_LShx_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + +/************************************************************************** +ASSUMPTIONS: +COEFS- +pBiquadState->coefs[0] is A1, +pBiquadState->coefs[1] is A0, +pBiquadState->coefs[2] is -B1, these are in Q15 format +pBiquadState->Shift is Shift value +DELAYS- +pBiquadState->pDelays[0] is x(n-1)L in Q15 format +pBiquadState->pDelays[1] is y(n-1)L in Q30 format +pBiquadState->pDelays[2] is x(n-1)R in Q15 format +pBiquadState->pDelays[3] is y(n-1)R in Q30 format +***************************************************************************/ + +void FO_2I_D16F32C15_LShx_TRC_WRA_01(Biquad_Instance_t *pInstance, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT16 NrSamples) + { + LVM_INT32 ynL,ynR; + LVM_INT32 Temp; + LVM_INT32 NegSatValue; + LVM_INT16 ii; + LVM_INT16 Shift; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + NegSatValue = LVM_MAXINT_16 +1; + NegSatValue = -NegSatValue; + + Shift = pBiquadState->Shift; + + + for (ii = NrSamples; ii != 0; ii--) + { + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + + // ynL =A1 (Q15) * x(n-1)L (Q15) in Q30 + ynL=(LVM_INT32)pBiquadState->coefs[0]* pBiquadState->pDelays[0]; + // ynR =A1 (Q15) * x(n-1)R (Q15) in Q30 + ynR=(LVM_INT32)pBiquadState->coefs[0]* pBiquadState->pDelays[2]; + + + // ynL+=A0 (Q15) * x(n)L (Q15) in Q30 + ynL+=(LVM_INT32)pBiquadState->coefs[1]* (*pDataIn); + // ynR+=A0 (Q15) * x(n)L (Q15) in Q30 + ynR+=(LVM_INT32)pBiquadState->coefs[1]* (*(pDataIn+1)); + + + // ynL += (-B1 (Q15) * y(n-1)L (Q30) ) in Q30 + MUL32x16INTO32(pBiquadState->pDelays[1],pBiquadState->coefs[2],Temp,15); + ynL +=Temp; + // ynR += (-B1 (Q15) * y(n-1)R (Q30) ) in Q30 + MUL32x16INTO32(pBiquadState->pDelays[3],pBiquadState->coefs[2],Temp,15); + ynR +=Temp; + + + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[1]=ynL; // Update y(n-1)L in Q30 + pBiquadState->pDelays[0]=(*pDataIn++); // Update x(n-1)L in Q15 + + pBiquadState->pDelays[3]=ynR; // Update y(n-1)R in Q30 + pBiquadState->pDelays[2]=(*pDataIn++); // Update x(n-1)R in Q15 + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + /*Apply shift: Instead of left shift on 16-bit result, right shift of (15-shift) is applied + for better SNR*/ + ynL = ynL>>(15-Shift); + ynR = ynR>>(15-Shift); + + /*Saturate results*/ + if(ynL > LVM_MAXINT_16) + { + ynL = LVM_MAXINT_16; + } + else + { + if(ynL < NegSatValue) + { + ynL = NegSatValue; + } + } + + if(ynR > LVM_MAXINT_16) + { + ynR = LVM_MAXINT_16; + } + else + { + if(ynR < NegSatValue) + { + ynR = NegSatValue; + } + } + + *pDataOut++=(LVM_INT16)ynL; + *pDataOut++=(LVM_INT16)ynR; + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/FO_2I_D16F32Css_LShx_TRC_WRA_01_Init.c b/media/libeffects/lvm/lib/Common/src/FO_2I_D16F32Css_LShx_TRC_WRA_01_Init.c new file mode 100755 index 0000000..7f212f5 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/FO_2I_D16F32Css_LShx_TRC_WRA_01_Init.c @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/*-------------------------------------------------------------------------*/ +#include "BIQUAD.h" +#include "FO_2I_D16F32Css_LShx_TRC_WRA_01_Private.h" + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* FO_2I_D16F32Css_LShx_TRC_WRA_01_Init */ +/* */ +/* DESCRIPTION: */ +/* These functions initializes a BIQUAD filter defined as a cascade of */ +/* biquadratic Filter Sections. */ +/* */ +/* PARAMETERS: */ +/* pInstance - output, returns the pointer to the State Variable */ +/* This state pointer must be passed to any subsequent */ +/* call to "Biquad" functions. */ +/* pTaps - input, pointer to the taps memory */ +/* pCoef - input, pointer to the coefficient structure */ +/* N - M coefficient factor of QM.N */ +/* RETURNS: */ +/* void return code */ +/*-------------------------------------------------------------------------*/ +void FO_2I_D16F32Css_LShx_TRC_WRA_01_Init(Biquad_Instance_t *pInstance, + Biquad_2I_Order1_Taps_t *pTaps, + FO_C16_LShx_Coefs_t *pCoef) +{ + LVM_INT16 temp; + PFilter_State pBiquadState = (PFilter_State) pInstance; + pBiquadState->pDelays =(LVM_INT32 *) pTaps ; + + temp=pCoef->A1; + pBiquadState->coefs[0]=temp; + temp=pCoef->A0; + pBiquadState->coefs[1]=temp; + temp=pCoef->B1; + pBiquadState->coefs[2]=temp; + + temp=pCoef->Shift; + pBiquadState->Shift = temp; +} +/*-------------------------------------------------------------------------*/ +/* End Of File: FO_2I_D16F32Css_LShx_TRC_WRA_01_Init.c */ + diff --git a/media/libeffects/lvm/lib/Common/src/FO_2I_D16F32Css_LShx_TRC_WRA_01_Private.h b/media/libeffects/lvm/lib/Common/src/FO_2I_D16F32Css_LShx_TRC_WRA_01_Private.h new file mode 100755 index 0000000..6a4564a --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/FO_2I_D16F32Css_LShx_TRC_WRA_01_Private.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _FO_2I_D16F32CSS_LSHX_TRC_WRA_01_PRIVATE_H_ +#define _FO_2I_D16F32CSS_LSHX_TRC_WRA_01_PRIVATE_H_ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/* The internal state variables are implemented in a (for the user) hidden structure */ +/* In this (private) file, the internal structure is declared fro private use. */ +typedef struct _Filter_State_ +{ + LVM_INT32 *pDelays; /* pointer to the delayed samples (data of 32 bits) */ + LVM_INT16 coefs[3]; /* pointer to the filter coefficients */ + LVM_INT16 Shift; /* Shift value*/ +}Filter_State; + +typedef Filter_State * PFilter_State ; + +#endif /* _FO_2I_D16F32CSS_LSHX_TRC_WRA_01_PRIVATE_H_ */ diff --git a/media/libeffects/lvm/lib/Common/src/Filters.h b/media/libeffects/lvm/lib/Common/src/Filters.h new file mode 100755 index 0000000..a274f32 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Filters.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1001 $ + $Date: 2010-06-28 13:23:02 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + +#ifndef FILTERS_H +#define FILTERS_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include "LVM_Types.h" + +/************************************************************************************/ +/* */ +/* Structures */ +/* */ +/************************************************************************************/ + +/* + * Biquad with coefficients A0, A1, A2, B1 and B2 coefficients + */ +/* Single precision (16-bit) Biquad section coefficients */ +typedef struct +{ + LVM_INT16 A0; + LVM_INT16 A1; + LVM_INT16 A2; + LVM_INT16 B1; + LVM_INT16 B2; + LVM_UINT16 Scale; +} BiquadA012B12CoefsSP_t; + + +/* + * Biquad with coefficients A0, A1 and B1 coefficients + */ +/* Single precision (16-bit) Biquad section coefficients */ +typedef struct +{ + LVM_INT16 A0; + LVM_INT16 A1; + LVM_INT16 B1; + LVM_UINT16 Scale; +} BiquadA01B1CoefsSP_t; + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* FILTERS_H */ + diff --git a/media/libeffects/lvm/lib/Common/src/From2iToMS_16x16.c b/media/libeffects/lvm/lib/Common/src/From2iToMS_16x16.c new file mode 100755 index 0000000..fb00768 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/From2iToMS_16x16.c @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION From2iToMS_16x16 +***********************************************************************************/ + +void From2iToMS_16x16( const LVM_INT16 *src, + LVM_INT16 *dstM, + LVM_INT16 *dstS, + LVM_INT16 n ) +{ + LVM_INT32 temp1,left,right; + LVM_INT16 ii; + for (ii = n; ii != 0; ii--) + { + left = (LVM_INT32)*src; + src++; + + right = (LVM_INT32)*src; + src++; + + /* Compute M signal*/ + temp1 = (left+right)>>1; + *dstM = (LVM_INT16)temp1; + dstM++; + + /* Compute S signal*/ + temp1 = (left-right)>>1; + *dstS = (LVM_INT16)temp1; + dstS++; + } + + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/From2iToMono_16.c b/media/libeffects/lvm/lib/Common/src/From2iToMono_16.c new file mode 100755 index 0000000..0ebb4ae --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/From2iToMono_16.c @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION From2iToMono_16 +***********************************************************************************/ + +void From2iToMono_16( const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n) +{ + LVM_INT16 ii; + LVM_INT32 Temp; + for (ii = n; ii != 0; ii--) + { + Temp = (LVM_INT32)*src; + src++; + + Temp += (LVM_INT32)*src; + src++; + + *dst = (LVM_INT16)(Temp >>1); + dst++; + } + + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/From2iToMono_32.c b/media/libeffects/lvm/lib/Common/src/From2iToMono_32.c new file mode 100755 index 0000000..5181368 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/From2iToMono_32.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION From2iToMono_32 +***********************************************************************************/ + +void From2iToMono_32( const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n) +{ + LVM_INT16 ii; + LVM_INT32 Temp; + + for (ii = n; ii != 0; ii--) + { + Temp = (*src>>1); + src++; + + Temp +=(*src>>1); + src++; + + *dst = Temp; + dst++; + } + + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/InstAlloc.c b/media/libeffects/lvm/lib/Common/src/InstAlloc.c new file mode 100755 index 0000000..ff900e0 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/InstAlloc.c @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "InstAlloc.h" + +/**************************************************************************************** + * Name : InstAlloc_Init() + * Input : pms - Pointer to the INST_ALLOC instance + StartAddr - Base address of the instance memory + * Returns : Error code + * Description : Initializes the instance distribution and memory size calculation function + * Remarks : + ****************************************************************************************/ + +void InstAlloc_Init( INST_ALLOC *pms, + void *StartAddr ) +{ + pms->TotalSize = 3; + pms->pNextMember = (LVM_UINT32)(((LVM_UINT32)StartAddr + 3) & 0xFFFFFFFC);/* This code will fail if the platform address space is more than 32-bits*/ +} + + +/**************************************************************************************** + * Name : InstAlloc_AddMember() + * Input : pms - Pointer to the INST_ALLOC instance + Size - The size in bytes of the new added member + * Returns : A pointer to the new added member + * Description : Allocates space for a new member in the instance memory and returns + a pointer to this new member. The start address of all members will + be 32 bit alligned. + * Remarks : + ****************************************************************************************/ + +void* InstAlloc_AddMember( INST_ALLOC *pms, + LVM_UINT32 Size ) +{ + void *NewMemberAddress; /* Variable to temporarily store the return value */ + NewMemberAddress = (void*)pms->pNextMember; + + Size = ((Size + 3) & 0xFFFFFFFC); /* Ceil the size to a multiple of four */ + + pms->TotalSize += Size; + pms->pNextMember += Size; + + return(NewMemberAddress); +} + + +/**************************************************************************************** + * Name : InstAlloc_GetTotal() + * Input : pms - Pointer to the INST_ALLOC instance + * Returns : The instance memory size + * Description : This functions returns the calculated instance memory size + * Remarks : + ****************************************************************************************/ + +LVM_UINT32 InstAlloc_GetTotal( INST_ALLOC *pms) +{ + if (pms->TotalSize > 3) + { + return(pms->TotalSize); + } + else + { + return 0; /* No memory added */ + } +} + + +void InstAlloc_InitAll( INST_ALLOC *pms, + LVM_MemoryTable_st *pMemoryTable) +{ + LVM_UINT32 StartAddr; + + StartAddr = (LVM_UINT32)pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].pBaseAddress; + + pms[0].TotalSize = 3; + pms[0].pNextMember = (LVM_UINT32)(((LVM_UINT32)StartAddr + 3) & 0xFFFFFFFC); + + + StartAddr = (LVM_UINT32)pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].pBaseAddress; + + pms[1].TotalSize = 3; + pms[1].pNextMember = (LVM_UINT32)(((LVM_UINT32)StartAddr + 3) & 0xFFFFFFFC); + + + StartAddr = (LVM_UINT32)pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].pBaseAddress; + + pms[2].TotalSize = 3; + pms[2].pNextMember = (LVM_UINT32)(((LVM_UINT32)StartAddr + 3) & 0xFFFFFFFC); + + + StartAddr = (LVM_UINT32)pMemoryTable->Region[LVM_TEMPORARY_FAST].pBaseAddress; + + pms[3].TotalSize = 3; + pms[3].pNextMember = (LVM_UINT32)(((LVM_UINT32)StartAddr + 3) & 0xFFFFFFFC); + +} + +/**************************************************************************************** + * Name : InstAlloc_InitAll_NULL() + * Input : pms - Pointer to array of four INST_ALLOC instances + * Returns : Nothing + * Description : This function reserves Size of 3 bytes for all memory regions and + * intializes pNextMember for all regions to 0 + * Remarks : + ****************************************************************************************/ + +void InstAlloc_InitAll_NULL( INST_ALLOC *pms) +{ + pms[0].TotalSize = 3; + pms[0].pNextMember = 0; + + + pms[1].TotalSize = 3; + pms[1].pNextMember = 0; + + pms[2].TotalSize = 3; + pms[2].pNextMember = 0; + + pms[3].TotalSize = 3; + pms[3].pNextMember = 0; + +} + + +void* InstAlloc_AddMemberAll( INST_ALLOC *pms, + LVM_UINT32 Size[], + LVM_MemoryTable_st *pMemoryTable) +{ + void *NewMemberAddress; /* Variable to temporarily store the return value */ + + /* coverity[returned_pointer] Ignore coverity warning that ptr is not used */ + NewMemberAddress = InstAlloc_AddMember(&pms[LVM_PERSISTENT_SLOW_DATA], Size[LVM_PERSISTENT_SLOW_DATA]); + + pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].Size = InstAlloc_GetTotal(&pms[LVM_PERSISTENT_SLOW_DATA]); + pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].Type = LVM_PERSISTENT_SLOW_DATA; + pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].pBaseAddress = LVM_NULL; + + NewMemberAddress = InstAlloc_AddMember(&pms[LVM_PERSISTENT_FAST_DATA], Size[LVM_PERSISTENT_FAST_DATA]); + + pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Size = InstAlloc_GetTotal(&pms[LVM_PERSISTENT_FAST_DATA]); + pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Type = LVM_PERSISTENT_FAST_DATA; + pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].pBaseAddress = LVM_NULL; + + NewMemberAddress = InstAlloc_AddMember(&pms[LVM_PERSISTENT_FAST_COEF], Size[LVM_PERSISTENT_FAST_COEF]); + + pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Size = InstAlloc_GetTotal(&pms[LVM_PERSISTENT_FAST_COEF]); + pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Type = LVM_PERSISTENT_FAST_COEF; + pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].pBaseAddress = LVM_NULL; + + NewMemberAddress = InstAlloc_AddMember(&pms[LVM_TEMPORARY_FAST], Size[LVM_TEMPORARY_FAST]); + + pMemoryTable->Region[LVM_TEMPORARY_FAST].Size = InstAlloc_GetTotal(&pms[LVM_TEMPORARY_FAST]); + pMemoryTable->Region[LVM_TEMPORARY_FAST].Type = LVM_TEMPORARY_FAST; + pMemoryTable->Region[LVM_TEMPORARY_FAST].pBaseAddress = LVM_NULL; + + return(NewMemberAddress); +} + + +void* InstAlloc_AddMemberAllRet( INST_ALLOC *pms, + LVM_UINT32 Size[], + void **ptr) +{ + ptr[0] = InstAlloc_AddMember(&pms[LVM_PERSISTENT_SLOW_DATA], Size[LVM_PERSISTENT_SLOW_DATA]); + ptr[1] = InstAlloc_AddMember(&pms[LVM_PERSISTENT_FAST_DATA], Size[LVM_PERSISTENT_FAST_DATA]); + ptr[2] = InstAlloc_AddMember(&pms[LVM_PERSISTENT_FAST_COEF], Size[LVM_PERSISTENT_FAST_COEF]); + ptr[3] = InstAlloc_AddMember(&pms[LVM_TEMPORARY_FAST], Size[LVM_TEMPORARY_FAST]); + + return (ptr[0]); +} diff --git a/media/libeffects/lvm/lib/Common/src/Int16LShiftToInt32_16x32.c b/media/libeffects/lvm/lib/Common/src/Int16LShiftToInt32_16x32.c new file mode 100755 index 0000000..e6be756 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Int16LShiftToInt32_16x32.c @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION INT16LSHIFTTOINT32_16X32 +***********************************************************************************/ + +void Int16LShiftToInt32_16x32(const LVM_INT16 *src, + LVM_INT32 *dst, + LVM_INT16 n, + LVM_INT16 shift ) +{ + LVM_INT16 ii; + + src += n-1; + dst += n-1; + + for (ii = n; ii != 0; ii--) + { + *dst = ( ((LVM_INT32)*src) << shift); + src--; + dst--; + } + + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/Int32RShiftToInt16_Sat_32x16.c b/media/libeffects/lvm/lib/Common/src/Int32RShiftToInt16_Sat_32x16.c new file mode 100755 index 0000000..b21eef5 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Int32RShiftToInt16_Sat_32x16.c @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION INT32RSHIFTTOINT16_SAT_32X16 +***********************************************************************************/ + +void Int32RShiftToInt16_Sat_32x16(const LVM_INT32 *src, + LVM_INT16 *dst, + LVM_INT16 n, + LVM_INT16 shift ) +{ + LVM_INT32 temp; + LVM_INT16 ii; + + for (ii = n; ii != 0; ii--) + { + temp = *src >> shift; + src++; + + if (temp > 0x00007FFF) + { + *dst = 0x7FFF; + } + else if (temp < -0x00008000) + { + *dst = - 0x8000; + } + else + { + *dst = (LVM_INT16)temp; + } + + dst++; + } + + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/JoinTo2i_32x32.c b/media/libeffects/lvm/lib/Common/src/JoinTo2i_32x32.c new file mode 100755 index 0000000..e04f1c3 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/JoinTo2i_32x32.c @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION JoinTo2i_32x32 +***********************************************************************************/ + +void JoinTo2i_32x32( const LVM_INT32 *srcL, + const LVM_INT32 *srcR, + LVM_INT32 *dst, + LVM_INT16 n ) +{ + LVM_INT16 ii; + + srcL += n-1; + srcR += n-1; + dst += ((2*n)-1); + + for (ii = n; ii != 0; ii--) + { + *dst = *srcR; + dst--; + srcR--; + + *dst = *srcL; + dst--; + srcL--; + } + + return; +} + +/**********************************************************************************/ + diff --git a/media/libeffects/lvm/lib/Common/src/LVC_Core_MixHard_1St_2i_D16C31_SAT.c b/media/libeffects/lvm/lib/Common/src/LVC_Core_MixHard_1St_2i_D16C31_SAT.c new file mode 100755 index 0000000..c1d2b2c --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_Core_MixHard_1St_2i_D16C31_SAT.c @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "LVC_Mixer_Private.h" +#include "LVM_Macros.h" +#include "ScalarArithmetic.h" + + +/********************************************************************************** + FUNCTION LVC_Core_MixHard_1St_2i_D16C31_SAT +***********************************************************************************/ + +void LVC_Core_MixHard_1St_2i_D16C31_SAT( LVMixer3_st *ptrInstance1, + LVMixer3_st *ptrInstance2, + const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n) +{ + LVM_INT32 Temp; + LVM_INT16 ii; + LVM_INT16 Current1Short; + LVM_INT16 Current2Short; + Mix_Private_st *pInstance1=(Mix_Private_st *)(ptrInstance1->PrivateParams); + Mix_Private_st *pInstance2=(Mix_Private_st *)(ptrInstance2->PrivateParams); + + + Current1Short = (LVM_INT16)(pInstance1->Current >> 16); + Current2Short = (LVM_INT16)(pInstance2->Current >> 16); + + for (ii = n; ii != 0; ii--) + { + Temp = ((LVM_INT32)*(src++) * (LVM_INT32)Current1Short)>>15; + if (Temp > 0x00007FFF) + *dst++ = 0x7FFF; + else if (Temp < -0x00008000) + *dst++ = - 0x8000; + else + *dst++ = (LVM_INT16)Temp; + + Temp = ((LVM_INT32)*(src++) * (LVM_INT32)Current2Short)>>15; + if (Temp > 0x00007FFF) + *dst++ = 0x7FFF; + else if (Temp < -0x00008000) + *dst++ = - 0x8000; + else + *dst++ = (LVM_INT16)Temp; + } + + +} +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/LVC_Core_MixHard_2St_D16C31_SAT.c b/media/libeffects/lvm/lib/Common/src/LVC_Core_MixHard_2St_D16C31_SAT.c new file mode 100755 index 0000000..2bb212c --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_Core_MixHard_2St_D16C31_SAT.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "LVC_Mixer_Private.h" + +/********************************************************************************** + FUNCTION LVCore_MIXHARD_2ST_D16C31_SAT +***********************************************************************************/ + +void LVC_Core_MixHard_2St_D16C31_SAT( LVMixer3_st *ptrInstance1, + LVMixer3_st *ptrInstance2, + const LVM_INT16 *src1, + const LVM_INT16 *src2, + LVM_INT16 *dst, + LVM_INT16 n) +{ + LVM_INT32 Temp; + LVM_INT16 ii; + LVM_INT16 Current1Short; + LVM_INT16 Current2Short; + Mix_Private_st *pInstance1=(Mix_Private_st *)(ptrInstance1->PrivateParams); + Mix_Private_st *pInstance2=(Mix_Private_st *)(ptrInstance2->PrivateParams); + + + Current1Short = (LVM_INT16)(pInstance1->Current >> 16); + Current2Short = (LVM_INT16)(pInstance2->Current >> 16); + + for (ii = n; ii != 0; ii--){ + Temp = (((LVM_INT32)*(src1++) * (LVM_INT32)Current1Short)>>15) + + (((LVM_INT32)*(src2++) * (LVM_INT32)Current2Short)>>15); + if (Temp > 0x00007FFF) + *dst++ = 0x7FFF; + else if (Temp < -0x00008000) + *dst++ = - 0x8000; + else + *dst++ = (LVM_INT16)Temp; + } +} + + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/LVC_Core_MixInSoft_D16C31_SAT.c b/media/libeffects/lvm/lib/Common/src/LVC_Core_MixInSoft_D16C31_SAT.c new file mode 100755 index 0000000..0408f42 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_Core_MixInSoft_D16C31_SAT.c @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "LVC_Mixer_Private.h" +#include "LVM_Macros.h" + +/********************************************************************************** + FUNCTION LVCore_MIXSOFT_1ST_D16C31_WRA +***********************************************************************************/ + +void LVC_Core_MixInSoft_D16C31_SAT( LVMixer3_st *ptrInstance, + const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n) +{ + + LVM_INT16 OutLoop; + LVM_INT16 InLoop; + LVM_INT16 CurrentShort; + LVM_INT32 ii,jj; + Mix_Private_st *pInstance=(Mix_Private_st *)(ptrInstance->PrivateParams); + LVM_INT32 Delta=pInstance->Delta; + LVM_INT32 Current=pInstance->Current; + LVM_INT32 Target=pInstance->Target; + LVM_INT32 Temp; + + InLoop = (LVM_INT16)(n >> 2); /* Process per 4 samples */ + OutLoop = (LVM_INT16)(n - (InLoop << 2)); + + if(Current Target) + Current = Target; + + CurrentShort = (LVM_INT16)(Current>>16); /* From Q31 to Q15*/ + + for (ii = OutLoop; ii != 0; ii--){ + Temp = ((LVM_INT32)*dst) + (((LVM_INT32)*(src++) * CurrentShort)>>15); /* Q15 + Q15*Q15>>15 into Q15 */ + if (Temp > 0x00007FFF) + *dst++ = 0x7FFF; + else if (Temp < -0x00008000) + *dst++ = - 0x8000; + else + *dst++ = (LVM_INT16)Temp; + } + } + + for (ii = InLoop; ii != 0; ii--){ + ADD2_SAT_32x32(Current,Delta,Temp); /* Q31 + Q31 into Q31*/ + Current=Temp; + if (Current > Target) + Current = Target; + + CurrentShort = (LVM_INT16)(Current>>16); /* From Q31 to Q15*/ + + for (jj = 4; jj!=0 ; jj--){ + Temp = ((LVM_INT32)*dst) + (((LVM_INT32)*(src++) * CurrentShort)>>15); /* Q15 + Q15*Q15>>15 into Q15 */ + if (Temp > 0x00007FFF) + *dst++ = 0x7FFF; + else if (Temp < -0x00008000) + *dst++ = - 0x8000; + else + *dst++ = (LVM_INT16)Temp; + } + } + } + else{ + if (OutLoop){ + Current -= Delta; /* Q31 + Q31 into Q31*/ + if (Current < Target) + Current = Target; + + CurrentShort = (LVM_INT16)(Current>>16); /* From Q31 to Q15*/ + + for (ii = OutLoop; ii != 0; ii--){ + Temp = ((LVM_INT32)*dst) + (((LVM_INT32)*(src++) * CurrentShort)>>15); /* Q15 + Q15*Q15>>15 into Q15 */ + if (Temp > 0x00007FFF) + *dst++ = 0x7FFF; + else if (Temp < -0x00008000) + *dst++ = - 0x8000; + else + *dst++ = (LVM_INT16)Temp; + } + } + + for (ii = InLoop; ii != 0; ii--){ + Current -= Delta; /* Q31 + Q31 into Q31*/ + if (Current < Target) + Current = Target; + + CurrentShort = (LVM_INT16)(Current>>16); /* From Q31 to Q15*/ + + for (jj = 4; jj!=0 ; jj--){ + Temp = ((LVM_INT32)*dst) + (((LVM_INT32)*(src++) * CurrentShort)>>15); /* Q15 + Q15*Q15>>15 into Q15 */ + if (Temp > 0x00007FFF) + *dst++ = 0x7FFF; + else if (Temp < -0x00008000) + *dst++ = - 0x8000; + else + *dst++ = (LVM_INT16)Temp; + } + } + } + pInstance->Current=Current; +} + + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/LVC_Core_MixSoft_1St_2i_D16C31_WRA.c b/media/libeffects/lvm/lib/Common/src/LVC_Core_MixSoft_1St_2i_D16C31_WRA.c new file mode 100755 index 0000000..2847d47 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_Core_MixSoft_1St_2i_D16C31_WRA.c @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "LVC_Mixer_Private.h" +#include "ScalarArithmetic.h" +#include "LVM_Macros.h" + +/********************************************************************************** + FUNCTION LVC_Core_MixSoft_1St_2i_D16C31_WRA +***********************************************************************************/ + +void LVC_Core_MixSoft_1St_2i_D16C31_WRA( LVMixer3_st *ptrInstance1, + LVMixer3_st *ptrInstance2, + const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n) +{ + LVM_INT16 OutLoop; + LVM_INT16 InLoop; + LVM_INT16 CurrentShortL; + LVM_INT16 CurrentShortR; + LVM_INT32 ii; + Mix_Private_st *pInstanceL=(Mix_Private_st *)(ptrInstance1->PrivateParams); + Mix_Private_st *pInstanceR=(Mix_Private_st *)(ptrInstance2->PrivateParams); + + LVM_INT32 DeltaL=pInstanceL->Delta; + LVM_INT32 CurrentL=pInstanceL->Current; + LVM_INT32 TargetL=pInstanceL->Target; + + LVM_INT32 DeltaR=pInstanceR->Delta; + LVM_INT32 CurrentR=pInstanceR->Current; + LVM_INT32 TargetR=pInstanceR->Target; + + LVM_INT32 Temp; + + InLoop = (LVM_INT16)(n >> 2); /* Process per 4 samples */ + OutLoop = (LVM_INT16)(n - (InLoop << 2)); + + if (OutLoop) + { + if(CurrentL TargetL) + CurrentL = TargetL; + } + else + { + CurrentL -= DeltaL; /* Q31 + Q31 into Q31*/ + if (CurrentL < TargetL) + CurrentL = TargetL; + } + + if(CurrentR TargetR) + CurrentR = TargetR; + } + else + { + CurrentR -= DeltaR; /* Q31 + Q31 into Q31*/ + if (CurrentR < TargetR) + CurrentR = TargetR; + } + + CurrentShortL = (LVM_INT16)(CurrentL>>16); /* From Q31 to Q15*/ + CurrentShortR = (LVM_INT16)(CurrentR>>16); /* From Q31 to Q15*/ + + for (ii = OutLoop*2; ii != 0; ii-=2) + { + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShortL)>>15); /* Q15*Q15>>15 into Q15 */ + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShortR)>>15); /* Q15*Q15>>15 into Q15 */ + } + } + + for (ii = InLoop*2; ii != 0; ii-=2) + { + if(CurrentL TargetL) + CurrentL = TargetL; + } + else + { + CurrentL -= DeltaL; /* Q31 + Q31 into Q31*/ + if (CurrentL < TargetL) + CurrentL = TargetL; + } + + if(CurrentR TargetR) + CurrentR = TargetR; + } + else + { + CurrentR -= DeltaR; /* Q31 + Q31 into Q31*/ + if (CurrentR < TargetR) + CurrentR = TargetR; + } + + CurrentShortL = (LVM_INT16)(CurrentL>>16); /* From Q31 to Q15*/ + CurrentShortR = (LVM_INT16)(CurrentR>>16); /* From Q31 to Q15*/ + + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShortL)>>15); /* Q15*Q15>>15 into Q15 */ + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShortR)>>15); /* Q15*Q15>>15 into Q15 */ + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShortL)>>15); + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShortR)>>15); + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShortL)>>15); + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShortR)>>15); + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShortL)>>15); + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShortR)>>15); + } + pInstanceL->Current=CurrentL; + pInstanceR->Current=CurrentR; + +} +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/LVC_Core_MixSoft_1St_D16C31_WRA.c b/media/libeffects/lvm/lib/Common/src/LVC_Core_MixSoft_1St_D16C31_WRA.c new file mode 100755 index 0000000..78f0122 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_Core_MixSoft_1St_D16C31_WRA.c @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "LVC_Mixer_Private.h" +#include "LVM_Macros.h" +#include "ScalarArithmetic.h" + +/********************************************************************************** + FUNCTION LVCore_MIXSOFT_1ST_D16C31_WRA +***********************************************************************************/ + +void LVC_Core_MixSoft_1St_D16C31_WRA( LVMixer3_st *ptrInstance, + const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n) +{ + LVM_INT16 OutLoop; + LVM_INT16 InLoop; + LVM_INT16 CurrentShort; + LVM_INT32 ii; + Mix_Private_st *pInstance=(Mix_Private_st *)(ptrInstance->PrivateParams); + LVM_INT32 Delta=pInstance->Delta; + LVM_INT32 Current=pInstance->Current; + LVM_INT32 Target=pInstance->Target; + LVM_INT32 Temp; + + InLoop = (LVM_INT16)(n >> 2); /* Process per 4 samples */ + OutLoop = (LVM_INT16)(n - (InLoop << 2)); + + if(Current Target) + Current = Target; + + CurrentShort = (LVM_INT16)(Current>>16); /* From Q31 to Q15*/ + + for (ii = OutLoop; ii != 0; ii--){ + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15); /* Q15*Q15>>15 into Q15 */ + } + } + + for (ii = InLoop; ii != 0; ii--){ + ADD2_SAT_32x32(Current,Delta,Temp); /* Q31 + Q31 into Q31*/ + Current=Temp; + if (Current > Target) + Current = Target; + + CurrentShort = (LVM_INT16)(Current>>16); /* From Q31 to Q15*/ + + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15); /* Q15*Q15>>15 into Q15 */ + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15); + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15); + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15); + } + } + else{ + if (OutLoop){ + Current -= Delta; /* Q31 + Q31 into Q31*/ + if (Current < Target) + Current = Target; + + CurrentShort = (LVM_INT16)(Current>>16); /* From Q31 to Q15*/ + + for (ii = OutLoop; ii != 0; ii--){ + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15); /* Q15*Q15>>15 into Q15 */ + } + } + + for (ii = InLoop; ii != 0; ii--){ + Current -= Delta; /* Q31 + Q31 into Q31*/ + if (Current < Target) + Current = Target; + + CurrentShort = (LVM_INT16)(Current>>16); /* From Q31 to Q15*/ + + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15); /* Q15*Q15>>15 into Q15 */ + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15); + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15); + *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15); + } + } + pInstance->Current=Current; +} + + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/LVC_MixInSoft_D16C31_SAT.c b/media/libeffects/lvm/lib/Common/src/LVC_MixInSoft_D16C31_SAT.c new file mode 100755 index 0000000..52be129 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_MixInSoft_D16C31_SAT.c @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "LVC_Mixer_Private.h" +#include "VectorArithmetic.h" +#include "ScalarArithmetic.h" + +/********************************************************************************** + DEFINITIONS +***********************************************************************************/ + +#define TRUE 1 +#define FALSE 0 + +/********************************************************************************** + FUNCTION MIXINSOFT_D16C31_SAT +***********************************************************************************/ + +void LVC_MixInSoft_D16C31_SAT( LVMixer3_1St_st *ptrInstance, + LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n) +{ + char HardMixing = TRUE; + LVM_INT32 TargetGain; + Mix_Private_st *pInstance=(Mix_Private_st *)(ptrInstance->MixerStream[0].PrivateParams); + + if(n<=0) return; + + /****************************************************************************** + SOFT MIXING + *******************************************************************************/ + if (pInstance->Current != pInstance->Target) + { + if(pInstance->Delta == 0x7FFFFFFF){ + pInstance->Current = pInstance->Target; + TargetGain=pInstance->Target>>(16-pInstance->Shift); // TargetGain in Q16.15 format + LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]),TargetGain); + }else if (Abs_32(pInstance->Current-pInstance->Target) < pInstance->Delta){ + pInstance->Current = pInstance->Target; /* Difference is not significant anymore. Make them equal. */ + TargetGain=pInstance->Target>>(16-pInstance->Shift); // TargetGain in Q16.15 format + LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]),TargetGain); + }else{ + /* Soft mixing has to be applied */ + HardMixing = FALSE; + if(pInstance->Shift!=0){ + Shift_Sat_v16xv16 ((LVM_INT16)pInstance->Shift,src,src,n); + LVC_Core_MixInSoft_D16C31_SAT( &(ptrInstance->MixerStream[0]), src, dst, n); + } + else + LVC_Core_MixInSoft_D16C31_SAT( &(ptrInstance->MixerStream[0]), src, dst, n); + } + } + + /****************************************************************************** + HARD MIXING + *******************************************************************************/ + + if (HardMixing){ + if (pInstance->Target != 0){ /* Nothing to do in case Target = 0 */ + if ((pInstance->Target>>16) == 0x7FFF){ + if(pInstance->Shift!=0) + Shift_Sat_v16xv16 ((LVM_INT16)pInstance->Shift,src,src,n); + Add2_Sat_16x16( src, dst, n ); + } + else{ + if(pInstance->Shift!=0) + Shift_Sat_v16xv16 ((LVM_INT16)pInstance->Shift,src,src,n); + Mac3s_Sat_16x16(src,(LVM_INT16)(pInstance->Target>>16),dst,n); + pInstance->Current = pInstance->Target; /* In case the LVCore function would have changed the Current value */ + } + } + } + + + /****************************************************************************** + CALL BACK + *******************************************************************************/ + + if (ptrInstance->MixerStream[0].CallbackSet){ + if (Abs_32(pInstance->Current-pInstance->Target) < pInstance->Delta){ + pInstance->Current = pInstance->Target; /* Difference is not significant anymore. Make them equal. */ + TargetGain=pInstance->Target>>(16-pInstance->Shift); // TargetGain in Q16.15 format + LVC_Mixer_SetTarget(ptrInstance->MixerStream,TargetGain); + ptrInstance->MixerStream[0].CallbackSet = FALSE; + if (ptrInstance->MixerStream[0].pCallBack != 0){ + (*ptrInstance->MixerStream[0].pCallBack) ( ptrInstance->MixerStream[0].pCallbackHandle, ptrInstance->MixerStream[0].pGeneralPurpose,ptrInstance->MixerStream[0].CallbackParam ); + } + } + } + +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/LVC_MixSoft_1St_2i_D16C31_SAT.c b/media/libeffects/lvm/lib/Common/src/LVC_MixSoft_1St_2i_D16C31_SAT.c new file mode 100755 index 0000000..d832e06 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_MixSoft_1St_2i_D16C31_SAT.c @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "LVC_Mixer_Private.h" +#include "VectorArithmetic.h" +#include "ScalarArithmetic.h" + +/********************************************************************************** + DEFINITIONS +***********************************************************************************/ + +#define TRUE 1 +#define FALSE 0 + +/********************************************************************************** + FUNCTION LVC_MixSoft_1St_2i_D16C31_SAT +***********************************************************************************/ + +void LVC_MixSoft_1St_2i_D16C31_SAT( LVMixer3_2St_st *ptrInstance, + const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n) +{ + char HardMixing = TRUE; + LVM_INT32 TargetGain; + Mix_Private_st *pInstance1=(Mix_Private_st *)(ptrInstance->MixerStream[0].PrivateParams); + Mix_Private_st *pInstance2=(Mix_Private_st *)(ptrInstance->MixerStream[1].PrivateParams); + + if(n<=0) return; + + /****************************************************************************** + SOFT MIXING + *******************************************************************************/ + if ((pInstance1->Current != pInstance1->Target)||(pInstance2->Current != pInstance2->Target)) + { + if(pInstance1->Delta == 0x7FFFFFFF) + { + pInstance1->Current = pInstance1->Target; + TargetGain=pInstance1->Target>>16; // TargetGain in Q16.15 format, no integer part + LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]),TargetGain); + } + else if (Abs_32(pInstance1->Current-pInstance1->Target) < pInstance1->Delta) + { + pInstance1->Current = pInstance1->Target; /* Difference is not significant anymore. Make them equal. */ + TargetGain=pInstance1->Target>>16; // TargetGain in Q16.15 format, no integer part + LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]),TargetGain); + } + else + { + /* Soft mixing has to be applied */ + HardMixing = FALSE; + } + + if(HardMixing == TRUE) + { + if(pInstance2->Delta == 0x7FFFFFFF) + { + pInstance2->Current = pInstance2->Target; + TargetGain=pInstance2->Target>>16; // TargetGain in Q16.15 format, no integer part + LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[1]),TargetGain); + } + else if (Abs_32(pInstance2->Current-pInstance2->Target) < pInstance2->Delta) + { + pInstance2->Current = pInstance2->Target; /* Difference is not significant anymore. Make them equal. */ + TargetGain=pInstance2->Target>>16; // TargetGain in Q16.15 format, no integer part + LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[1]),TargetGain); + } + else + { + /* Soft mixing has to be applied */ + HardMixing = FALSE; + } + } + + if(HardMixing == FALSE) + { + LVC_Core_MixSoft_1St_2i_D16C31_WRA( &(ptrInstance->MixerStream[0]),&(ptrInstance->MixerStream[1]), src, dst, n); + } + } + + /****************************************************************************** + HARD MIXING + *******************************************************************************/ + + if (HardMixing) + { + if (((pInstance1->Target>>16) == 0x7FFF)&&((pInstance2->Target>>16) == 0x7FFF)) + { + if(src!=dst) + { + Copy_16(src, dst, n); + } + } + else + { + LVC_Core_MixHard_1St_2i_D16C31_SAT(&(ptrInstance->MixerStream[0]),&(ptrInstance->MixerStream[1]), src, dst, n); + } + } + + /****************************************************************************** + CALL BACK + *******************************************************************************/ + + if (ptrInstance->MixerStream[0].CallbackSet) + { + if (Abs_32(pInstance1->Current-pInstance1->Target) < pInstance1->Delta) + { + pInstance1->Current = pInstance1->Target; /* Difference is not significant anymore. Make them equal. */ + TargetGain=pInstance1->Target>>(16-pInstance1->Shift); // TargetGain in Q16.15 format + LVC_Mixer_SetTarget(&ptrInstance->MixerStream[0],TargetGain); + ptrInstance->MixerStream[0].CallbackSet = FALSE; + if (ptrInstance->MixerStream[0].pCallBack != 0) + { + (*ptrInstance->MixerStream[0].pCallBack) ( ptrInstance->MixerStream[0].pCallbackHandle, ptrInstance->MixerStream[0].pGeneralPurpose,ptrInstance->MixerStream[0].CallbackParam ); + } + } + } + if (ptrInstance->MixerStream[1].CallbackSet) + { + if (Abs_32(pInstance2->Current-pInstance2->Target) < pInstance2->Delta) + { + pInstance2->Current = pInstance2->Target; /* Difference is not significant anymore. Make them equal. */ + TargetGain=pInstance2->Target>>(16-pInstance2->Shift); // TargetGain in Q16.15 format + LVC_Mixer_SetTarget(&ptrInstance->MixerStream[1],TargetGain); + ptrInstance->MixerStream[1].CallbackSet = FALSE; + if (ptrInstance->MixerStream[1].pCallBack != 0) + { + (*ptrInstance->MixerStream[1].pCallBack) ( ptrInstance->MixerStream[1].pCallbackHandle, ptrInstance->MixerStream[1].pGeneralPurpose,ptrInstance->MixerStream[1].CallbackParam ); + } + } + } +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/LVC_MixSoft_1St_D16C31_SAT.c b/media/libeffects/lvm/lib/Common/src/LVC_MixSoft_1St_D16C31_SAT.c new file mode 100755 index 0000000..cfb1239 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_MixSoft_1St_D16C31_SAT.c @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "LVC_Mixer_Private.h" +#include "VectorArithmetic.h" +#include "ScalarArithmetic.h" + +/********************************************************************************** + DEFINITIONS +***********************************************************************************/ + +#define TRUE 1 +#define FALSE 0 + +/********************************************************************************** + FUNCTION LVMixer3_MIXSOFT_1ST_D16C31_SAT +***********************************************************************************/ + +void LVC_MixSoft_1St_D16C31_SAT( LVMixer3_1St_st *ptrInstance, + const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n) +{ + char HardMixing = TRUE; + LVM_INT32 TargetGain; + Mix_Private_st *pInstance=(Mix_Private_st *)(ptrInstance->MixerStream[0].PrivateParams); + + if(n<=0) return; + + /****************************************************************************** + SOFT MIXING + *******************************************************************************/ + if (pInstance->Current != pInstance->Target) + { + if(pInstance->Delta == 0x7FFFFFFF){ + pInstance->Current = pInstance->Target; + TargetGain=pInstance->Target>>(16-pInstance->Shift); // TargetGain in Q16.15 format + LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]),TargetGain); + }else if (Abs_32(pInstance->Current-pInstance->Target) < pInstance->Delta){ + pInstance->Current = pInstance->Target; /* Difference is not significant anymore. Make them equal. */ + TargetGain=pInstance->Target>>(16-pInstance->Shift); // TargetGain in Q16.15 format + LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]),TargetGain); + }else{ + /* Soft mixing has to be applied */ + HardMixing = FALSE; + if(pInstance->Shift!=0){ + Shift_Sat_v16xv16 ((LVM_INT16)pInstance->Shift,src,dst,n); + LVC_Core_MixSoft_1St_D16C31_WRA( &(ptrInstance->MixerStream[0]), dst, dst, n); + } + else + LVC_Core_MixSoft_1St_D16C31_WRA( &(ptrInstance->MixerStream[0]), src, dst, n); + } + } + + /****************************************************************************** + HARD MIXING + *******************************************************************************/ + + if (HardMixing){ + if (pInstance->Target == 0) + LoadConst_16(0, dst, n); + else if(pInstance->Shift!=0){ + Shift_Sat_v16xv16 ((LVM_INT16)pInstance->Shift,src,dst,n); + if ((pInstance->Target>>16) != 0x7FFF) + Mult3s_16x16( dst, (LVM_INT16)(pInstance->Target>>16), dst, n ); + } + else { + if ((pInstance->Target>>16) != 0x7FFF) + Mult3s_16x16( src, (LVM_INT16)(pInstance->Target>>16), dst, n ); + else if(src!=dst) + Copy_16(src, dst, n); + } + + } + + /****************************************************************************** + CALL BACK + *******************************************************************************/ + + if (ptrInstance->MixerStream[0].CallbackSet){ + if (Abs_32(pInstance->Current-pInstance->Target) < pInstance->Delta){ + pInstance->Current = pInstance->Target; /* Difference is not significant anymore. Make them equal. */ + TargetGain=pInstance->Target>>(16-pInstance->Shift); // TargetGain in Q16.15 format + LVC_Mixer_SetTarget(ptrInstance->MixerStream,TargetGain); + ptrInstance->MixerStream[0].CallbackSet = FALSE; + if (ptrInstance->MixerStream[0].pCallBack != 0){ + (*ptrInstance->MixerStream[0].pCallBack) ( ptrInstance->MixerStream[0].pCallbackHandle, ptrInstance->MixerStream[0].pGeneralPurpose,ptrInstance->MixerStream[0].CallbackParam ); + } + } + } +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/LVC_MixSoft_2St_D16C31_SAT.c b/media/libeffects/lvm/lib/Common/src/LVC_MixSoft_2St_D16C31_SAT.c new file mode 100755 index 0000000..6184736 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_MixSoft_2St_D16C31_SAT.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "LVC_Mixer_Private.h" +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION LVC_MixSoft_2St_D16C31_SAT.c +***********************************************************************************/ + +void LVC_MixSoft_2St_D16C31_SAT( LVMixer3_2St_st *ptrInstance, + const LVM_INT16 *src1, + LVM_INT16 *src2, + LVM_INT16 *dst, + LVM_INT16 n) +{ + Mix_Private_st *pInstance1=(Mix_Private_st *)(ptrInstance->MixerStream[0].PrivateParams); + Mix_Private_st *pInstance2=(Mix_Private_st *)(ptrInstance->MixerStream[1].PrivateParams); + + if(n<=0) return; + + /****************************************************************************** + SOFT MIXING + *******************************************************************************/ + if ((pInstance1->Current == pInstance1->Target)&&(pInstance1->Current == 0)){ + LVC_MixSoft_1St_D16C31_SAT( (LVMixer3_1St_st *)(&ptrInstance->MixerStream[1]), src2, dst, n); + } + else if ((pInstance2->Current == pInstance2->Target)&&(pInstance2->Current == 0)){ + LVC_MixSoft_1St_D16C31_SAT( (LVMixer3_1St_st *)(&ptrInstance->MixerStream[0]), src1, dst, n); + } + else if ((pInstance1->Current != pInstance1->Target) || (pInstance2->Current != pInstance2->Target)) + { + LVC_MixSoft_1St_D16C31_SAT((LVMixer3_1St_st *)(&ptrInstance->MixerStream[0]), src1, dst, n); + LVC_MixInSoft_D16C31_SAT( (LVMixer3_1St_st *)(&ptrInstance->MixerStream[1]), src2, dst, n); + } + else{ + /****************************************************************************** + HARD MIXING + *******************************************************************************/ + if(pInstance2->Shift!=0) + Shift_Sat_v16xv16 ((LVM_INT16)pInstance2->Shift,src2,src2,n); + if(pInstance1->Shift!=0) + { + Shift_Sat_v16xv16 ((LVM_INT16)pInstance1->Shift,src1,dst,n); + LVC_Core_MixHard_2St_D16C31_SAT( &ptrInstance->MixerStream[0], &ptrInstance->MixerStream[1], dst, src2, dst, n); + } + else + LVC_Core_MixHard_2St_D16C31_SAT( &ptrInstance->MixerStream[0], &ptrInstance->MixerStream[1], src1, src2, dst, n); + } +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/LVC_Mixer.h b/media/libeffects/lvm/lib/Common/src/LVC_Mixer.h new file mode 100755 index 0000000..3b32e21 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_Mixer.h @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +#ifndef __LVC_MIXER_H__ +#define __LVC_MIXER_H__ + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#include "LVM_Types.h" + +/********************************************************************************** + INSTANCE MEMORY TYPE DEFINITION +***********************************************************************************/ + +/* LVMixer3_st structure stores Instance parameters for one audio stream */ +typedef struct +{ + LVM_INT32 PrivateParams[4]; /* Private Instance params for Audio Stream */ + LVM_INT16 CallbackSet; /* Boolean. Should be set by calling application each time the target value is updated */ + LVM_INT16 CallbackParam; /* Parameter that will be used in the calback function */ + void *pCallbackHandle; /* Pointer to the instance of the callback function */ + void *pGeneralPurpose; /* Pointer for general purpose usage */ + LVM_Callback pCallBack; /* Pointer to the callback function */ +} LVMixer3_st; + +typedef struct +{ + LVMixer3_st MixerStream[1]; /* Instance Params for one Audio Stream */ +} LVMixer3_1St_st; + +typedef struct +{ + LVMixer3_st MixerStream[2]; /* Instance Params for two Audio Streams */ +} LVMixer3_2St_st; + +typedef struct +{ + LVMixer3_st MixerStream[3]; /* Instance Params for three Audio Streams */ +} LVMixer3_3St_st; + +/********************************************************************************** + FUNCTION PROTOTYPES (HIGH LEVEL FUNCTIONS) +***********************************************************************************/ + +/* Function names should be unique within first 16 characters */ +#define LVMixer3_MixSoft_1St_D16C31_SAT LVMixer3_1St_D16C31_SAT_MixSoft +#define LVMixer3_MixInSoft_D16C31_SAT LVMixer3_D16C31_SAT_MixInSoft +#define LVMixer3_MixSoft_2St_D16C31_SAT LVMixer3_2St_D16C31_SAT_MixSoft +#define LVMixer3_MixSoft_3St_D16C31_SAT LVMixer3_3St_D16C31_SAT_MixSoft + + +/*** General functions ************************************************************/ + +/**********************************************************************************/ +/* This time constant calculation function assumes the mixer will be called with */ +/* large block sizes. When the block size is small, especially if less than 4, */ +/* then the calculation will give an incorrect value for alpha, see the mixer */ +/* documentation for further details. */ +/* ********************************************************************************/ +void LVC_Mixer_SetTarget( LVMixer3_st *pStream, + LVM_INT32 TargetGain); + +LVM_INT32 LVC_Mixer_GetTarget( LVMixer3_st *pStream); + +LVM_INT32 LVC_Mixer_GetCurrent( LVMixer3_st *pStream); + +void LVC_Mixer_Init( LVMixer3_st *pStream, + LVM_INT32 TargetGain, + LVM_INT32 CurrentGain); + +void LVC_Mixer_SetTimeConstant( LVMixer3_st *pStream, + LVM_INT32 Tc_millisec, + LVM_Fs_en Fs, + LVM_INT16 NumChannels); + +void LVC_Mixer_VarSlope_SetTimeConstant( LVMixer3_st *pStream, + LVM_INT32 Tc_millisec, + LVM_Fs_en Fs, + LVM_INT16 NumChannels); + +/*** 16 bit functions *************************************************************/ + +void LVC_MixSoft_1St_D16C31_SAT( LVMixer3_1St_st *pInstance, + const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n); + +void LVC_MixInSoft_D16C31_SAT( LVMixer3_1St_st *pInstance, + LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n); + +void LVC_MixSoft_2St_D16C31_SAT( LVMixer3_2St_st *pInstance, + const LVM_INT16 *src1, + LVM_INT16 *src2, + LVM_INT16 *dst, /* dst cannot be equal to src2 */ + LVM_INT16 n); + +/**********************************************************************************/ +/* For applying different gains to Left and right chennals */ +/* MixerStream[0] applies to Left channel */ +/* MixerStream[1] applies to Right channel */ +/* Gain values should not be more that 1.0 */ +/**********************************************************************************/ +void LVC_MixSoft_1St_2i_D16C31_SAT( LVMixer3_2St_st *pInstance, + const LVM_INT16 *src, + LVM_INT16 *dst, /* dst can be equal to src */ + LVM_INT16 n); /* Number of stereo samples */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/**********************************************************************************/ + +#endif //#ifndef __LVC_MIXER_H__ + diff --git a/media/libeffects/lvm/lib/Common/src/LVC_Mixer_GetCurrent.c b/media/libeffects/lvm/lib/Common/src/LVC_Mixer_GetCurrent.c new file mode 100755 index 0000000..09658ba --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_Mixer_GetCurrent.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 839 $*/ +/* $Date: 2010-06-16 14:15:52 +0200 (Wed, 16 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "LVM_Types.h" +#include "LVM_Macros.h" +#include "LVC_Mixer_Private.h" + + +/************************************************************************/ +/* FUNCTION: */ +/* LVMixer3_GetCurrent */ +/* */ +/* DESCRIPTION: */ +/* This function returns the CurrentGain in Q16.15 format */ +/* */ +/* RETURNS: */ +/* CurrentGain - CurrentGain value in Q 16.15 format */ +/* */ +/************************************************************************/ + +LVM_INT32 LVC_Mixer_GetCurrent( LVMixer3_st *pStream) +{ + LVM_INT32 CurrentGain; + Mix_Private_st *pInstance=(Mix_Private_st *)pStream->PrivateParams; + CurrentGain=pInstance->Current>>(16-pInstance->Shift); // CurrentGain in Q16.15 format + return CurrentGain; +} diff --git a/media/libeffects/lvm/lib/Common/src/LVC_Mixer_GetTarget.c b/media/libeffects/lvm/lib/Common/src/LVC_Mixer_GetTarget.c new file mode 100755 index 0000000..ed2cf94 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_Mixer_GetTarget.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 839 $*/ +/* $Date: 2010-06-16 14:15:52 +0200 (Wed, 16 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "LVM_Types.h" +#include "LVM_Macros.h" +#include "LVC_Mixer_Private.h" + +/************************************************************************/ +/* FUNCTION: */ +/* LVMixer3_GetTarget */ +/* */ +/* DESCRIPTION: */ +/* This function returns the TargetGain in Q16.15 format */ +/* */ +/* RETURNS: */ +/* TargetGain - TargetGain value in Q 16.15 format */ +/* */ +/************************************************************************/ + +LVM_INT32 LVC_Mixer_GetTarget( LVMixer3_st *pStream) +{ + LVM_INT32 TargetGain; + Mix_Private_st *pInstance=(Mix_Private_st *)pStream->PrivateParams; + + TargetGain=pInstance->Target>>(16-pInstance->Shift); // TargetGain in Q16.15 format + + return TargetGain; +} diff --git a/media/libeffects/lvm/lib/Common/src/LVC_Mixer_Init.c b/media/libeffects/lvm/lib/Common/src/LVC_Mixer_Init.c new file mode 100755 index 0000000..c61e468 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_Mixer_Init.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "LVM_Types.h" +#include "LVM_Macros.h" +#include "LVC_Mixer_Private.h" + +/************************************************************************/ +/* FUNCTION: */ +/* LVMixer3_Init */ +/* */ +/* DESCRIPTION: */ +/* This intialization function intializes the private instance */ +/* paramters for a given Audio Stream based on TargetGain and */ +/* CurrentGain */ +/* This function caclulates the "Shift" required to provide the */ +/* integer part of TargetGain and fractional gain values "Target" and */ +/* "Current" based on maximum(TargetGain,CurrentGain) */ +/* E.g. CurrentGain=1.9 and TargetGain=2.5 then based on */ +/* MaxGain of 2.5, Shift = 2, Current=1.9/4=0.475, Target=2.5/4=0.625 */ +/* Therefore integer gain of 4 is provided by Left Shift of 2 and */ +/* fraction gain is provided through Current=0.475 and Target=0.625 */ +/* PARAMETERS: */ +/* pStream - ptr to Instance Parameter Structure LVMixer3_st for an*/ +/* Audio Stream */ +/* TargetGain - TargetGain value in Q 16.15 format */ +/* CurrentGain - CurrentGain value in Q 16.15 format */ +/* */ +/* RETURNS: */ +/* void */ +/* */ +/************************************************************************/ + +void LVC_Mixer_Init( LVMixer3_st *pStream, + LVM_INT32 TargetGain, + LVM_INT32 CurrentGain) +{ + LVM_INT16 Shift=0; + LVM_INT32 MaxGain=TargetGain; // MaxGain is in Q16.15 format + Mix_Private_st *pInstance=(Mix_Private_st *)pStream->PrivateParams; + if(CurrentGain>MaxGain) + MaxGain=CurrentGain; // MaxGain=max(CurrentGain,TargetGain) + + MaxGain=MaxGain>>15; // MaxGain in Q31.0 format i.e Integer part only + while(MaxGain>0){ // Update Shift required to provide integer gain + Shift++; + MaxGain=MaxGain>>1; + } + pInstance->Target=TargetGain<<(16-Shift); // Update fractional gain Target + pInstance->Current=CurrentGain<<(16-Shift); // Update fractional gain Current + pInstance->Shift=Shift; // Update Shift +} + diff --git a/media/libeffects/lvm/lib/Common/src/LVC_Mixer_Private.h b/media/libeffects/lvm/lib/Common/src/LVC_Mixer_Private.h new file mode 100755 index 0000000..d61d670 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_Mixer_Private.h @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +#ifndef __LVC_MIXER_PRIVATE_H__ +#define __LVC_MIXER_PRIVATE_H__ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "LVC_Mixer.h" +#include "VectorArithmetic.h" + +/* Instance parameter structure */ +typedef struct +{ + /* General */ + LVM_INT32 Target; /* 32 bit number specifying fractional value of Target Gain */ + LVM_INT32 Current; /* 32 bit number specifying fractional valude of Current Gain */ + LVM_INT32 Shift; /* Left Shift for Integer part of Gain */ + LVM_INT32 Delta; /* 32 bit number specifying the fractional value of Delta Gain */ +} Mix_Private_st; + + + +/********************************************************************************** + DEFINITIONS +***********************************************************************************/ +#define LVCore_MixInSoft_D32C31_SAT LVCore_InSoft_D32C31_SAT +#define LVCore_MixSoft_1St_D32C31_WRA LVCore_Soft_1St_D32C31_WRA +#define LVCore_MixHard_2St_D32C31_SAT LVCore_Hard_2St_D32C31_SAT + +/********************************************************************************** + FUNCTION PROTOTYPES (LOW LEVEL SUBFUNCTIONS) +***********************************************************************************/ + +/*** 16 bit functions *************************************************************/ + +void LVC_Core_MixInSoft_D16C31_SAT( LVMixer3_st *pInstance, + const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n); + +void LVC_Core_MixSoft_1St_D16C31_WRA( LVMixer3_st *pInstance, + const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n); + +void LVC_Core_MixHard_2St_D16C31_SAT( LVMixer3_st *pInstance1, + LVMixer3_st *pInstance2, + const LVM_INT16 *src1, + const LVM_INT16 *src2, + LVM_INT16 *dst, + LVM_INT16 n); + +/**********************************************************************************/ +/* For applying different gains to Left and right chennals */ +/* ptrInstance1 applies to Left channel */ +/* ptrInstance2 applies to Right channel */ +/* Gain values should not be more that 1.0 */ +/**********************************************************************************/ + +void LVC_Core_MixSoft_1St_2i_D16C31_WRA( LVMixer3_st *ptrInstance1, + LVMixer3_st *ptrInstance2, + const LVM_INT16 *src, + LVM_INT16 *dst, /* dst can be equal to src */ + LVM_INT16 n); /* Number of stereo samples */ + +/**********************************************************************************/ +/* For applying different gains to Left and right chennals */ +/* ptrInstance1 applies to Left channel */ +/* ptrInstance2 applies to Right channel */ +/* Gain values should not be more that 1.0 */ +/**********************************************************************************/ +void LVC_Core_MixHard_1St_2i_D16C31_SAT( LVMixer3_st *ptrInstance1, + LVMixer3_st *ptrInstance2, + const LVM_INT16 *src, + LVM_INT16 *dst, /* dst can be equal to src */ + LVM_INT16 n); /* Number of stereo samples */ + + + +/*** 32 bit functions *************************************************************/ + +void LVC_Core_MixInSoft_D32C31_SAT( LVMixer3_st *pInstance, + const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n); + +void LVC_Core_MixSoft_1St_D32C31_WRA( LVMixer3_st *pInstance, + const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n); + +void LVC_Core_MixHard_2St_D32C31_SAT( LVMixer3_st *pInstance1, + LVMixer3_st *pInstance2, + const LVM_INT32 *src1, + const LVM_INT32 *src2, + LVM_INT32 *dst, + LVM_INT16 n); + +/**********************************************************************************/ + +#endif //#ifndef __LVC_MIXER_PRIVATE_H__ + + + + + + + + + + diff --git a/media/libeffects/lvm/lib/Common/src/LVC_Mixer_SetTarget.c b/media/libeffects/lvm/lib/Common/src/LVC_Mixer_SetTarget.c new file mode 100755 index 0000000..4d3fe0c --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_Mixer_SetTarget.c @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "LVM_Types.h" +#include "LVM_Macros.h" +#include "LVC_Mixer_Private.h" + +/************************************************************************/ +/* FUNCTION: */ +/* LVMixer3_SetTarget */ +/* */ +/* DESCRIPTION: */ +/* This function updates the private instance parameters: Shift,Target,*/ +/* Current for a given Audio Stream based on new value of TargetGain */ +/* */ +/* This function caclulates the "Shift" required to provide the */ +/* integer part of TargetGain and fractional gain values "Target" and */ +/* "Current" based on maximum(TargetGain,CurrentGain) */ +/* E.g. CurrentGain=1.9 and TargetGain=2.5 then based on */ +/* MaxGain of 2.5, Shift = 2, Current=1.9/4=0.475, Target=2.5/4=0.625 */ +/* Therefore integer gain of 4 is provided by Left Shift of 2 and */ +/* fraction gain is provided through Current=0.475 and Target=0.625 */ +/* PARAMETERS: */ +/* pStream - ptr to Instance Parameter Structure LVMixer3_st */ +/* for an Audio Stream */ +/* TargetGain - TargetGain value in Q 16.15 format */ +/* */ +/* RETURNS: */ +/* void */ +/* */ +/************************************************************************/ + +void LVC_Mixer_SetTarget(LVMixer3_st *pStream, + LVM_INT32 TargetGain) +{ + LVM_INT32 Shift=0; + LVM_INT32 CurrentGain; + LVM_INT32 MaxGain=TargetGain; // MaxGain is in Q16.15 format + Mix_Private_st *pInstance=(Mix_Private_st *)pStream->PrivateParams; + CurrentGain=pInstance->Current>>(16-pInstance->Shift); // CurrentGain in Q16.15 format + if(CurrentGain>MaxGain) + MaxGain=CurrentGain; // MaxGain=max(CurrentGain,TargetGain) + + MaxGain=MaxGain>>15; // MaxGain in Q31.0 format i.e Integer part only + while(MaxGain>0){ // Update Shift required to provide integer gain + Shift++; + MaxGain=MaxGain>>1; + } + pInstance->Target=TargetGain<<(16-Shift); // Update fractional gain Target + pInstance->Current=CurrentGain<<(16-Shift); // Update fractional gain Current + pInstance->Shift=Shift; // Update Shift +} diff --git a/media/libeffects/lvm/lib/Common/src/LVC_Mixer_SetTimeConstant.c b/media/libeffects/lvm/lib/Common/src/LVC_Mixer_SetTimeConstant.c new file mode 100755 index 0000000..df0fd37 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_Mixer_SetTimeConstant.c @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "LVM_Types.h" +#include "LVM_Macros.h" +#include "LVC_Mixer_Private.h" + +/************************************************************************/ +/* FUNCTION: */ +/* LVMixer3_SetTimeConstant */ +/* */ +/* DESCRIPTION: */ +/* This function calculates the step change for fractional gain for a */ +/* given time constant, sample rate and num channels */ +/* Delta=(2147483647*4*1000)/(NumChannels*SampleRate*Tc_millisec) */ +/* in Q 0.31 format */ +/* */ +/* PARAMETERS: */ +/* pStream - ptr to Instance Parameter Structure LVMixer3_st for an*/ +/* Audio Stream */ +/* Tc_millisec - TimeConstant i.e time required in milli second to */ +/* go from linear fractional gain of 0 to 0.99999999 */ +/* Fs - LVM_Fs_en enumerator for Sampling Frequency */ +/* NumChannels - Number of channels in Audio Stream 1=Mono, 2=Stereo */ +/* */ +/* UPDATES: */ +/* Delta - the step change for fractional gain per 4 samples */ +/* in Q0.31 format for a given Time Constant, */ +/* Sample Rate and NumChannels */ +/* RETURNS: */ +/* void */ +/************************************************************************/ + +void LVC_Mixer_SetTimeConstant(LVMixer3_st *pStream, + LVM_INT32 Tc_millisec, + LVM_Fs_en Fs, + LVM_INT16 NumChannels) +{ + LVM_INT32 DeltaTable[9]={1073741824, + 779132389, + 715827882, + 536870912, + 389566194, + 357913941, + 268435456, + 194783097, + 178956971}; + Mix_Private_st *pInstance=(Mix_Private_st *)pStream->PrivateParams; + LVM_INT32 Delta=DeltaTable[Fs]; + Delta=Delta>>(NumChannels-1); + + if(Tc_millisec==0) + Delta=0x7FFFFFFF; + else + Delta=Delta/Tc_millisec; + + if(Delta==0) + Delta=1; // If Time Constant is so large that Delta is 0, assign minimum value to Delta + + pInstance->Delta=Delta; // Delta=(2147483647*4*1000)/(NumChannels*SampleRate*Tc_millisec) in Q 0.31 format +} diff --git a/media/libeffects/lvm/lib/Common/src/LVC_Mixer_VarSlope_SetTimeConstant.c b/media/libeffects/lvm/lib/Common/src/LVC_Mixer_VarSlope_SetTimeConstant.c new file mode 100755 index 0000000..420af9a --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVC_Mixer_VarSlope_SetTimeConstant.c @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "LVM_Types.h" +#include "LVM_Macros.h" +#include "LVC_Mixer_Private.h" + + +/************************************************************************/ +/* FUNCTION: */ +/* LVMixer3_VarSlope_SetTimeConstant */ +/* */ +/* DESCRIPTION: */ +/* This function calculates the step change for fractional gain for a */ +/* given time constant, sample rate and num channels */ +/* Delta=(2147483647*4*1000)/(NumChannels*SampleRate*Tc_millisec) */ +/* in Q 0.31 format */ +/* */ +/* PARAMETERS: */ +/* pStream - ptr to Instance Parameter Structure LVMixer3_st for an*/ +/* Audio Stream */ +/* Tc_millisec - TimeConstant i.e time required in milli second to */ +/* go from linear fractional gain of 0 to 0.99999999 */ +/* Fs - LVM_Fs_en enumerator for Sampling Frequency */ +/* NumChannels - Number of channels in Audio Stream 1=Mono, 2=Stereo */ +/* */ +/* UPDATES: */ +/* Delta - the step change for fractional gain per 4 samples */ +/* in Q0.31 format for a given Time Constant, */ +/* Sample Rate and NumChannels */ +/* RETURNS: */ +/* void */ +/************************************************************************/ + +void LVC_Mixer_VarSlope_SetTimeConstant( LVMixer3_st *pStream, + LVM_INT32 Tc_millisec, + LVM_Fs_en Fs, + LVM_INT16 NumChannels) +{ + LVM_INT32 DeltaTable[9]={1073741824, + 779132389, + 715827882, + 536870912, + 389566194, + 357913941, + 268435456, + 194783097, + 178956971}; + Mix_Private_st *pInstance=(Mix_Private_st *)pStream->PrivateParams; + LVM_INT32 Delta=DeltaTable[Fs]; + + LVM_INT32 Current; + LVM_INT32 Target; + + Delta=Delta>>(NumChannels-1); + + /* Get gain values */ + Current = LVC_Mixer_GetCurrent( pStream ); + Target = LVC_Mixer_GetTarget( pStream ); + + if (Current != Target) + { + Tc_millisec = Tc_millisec * 32767 / (Current - Target); + if (Tc_millisec<0) Tc_millisec = -Tc_millisec; + + if(Tc_millisec==0) + Delta=0x7FFFFFFF; + else + Delta=Delta/Tc_millisec; + + if(Delta==0) + Delta=1; // If Time Constant is so large that Delta is 0, assign minimum value to Delta + } + else + { + Delta =1; // Minimum value for proper call-backs (setting it to zero has some problems, to be corrected) + } + + + pInstance->Delta=Delta; // Delta=(2147483647*4*1000)/(NumChannels*SampleRate*Tc_millisec) in Q 0.31 format +} diff --git a/media/libeffects/lvm/lib/Common/src/LVM_FO_HPF.c b/media/libeffects/lvm/lib/Common/src/LVM_FO_HPF.c new file mode 100755 index 0000000..37c199e --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVM_FO_HPF.c @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: nxp27078 $*/ +/* $Revision: 762 $*/ +/* $Date: 2010-06-11 14:50:33 +0200 (vr, 11 jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "LVM_Types.h" +#include "LVM_Macros.h" +#include "ScalarArithmetic.h" +#include "BIQUAD.h" +#include "Filter.h" + + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* void LVM_FO_LPF( LVM_INT32 w , */ +/* FO_C32_Coefs_t *pCoeffs); */ +/* */ +/* */ +/* DESCRIPTION: */ +/* This function calculates the coefficient of first order low pass */ +/* filter. It uses the equations: */ +/* */ +/* B1 = (tan(w/2) - 1 ) / (tan(w/2) + 1 ) */ +/* A0 = (1 - B1) / 2 */ +/* A1 = A0 */ +/* */ +/* The value of B1 is then calculated directly from the value w by a */ +/* polynomial expansion using a 9th order polynomial. It uses the */ +/* following table of 32-bit integer polynomial coefficients: */ +/* */ +/* Coefficient Value */ +/* A0 -8388571 */ +/* A1 33547744 */ +/* A2 -66816791 */ +/* A3 173375308 */ +/* A4 -388437573 */ +/* A5 752975383 */ +/* A6 -1103016663 */ +/* A7 1121848567 */ +/* A8 -688078159 */ +/* A9 194669577 */ +/* A10 8 */ +/* */ +/* Y = (A0 + A1*X + A2*X2 + A3*X3 + ….. + AN*xN) << AN+1 */ +/* */ +/* */ +/* PARAMETERS: */ +/* */ +/* w Sample rate in radians, where: */ +/* w = 2 * Pi * Fc / Fs */ +/* Fc is the corner frequency in Hz */ +/* Fs is the sample rate in Hz */ +/* w is in Q2.29 format and data range is [0 Pi] */ +/* pCoeffs Points to the filter coefficients calculated here */ +/* in Q1.30 format */ +/* RETURNS: */ +/* */ +/*-------------------------------------------------------------------------*/ + +LVM_INT32 LVM_FO_HPF( LVM_INT32 w, + FO_C32_Coefs_t *pCoeffs) +{ + LVM_INT32 Y,Coefficients[13]={ -8388571, + 33547744, + -66816791, + 173375308, + -388437573, + 752975383, + -1103016663, + 1121848567, + -688078159, + 194669577, + 8, + 0, + 0}; + Y=LVM_Polynomial( (LVM_UINT16)9, + Coefficients, + w); + pCoeffs->B1=-Y; /* Store -B1 in filter structure instead of B1!*/ + /* A0=(1-B1)/2= B1/2 - 0.5*/ + Y=Y>>1; /* A0=Y=B1/2*/ + Y=Y-0x40000000; /* A0=Y=(B1/2 - 0.5)*/ + MUL32x16INTO32(Y, FILTER_LOSS ,pCoeffs->A0 ,15) /* Apply loss to avoid overflow*/ + pCoeffs->A1=-pCoeffs->A0; /* Store A1=-A0*/ + + return 1; +} + diff --git a/media/libeffects/lvm/lib/Common/src/LVM_FO_LPF.c b/media/libeffects/lvm/lib/Common/src/LVM_FO_LPF.c new file mode 100755 index 0000000..6c73d59 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVM_FO_LPF.c @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: nxp27078 $*/ +/* $Revision: 762 $*/ +/* $Date: 2010-06-11 14:50:33 +0200 (vr, 11 jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "LVM_Types.h" +#include "LVM_Macros.h" +#include "ScalarArithmetic.h" +#include "BIQUAD.h" +#include "Filter.h" + + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* void LVM_FO_LPF( LVM_INT32 w , */ +/* FO_C32_Coefs_t *pCoeffs); */ +/* */ +/* */ +/* DESCRIPTION: */ +/* This function calculates the coefficient of first order low pass */ +/* filter. It uses the equations: */ +/* */ +/* B1 = (tan(w/2) - 1 ) / (tan(w/2) + 1 ) */ +/* A0 = (1 + B1) / 2 */ +/* A1 = A0 */ +/* */ +/* The value of B1 is then calculated directly from the value w by a */ +/* polynomial expansion using a 9th order polynomial. It uses the */ +/* following table of 32-bit integer polynomial coefficients: */ +/* */ +/* Coefficient Value */ +/* A0 -8388571 */ +/* A1 33547744 */ +/* A2 -66816791 */ +/* A3 173375308 */ +/* A4 -388437573 */ +/* A5 752975383 */ +/* A6 -1103016663 */ +/* A7 1121848567 */ +/* A8 -688078159 */ +/* A9 194669577 */ +/* A10 8 */ +/* */ +/* Y = (A0 + A1*X + A2*X2 + A3*X3 + ….. + AN*xN) << AN+1 */ +/* */ +/* */ +/* PARAMETERS: */ +/* */ +/* w Sample rate in radians, where: */ +/* w = 2 * Pi * Fc / Fs */ +/* Fc is the corner frequency in Hz */ +/* Fs is the sample rate in Hz */ +/* w is in Q2.29 format and data range is [0 Pi] */ +/* pCoeffs Points to the filter coefficients calculated here */ +/* in Q1.30 format */ +/* RETURNS: */ +/* */ +/*-------------------------------------------------------------------------*/ + +LVM_INT32 LVM_FO_LPF( LVM_INT32 w, + FO_C32_Coefs_t *pCoeffs) +{ + LVM_INT32 Y,Coefficients[13]={ -8388571, + 33547744, + -66816791, + 173375308, + -388437573, + 752975383, + -1103016663, + 1121848567, + -688078159, + 194669577, + 8}; + Y=LVM_Polynomial( (LVM_UINT16)9, + Coefficients, + w); + pCoeffs->B1=-Y; // Store -B1 in filter structure instead of B1! + // A0=(1+B1)/2= B1/2 + 0.5 + Y=Y>>1; // A0=Y=B1/2 + Y=Y+0x40000000; // A0=Y=(B1/2 + 0.5) + MUL32x16INTO32(Y, FILTER_LOSS ,pCoeffs->A0 ,15) // Apply loss to avoid overflow + pCoeffs->A1=pCoeffs->A0; + return 1; +} + diff --git a/media/libeffects/lvm/lib/Common/src/LVM_GetOmega.c b/media/libeffects/lvm/lib/Common/src/LVM_GetOmega.c new file mode 100755 index 0000000..1cc10db --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVM_GetOmega.c @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: nxp27078 $*/ +/* $Revision: 762 $*/ +/* $Date: 2010-06-11 14:50:33 +0200 (vr, 11 jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "LVM_Types.h" +#include "Filter.h" +#include "LVM_Macros.h" + +/************************************************************************************/ +/* */ +/* Defines and Tables for 2*Pi/Fs */ +/* */ +/************************************************************************************/ + +#define LVVDL_2PiBy_8000 1727108826 /* In Q41 format */ +#define LVVDL_2PiBy_11025 1253230894 /* In Q41 format */ +#define LVVDL_2PiBy_12000 1151405884 /* In Q41 format */ + +#define LVVDL_2PiByFs_SHIFT1 12 /* Qformat shift for 8kHz, 11.025kHz and 12kHz i.e. 12=41-29 */ +#define LVVDL_2PiByFs_SHIFT2 13 /* Qformat shift for 16kHz, 22.050kHz and 24kHz i.e. 13=42-29 */ +#define LVVDL_2PiByFs_SHIFT3 14 /* Qformat shift for 32kHz, 44.1kHz and 48kHz i.e. 14=43-29 */ + +const LVM_INT32 LVVDL_2PiOnFsTable[] = {LVVDL_2PiBy_8000 , /* 8kHz in Q41, 16kHz in Q42, 32kHz in Q43 */ + LVVDL_2PiBy_11025, /* 11025 Hz in Q41, 22050Hz in Q42, 44100 Hz in Q43*/ + LVVDL_2PiBy_12000}; /* 12kHz in Q41, 24kHz in Q42, 48kHz in Q43 */ + + +const LVM_INT32 LVVDL_2PiOnFsShiftTable[]={LVVDL_2PiByFs_SHIFT1 , /* 8kHz, 11025Hz, 12kHz */ + LVVDL_2PiByFs_SHIFT2, /* 16kHz, 22050Hz, 24kHz*/ + LVVDL_2PiByFs_SHIFT3}; /* 32kHz, 44100Hz, 48kHz */ + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* LVM_GetOmega */ +/* */ +/* LVM_INT32 LVM_GetOmega(LVM_UINT16 Fc, */ +/* LVM_Fs_en Fs) */ +/* */ +/* DESCRIPTION: */ +/* This function calculates the value of w using Fc and Fs */ +/* */ +/* PARAMETERS: */ +/* */ +/* LVM_UINT16 Fc The corner frequency in Hz Q16.0 format */ +/* LVM_Fs_en Fs The SampleRate */ +/* RETURNS: */ +/* w=2*pi*Fc/Fs in Q2.29 format */ +/*-------------------------------------------------------------------------*/ + +LVM_INT32 LVM_GetOmega(LVM_UINT16 Fc, + LVM_Fs_en Fs) +{ + LVM_INT32 w; + MUL32x32INTO32((LVM_INT32)Fc,LVVDL_2PiOnFsTable[Fs%3],w,LVVDL_2PiOnFsShiftTable[Fs/3]) + return w; +} + diff --git a/media/libeffects/lvm/lib/Common/src/LVM_Mixer_FilterCoeffs.h b/media/libeffects/lvm/lib/Common/src/LVM_Mixer_FilterCoeffs.h new file mode 100755 index 0000000..00235e0 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVM_Mixer_FilterCoeffs.h @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/************************************************************************************/ +/* */ +/* Mixer library tables */ +/* */ +/* Coefficients and table values for the mixer library, generated by the Matlab */ +/* Script: Mixer_GenerateCoeffs.m */ +/* */ +/************************************************************************************/ + +#ifndef __LVM_MIXER_FILTER_COEFFS_H__ +#define __LVM_MIXER_FILTER_COEFFS_H__ + + +/************************************************************************************/ +/* */ +/* Alpha Time Constant table */ +/* */ +/************************************************************************************/ + +#define Alpha_TableSize 50 /* The number of table entires */ +#define ALPHA_0 2147480769 /* Floating point Alpha = 0.999999 */ +#define ALPHA_1 2147479577 /* Floating point Alpha = 0.999998 */ +#define ALPHA_2 2147477892 /* Floating point Alpha = 0.999997 */ +#define ALPHA_3 2147475510 /* Floating point Alpha = 0.999996 */ +#define ALPHA_4 2147472141 /* Floating point Alpha = 0.999995 */ +#define ALPHA_5 2147467377 /* Floating point Alpha = 0.999992 */ +#define ALPHA_6 2147460642 /* Floating point Alpha = 0.999989 */ +#define ALPHA_7 2147451118 /* Floating point Alpha = 0.999985 */ +#define ALPHA_8 2147437651 /* Floating point Alpha = 0.999979 */ +#define ALPHA_9 2147418608 /* Floating point Alpha = 0.999970 */ +#define ALPHA_10 2147391683 /* Floating point Alpha = 0.999957 */ +#define ALPHA_11 2147353611 /* Floating point Alpha = 0.999939 */ +#define ALPHA_12 2147299779 /* Floating point Alpha = 0.999914 */ +#define ALPHA_13 2147223662 /* Floating point Alpha = 0.999879 */ +#define ALPHA_14 2147116037 /* Floating point Alpha = 0.999829 */ +#define ALPHA_15 2146963865 /* Floating point Alpha = 0.999758 */ +#define ALPHA_16 2146748712 /* Floating point Alpha = 0.999658 */ +#define ALPHA_17 2146444522 /* Floating point Alpha = 0.999516 */ +#define ALPHA_18 2146014472 /* Floating point Alpha = 0.999316 */ +#define ALPHA_19 2145406527 /* Floating point Alpha = 0.999033 */ +#define ALPHA_20 2144547188 /* Floating point Alpha = 0.998633 */ +#define ALPHA_21 2143332669 /* Floating point Alpha = 0.998067 */ +#define ALPHA_22 2141616514 /* Floating point Alpha = 0.997268 */ +#define ALPHA_23 2139192215 /* Floating point Alpha = 0.996139 */ +#define ALPHA_24 2135768939 /* Floating point Alpha = 0.994545 */ +#define ALPHA_25 2130937774 /* Floating point Alpha = 0.992295 */ +#define ALPHA_26 2124125153 /* Floating point Alpha = 0.989123 */ +#define ALPHA_27 2114529263 /* Floating point Alpha = 0.984654 */ +#define ALPHA_28 2101034612 /* Floating point Alpha = 0.978370 */ +#define ALPHA_29 2082100030 /* Floating point Alpha = 0.969553 */ +#define ALPHA_30 2055617398 /* Floating point Alpha = 0.957221 */ +#define ALPHA_31 2018744824 /* Floating point Alpha = 0.940051 */ +#define ALPHA_32 1967733015 /* Floating point Alpha = 0.916297 */ +#define ALPHA_33 1897794587 /* Floating point Alpha = 0.883729 */ +#define ALPHA_34 1803123234 /* Floating point Alpha = 0.839645 */ +#define ALPHA_35 1677262220 /* Floating point Alpha = 0.781036 */ +#define ALPHA_36 1514142675 /* Floating point Alpha = 0.705078 */ +#define ALPHA_37 1310197875 /* Floating point Alpha = 0.610108 */ +#define ALPHA_38 1067813480 /* Floating point Alpha = 0.497239 */ +#define ALPHA_39 799601371 /* Floating point Alpha = 0.372343 */ +#define ALPHA_40 531183049 /* Floating point Alpha = 0.247351 */ +#define ALPHA_41 297904007 /* Floating point Alpha = 0.138722 */ +#define ALPHA_42 131499768 /* Floating point Alpha = 0.061234 */ +#define ALPHA_43 41375282 /* Floating point Alpha = 0.019267 */ +#define ALPHA_44 8065899 /* Floating point Alpha = 0.003756 */ +#define ALPHA_45 799076 /* Floating point Alpha = 0.000372 */ +#define ALPHA_46 30398 /* Floating point Alpha = 0.000014 */ +#define ALPHA_47 299 /* Floating point Alpha = 0.000000 */ +#define ALPHA_48 0 /* Floating point Alpha = 0.000000 */ +#define ALPHA_49 0 /* Floating point Alpha = 0.000000 */ +#define ALPHA_50 0 /* Floating point Alpha = 0.000000 */ + + +#endif diff --git a/media/libeffects/lvm/lib/Common/src/LVM_Mixer_TimeConstant.c b/media/libeffects/lvm/lib/Common/src/LVM_Mixer_TimeConstant.c new file mode 100755 index 0000000..db6975a --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVM_Mixer_TimeConstant.c @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "LVM_Types.h" +#include "LVM_Macros.h" +#include "Mixer.h" +#include "LVM_Mixer_FilterCoeffs.h" + + +/************************************************************************/ +/* FUNCTION: */ +/* LVM_Mix_GetTimeConstant */ +/* */ +/* DESCRIPTION: */ +/* This function calculates the filter coefficient using the following */ +/* equation: */ +/* Alpha = exp(ln(0.1)/ (tc * Update + 1.0)) */ +/* */ +/* This is to be used with the follow first order filter, called at a */ +/* rate of Update times a second. tc is the required time constant in */ +/* units of 100us. */ +/* */ +/* Output(n) = Alpha * Output(n-1) + (1 - Alpha) * Target(n) */ +/* */ +/* The function assumes the block size is large, i.e. the update rate */ +/* is approximately a fixed, and correct factor of the value of Fs */ +/* given in the call. This is especially not true when the block size */ +/* is very small, see the mixer documentation for further details. */ +/* */ +/* The function does not support all possible combinations of input */ +/* values: */ +/* */ +/* 1. NumChannels is limited to the values 1 (Mono) and 2 (Stereo) */ +/* 2. The product tc * Fs is limited approximately to the range */ +/* 8 < (tc * Fs) < 2^35 */ +/* */ +/* PARAMETERS: */ +/* tc - the time constant in 100us steps, i.e. 10 = 1ms */ +/* Fs - the filter update rate in Hz */ +/* NumChannels - Number of channels 1=Mono, 2=Stereo */ +/* */ +/* RETURNS: */ +/* Alpha - the filter coefficient Q31 format */ +/* */ +/************************************************************************/ + +LVM_UINT32 LVM_Mixer_TimeConstant(LVM_UINT32 tc, + LVM_UINT16 Fs, + LVM_UINT16 NumChannels) +{ + + LVM_UINT32 Product; + LVM_INT16 Interpolate; + LVM_UINT16 Shift; + LVM_INT32 Diff; + LVM_UINT32 Table[] = {ALPHA_0, /* Log spaced look-up table */ + ALPHA_1, + ALPHA_2, + ALPHA_3, + ALPHA_4, + ALPHA_5, + ALPHA_6, + ALPHA_7, + ALPHA_8, + ALPHA_9, + ALPHA_10, + ALPHA_11, + ALPHA_12, + ALPHA_13, + ALPHA_14, + ALPHA_15, + ALPHA_16, + ALPHA_17, + ALPHA_18, + ALPHA_19, + ALPHA_20, + ALPHA_21, + ALPHA_22, + ALPHA_23, + ALPHA_24, + ALPHA_25, + ALPHA_26, + ALPHA_27, + ALPHA_28, + ALPHA_29, + ALPHA_30, + ALPHA_31, + ALPHA_32, + ALPHA_33, + ALPHA_34, + ALPHA_35, + ALPHA_36, + ALPHA_37, + ALPHA_38, + ALPHA_39, + ALPHA_40, + ALPHA_41, + ALPHA_42, + ALPHA_43, + ALPHA_44, + ALPHA_45, + ALPHA_46, + ALPHA_47, + ALPHA_48, + ALPHA_49, + ALPHA_50}; + + + /* Calculate the product of the time constant and the sample rate */ + Product = ((tc >> 16) * (LVM_UINT32)Fs) << 13; /* Stereo value */ + Product = Product + (((tc & 0x0000FFFF) * (LVM_UINT32)Fs) >> 3); + + if (NumChannels == 1) + { + Product = Product >> 1; /* Mono value */ + } + + /* Normalize to get the table index and interpolation factor */ + for (Shift=0; Shift<((Alpha_TableSize-1)/2); Shift++) + { + if ((Product & 0x80000000)!=0) + { + break; + } + + Product = Product << 1; + } + Shift = (LVM_UINT16)((Shift << 1)); + + if ((Product & 0x40000000)==0) + { + Shift++; + } + + Interpolate = (LVM_INT16)((Product >> 15) & 0x00007FFF); + + Diff = (LVM_INT32)(Table[Shift] - Table[Shift+1]); + MUL32x16INTO32(Diff,Interpolate,Diff,15) + Product = Table[Shift+1] + (LVM_UINT32)Diff; + + return Product; +} diff --git a/media/libeffects/lvm/lib/Common/src/LVM_Polynomial.c b/media/libeffects/lvm/lib/Common/src/LVM_Polynomial.c new file mode 100755 index 0000000..b8cf4b4 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVM_Polynomial.c @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "LVM_Types.h" +#include "LVM_Macros.h" +#include "ScalarArithmetic.h" + +/*-------------------------------------------------------------------------*/ +/* FUNCTION: */ +/* LVM_Polynomial */ +/* */ +/* DESCRIPTION: */ +/* This function performs polynomial expansion */ +/* Y = (A0 + A1*X + A2*X2 + A3*X3 + ….. + AN*xN) << AN+1 */ +/* */ +/* LVM_INT32 LVM_Polynomial(LVM_UINT16 N, */ +/* LVM_INT32 *pCoefficients, */ +/* LVM_INT32 X) */ +/* */ +/* PARAMETERS: */ +/* */ +/* N is the polynomial order */ +/* pCoefficients is the ptr to polynomial coefficients A0,A1.. in Q.31 */ +/* X is the input variable */ +/* */ +/* RETURNS: */ +/* The result of the polynomial expansion in Q1.31 format */ +/*-------------------------------------------------------------------------*/ + +LVM_INT32 LVM_Polynomial(LVM_UINT16 N, + LVM_INT32 *pCoefficients, + LVM_INT32 X) +{ + LVM_INT32 i; + LVM_INT32 Y,A,XTemp,Temp,sign; + + Y=*pCoefficients; /* Y=A0*/ + pCoefficients++; + + if((LVM_UINT32)X==0x80000000) + { + Temp=-1; + sign=Temp; + for(i=1;i<=N;i++) + { + Y+=((*pCoefficients)*sign); + pCoefficients++; + sign*=Temp; + } + + + } + else + { + XTemp=X; + for(i=N-1;i>=0;i--) + { + A=*pCoefficients; + pCoefficients++; + + MUL32x32INTO32(A,XTemp,Temp,31) + Y+=Temp; + + MUL32x32INTO32(XTemp,X,Temp,31) + XTemp=Temp; + } + } + A=*pCoefficients; + pCoefficients++; + + if(A<0) + { + A=Abs_32(A); + Y=Y>>A; + } + else + { + Y = Y<TimerArmed){ + pInstancePr->RemainingTimeInSamples -= BlockSize; + if (pInstancePr->RemainingTimeInSamples <= 0){ + pInstancePr->TimerArmed = 0; + (*pInstancePr->pCallBack) ( pInstancePr->pCallbackInstance, + pInstancePr->pCallBackParams, + pInstancePr->CallBackParam ); + } + } +} + +/****************************************************************************************/ +/* END OF FILE */ +/****************************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/LVM_Timer_Init.c b/media/libeffects/lvm/lib/Common/src/LVM_Timer_Init.c new file mode 100755 index 0000000..e473038 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVM_Timer_Init.c @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: My Project */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/****************************************************************************************/ +/* INCLUDE FILES */ +/****************************************************************************************/ + +#include "LVM_Timer.h" +#include "LVM_Timer_Private.h" +#include "LVM_Macros.h" + +/****************************************************************************************/ +/* DEFINITIONS */ +/****************************************************************************************/ + +#define OneOverThousandInQ24 16777 + +/****************************************************************************************/ +/* INIT FUNCTION */ +/****************************************************************************************/ + +void LVM_Timer_Init ( LVM_Timer_Instance_t *pInstance, + LVM_Timer_Params_t *pParams ){ + + LVM_Timer_Instance_Private_t *pInstancePr; + pInstancePr = (LVM_Timer_Instance_Private_t *)pInstance; + + pInstancePr->CallBackParam = pParams->CallBackParam; + pInstancePr->pCallBackParams = pParams->pCallBackParams; + pInstancePr->pCallbackInstance = pParams->pCallbackInstance; + pInstancePr->pCallBack = pParams->pCallBack; + pInstancePr->TimerArmed = 1; + + MUL32x16INTO32(pParams->SamplingRate,OneOverThousandInQ24,pInstancePr->RemainingTimeInSamples,16); /* (Q0 * Q24) >>16 into Q8*/ + MUL32x16INTO32(pInstancePr->RemainingTimeInSamples,pParams->TimeInMs,pInstancePr->RemainingTimeInSamples,8); /* (Q8 * Q0) >>8 into Q0*/ +} + +/****************************************************************************************/ +/* END OF FILE */ +/****************************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/LVM_Timer_Private.h b/media/libeffects/lvm/lib/Common/src/LVM_Timer_Private.h new file mode 100755 index 0000000..04d5af6 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LVM_Timer_Private.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: My Project */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#ifndef LVM_TIMER_PRIVATE_H +#define LVM_TIMER_PRIVATE_H + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#include "LVM_Types.h" + +/****************************************************************************************/ +/* TYPE DEFINITIONS */ +/****************************************************************************************/ + +typedef struct +{ + LVM_INT32 RemainingTimeInSamples; + LVM_INT32 CallBackParam; + LVM_INT32 *pCallBackParams; + void *pCallbackInstance; + void (*pCallBack)(void*,void*,LVM_INT32); + LVM_INT16 TimerArmed; /* Boolean, true between init and callback */ + +} LVM_Timer_Instance_Private_t; + +/****************************************************************************************/ +/* END OF HEADER */ +/****************************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LVM_TIMER_PRIVATE_H */ diff --git a/media/libeffects/lvm/lib/Common/src/LoadConst_16.c b/media/libeffects/lvm/lib/Common/src/LoadConst_16.c new file mode 100755 index 0000000..bc2735f --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LoadConst_16.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION LoadConst_16 +***********************************************************************************/ + +void LoadConst_16(const LVM_INT16 val, + LVM_INT16 *dst, + LVM_INT16 n ) +{ + LVM_INT16 ii; + + for (ii = n; ii != 0; ii--) + { + *dst = val; + dst++; + } + + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/LoadConst_32.c b/media/libeffects/lvm/lib/Common/src/LoadConst_32.c new file mode 100755 index 0000000..19d5d4e --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/LoadConst_32.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION LoadConst_32 +***********************************************************************************/ + +void LoadConst_32(const LVM_INT32 val, + LVM_INT32 *dst, + LVM_INT16 n ) +{ + LVM_INT16 ii; + + for (ii = n; ii != 0; ii--) + { + *dst = val; + dst++; + } + + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/MSTo2i_Sat_16x16.c b/media/libeffects/lvm/lib/Common/src/MSTo2i_Sat_16x16.c new file mode 100755 index 0000000..1949f3c --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/MSTo2i_Sat_16x16.c @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION MSTO2I_SAT_16X16 +***********************************************************************************/ + +void MSTo2i_Sat_16x16(const LVM_INT16 *srcM, + const LVM_INT16 *srcS, + LVM_INT16 *dst, + LVM_INT16 n ) +{ + LVM_INT32 temp,mVal,sVal; + LVM_INT16 ii; + + + for (ii = n; ii != 0; ii--) + { + mVal=(LVM_INT32)*srcM; + srcM++; + + sVal=(LVM_INT32)*srcS; + srcS++; + + temp = mVal + sVal; + + if (temp > 0x00007FFF) + { + *dst = 0x7FFF; + } + else if (temp < -0x00008000) + { + *dst = - 0x8000; + } + else + { + *dst = (LVM_INT16)temp; + } + dst++; + + temp = mVal - sVal; + + if (temp > 0x00007FFF) + { + *dst = 0x7FFF; + } + else if (temp < -0x00008000) + { + *dst = - 0x8000; + } + else + { + *dst = (LVM_INT16)temp; + } + dst++; + } + + return; +} +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/Mac3s_Sat_16x16.c b/media/libeffects/lvm/lib/Common/src/Mac3s_Sat_16x16.c new file mode 100755 index 0000000..ef04ae8 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Mac3s_Sat_16x16.c @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + %created_by: sra % (CM/S) + %name: Mac3s_Sat_16x16.c % (CM/S) + %version: 1 % (CM/S) + %date_created: Fri Nov 13 12:07:13 2009 % (CM/S) + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" +#include "LVM_Macros.h" + +/********************************************************************************** + FUNCTION Mac3S_16X16 +***********************************************************************************/ + +void Mac3s_Sat_16x16( const LVM_INT16 *src, + const LVM_INT16 val, + LVM_INT16 *dst, + LVM_INT16 n) +{ + LVM_INT16 ii; + LVM_INT16 srcval; + LVM_INT32 Temp,dInVal; + + + for (ii = n; ii != 0; ii--) + { + srcval=*src; + src++; + + Temp = (srcval *val)>>15; + + dInVal = (LVM_INT32)*dst; + + Temp = Temp + dInVal; + + if (Temp > 0x00007FFF) + { + *dst = 0x7FFF; + } + else if (Temp < -0x00008000) + { + *dst = - 0x8000; + } + else + { + *dst = (LVM_INT16)Temp; + } + + dst++; + } + + return; +} + +/**********************************************************************************/ + + + diff --git a/media/libeffects/lvm/lib/Common/src/Mac3s_Sat_32x16.c b/media/libeffects/lvm/lib/Common/src/Mac3s_Sat_32x16.c new file mode 100755 index 0000000..746a273 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Mac3s_Sat_32x16.c @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" +#include "LVM_Macros.h" + +/********************************************************************************** + FUNCTION MAC3S_16X16 +***********************************************************************************/ + +void Mac3s_Sat_32x16( const LVM_INT32 *src, + const LVM_INT16 val, + LVM_INT32 *dst, + LVM_INT16 n) +{ + LVM_INT16 ii; + LVM_INT32 srcval,temp, dInVal, dOutVal; + + + for (ii = n; ii != 0; ii--) + { + srcval=*src; + src++; + + MUL32x16INTO32(srcval,val,temp,15) + + dInVal = *dst; + dOutVal = temp + dInVal; + + + if ((((dOutVal ^ temp) & (dOutVal ^ dInVal)) >> 31)!=0) /* overflow / underflow */ + { + if(temp<0) + { + dOutVal=0x80000000l; + } + else + { + dOutVal=0x7FFFFFFFl; + } + } + + *dst = dOutVal; + dst++; + } + + return; +} + +/**********************************************************************************/ + + + diff --git a/media/libeffects/lvm/lib/Common/src/MixInSoft_D32C31_SAT.c b/media/libeffects/lvm/lib/Common/src/MixInSoft_D32C31_SAT.c new file mode 100755 index 0000000..36de6c1 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/MixInSoft_D32C31_SAT.c @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "Mixer_private.h" +#include "VectorArithmetic.h" + +/********************************************************************************** + DEFINITIONS +***********************************************************************************/ + +#define TRUE 1 +#define FALSE 0 + +/********************************************************************************** + FUNCTION MIXINSOFT_D32C31_SAT +***********************************************************************************/ + +void MixInSoft_D32C31_SAT( Mix_1St_Cll_t *pInstance, + const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n) +{ + char HardMixing = TRUE; + + if(n<=0) return; + + /****************************************************************************** + SOFT MIXING + *******************************************************************************/ + if (pInstance->Current != pInstance->Target) + { + if(pInstance->Alpha == 0){ + pInstance->Current = pInstance->Target; + }else if ((pInstance->Current-pInstance->Target Current-pInstance->Target > -POINT_ZERO_ONE_DB)){ + pInstance->Current = pInstance->Target; /* Difference is not significant anymore. Make them equal. */ + }else{ + /* Soft mixing has to be applied */ + HardMixing = FALSE; + Core_MixInSoft_D32C31_SAT( pInstance, src, dst, n); + } + } + + /****************************************************************************** + HARD MIXING + *******************************************************************************/ + + if (HardMixing){ + if (pInstance->Target != 0){ /* Nothing to do in case Target = 0 */ + if ((pInstance->Target>>16) == 0x7FFF) + Add2_Sat_32x32( src, dst, n ); + else{ + Core_MixInSoft_D32C31_SAT( pInstance, src, dst, n); + pInstance->Current = pInstance->Target; /* In case the core function would have changed the Current value */ + } + } + } + + /****************************************************************************** + CALL BACK + *******************************************************************************/ + /* Call back before the hard mixing, because in this case, hard mixing makes + use of the core soft mix function which can change the Current value! */ + + if (pInstance->CallbackSet){ + if ((pInstance->Current-pInstance->Target Current-pInstance->Target > -POINT_ZERO_ONE_DB)){ + pInstance->Current = pInstance->Target; /* Difference is not significant anymore. Make them equal. */ + pInstance->CallbackSet = FALSE; + if (pInstance->pCallBack != 0){ + (*pInstance->pCallBack) ( pInstance->pCallbackHandle, pInstance->pGeneralPurpose,pInstance->CallbackParam ); + } + } + } +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/MixSoft_1St_D32C31_WRA.c b/media/libeffects/lvm/lib/Common/src/MixSoft_1St_D32C31_WRA.c new file mode 100755 index 0000000..5cf1a29 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/MixSoft_1St_D32C31_WRA.c @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "Mixer_private.h" +#include "VectorArithmetic.h" + +/********************************************************************************** + DEFINITIONS +***********************************************************************************/ + +#define TRUE 1 +#define FALSE 0 + + + +/********************************************************************************** + FUNCTION MIXSOFT_1ST_D32C31_WRA +***********************************************************************************/ + +void MixSoft_1St_D32C31_WRA( Mix_1St_Cll_t *pInstance, + const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n) +{ + char HardMixing = TRUE; + + if(n<=0) return; + + /****************************************************************************** + SOFT MIXING + *******************************************************************************/ + if (pInstance->Current != pInstance->Target) + { + if(pInstance->Alpha == 0){ + pInstance->Current = pInstance->Target; + }else if ((pInstance->Current-pInstance->Target Current-pInstance->Target > -POINT_ZERO_ONE_DB)){ + pInstance->Current = pInstance->Target; /* Difference is not significant anymore. Make them equal. */ + }else{ + /* Soft mixing has to be applied */ + HardMixing = FALSE; + Core_MixSoft_1St_D32C31_WRA( pInstance, src, dst, n); + } + } + + /****************************************************************************** + HARD MIXING + *******************************************************************************/ + + if (HardMixing){ + if (pInstance->Target == 0) + LoadConst_32(0, dst, n); + else if ((pInstance->Target>>16) == 0x7FFF){ + if (src != dst) + Copy_16((LVM_INT16*)src, (LVM_INT16*)dst, (LVM_INT16)(n * 2)); + } + else + Mult3s_32x16( src, (LVM_INT16)(pInstance->Current>>16), dst, n ); + } + + /****************************************************************************** + CALL BACK + *******************************************************************************/ + + if (pInstance->CallbackSet){ + if ((pInstance->Current-pInstance->Target Current-pInstance->Target > -POINT_ZERO_ONE_DB)){ + pInstance->Current = pInstance->Target; /* Difference is not significant anymore. Make them equal. */ + pInstance->CallbackSet = FALSE; + if (pInstance->pCallBack != 0){ + (*pInstance->pCallBack) ( pInstance->pCallbackHandle, pInstance->pGeneralPurpose,pInstance->CallbackParam ); + } + } + } +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/MixSoft_2St_D32C31_SAT.c b/media/libeffects/lvm/lib/Common/src/MixSoft_2St_D32C31_SAT.c new file mode 100755 index 0000000..b03f0ba --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/MixSoft_2St_D32C31_SAT.c @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "Mixer_private.h" +#include "VectorArithmetic.h" + + +/********************************************************************************** + FUNCTION MIXSOFT_2ST_D32C31_SAT +***********************************************************************************/ + +void MixSoft_2St_D32C31_SAT( Mix_2St_Cll_t *pInstance, + const LVM_INT32 *src1, + const LVM_INT32 *src2, + LVM_INT32 *dst, + LVM_INT16 n) +{ + + if(n<=0) return; + + /****************************************************************************** + SOFT MIXING + *******************************************************************************/ + if ((pInstance->Current1 != pInstance->Target1) || (pInstance->Current2 != pInstance->Target2)) + { + MixSoft_1St_D32C31_WRA( (Mix_1St_Cll_t*) pInstance, src1, dst, n); + MixInSoft_D32C31_SAT( (Mix_1St_Cll_t*) &pInstance->Alpha2, src2, dst, n); + } + + /****************************************************************************** + HARD MIXING + *******************************************************************************/ + + else + { + if (pInstance->Current1 == 0) + MixSoft_1St_D32C31_WRA( (Mix_1St_Cll_t*) &pInstance->Alpha2, src2, dst, n); + else if (pInstance->Current2 == 0) + MixSoft_1St_D32C31_WRA( (Mix_1St_Cll_t*) pInstance, src1, dst, n); + else + Core_MixHard_2St_D32C31_SAT( pInstance, src1, src2, dst, n); + } +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/Mixer_private.h b/media/libeffects/lvm/lib/Common/src/Mixer_private.h new file mode 100755 index 0000000..d012548 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Mixer_private.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +#ifndef __MIXER_PRIVATE_H__ +#define __MIXER_PRIVATE_H__ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "Mixer.h" + +#define POINT_ZERO_ONE_DB 2473805 /* 0.01 dB on a full scale signal = (10^(0.01/20) -1) * 2^31 */ + +/********************************************************************************** + DEFINITIONS +***********************************************************************************/ + +/**********************************************************************************/ + +#endif //#ifndef __MIXER_PRIVATE_H__ + diff --git a/media/libeffects/lvm/lib/Common/src/MonoTo2I_16.c b/media/libeffects/lvm/lib/Common/src/MonoTo2I_16.c new file mode 100755 index 0000000..b053e55 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/MonoTo2I_16.c @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION MonoTo2I_16 +***********************************************************************************/ + +void MonoTo2I_16( const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n) +{ + LVM_INT16 ii; + src += (n-1); + dst += ((n*2)-1); + + for (ii = n; ii != 0; ii--) + { + *dst = *src; + dst--; + + *dst = *src; + dst--; + src--; + } + + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/MonoTo2I_32.c b/media/libeffects/lvm/lib/Common/src/MonoTo2I_32.c new file mode 100755 index 0000000..e8164bb --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/MonoTo2I_32.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION MonoTo2I_32 +***********************************************************************************/ + +void MonoTo2I_32( const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n) +{ + LVM_INT16 ii; + src += (n-1); + dst += ((n*2)-1); + + for (ii = n; ii != 0; ii--) + { + *dst = *src; + dst--; + + *dst = *src; + dst--; + src--; + } + + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/Mult3s_32x16.c b/media/libeffects/lvm/lib/Common/src/Mult3s_32x16.c new file mode 100755 index 0000000..ee83524 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Mult3s_32x16.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" +#include "LVM_Macros.h" + +/********************************************************************************** +FUNCTION MULT3S_16X16 +***********************************************************************************/ + +void Mult3s_32x16( const LVM_INT32 *src, + const LVM_INT16 val, + LVM_INT32 *dst, + LVM_INT16 n) +{ + LVM_INT16 ii; + LVM_INT32 srcval,temp; + + for (ii = n; ii != 0; ii--) + { + srcval=*src; + src++; + + MUL32x16INTO32(srcval,val,temp,15) + + *dst = temp; + dst++; + } + + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/NonLinComp_D16.c b/media/libeffects/lvm/lib/Common/src/NonLinComp_D16.c new file mode 100755 index 0000000..1428777 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/NonLinComp_D16.c @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "CompLim_private.h" + +/****************************************************************************************/ +/* */ +/* FUNCTION: NonLinComp_D16 */ +/* */ +/* DESCRIPTION: */ +/* Non-linear compression by companding. The function works on a sample by sample */ +/* basis by increasing the level near the zero crossing. This gives a ttrade-off */ +/* between THD and compression. It uses the equation: */ +/* */ +/* Output = Input + K * (Input - Input^2) if Input > 0 */ +/* = Input + K * (Input + Input^2) if Input <= 0 */ +/* */ +/* The value of K controls the amount of compression and as a side effect the amount */ +/* distortion introduced. The amount of compression is signal dependent and the values */ +/* given below are approximate. */ +/* */ +/* Gain (fractional) Gain (integer) Compression Pk-Pk THD */ +/* 1.0 32767 +6dB 16dB */ +/* 0.78 25559 +5dB 19dB */ +/* 0.6 19661 +4dB 21dB */ +/* 0.41 13435 +3dB 24dB */ +/* 0.26 8520 +2dB 28dB */ +/* 0.12 3932 +1dB 34dB */ +/* 0.0 0 +0dB 98dB */ +/* */ +/* PARAMETERS: */ +/* Gain - compression control parameter */ +/* pDataIn - pointer to the input data buffer */ +/* pDataOut - pointer to the output data buffer */ +/* BlockLength - number of samples to process */ +/* */ +/* RETURNS: */ +/* None */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +void NonLinComp_D16(LVM_INT16 Gain, + LVM_INT16 *pDataIn, + LVM_INT16 *pDataOut, + LVM_INT32 BlockLength) +{ + + LVM_INT16 Sample; /* Input samples */ + LVM_INT32 SampleNo; /* Sample index */ + LVM_INT16 Temp; + + + /* + * Process a block of samples + */ + for(SampleNo = 0; SampleNo> 15); + if(Sample >0) + { + Sample = (LVM_INT16)(Sample + ((Gain * (Sample - Temp)) >> 15)); + } + else + { + Sample = (LVM_INT16)(Sample + ((Gain * (Sample + Temp)) >> 15)); + } + } + + + /* + * Save the output + */ + *pDataOut = Sample; + pDataOut++; + + + } + +} + diff --git a/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32C14G11_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32C14G11_TRC_WRA_01.c new file mode 100755 index 0000000..06cfe88 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32C14G11_TRC_WRA_01.c @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "PK_2I_D32F32CssGss_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A0, + pBiquadState->coefs[1] is -B2, + pBiquadState->coefs[2] is -B1, these are in Q14 format + pBiquadState->coefs[3] is Gain, in Q11 format + + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is x(n-1)R in Q0 format + pBiquadState->pDelays[2] is x(n-2)L in Q0 format + pBiquadState->pDelays[3] is x(n-2)R in Q0 format + pBiquadState->pDelays[4] is y(n-1)L in Q0 format + pBiquadState->pDelays[5] is y(n-1)R in Q0 format + pBiquadState->pDelays[6] is y(n-2)L in Q0 format + pBiquadState->pDelays[7] is y(n-2)R in Q0 format +***************************************************************************/ +void PK_2I_D32F32C14G11_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT32 *pDataIn, + LVM_INT32 *pDataOut, + LVM_INT16 NrSamples) + { + LVM_INT32 ynL,ynR,ynLO,ynRO,templ; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + /* ynL= (A0 (Q14) * (x(n)L (Q0) - x(n-2)L (Q0) ) >>14) in Q0*/ + templ=(*pDataIn)-pBiquadState->pDelays[2]; + MUL32x16INTO32(templ,pBiquadState->coefs[0],ynL,14) + + /* ynL+= ((-B2 (Q14) * y(n-2)L (Q0) ) >>14) in Q0*/ + MUL32x16INTO32(pBiquadState->pDelays[6],pBiquadState->coefs[1],templ,14) + ynL+=templ; + + /* ynL+= ((-B1 (Q14) * y(n-1)L (Q0) ) >>14) in Q0 */ + MUL32x16INTO32(pBiquadState->pDelays[4],pBiquadState->coefs[2],templ,14) + ynL+=templ; + + /* ynLO= ((Gain (Q11) * ynL (Q0))>>11) in Q0*/ + MUL32x16INTO32(ynL,pBiquadState->coefs[3],ynLO,11) + + /* ynLO=( ynLO(Q0) + x(n)L (Q0) ) in Q0*/ + ynLO+= (*pDataIn); + + /************************************************************************** + PROCESSING OF THE RIGHT CHANNEL + ***************************************************************************/ + /* ynR= (A0 (Q14) * (x(n)R (Q0) - x(n-2)R (Q0) ) >>14) in Q0*/ + templ=(*(pDataIn+1))-pBiquadState->pDelays[3]; + MUL32x16INTO32(templ,pBiquadState->coefs[0],ynR,14) + + /* ynR+= ((-B2 (Q14) * y(n-2)R (Q0) ) >>14) in Q0*/ + MUL32x16INTO32(pBiquadState->pDelays[7],pBiquadState->coefs[1],templ,14) + ynR+=templ; + + /* ynR+= ((-B1 (Q14) * y(n-1)R (Q0) ) >>14) in Q0 */ + MUL32x16INTO32(pBiquadState->pDelays[5],pBiquadState->coefs[2],templ,14) + ynR+=templ; + + /* ynRO= ((Gain (Q11) * ynR (Q0))>>11) in Q0*/ + MUL32x16INTO32(ynR,pBiquadState->coefs[3],ynRO,11) + + /* ynRO=( ynRO(Q0) + x(n)R (Q0) ) in Q0*/ + ynRO+= (*(pDataIn+1)); + + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[7]=pBiquadState->pDelays[5]; /* y(n-2)R=y(n-1)R*/ + pBiquadState->pDelays[6]=pBiquadState->pDelays[4]; /* y(n-2)L=y(n-1)L*/ + pBiquadState->pDelays[3]=pBiquadState->pDelays[1]; /* x(n-2)R=x(n-1)R*/ + pBiquadState->pDelays[2]=pBiquadState->pDelays[0]; /* x(n-2)L=x(n-1)L*/ + pBiquadState->pDelays[5]=ynR; /* Update y(n-1)R in Q0*/ + pBiquadState->pDelays[4]=ynL; /* Update y(n-1)L in Q0*/ + pBiquadState->pDelays[0]=(*pDataIn); /* Update x(n-1)L in Q0*/ + pDataIn++; + pBiquadState->pDelays[1]=(*pDataIn); /* Update x(n-1)R in Q0*/ + pDataIn++; + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut=ynLO; /* Write Left output in Q0*/ + pDataOut++; + *pDataOut=ynRO; /* Write Right ouput in Q0*/ + pDataOut++; + + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32C30G11_TRC_WRA_01.c b/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32C30G11_TRC_WRA_01.c new file mode 100755 index 0000000..5b78f62 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32C30G11_TRC_WRA_01.c @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "PK_2I_D32F32CllGss_TRC_WRA_01_Private.h" +#include "LVM_Macros.h" + +/************************************************************************** + ASSUMPTIONS: + COEFS- + pBiquadState->coefs[0] is A0, + pBiquadState->coefs[1] is -B2, + pBiquadState->coefs[2] is -B1, these are in Q30 format + pBiquadState->coefs[3] is Gain, in Q11 format + + + DELAYS- + pBiquadState->pDelays[0] is x(n-1)L in Q0 format + pBiquadState->pDelays[1] is x(n-1)R in Q0 format + pBiquadState->pDelays[2] is x(n-2)L in Q0 format + pBiquadState->pDelays[3] is x(n-2)R in Q0 format + pBiquadState->pDelays[4] is y(n-1)L in Q0 format + pBiquadState->pDelays[5] is y(n-1)R in Q0 format + pBiquadState->pDelays[6] is y(n-2)L in Q0 format + pBiquadState->pDelays[7] is y(n-2)R in Q0 format +***************************************************************************/ +void PK_2I_D32F32C30G11_TRC_WRA_01 ( Biquad_Instance_t *pInstance, + LVM_INT32 *pDataIn, + LVM_INT32 *pDataOut, + LVM_INT16 NrSamples) + { + LVM_INT32 ynL,ynR,ynLO,ynRO,templ; + LVM_INT16 ii; + PFilter_State pBiquadState = (PFilter_State) pInstance; + + for (ii = NrSamples; ii != 0; ii--) + { + + + /************************************************************************** + PROCESSING OF THE LEFT CHANNEL + ***************************************************************************/ + /* ynL= (A0 (Q30) * (x(n)L (Q0) - x(n-2)L (Q0) ) >>30) in Q0*/ + templ=(*pDataIn)-pBiquadState->pDelays[2]; + MUL32x32INTO32(templ,pBiquadState->coefs[0],ynL,30) + + /* ynL+= ((-B2 (Q30) * y(n-2)L (Q0) ) >>30) in Q0*/ + MUL32x32INTO32(pBiquadState->pDelays[6],pBiquadState->coefs[1],templ,30) + ynL+=templ; + + /* ynL+= ((-B1 (Q30) * y(n-1)L (Q0) ) >>30) in Q0 */ + MUL32x32INTO32(pBiquadState->pDelays[4],pBiquadState->coefs[2],templ,30) + ynL+=templ; + + /* ynLO= ((Gain (Q11) * ynL (Q0))>>11) in Q0*/ + MUL32x16INTO32(ynL,pBiquadState->coefs[3],ynLO,11) + /* ynLO=( ynLO(Q0) + x(n)L (Q0) ) in Q0*/ + ynLO+= (*pDataIn); + + /************************************************************************** + PROCESSING OF THE RIGHT CHANNEL + ***************************************************************************/ + /* ynR= (A0 (Q30) * (x(n)R (Q0) - x(n-2)R (Q0) ) >>30) in Q0*/ + templ=(*(pDataIn+1))-pBiquadState->pDelays[3]; + MUL32x32INTO32(templ,pBiquadState->coefs[0],ynR,30) + + /* ynR+= ((-B2 (Q30) * y(n-2)R (Q0) ) >>30) in Q0*/ + MUL32x32INTO32(pBiquadState->pDelays[7],pBiquadState->coefs[1],templ,30) + ynR+=templ; + + /* ynR+= ((-B1 (Q30) * y(n-1)R (Q0) ) >>30) in Q0 */ + MUL32x32INTO32(pBiquadState->pDelays[5],pBiquadState->coefs[2],templ,30) + ynR+=templ; + + /* ynRO= ((Gain (Q11) * ynR (Q0))>>11) in Q0*/ + MUL32x16INTO32(ynR,pBiquadState->coefs[3],ynRO,11) + + /* ynRO=( ynRO(Q0) + x(n)R (Q0) ) in Q0*/ + ynRO+= (*(pDataIn+1)); + + /************************************************************************** + UPDATING THE DELAYS + ***************************************************************************/ + pBiquadState->pDelays[7]=pBiquadState->pDelays[5]; /* y(n-2)R=y(n-1)R*/ + pBiquadState->pDelays[6]=pBiquadState->pDelays[4]; /* y(n-2)L=y(n-1)L*/ + pBiquadState->pDelays[3]=pBiquadState->pDelays[1]; /* x(n-2)R=x(n-1)R*/ + pBiquadState->pDelays[2]=pBiquadState->pDelays[0]; /* x(n-2)L=x(n-1)L*/ + pBiquadState->pDelays[5]=ynR; /* Update y(n-1)R in Q0*/ + pBiquadState->pDelays[4]=ynL; /* Update y(n-1)L in Q0*/ + pBiquadState->pDelays[0]=(*pDataIn); /* Update x(n-1)L in Q0*/ + pDataIn++; + pBiquadState->pDelays[1]=(*pDataIn); /* Update x(n-1)R in Q0*/ + pDataIn++; + + /************************************************************************** + WRITING THE OUTPUT + ***************************************************************************/ + *pDataOut=ynLO; /* Write Left output in Q0*/ + pDataOut++; + *pDataOut=ynRO; /* Write Right ouput in Q0*/ + pDataOut++; + } + + } + diff --git a/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CllGss_TRC_WRA_01_Init.c b/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CllGss_TRC_WRA_01_Init.c new file mode 100755 index 0000000..e7bcd0c --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CllGss_TRC_WRA_01_Init.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "PK_2I_D32F32CllGss_TRC_WRA_01_Private.h" + + +void PK_2I_D32F32CllGss_TRC_WRA_01_Init(Biquad_Instance_t *pInstance, + Biquad_2I_Order2_Taps_t *pTaps, + PK_C32_Coefs_t *pCoef) +{ + PFilter_State pBiquadState = (PFilter_State) pInstance; + pBiquadState->pDelays =(LVM_INT32 *) pTaps; + + pBiquadState->coefs[0]=pCoef->A0; + + pBiquadState->coefs[1]=pCoef->B2; + + pBiquadState->coefs[2]=pCoef->B1; + + pBiquadState->coefs[3]=pCoef->G; + +} + diff --git a/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CllGss_TRC_WRA_01_Private.h b/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CllGss_TRC_WRA_01_Private.h new file mode 100755 index 0000000..741f504 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CllGss_TRC_WRA_01_Private.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _PK_2I_D32F32CLLGSS_TRC_WRA_01_PRIVATE_H_ +#define _PK_2I_D32F32CLLGSS_TRC_WRA_01_PRIVATE_H_ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/* The internal state variables are implemented in a (for the user) hidden structure */ +/* In this (private) file, the internal structure is declared fro private use. */ +typedef struct _Filter_State_ +{ + LVM_INT32 * pDelays; /* pointer to the delayed samples (data of 32 bits) */ + LVM_INT32 coefs[5]; /* pointer to the filter coefficients */ +}Filter_State; + +typedef Filter_State * PFilter_State ; + +#endif /* _PK_2I_D32F32CLLGSS_TRC_WRA_01_PRIVATE_H_ */ diff --git a/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CssGss_TRC_WRA_01_Init.c b/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CssGss_TRC_WRA_01_Init.c new file mode 100755 index 0000000..f02305e --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CssGss_TRC_WRA_01_Init.c @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +#include "BIQUAD.h" +#include "PK_2I_D32F32CssGss_TRC_WRA_01_Private.h" + +void PK_2I_D32F32CssGss_TRC_WRA_01_Init(Biquad_Instance_t *pInstance, + Biquad_2I_Order2_Taps_t *pTaps, + PK_C16_Coefs_t *pCoef) +{ + PFilter_State pBiquadState = (PFilter_State) pInstance; + pBiquadState->pDelays =(LVM_INT32 *) pTaps; + + pBiquadState->coefs[0]=pCoef->A0; + + pBiquadState->coefs[1]=pCoef->B2; + + pBiquadState->coefs[2]=pCoef->B1; + + pBiquadState->coefs[3]=pCoef->G; + +} + diff --git a/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CssGss_TRC_WRA_01_Private.h b/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CssGss_TRC_WRA_01_Private.h new file mode 100755 index 0000000..ca31669 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/PK_2I_D32F32CssGss_TRC_WRA_01_Private.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _PK_2I_D32F32CSSGSS_TRC_WRA_01_PRIVATE_H_ +#define _PK_2I_D32F32CSSGSS_TRC_WRA_01_PRIVATE_H_ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + + +/* The internal state variables are implemented in a (for the user) hidden structure */ +/* In this (private) file, the internal structure is declared fro private use. */ +typedef struct _Filter_State_ +{ + LVM_INT32 * pDelays; /* pointer to the delayed samples (data of 32 bits) */ + LVM_INT32 coefs[5]; /* pointer to the filter coefficients */ +}Filter_State; + +typedef Filter_State * PFilter_State ; + +#endif /* _PK_2I_D32F32CSSGSS_TRC_WRA_01_PRIVATE_H_ */ diff --git a/media/libeffects/lvm/lib/Common/src/Shift_Sat_v16xv16.c b/media/libeffects/lvm/lib/Common/src/Shift_Sat_v16xv16.c new file mode 100755 index 0000000..e449a7f --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Shift_Sat_v16xv16.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION Shift_Sat_v16xv16 +***********************************************************************************/ + +void Shift_Sat_v16xv16 (const LVM_INT16 val, + const LVM_INT16 *src, + LVM_INT16 *dst, + LVM_INT16 n) +{ + LVM_INT32 temp; + LVM_INT32 ii; + LVM_INT16 RShift; + if(val>0) + { + for (ii = n; ii != 0; ii--) + { + temp = (LVM_INT32)*src; + src++; + + temp = temp << val; + + if (temp > 0x00007FFF) + { + *dst = 0x7FFF; + } + else if (temp < -0x00008000) + { + *dst = - 0x8000; + } + else + { + *dst = (LVM_INT16)temp; + } + dst++; + } + } + else if(val<0) + { + RShift=(LVM_INT16)(-val); + + for (ii = n; ii != 0; ii--) + { + *dst = (LVM_INT16)(*src >> RShift); + dst++; + src++; + } + } + else + { + if(src!=dst) + { + Copy_16(src,dst,n); + } + } + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/Shift_Sat_v32xv32.c b/media/libeffects/lvm/lib/Common/src/Shift_Sat_v32xv32.c new file mode 100755 index 0000000..0ab98ea --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/Shift_Sat_v32xv32.c @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: */ +/* $Author: beq07716 $*/ +/* $Revision: 1000 $*/ +/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION Shift_Sat_v32xv32 +***********************************************************************************/ + +void Shift_Sat_v32xv32 (const LVM_INT16 val, + const LVM_INT32 *src, + LVM_INT32 *dst, + LVM_INT16 n) +{ + LVM_INT32 ii; + LVM_INT16 RShift; + + if(val>0) + { + LVM_INT32 a,b; + + for (ii = n; ii != 0; ii--) + { + a=*src; + src++; + + b=(a<>val) != a ) /* if overflow occured, right shift will show difference*/ + { + if(a<0) + { + b=0x80000000l; + } + else + { + b=0x7FFFFFFFl; + } + } + + *dst = b; + dst++; + } + } + else if(val<0) + { + RShift=(LVM_INT16)(-val); + for (ii = n; ii != 0; ii--) + { + *dst = (*src >> RShift); + dst++; + src++; + } + } + else + { + if(src!=dst) + { + Copy_16((LVM_INT16 *)src,(LVM_INT16 *)dst,(LVM_INT16)(n<<1)); + } + } + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Common/src/dB_to_Lin32.c b/media/libeffects/lvm/lib/Common/src/dB_to_Lin32.c new file mode 100755 index 0000000..ac0343f --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/dB_to_Lin32.c @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* %created_by: sra % (CM/S)*/ +/* %name: dB_to_Lin32.c % (CM/S)*/ +/* %version: 2 % (CM/S)*/ +/* %date_created: Wed Jun 18 11:27:46 2008 % (CM/S)*/ +/* */ +/************************************************************************/ + +/*######################################################################################*/ +/* Include files */ +/*######################################################################################*/ + +#include "ScalarArithmetic.h" + + +/**************************************************************************************** + * Name : dB_to_Lin32() + * Input : Signed 16-bit integer + * MSB (16) = sign bit + * (15->05) = integer part + * (04->01) = decimal part + * Output : Signed 32-bit integer + * MSB (32) = sign bit + * (31->16) = integer part + * (15->01) = decimal part + * Returns : Lin value format 1.16.15 + * Description : + * Remarks : Makes an approximation to the conversion by counting the number + * of 6dB steps for use as shifts and then interpolates with a remainder + * with the equation: + * + * Correction = (Remainder / 1.5029) - (Remainder^2 / 6) + * + * The two coefficients are scaled from 0x40000000 in 96 steps and calculated + * as follows: + * + * FIRST_COEF = 0x80000000 / (96 * 1.5029) + * SECOND_COEF = 0x80000000 / (96^2 * 6) + * + ****************************************************************************************/ + +#define FOUR_OVER_SIX 21846 /* (4 / 6) * 2^15 */ +#define SIX_DB 96 /* 6 * 16 or 6dB in Q11.4 format */ +#define FIRST_COEF_NEG 14884305 +#define FIRST_COEF_POS 7442152 /* FIRST_COEF_NEG / 2 */ +#define SECOND_COEF 38836 +#define MAX_VALUE 1536 /* 96 * 16 */ + +LVM_INT32 dB_to_Lin32(LVM_INT16 db_fix) +{ + LVM_INT32 Lin_val_32; + LVM_INT16 Shift; + LVM_INT32 Remain; + + + /* + * Check sign of the input + */ + if (db_fix<0) + { + if (db_fix > -MAX_VALUE) + { + Shift = (LVM_INT16)((((LVM_UINT32)(-db_fix) >> 4) * FOUR_OVER_SIX) >> 17); /* Number of 6dB steps in Q11.4 format */ + Remain = -db_fix - (Shift * SIX_DB); + Remain = (0x7FFFFFFF - (Remain * FIRST_COEF_NEG)) + (Remain * Remain * SECOND_COEF); + Lin_val_32 = (LVM_INT32)((LVM_UINT32)Remain >> (16 + Shift)); + } + else + { + Lin_val_32 = 0; + } + } + else + { + if (db_fix < MAX_VALUE) + { + Shift = (LVM_INT16)((((LVM_UINT32)db_fix >> 4) * FOUR_OVER_SIX) >> 17); /* Number of 6dB steps in Q11.4 format */ + Remain = db_fix - (Shift * SIX_DB); + Remain = 0x3FFFFFFF + (Remain * FIRST_COEF_POS) + (Remain * Remain * SECOND_COEF); + Lin_val_32 = (LVM_INT32)((LVM_UINT32)Remain >> (15 - Shift)); + } + else + { + Lin_val_32 = 0x7FFFFFFF; + } + } + + + return Lin_val_32; /* format 1.16.15 */ +} + diff --git a/media/libeffects/lvm/lib/Common/src/mult3s_16x16.c b/media/libeffects/lvm/lib/Common/src/mult3s_16x16.c new file mode 100755 index 0000000..b500979 --- /dev/null +++ b/media/libeffects/lvm/lib/Common/src/mult3s_16x16.c @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1000 $ + $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/********************************************************************************** + INCLUDE FILES +***********************************************************************************/ + +#include "VectorArithmetic.h" + +/********************************************************************************** + FUNCTION MULT3S_16X16 +***********************************************************************************/ + +void Mult3s_16x16( const LVM_INT16 *src, + const LVM_INT16 val, + LVM_INT16 *dst, + LVM_INT16 n) +{ + LVM_INT16 ii; + LVM_INT32 temp; + + for (ii = n; ii != 0; ii--) + { + temp = (LVM_INT32)(*src) * (LVM_INT32)val; + src++; + + *dst = (LVM_INT16)(temp >> 15); + dst++; + } + + return; +} + +/**********************************************************************************/ diff --git a/media/libeffects/lvm/lib/Eq/lib/LVEQNB.h b/media/libeffects/lvm/lib/Eq/lib/LVEQNB.h new file mode 100755 index 0000000..7ba583f --- /dev/null +++ b/media/libeffects/lvm/lib/Eq/lib/LVEQNB.h @@ -0,0 +1,484 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1005 $ + $Date: 2010-06-28 13:58:28 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Header file for the application layer interface of the N-Band equaliser. */ +/* */ +/* This files includes all definitions, types, structures and function */ +/* prototypes required by the calling layer. All other types, structures and */ +/* functions are private. */ +/* */ +/****************************************************************************************/ +/* */ +/* Note: 1 */ +/* ======= */ +/* The algorithm can execute either with separate input and output buffers or with */ +/* a common buffer, i.e. the data is processed in-place. */ +/* */ +/****************************************************************************************/ +/* */ +/* Note: 2 */ +/* ======= */ +/* Two data formats are support Stereo and Mono-In-Stereo. The data is interleaved as */ +/* follows: */ +/* Byte Offset Stereo Input Mono-In-Stereo Input */ +/* =========== ============ ==================== */ +/* 0 Left Sample #1 Mono Sample #1 */ +/* 2 Right Sample #1 Mono Sample #1 */ +/* 4 Left Sample #2 Mono Sample #2 */ +/* 6 Right Sample #2 Mono Sample #2 */ +/* . . . */ +/* . . . */ +/* */ +/* Mono format data is not supported, the calling routine must convert a Mono stream */ +/* in to Mono-In-Stereo format. */ +/* */ +/****************************************************************************************/ +/* */ +/* Note: 3 */ +/* ======= */ +/* The format of the data in the filter band definition structure is as follows: */ +/* */ +/* Gain is in integer dB, range -15dB to +15dB inclusive */ +/* Frequency is the centre frequency in Hz, range DC to Nyquist */ +/* QFactor is the Q multiplied by 100, range 0.25 (25) to 12 (1200) */ +/* */ +/* Example: */ +/* Gain = 7 7dB gain */ +/* Frequency = 2467 Centre frequency = 2.467kHz */ +/* QFactor = 1089 Q = 10.89 */ +/* */ +/* The equaliser filters are passed as a pointer to and array of filter band */ +/* definitions structures. There must be one filter definition for each band. */ +/* */ +/****************************************************************************************/ + + +#ifndef __LVEQNB_H__ +#define __LVEQNB_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVM_Types.h" +#include "LVM_Common.h" + +/****************************************************************************************/ +/* */ +/* Definitions */ +/* */ +/****************************************************************************************/ + +/* Memory table */ +#define LVEQNB_MEMREGION_INSTANCE 0 /* Offset to the instance memory region */ +#define LVEQNB_MEMREGION_PERSISTENT_DATA 1 /* Offset to persistent data memory region */ +#define LVEQNB_MEMREGION_PERSISTENT_COEF 2 /* Offset to persistent coefficient region */ +#define LVEQNB_MEMREGION_SCRATCH 3 /* Offset to data scratch memory region */ +#define LVEQNB_NR_MEMORY_REGIONS 4 /* Number of memory regions */ + +/* Callback events */ +#define LVEQNB_EVENT_NONE 0x0000 /* Not a valid event */ +#define LVEQNB_EVENT_ALGOFF 0x0001 /* EQNB has completed switch off */ + +/****************************************************************************************/ +/* */ +/* Types */ +/* */ +/****************************************************************************************/ + +/* Instance handle */ +typedef void *LVEQNB_Handle_t; + + +/* Operating modes */ +typedef enum +{ + LVEQNB_BYPASS = 0, + LVEQNB_ON = 1, + LVEQNB_MODE_MAX = LVM_MAXINT_32 +} LVEQNB_Mode_en; + + +/* Filter mode control */ +typedef enum +{ + LVEQNB_FILTER_OFF = 0, + LVEQNB_FILTER_ON = 1, + LVEQNB_FILTER_DUMMY = LVM_MAXINT_32 +} LVEQNB_FilterMode_en; + + +/* Memory Types */ +typedef enum +{ + LVEQNB_PERSISTENT = 0, + LVEQNB_PERSISTENT_DATA = 1, + LVEQNB_PERSISTENT_COEF = 2, + LVEQNB_SCRATCH = 3, + LVEQNB_MEMORY_MAX = LVM_MAXINT_32 +} LVEQNB_MemoryTypes_en; + + +/* Function return status */ +typedef enum +{ + LVEQNB_SUCCESS = 0, /* Successful return from a routine */ + LVEQNB_ALIGNMENTERROR = 1, /* Memory alignment error */ + LVEQNB_NULLADDRESS = 2, /* NULL allocation address */ + LVEQNB_TOOMANYSAMPLES = 3, /* Maximum block size exceeded */ + LVEQNB_STATUS_MAX = LVM_MAXINT_32 +} LVEQNB_ReturnStatus_en; + + +/****************************************************************************************/ +/* */ +/* Linked enumerated type and capability definitions */ +/* */ +/* The capability definitions are used to define the required capabilities at */ +/* initialisation, these are added together to give the capability word. The */ +/* enumerated type is used to select the mode through a control function at run time. */ +/* */ +/* The capability definition is related to the enumerated type value by the equation: */ +/* */ +/* Capability_value = 2^Enumerated_value */ +/* */ +/* For example, a module could be configurd at initialisation to support two sample */ +/* rates only by calling the init function with the value: */ +/* Capabilities.SampleRate = LVEQNB_CAP_32000 + LVEQNB_CAP_44100; */ +/* */ +/* and at run time it would be passed the value LVEQNB_FS_32000 through the control */ +/* function to select operation at 32kHz */ +/* */ +/****************************************************************************************/ + +/* + * Supported source data formats + */ +#define LVEQNB_CAP_STEREO 1 +#define LVEQNB_CAP_MONOINSTEREO 2 + +typedef enum +{ + LVEQNB_STEREO = 0, + LVEQNB_MONOINSTEREO = 1, + LVEQNB_SOURCE_MAX = LVM_MAXINT_32 +} LVEQNB_SourceFormat_en; + + +/* + * Supported sample rates in samples per second + */ +#define LVEQNB_CAP_FS_8000 1 +#define LVEQNB_CAP_FS_11025 2 +#define LVEQNB_CAP_FS_12000 4 +#define LVEQNB_CAP_FS_16000 8 +#define LVEQNB_CAP_FS_22050 16 +#define LVEQNB_CAP_FS_24000 32 +#define LVEQNB_CAP_FS_32000 64 +#define LVEQNB_CAP_FS_44100 128 +#define LVEQNB_CAP_FS_48000 256 + +typedef enum +{ + LVEQNB_FS_8000 = 0, + LVEQNB_FS_11025 = 1, + LVEQNB_FS_12000 = 2, + LVEQNB_FS_16000 = 3, + LVEQNB_FS_22050 = 4, + LVEQNB_FS_24000 = 5, + LVEQNB_FS_32000 = 6, + LVEQNB_FS_44100 = 7, + LVEQNB_FS_48000 = 8, + LVEQNB_FS_MAX = LVM_MAXINT_32 +} LVEQNB_Fs_en; + + +/****************************************************************************************/ +/* */ +/* Structures */ +/* */ +/****************************************************************************************/ + +/* Memory region definition */ +typedef struct +{ + LVM_UINT32 Size; /* Region size in bytes */ + LVM_UINT16 Alignment; /* Region alignment in bytes */ + LVEQNB_MemoryTypes_en Type; /* Region type */ + void *pBaseAddress; /* Pointer to the region base address */ +} LVEQNB_MemoryRegion_t; + + +/* Memory table containing the region definitions */ +typedef struct +{ + LVEQNB_MemoryRegion_t Region[LVEQNB_NR_MEMORY_REGIONS]; /* One definition for each region */ +} LVEQNB_MemTab_t; + + +/* Equaliser band definition */ +typedef struct +{ + LVM_INT16 Gain; /* Band gain in dB */ + LVM_UINT16 Frequency; /* Band centre frequency in Hz */ + LVM_UINT16 QFactor; /* Band quality factor */ +} LVEQNB_BandDef_t; + + +/* Parameter structure */ +typedef struct +{ + /* General parameters */ + LVEQNB_Mode_en OperatingMode; + LVEQNB_Fs_en SampleRate; + LVEQNB_SourceFormat_en SourceFormat; + + /* Equaliser parameters */ + LVM_UINT16 NBands; /* Number of bands */ + LVEQNB_BandDef_t *pBandDefinition; /* Pointer to equaliser definitions */ + +} LVEQNB_Params_t; + + +/* Capability structure */ +typedef struct +{ + /* General parameters */ + LVM_UINT16 SampleRate; + LVM_UINT16 SourceFormat; + LVM_UINT16 MaxBlockSize; + LVM_UINT16 MaxBands; + + /* Callback parameters */ + LVM_Callback CallBack; /* Bundle callback */ + void *pBundleInstance; /* Bundle instance handle */ + +} LVEQNB_Capabilities_t; + + +/****************************************************************************************/ +/* */ +/* Function Prototypes */ +/* */ +/****************************************************************************************/ + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_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 default capabilities */ +/* */ +/* RETURNS: */ +/* LVEQNB_SUCCESS Succeeded */ +/* LVEQNB_NULLADDRESS When any of pMemoryTable and pCapabilities is NULL address */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVEQNB_Process function */ +/* */ +/****************************************************************************************/ + +LVEQNB_ReturnStatus_en LVEQNB_Memory(LVEQNB_Handle_t hInstance, + LVEQNB_MemTab_t *pMemoryTable, + LVEQNB_Capabilities_t *pCapabilities); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_Init */ +/* */ +/* DESCRIPTION: */ +/* Create and initialisation function for the N-Band equalliser 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 */ +/* LVEQNB_Memory before calling this function. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pMemoryTable Pointer to the memory definition table */ +/* pCapabilities Pointer to the initialisation capabilities */ +/* */ +/* RETURNS: */ +/* LVEQNB_SUCCESS Initialisation succeeded */ +/* LVEQNB_NULLADDRESS When pCapabilities or pMemoryTableis or phInstance are NULL */ +/* LVEQNB_NULLADDRESS One or more of the memory regions has a NULL base address */ +/* pointer for a memory region with a non-zero size. */ +/* */ +/* */ +/* 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 LVEQNB_Process function */ +/* */ +/****************************************************************************************/ + +LVEQNB_ReturnStatus_en LVEQNB_Init(LVEQNB_Handle_t *phInstance, + LVEQNB_MemTab_t *pMemoryTable, + LVEQNB_Capabilities_t *pCapabilities); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_GetParameters */ +/* */ +/* DESCRIPTION: */ +/* Request the equaliser module parameters. The current parameter set is returned */ +/* via the parameter pointer. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to an empty parameter structure */ +/* */ +/* RETURNS: */ +/* LVEQNB_SUCCESS Succeeds */ +/* LVEQNB_NULLADDRESS Instance or pParams is NULL pointer */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVEQNB_Process function */ +/* */ +/****************************************************************************************/ + +LVEQNB_ReturnStatus_en LVEQNB_GetParameters(LVEQNB_Handle_t hInstance, + LVEQNB_Params_t *pParams); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_GetCapabilities */ +/* */ +/* DESCRIPTION: */ +/* Request the equaliser module capabilities. The capabilities set is returned */ +/* via the pointer. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pCapabilities Pointer to an empty capability structure */ +/* */ +/* RETURNS: */ +/* LVEQNB_SUCCESS Succeeds */ +/* LVEQNB_NULLADDRESS hInstance or pCapabilities is NULL */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVEQNB_Process function */ +/* */ +/****************************************************************************************/ + +LVEQNB_ReturnStatus_en LVEQNB_GetCapabilities(LVEQNB_Handle_t hInstance, + LVEQNB_Capabilities_t *pCapabilities); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_Control */ +/* */ +/* DESCRIPTION: */ +/* Sets or changes the equaliser module parameters. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to a parameter structure */ +/* */ +/* RETURNS: */ +/* LVEQNB_SUCCESS Succeeded */ +/* LVEQNB_NULLADDRESS Instance or pParams is NULL pointer */ +/* LVEQNB_NULLADDRESS NULL address for the equaliser filter definitions and the */ +/* number of bands is non-zero */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVEQNB_Process function */ +/* */ +/****************************************************************************************/ + +LVEQNB_ReturnStatus_en LVEQNB_Control(LVEQNB_Handle_t hInstance, + LVEQNB_Params_t *pParams); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_Process */ +/* */ +/* DESCRIPTION: */ +/* Process function for the LifeVibes module. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pInData Pointer to the input data */ +/* pOutData Pointer to the output data */ +/* NumSamples Number of samples in the input buffer */ +/* */ +/* RETURNS: */ +/* LVEQNB_SUCCESS Succeeded */ +/* LVEQNB_NULLADDRESS When hInstance, pInData or pOutData are NULL */ +/* LVEQNB_ALIGNMENTERROR When pInData or pOutData are not 32-bit aligned */ +/* LVEQNB_TOOMANYSAMPLES NumSamples was larger than the maximum block size */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +LVEQNB_ReturnStatus_en LVEQNB_Process(LVEQNB_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 *pOutData, + LVM_UINT16 NumSamples); + + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LVEQNB__ */ + diff --git a/media/libeffects/lvm/lib/Eq/src/LVEQNB_CalcCoef.c b/media/libeffects/lvm/lib/Eq/src/LVEQNB_CalcCoef.c new file mode 100755 index 0000000..4881049 --- /dev/null +++ b/media/libeffects/lvm/lib/Eq/src/LVEQNB_CalcCoef.c @@ -0,0 +1,306 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1005 $ + $Date: 2010-06-28 13:58:28 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVEQNB_Private.h" + + +/****************************************************************************************/ +/* */ +/* Defines */ +/* */ +/****************************************************************************************/ + +#define PI 3.14159265358979 + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_DoublePrecCoefs */ +/* */ +/* DESCRIPTION: */ +/* Calculate double precision coefficients for a peaking filter */ +/* */ +/* PARAMETERS: */ +/* Fs Sampling frequency index */ +/* pFilterDefinition Pointer to the filter definition */ +/* pCoefficients Pointer to the coefficients */ +/* */ +/* RETURNS: */ +/* LVEQNB_SUCCESS Always succeeds */ +/* */ +/* NOTES: */ +/* 1. The equations used are as follows: */ +/* */ +/* G = 10^(GaindB/20) - 1 */ +/* t0 = 2 * Pi * Fc / Fs */ +/* D = 1 if GaindB >= 0 */ +/* D = 1 / (1 + G) if GaindB < 0 */ +/* */ +/* b2 = -0.5 * (2Q - D * t0) / (2Q + D * t0) */ +/* b1 = (0.5 - b2) * (1 - coserr(t0)) */ +/* a0 = (0.5 + b2) / 2 */ +/* */ +/* Where: */ +/* GaindB is the gain in dBs, range -15dB to +15dB */ +/* Fc is the centre frequency, DC to Fs/50 */ +/* Fs is the sample frequency, 8000 to 48000 in descrete steps */ +/* Q is the Q factor, 0.25 to 12 (represented by 25 to 1200) */ +/* */ +/* 2. The double precision coefficients are only used when fc is less than fs/85, so */ +/* the cosine of t0 is always close to 1.0. Instead of calculating the cosine */ +/* itself the difference from the value 1.0 is calculated, this can be done with */ +/* lower precision maths. */ +/* */ +/* 3. The value of the B2 coefficient is only calculated as a single precision value, */ +/* small errors in this value have a combined effect on the Q and Gain but not the */ +/* the frequency of the filter. */ +/* */ +/****************************************************************************************/ + + +LVEQNB_ReturnStatus_en LVEQNB_DoublePrecCoefs(LVM_UINT16 Fs, + LVEQNB_BandDef_t *pFilterDefinition, + PK_C32_Coefs_t *pCoefficients) +{ + + extern LVM_INT16 LVEQNB_GainTable[]; + extern LVM_INT16 LVEQNB_TwoPiOnFsTable[]; + extern LVM_INT16 LVEQNB_DTable[]; + extern LVM_INT16 LVEQNB_DPCosCoef[]; + + /* + * Get the filter definition + */ + LVM_INT16 Gain = pFilterDefinition->Gain; + LVM_UINT16 Frequency = pFilterDefinition->Frequency; + LVM_UINT16 QFactor = pFilterDefinition->QFactor; + + /* + * Intermediate variables and temporary values + */ + LVM_INT32 T0; + LVM_INT16 D; + LVM_INT32 A0; + LVM_INT32 B1; + LVM_INT32 B2; + LVM_INT32 Dt0; + LVM_INT32 B2_Den; + LVM_INT32 B2_Num; + LVM_INT32 CosErr; + LVM_INT16 coef; + LVM_INT32 factor; + LVM_INT16 t0; + LVM_INT16 i; + + /* + * Calculating the intermediate values + */ + T0 = (LVM_INT32)Frequency * LVEQNB_TwoPiOnFsTable[Fs]; /* T0 = 2 * Pi * Fc / Fs */ + if (Gain >= 0) + { + D = LVEQNB_DTable[15]; /* D = 1 if GaindB >= 0 */ + } + else + { + D = LVEQNB_DTable[Gain+15]; /* D = 1 / (1 + G) if GaindB < 0 */ + } + + /* + * Calculate the B2 coefficient + */ + Dt0 = D * (T0 >> 10); + B2_Den = ((LVM_INT32)QFactor << 19) + (Dt0 >> 2); + B2_Num = (Dt0 >> 3) - ((LVM_INT32)QFactor << 18); + B2 = (B2_Num / (B2_Den >> 16)) << 15; + + /* + * Calculate the cosine error by a polynomial expansion using the equation: + * + * CosErr += coef(n) * t0^n For n = 0 to 4 + */ + T0 = (T0 >> 6) * 0x7f53; /* Scale to 1.0 in 16-bit for range 0 to fs/50 */ + t0 = (LVM_INT16)(T0 >> 16); + factor = 0x7fff; /* Initialise to 1.0 for the a0 coefficient */ + CosErr = 0; /* Initialise the error to zero */ + for (i=1; i<5; i++) + { + coef = LVEQNB_DPCosCoef[i]; /* Get the nth coefficient */ + CosErr += (factor * coef) >> 5; /* The nth partial sum */ + factor = (factor * t0) >> 15; /* Calculate t0^n */ + } + CosErr = CosErr << (LVEQNB_DPCosCoef[0]); /* Correct the scaling */ + + /* + * Calculate the B1 and A0 coefficients + */ + B1 = (0x40000000 - B2); /* B1 = (0.5 - b2/2) */ + A0 = ((B1 >> 16) * (CosErr >> 10)) >> 6; /* Temporary storage for (0.5 - b2/2) * coserr(t0) */ + B1 -= A0; /* B1 = (0.5 - b2/2) * (1 - coserr(t0)) */ + A0 = (0x40000000 + B2) >> 1; /* A0 = (0.5 + b2) */ + + /* + * Write coeff into the data structure + */ + pCoefficients->A0 = A0; + pCoefficients->B1 = B1; + pCoefficients->B2 = B2; + pCoefficients->G = LVEQNB_GainTable[Gain+15]; + + return(LVEQNB_SUCCESS); + +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_SinglePrecCoefs */ +/* */ +/* DESCRIPTION: */ +/* Calculate single precision coefficients for a peaking filter */ +/* */ +/* PARAMETERS: */ +/* Fs Sampling frequency index */ +/* pFilterDefinition Pointer to the filter definition */ +/* pCoefficients Pointer to the coefficients */ +/* */ +/* RETURNS: */ +/* LVEQNB_SUCCESS Always succeeds */ +/* */ +/* NOTES: */ +/* 1. The equations used are as follows: */ +/* */ +/* G = 10^(GaindB/20) - 1 */ +/* t0 = 2 * Pi * Fc / Fs */ +/* D = 1 if GaindB >= 0 */ +/* D = 1 / (1 + G) if GaindB < 0 */ +/* */ +/* b2 = -0.5 * (2Q - D * t0) / (2Q + D * t0) */ +/* b1 = (0.5 - b2) * cos(t0) */ +/* a0 = (0.5 + b2) / 2 */ +/* */ +/* Where: */ +/* GaindB is the gain in dBs, range -15dB to +15dB */ +/* Fc is the centre frequency, DC to Nyquist */ +/* Fs is the sample frequency, 8000 to 48000 in descrete steps */ +/* Q is the Q factor, 0.25 to 12 */ +/* */ +/****************************************************************************************/ + + +LVEQNB_ReturnStatus_en LVEQNB_SinglePrecCoefs(LVM_UINT16 Fs, + LVEQNB_BandDef_t *pFilterDefinition, + PK_C16_Coefs_t *pCoefficients) +{ + + extern LVM_INT16 LVEQNB_GainTable[]; + extern LVM_INT16 LVEQNB_TwoPiOnFsTable[]; + extern LVM_INT16 LVEQNB_DTable[]; + extern LVM_INT16 LVEQNB_CosCoef[]; + + + /* + * Get the filter definition + */ + LVM_INT16 Gain = pFilterDefinition->Gain; + LVM_UINT16 Frequency = pFilterDefinition->Frequency; + LVM_UINT16 QFactor = pFilterDefinition->QFactor; + + + /* + * Intermediate variables and temporary values + */ + LVM_INT32 T0; + LVM_INT16 D; + LVM_INT32 A0; + LVM_INT32 B1; + LVM_INT32 B2; + LVM_INT32 Dt0; + LVM_INT32 B2_Den; + LVM_INT32 B2_Num; + LVM_INT32 COS_T0; + LVM_INT16 coef; + LVM_INT32 factor; + LVM_INT16 t0; + LVM_INT16 i; + + /* + * Calculating the intermediate values + */ + T0 = (LVM_INT32)Frequency * LVEQNB_TwoPiOnFsTable[Fs]; /* T0 = 2 * Pi * Fc / Fs */ + if (Gain >= 0) + { + D = LVEQNB_DTable[15]; /* D = 1 if GaindB >= 0 */ + } + else + { + D = LVEQNB_DTable[Gain+15]; /* D = 1 / (1 + G) if GaindB < 0 */ + } + + /* + * Calculate the B2 coefficient + */ + Dt0 = D * (T0 >> 10); + B2_Den = ((LVM_INT32)QFactor << 19) + (Dt0 >> 2); + B2_Num = (Dt0 >> 3) - ((LVM_INT32)QFactor << 18); + B2 = (B2_Num / (B2_Den >> 16)) << 15; + + /* + * Calculate the cosine by a polynomial expansion using the equation: + * + * Cos += coef(n) * t0^n For n = 0 to 6 + */ + T0 = (T0 >> 10) * 20859; /* Scale to 1.0 in 16-bit for range 0 to fs/2 */ + t0 = (LVM_INT16)(T0 >> 16); + factor = 0x7fff; /* Initialise to 1.0 for the a0 coefficient */ + COS_T0 = 0; /* Initialise the error to zero */ + for (i=1; i<7; i++) + { + coef = LVEQNB_CosCoef[i]; /* Get the nth coefficient */ + COS_T0 += (factor * coef) >> 5; /* The nth partial sum */ + factor = (factor * t0) >> 15; /* Calculate t0^n */ + } + COS_T0 = COS_T0 << (LVEQNB_CosCoef[0]+6); /* Correct the scaling */ + + + B1 = ((0x40000000 - B2) >> 16) * (COS_T0 >> 16); /* B1 = (0.5 - b2/2) * cos(t0) */ + A0 = (0x40000000 + B2) >> 1; /* A0 = (0.5 + b2/2) */ + + /* + * Write coeff into the data structure + */ + pCoefficients->A0 = (LVM_INT16)(A0>>16); + pCoefficients->B1 = (LVM_INT16)(B1>>15); + pCoefficients->B2 = (LVM_INT16)(B2>>16); + pCoefficients->G = LVEQNB_GainTable[Gain+15]; + + + return(LVEQNB_SUCCESS); + +} diff --git a/media/libeffects/lvm/lib/Eq/src/LVEQNB_Coeffs.h b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Coeffs.h new file mode 100755 index 0000000..87d7145 --- /dev/null +++ b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Coeffs.h @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __LVEQNB_COEFFS_H__ +#define __LVEQNB_COEFFS_H__ + + +/************************************************************************************/ +/* */ +/* Gain table for (10^(Gain/20) - 1) */ +/* */ +/************************************************************************************/ + +#define LVEQNB_GAINSHIFT 11 /* As a power of 2 */ +#define LVEQNB_Gain_Neg15_dB -1684 /* Floating point value -0.822172 */ +#define LVEQNB_Gain_Neg14_dB -1639 /* Floating point value -0.800474 */ +#define LVEQNB_Gain_Neg13_dB -1590 /* Floating point value -0.776128 */ +#define LVEQNB_Gain_Neg12_dB -1534 /* Floating point value -0.748811 */ +#define LVEQNB_Gain_Neg11_dB -1471 /* Floating point value -0.718162 */ +#define LVEQNB_Gain_Neg10_dB -1400 /* Floating point value -0.683772 */ +#define LVEQNB_Gain_Neg9_dB -1321 /* Floating point value -0.645187 */ +#define LVEQNB_Gain_Neg8_dB -1233 /* Floating point value -0.601893 */ +#define LVEQNB_Gain_Neg7_dB -1133 /* Floating point value -0.553316 */ +#define LVEQNB_Gain_Neg6_dB -1022 /* Floating point value -0.498813 */ +#define LVEQNB_Gain_Neg5_dB -896 /* Floating point value -0.437659 */ +#define LVEQNB_Gain_Neg4_dB -756 /* Floating point value -0.369043 */ +#define LVEQNB_Gain_Neg3_dB -598 /* Floating point value -0.292054 */ +#define LVEQNB_Gain_Neg2_dB -421 /* Floating point value -0.205672 */ +#define LVEQNB_Gain_Neg1_dB -223 /* Floating point value -0.108749 */ +#define LVEQNB_Gain_0_dB 0 /* Floating point value 0.000000 */ +#define LVEQNB_Gain_1_dB 250 /* Floating point value 0.122018 */ +#define LVEQNB_Gain_2_dB 530 /* Floating point value 0.258925 */ +#define LVEQNB_Gain_3_dB 845 /* Floating point value 0.412538 */ +#define LVEQNB_Gain_4_dB 1198 /* Floating point value 0.584893 */ +#define LVEQNB_Gain_5_dB 1594 /* Floating point value 0.778279 */ +#define LVEQNB_Gain_6_dB 2038 /* Floating point value 0.995262 */ +#define LVEQNB_Gain_7_dB 2537 /* Floating point value 1.238721 */ +#define LVEQNB_Gain_8_dB 3096 /* Floating point value 1.511886 */ +#define LVEQNB_Gain_9_dB 3724 /* Floating point value 1.818383 */ +#define LVEQNB_Gain_10_dB 4428 /* Floating point value 2.162278 */ +#define LVEQNB_Gain_11_dB 5219 /* Floating point value 2.548134 */ +#define LVEQNB_Gain_12_dB 6105 /* Floating point value 2.981072 */ +#define LVEQNB_Gain_13_dB 7100 /* Floating point value 3.466836 */ +#define LVEQNB_Gain_14_dB 8216 /* Floating point value 4.011872 */ +#define LVEQNB_Gain_15_dB 9469 /* Floating point value 4.623413 */ + + +/************************************************************************************/ +/* */ +/* Frequency table for 2*Pi/Fs */ +/* */ +/************************************************************************************/ + +#define LVEQNB_FREQSHIFT 25 /* As a power of 2 */ +#define LVEQNB_2PiOn_8000 26354 /* Floating point value 0.000785 */ +#define LVEQNB_2PiOn_11025 19123 /* Floating point value 0.000570 */ +#define LVEQNB_2PiOn_12000 17569 /* Floating point value 0.000524 */ +#define LVEQNB_2PiOn_16000 13177 /* Floating point value 0.000393 */ +#define LVEQNB_2PiOn_22050 9561 /* Floating point value 0.000285 */ +#define LVEQNB_2PiOn_24000 8785 /* Floating point value 0.000262 */ +#define LVEQNB_2PiOn_32000 6588 /* Floating point value 0.000196 */ +#define LVEQNB_2PiOn_44100 4781 /* Floating point value 0.000142 */ +#define LVEQNB_2PiOn_48000 4392 /* Floating point value 0.000131 */ + + +/************************************************************************************/ +/* */ +/* 50D table for 50 / ( 1 + Gain ) */ +/* */ +/************************************************************************************/ + +#define LVEQNB_100DSHIFT 5 /* As a power of 2 */ +#define LVEQNB_100D_Neg15_dB 17995 /* Floating point value 5.623413 */ +#define LVEQNB_100D_Neg14_dB 16038 /* Floating point value 5.011872 */ +#define LVEQNB_100D_Neg13_dB 14294 /* Floating point value 4.466836 */ +#define LVEQNB_100D_Neg12_dB 12739 /* Floating point value 3.981072 */ +#define LVEQNB_100D_Neg11_dB 11354 /* Floating point value 3.548134 */ +#define LVEQNB_100D_Neg10_dB 10119 /* Floating point value 3.162278 */ +#define LVEQNB_100D_Neg9_dB 9019 /* Floating point value 2.818383 */ +#define LVEQNB_100D_Neg8_dB 8038 /* Floating point value 2.511886 */ +#define LVEQNB_100D_Neg7_dB 7164 /* Floating point value 2.238721 */ +#define LVEQNB_100D_Neg6_dB 6385 /* Floating point value 1.995262 */ +#define LVEQNB_100D_Neg5_dB 5690 /* Floating point value 1.778279 */ +#define LVEQNB_100D_Neg4_dB 5072 /* Floating point value 1.584893 */ +#define LVEQNB_100D_Neg3_dB 4520 /* Floating point value 1.412538 */ +#define LVEQNB_100D_Neg2_dB 4029 /* Floating point value 1.258925 */ +#define LVEQNB_100D_Neg1_dB 3590 /* Floating point value 1.122018 */ +#define LVEQNB_100D_0_dB 3200 /* Floating point value 1.000000 */ + + +#endif diff --git a/media/libeffects/lvm/lib/Eq/src/LVEQNB_Control.c b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Control.c new file mode 100755 index 0000000..88f6fb0 --- /dev/null +++ b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Control.c @@ -0,0 +1,501 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: nxp007753 $ + $Revision: 1223 $ + $Date: 2010-07-15 14:27:01 +0200 (Thu, 15 Jul 2010) $ + +***********************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVEQNB.h" +#include "LVEQNB_Private.h" +#include "VectorArithmetic.h" +#include "BIQUAD.h" + + +/****************************************************************************************/ +/* */ +/* Defines */ +/* */ +/****************************************************************************************/ + +#define LOW_FREQ 298 /* 32768/110 for low test frequency */ +#define HIGH_FREQ 386 /* 32768/85 for high test frequency */ + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_GetParameters */ +/* */ +/* DESCRIPTION: */ +/* Request the N-Band equaliser parameters. The current parameter set is returned via */ +/* the parameter pointer. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to an empty parameter structure */ +/* */ +/* RETURNS: */ +/* LVEQNB_SUCCESS Succeeds */ +/* LVEQNB_NULLADDRESS Instance or pParams is NULL pointer */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVEQNB_Process function */ +/* */ +/****************************************************************************************/ + +LVEQNB_ReturnStatus_en LVEQNB_GetParameters(LVEQNB_Handle_t hInstance, + LVEQNB_Params_t *pParams) +{ + + LVEQNB_Instance_t *pInstance =(LVEQNB_Instance_t *)hInstance; + + /* + * Check for error conditions + */ + if((hInstance == LVM_NULL) || (pParams == LVM_NULL)) + { + return LVEQNB_NULLADDRESS; + } + + *pParams = pInstance->Params; + + return(LVEQNB_SUCCESS); +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_GetCapabilities */ +/* */ +/* DESCRIPTION: */ +/* Get the N-Band equaliser capabilities. The current capabilities are returned */ +/* via the pointer. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pCapabilities Pointer to an empty capability structure */ +/* */ +/* RETURNS: */ +/* LVEQNB_Success Succeeds */ +/* LVEQNB_NULLADDRESS hInstance or pCapabilities is NULL */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVEQNB_Process function */ +/* */ +/************************************************************************************/ + +LVEQNB_ReturnStatus_en LVEQNB_GetCapabilities(LVEQNB_Handle_t hInstance, + LVEQNB_Capabilities_t *pCapabilities) +{ + + LVEQNB_Instance_t *pInstance =(LVEQNB_Instance_t *)hInstance; + + if((hInstance == LVM_NULL) || (pCapabilities == LVM_NULL)) + { + return LVEQNB_NULLADDRESS; + } + + *pCapabilities = pInstance->Capabilities; + + return(LVEQNB_SUCCESS); +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_SetFilters */ +/* */ +/* DESCRIPTION: */ +/* Sets the filter type based on the definition. */ +/* */ +/* PARAMETERS: */ +/* pInstance Pointer to the instance */ +/* pParams Initialisation parameters */ +/* */ +/* RETURNS: */ +/* void Nothing */ +/* */ +/* NOTES: */ +/* 1. To select the biquad type the follow rules are applied: */ +/* Double precision if (fc <= fs/110) */ +/* Double precision if (fs/110 < fc < fs/85) & (Q>3) */ +/* Single precision otherwise */ +/* */ +/************************************************************************************/ + +void LVEQNB_SetFilters(LVEQNB_Instance_t *pInstance, + LVEQNB_Params_t *pParams) +{ + + extern const LVM_UINT16 LVEQNB_SampleRateTab[]; /* Sample rate table */ + LVM_UINT16 i; /* Filter band index */ + LVM_UINT32 fs = (LVM_UINT32)LVEQNB_SampleRateTab[(LVM_UINT16)pParams->SampleRate]; /* Sample rate */ + LVM_UINT32 fc; /* Filter centre frequency */ + LVM_INT16 QFactor; /* Filter Q factor */ + + + pInstance->NBands = pParams->NBands; + + for (i=0; iNBands; i++) + { + /* + * Get the filter settings + */ + fc = (LVM_UINT32)pParams->pBandDefinition[i].Frequency; /* Get the band centre frequency */ + QFactor = (LVM_INT16)pParams->pBandDefinition[i].QFactor; /* Get the band Q factor */ + + + /* + * For each filter set the type of biquad required + */ + pInstance->pBiquadType[i] = LVEQNB_SinglePrecision; /* Default to single precision */ + if ((fc << 15) <= (LOW_FREQ * fs)) + { + /* + * fc <= fs/110 + */ + pInstance->pBiquadType[i] = LVEQNB_DoublePrecision; + } + else if (((fc << 15) <= (HIGH_FREQ * fs)) && (QFactor > 300)) + { + /* + * (fs/110 < fc < fs/85) & (Q>3) + */ + pInstance->pBiquadType[i] = LVEQNB_DoublePrecision; + } + + + /* + * Check for out of range frequencies + */ + if (fc > (fs >> 1)) + { + pInstance->pBiquadType[i] = LVEQNB_OutOfRange; + } + + + /* + * Copy the filter definition to persistant memory + */ + pInstance->pBandDefinitions[i] = pParams->pBandDefinition[i]; + + } +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_SetCoefficients */ +/* */ +/* DESCRIPTION: */ +/* Sets the filter coefficients. This uses the type to select single or double */ +/* precision coefficients. */ +/* */ +/* PARAMETERS: */ +/* pInstance Pointer to the instance */ +/* pParams Initialisation parameters */ +/* */ +/************************************************************************************/ + +void LVEQNB_SetCoefficients(LVEQNB_Instance_t *pInstance) +{ + + LVM_UINT16 i; /* Filter band index */ + LVEQNB_BiquadType_en BiquadType; /* Filter biquad type */ + + + /* + * Set the coefficients for each band by the init function + */ + for (i=0; iParams.NBands; i++) + { + + /* + * Check band type for correct initialisation method and recalculate the coefficients + */ + BiquadType = pInstance->pBiquadType[i]; + switch (BiquadType) + { + case LVEQNB_DoublePrecision: + { + PK_C32_Coefs_t Coefficients; + + /* + * Calculate the double precision coefficients + */ + LVEQNB_DoublePrecCoefs((LVM_UINT16)pInstance->Params.SampleRate, + &pInstance->pBandDefinitions[i], + &Coefficients); + + /* + * Set the coefficients + */ + PK_2I_D32F32CllGss_TRC_WRA_01_Init(&pInstance->pEQNB_FilterState[i], + &pInstance->pEQNB_Taps[i], + &Coefficients); + break; + } + + case LVEQNB_SinglePrecision: + { + PK_C16_Coefs_t Coefficients; + + /* + * Calculate the single precision coefficients + */ + LVEQNB_SinglePrecCoefs((LVM_UINT16)pInstance->Params.SampleRate, + &pInstance->pBandDefinitions[i], + &Coefficients); + + /* + * Set the coefficients + */ + PK_2I_D32F32CssGss_TRC_WRA_01_Init(&pInstance->pEQNB_FilterState[i], + &pInstance->pEQNB_Taps[i], + &Coefficients); + break; + } + default: + break; + } + } + +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_ClearFilterHistory */ +/* */ +/* DESCRIPTION: */ +/* Clears the filter data history */ +/* */ +/* PARAMETERS: */ +/* pInstance Pointer to the instance */ +/* */ +/************************************************************************************/ + +void LVEQNB_ClearFilterHistory(LVEQNB_Instance_t *pInstance) +{ + LVM_INT16 *pTapAddress; + LVM_INT16 NumTaps; + + + pTapAddress = (LVM_INT16 *)pInstance->pEQNB_Taps; + NumTaps = (LVM_INT16)((pInstance->Capabilities.MaxBands * sizeof(Biquad_2I_Order2_Taps_t))/sizeof(LVM_INT16)); + + if (NumTaps != 0) + { + LoadConst_16(0, /* Clear the history, value 0 */ + pTapAddress, /* Destination */ + NumTaps); /* Number of words */ + } +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_Control */ +/* */ +/* DESCRIPTION: */ +/* Sets or changes the LifeVibes module parameters. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to a parameter structure */ +/* */ +/* RETURNS: */ +/* LVEQNB_Success Always succeeds */ +/* LVEQNB_NULLADDRESS Instance or pParams is NULL pointer */ +/* LVEQNB_NULLADDRESS NULL address for the equaliser filter definitions and the */ +/* number of bands is non-zero */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVEQNB_Process function */ +/* */ +/****************************************************************************************/ + +LVEQNB_ReturnStatus_en LVEQNB_Control(LVEQNB_Handle_t hInstance, + LVEQNB_Params_t *pParams) +{ + + LVEQNB_Instance_t *pInstance = (LVEQNB_Instance_t *)hInstance; + LVM_INT16 bChange = LVM_FALSE; + LVM_INT16 i = 0; + LVEQNB_Mode_en OperatingModeSave ; + + /* + * Check for error conditions + */ + if((hInstance == LVM_NULL) || (pParams == LVM_NULL)) + { + return LVEQNB_NULLADDRESS; + } + + if((pParams->NBands !=0) && (pParams->pBandDefinition==LVM_NULL)) + { + return LVEQNB_NULLADDRESS; + } + + OperatingModeSave = pInstance->Params.OperatingMode; + + /* Set the alpha factor of the mixer */ + if (pParams->SampleRate != pInstance->Params.SampleRate) + { + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->BypassMixer.MixerStream[0],LVEQNB_BYPASS_MIXER_TC,(LVM_Fs_en)pParams->SampleRate,2); + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->BypassMixer.MixerStream[1],LVEQNB_BYPASS_MIXER_TC,(LVM_Fs_en)pParams->SampleRate,2); + } + + + if( (pInstance->Params.NBands != pParams->NBands ) || + (pInstance->Params.OperatingMode != pParams->OperatingMode ) || + (pInstance->Params.pBandDefinition != pParams->pBandDefinition ) || + (pInstance->Params.SampleRate != pParams->SampleRate ) || + (pInstance->Params.SourceFormat != pParams->SourceFormat )) + { + + bChange = LVM_TRUE; + } + else + { + for(i = 0; i < pParams->NBands; i++) + { + + if((pInstance->pBandDefinitions[i].Frequency != pParams->pBandDefinition[i].Frequency )|| + (pInstance->pBandDefinitions[i].Gain != pParams->pBandDefinition[i].Gain )|| + (pInstance->pBandDefinitions[i].QFactor != pParams->pBandDefinition[i].QFactor )) + { + + bChange = LVM_TRUE; + } + } + } + + + if(bChange){ + + /* + * If the sample rate has changed clear the history + */ + if (pInstance->Params.SampleRate != pParams->SampleRate) + { + LVEQNB_ClearFilterHistory(pInstance); /* Clear the history */ + } + + /* + * Update the instance parameters + */ + pInstance->Params = *pParams; + + + /* + * Reset the filters except if the algo is switched off + */ + if(pParams->OperatingMode != LVEQNB_BYPASS){ + /* + * Reset the filters as all parameters could have changed + */ + LVEQNB_SetFilters(pInstance, /* Instance pointer */ + pParams); /* New parameters */ + + /* + * Update the filters + */ + LVEQNB_SetCoefficients(pInstance); /* Instance pointer */ + } + + if(pParams->OperatingMode != OperatingModeSave) + { + if(pParams->OperatingMode == LVEQNB_ON) + { + LVC_Mixer_SetTarget(&pInstance->BypassMixer.MixerStream[0],LVM_MAXINT_16); + LVC_Mixer_SetTarget(&pInstance->BypassMixer.MixerStream[1],0); + + pInstance->BypassMixer.MixerStream[0].CallbackSet = 1; + pInstance->BypassMixer.MixerStream[1].CallbackSet = 1; + } + else + { + /* Stay on the ON operating mode until the transition is done */ + pInstance->Params.OperatingMode = LVEQNB_ON; + + LVC_Mixer_SetTarget(&pInstance->BypassMixer.MixerStream[0],0); + LVC_Mixer_SetTarget(&pInstance->BypassMixer.MixerStream[1],LVM_MAXINT_16); + pInstance->BypassMixer.MixerStream[0].CallbackSet = 1; + pInstance->BypassMixer.MixerStream[1].CallbackSet = 1; + } + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->BypassMixer.MixerStream[0],LVEQNB_BYPASS_MIXER_TC,(LVM_Fs_en)pParams->SampleRate,2); + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->BypassMixer.MixerStream[1],LVEQNB_BYPASS_MIXER_TC,(LVM_Fs_en)pParams->SampleRate,2); + + pInstance->bInOperatingModeTransition = LVM_TRUE; + } + + } + return(LVEQNB_SUCCESS); +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_BypassMixerCallBack */ +/* */ +/* DESCRIPTION: */ +/* CallBack function of the mixer */ +/* transition */ +/* */ +/****************************************************************************************/ +LVM_INT32 LVEQNB_BypassMixerCallBack (void* hInstance, + void *pGeneralPurpose, + LVM_INT16 CallbackParam) +{ + LVEQNB_Instance_t *pInstance =(LVEQNB_Instance_t *)hInstance; + LVM_Callback CallBack = pInstance->Capabilities.CallBack; + + (void) pGeneralPurpose; + + /* + * Send an ALGOFF event if the ON->OFF switch transition is finished + */ + if((LVC_Mixer_GetTarget(&pInstance->BypassMixer.MixerStream[0]) == 0x00000000) && + (CallbackParam == 0)){ + pInstance->Params.OperatingMode = LVEQNB_BYPASS; + if (CallBack != LVM_NULL){ + CallBack(pInstance->Capabilities.pBundleInstance, LVM_NULL, ALGORITHM_EQNB_ID|LVEQNB_EVENT_ALGOFF); + } + } + + /* + * Exit transition state + */ + pInstance->bInOperatingModeTransition = LVM_FALSE; + + return 1; +} + + + + + + diff --git a/media/libeffects/lvm/lib/Eq/src/LVEQNB_Init.c b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Init.c new file mode 100755 index 0000000..a29fe05 --- /dev/null +++ b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Init.c @@ -0,0 +1,329 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1005 $ + $Date: 2010-06-28 13:58:28 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVEQNB.h" +#include "LVEQNB_Private.h" +#include "InstAlloc.h" + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_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: */ +/* LVEQNB_SUCCESS Succeeded */ +/* LVEQNB_NULLADDRESS When any of pMemoryTable and pCapabilities is NULL address */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVEQNB_Process function */ +/* */ +/****************************************************************************************/ + +LVEQNB_ReturnStatus_en LVEQNB_Memory(LVEQNB_Handle_t hInstance, + LVEQNB_MemTab_t *pMemoryTable, + LVEQNB_Capabilities_t *pCapabilities) +{ + + INST_ALLOC AllocMem; + LVEQNB_Instance_t *pInstance = (LVEQNB_Instance_t *)hInstance; + + + if((pMemoryTable == LVM_NULL)|| (pCapabilities == LVM_NULL)) + { + return LVEQNB_NULLADDRESS; + } + + + /* + * Fill in the memory table + */ + if (hInstance == LVM_NULL) + { + /* + * Instance memory + */ + InstAlloc_Init(&AllocMem, + LVM_NULL); + InstAlloc_AddMember(&AllocMem, /* Low pass filter */ + sizeof(LVEQNB_Instance_t)); + pMemoryTable->Region[LVEQNB_MEMREGION_INSTANCE].Size = InstAlloc_GetTotal(&AllocMem); + pMemoryTable->Region[LVEQNB_MEMREGION_INSTANCE].Alignment = LVEQNB_INSTANCE_ALIGN; + pMemoryTable->Region[LVEQNB_MEMREGION_INSTANCE].Type = LVEQNB_PERSISTENT; + pMemoryTable->Region[LVEQNB_MEMREGION_INSTANCE].pBaseAddress = LVM_NULL; + + + /* + * Persistant data memory + */ + InstAlloc_Init(&AllocMem, + LVM_NULL); + InstAlloc_AddMember(&AllocMem, /* Low pass filter */ + sizeof(Biquad_2I_Order2_Taps_t)); + InstAlloc_AddMember(&AllocMem, /* High pass filter */ + sizeof(Biquad_2I_Order2_Taps_t)); + InstAlloc_AddMember(&AllocMem, + (pCapabilities->MaxBands * sizeof(Biquad_2I_Order2_Taps_t))); /* Equaliser Biquad Taps */ + InstAlloc_AddMember(&AllocMem, + (pCapabilities->MaxBands * sizeof(LVEQNB_BandDef_t))); /* Filter definitions */ + InstAlloc_AddMember(&AllocMem, + (pCapabilities->MaxBands * sizeof(LVEQNB_BiquadType_en))); /* Biquad types */ + pMemoryTable->Region[LVEQNB_MEMREGION_PERSISTENT_DATA].Size = InstAlloc_GetTotal(&AllocMem); + pMemoryTable->Region[LVEQNB_MEMREGION_PERSISTENT_DATA].Alignment = LVEQNB_DATA_ALIGN; + pMemoryTable->Region[LVEQNB_MEMREGION_PERSISTENT_DATA].Type = LVEQNB_PERSISTENT_DATA; + pMemoryTable->Region[LVEQNB_MEMREGION_PERSISTENT_DATA].pBaseAddress = LVM_NULL; + + /* + * Persistant coefficient memory + */ + InstAlloc_Init(&AllocMem, + LVM_NULL); + InstAlloc_AddMember(&AllocMem, /* Low pass filter */ + sizeof(Biquad_Instance_t)); + InstAlloc_AddMember(&AllocMem, /* High pass filter */ + sizeof(Biquad_Instance_t)); + InstAlloc_AddMember(&AllocMem, + pCapabilities->MaxBands * sizeof(Biquad_Instance_t)); /* Equaliser Biquad Instance */ + pMemoryTable->Region[LVEQNB_MEMREGION_PERSISTENT_COEF].Size = InstAlloc_GetTotal(&AllocMem); + pMemoryTable->Region[LVEQNB_MEMREGION_PERSISTENT_COEF].Alignment = LVEQNB_COEF_ALIGN; + pMemoryTable->Region[LVEQNB_MEMREGION_PERSISTENT_COEF].Type = LVEQNB_PERSISTENT_COEF; + pMemoryTable->Region[LVEQNB_MEMREGION_PERSISTENT_COEF].pBaseAddress = LVM_NULL; + + /* + * Scratch memory + */ + InstAlloc_Init(&AllocMem, + LVM_NULL); + InstAlloc_AddMember(&AllocMem, /* Low pass filter */ + LVEQNB_SCRATCHBUFFERS*sizeof(LVM_INT16)*pCapabilities->MaxBlockSize); + pMemoryTable->Region[LVEQNB_MEMREGION_SCRATCH].Size = InstAlloc_GetTotal(&AllocMem); + pMemoryTable->Region[LVEQNB_MEMREGION_SCRATCH].Alignment = LVEQNB_SCRATCH_ALIGN; + pMemoryTable->Region[LVEQNB_MEMREGION_SCRATCH].Type = LVEQNB_SCRATCH; + pMemoryTable->Region[LVEQNB_MEMREGION_SCRATCH].pBaseAddress = LVM_NULL; + } + else + { + /* Read back memory allocation table */ + *pMemoryTable = pInstance->MemoryTable; + } + + return(LVEQNB_SUCCESS); +} + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_Init */ +/* */ +/* DESCRIPTION: */ +/* Create and initialisation function for the N-Band equaliser 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. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pMemoryTable Pointer to the memory definition table */ +/* pCapabilities Pointer to the instance capabilities */ +/* */ +/* RETURNS: */ +/* LVEQNB_SUCCESS Initialisation succeeded */ +/* LVEQNB_NULLADDRESS When pCapabilities or pMemoryTableis or phInstance are NULL */ +/* LVEQNB_NULLADDRESS One or more of the memory regions has a NULL base address */ +/* pointer for a memory region with a non-zero size. */ +/* */ +/* 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 LVEQNB_Process function */ +/* */ +/****************************************************************************************/ + +LVEQNB_ReturnStatus_en LVEQNB_Init(LVEQNB_Handle_t *phInstance, + LVEQNB_MemTab_t *pMemoryTable, + LVEQNB_Capabilities_t *pCapabilities) +{ + + LVEQNB_Instance_t *pInstance; + LVM_UINT32 MemSize; + INST_ALLOC AllocMem; + LVM_INT32 i; + + /* + * Check for NULL pointers + */ + if((phInstance == LVM_NULL) || (pMemoryTable == LVM_NULL) || (pCapabilities == LVM_NULL)) + { + return LVEQNB_NULLADDRESS; + } + + /* + * Check the memory table for NULL pointers + */ + for (i = 0; i < LVEQNB_NR_MEMORY_REGIONS; i++) + { + if (pMemoryTable->Region[i].Size!=0) + { + if (pMemoryTable->Region[i].pBaseAddress==LVM_NULL) + { + return(LVEQNB_NULLADDRESS); + } + } + } + + /* + * Set the instance handle if not already initialised + */ + + InstAlloc_Init(&AllocMem, pMemoryTable->Region[LVEQNB_MEMREGION_INSTANCE].pBaseAddress); + + if (*phInstance == LVM_NULL) + { + *phInstance = InstAlloc_AddMember(&AllocMem, sizeof(LVEQNB_Instance_t)); + } + pInstance =(LVEQNB_Instance_t *)*phInstance; + + + + /* + * Save the memory table in the instance structure + */ + pInstance->Capabilities = *pCapabilities; + + + /* + * Save the memory table in the instance structure and + * set the structure pointers + */ + pInstance->MemoryTable = *pMemoryTable; + + /* + * Allocate coefficient memory + */ + InstAlloc_Init(&AllocMem, + pMemoryTable->Region[LVEQNB_MEMREGION_PERSISTENT_COEF].pBaseAddress); + + pInstance->pEQNB_FilterState = InstAlloc_AddMember(&AllocMem, + pCapabilities->MaxBands * sizeof(Biquad_Instance_t)); /* Equaliser Biquad Instance */ + + + + /* + * Allocate data memory + */ + InstAlloc_Init(&AllocMem, + pMemoryTable->Region[LVEQNB_MEMREGION_PERSISTENT_DATA].pBaseAddress); + + MemSize = (pCapabilities->MaxBands * sizeof(Biquad_2I_Order2_Taps_t)); + pInstance->pEQNB_Taps = (Biquad_2I_Order2_Taps_t *)InstAlloc_AddMember(&AllocMem, + MemSize); + MemSize = (pCapabilities->MaxBands * sizeof(LVEQNB_BandDef_t)); + pInstance->pBandDefinitions = (LVEQNB_BandDef_t *)InstAlloc_AddMember(&AllocMem, + MemSize); + MemSize = (pCapabilities->MaxBands * sizeof(LVEQNB_BiquadType_en)); + pInstance->pBiquadType = (LVEQNB_BiquadType_en *)InstAlloc_AddMember(&AllocMem, + MemSize); + + + /* + * Internally map, structure and allign scratch memory + */ + InstAlloc_Init(&AllocMem, + pMemoryTable->Region[LVEQNB_MEMREGION_SCRATCH].pBaseAddress); + + pInstance->pFastTemporary = (LVM_INT16 *)InstAlloc_AddMember(&AllocMem, + sizeof(LVM_INT16)); + + /* + * Update the instance parameters + */ + pInstance->Params.NBands = 0; + pInstance->Params.OperatingMode = LVEQNB_BYPASS; + pInstance->Params.pBandDefinition = LVM_NULL; + pInstance->Params.SampleRate = LVEQNB_FS_8000; + pInstance->Params.SourceFormat = LVEQNB_STEREO; + + /* + * Initialise the filters + */ + LVEQNB_SetFilters(pInstance, /* Set the filter types */ + &pInstance->Params); + + LVEQNB_SetCoefficients(pInstance); /* Set the filter coefficients */ + + LVEQNB_ClearFilterHistory(pInstance); /* Clear the filter history */ + + /* + * Initialise the bypass variables + */ + pInstance->BypassMixer.MixerStream[0].CallbackSet = 0; + pInstance->BypassMixer.MixerStream[0].CallbackParam = 0; + pInstance->BypassMixer.MixerStream[0].pCallbackHandle = (void*)pInstance; + pInstance->BypassMixer.MixerStream[0].pCallBack = LVEQNB_BypassMixerCallBack; + LVC_Mixer_Init(&pInstance->BypassMixer.MixerStream[0],0,0); + LVC_Mixer_SetTimeConstant(&pInstance->BypassMixer.MixerStream[0],0,LVM_FS_8000,2); + + pInstance->BypassMixer.MixerStream[1].CallbackSet = 1; + pInstance->BypassMixer.MixerStream[1].CallbackParam = 0; + pInstance->BypassMixer.MixerStream[1].pCallbackHandle = LVM_NULL; + pInstance->BypassMixer.MixerStream[1].pCallBack = LVM_NULL; + LVC_Mixer_Init(&pInstance->BypassMixer.MixerStream[1],0,LVM_MAXINT_16); + LVC_Mixer_SetTimeConstant(&pInstance->BypassMixer.MixerStream[1],0,LVM_FS_8000,2); + + pInstance->bInOperatingModeTransition = LVM_FALSE; + + return(LVEQNB_SUCCESS); +} + diff --git a/media/libeffects/lvm/lib/Eq/src/LVEQNB_Private.h b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Private.h new file mode 100755 index 0000000..0ae84af --- /dev/null +++ b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Private.h @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1005 $ + $Date: 2010-06-28 13:58:28 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +#ifndef __LVEQNB_PRIVATE_H__ +#define __LVEQNB_PRIVATE_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVEQNB.h" /* Calling or Application layer definitions */ +#include "BIQUAD.h" +#include "LVC_Mixer.h" + +/****************************************************************************************/ +/* */ +/* Defines */ +/* */ +/****************************************************************************************/ + +/* General */ +#define LVEQNB_INVALID 0xFFFF /* Invalid init parameter */ + +/* Memory */ +#define LVEQNB_INSTANCE_ALIGN 4 /* 32-bit alignment for instance structures */ +#define LVEQNB_DATA_ALIGN 4 /* 32-bit alignment for structures */ +#define LVEQNB_COEF_ALIGN 4 /* 32-bit alignment for long words */ +#define LVEQNB_SCRATCHBUFFERS 4 /* Number of buffers required for inplace processing */ +#define LVEQNB_SCRATCH_ALIGN 4 /* 32-bit alignment for long data */ + +#define LVEQNB_BYPASS_MIXER_TC 100 /* Bypass Mixer TC */ + +/****************************************************************************************/ +/* */ +/* Types */ +/* */ +/****************************************************************************************/ + +/* Filter biquad types */ +typedef enum +{ + LVEQNB_SinglePrecision = 0, + LVEQNB_DoublePrecision = 1, + LVEQNB_OutOfRange = 2, + LVEQNB_BIQUADTYPE_MAX = LVM_MAXINT_32 +} LVEQNB_BiquadType_en; + + +/****************************************************************************************/ +/* */ +/* Structures */ +/* */ +/****************************************************************************************/ + + + +/* Instance structure */ +typedef struct +{ + /* Public parameters */ + LVEQNB_MemTab_t MemoryTable; /* Instance memory allocation table */ + LVEQNB_Params_t Params; /* Instance parameters */ + LVEQNB_Capabilities_t Capabilities; /* Instance capabilities */ + + /* Aligned memory pointers */ + LVM_INT16 *pFastTemporary; /* Fast temporary data base address */ + + /* Process variables */ + Biquad_2I_Order2_Taps_t *pEQNB_Taps; /* Equaliser Taps */ + Biquad_Instance_t *pEQNB_FilterState; /* State for each filter band */ + + /* Filter definitions and call back */ + LVM_UINT16 NBands; /* Number of bands */ + LVEQNB_BandDef_t *pBandDefinitions; /* Filter band definitions */ + LVEQNB_BiquadType_en *pBiquadType; /* Filter biquad types */ + + /* Bypass variable */ + LVMixer3_2St_st BypassMixer; /* Bypass mixer used in transitions */ + LVM_INT16 bInOperatingModeTransition; /* Operating mode transition flag */ + +} LVEQNB_Instance_t; + + +/****************************************************************************************/ +/* */ +/* Function prototypes */ +/* */ +/****************************************************************************************/ + +void LVEQNB_SetFilters(LVEQNB_Instance_t *pInstance, + LVEQNB_Params_t *pParams); + +void LVEQNB_SetCoefficients(LVEQNB_Instance_t *pInstance); + +void LVEQNB_ClearFilterHistory(LVEQNB_Instance_t *pInstance); + +LVEQNB_ReturnStatus_en LVEQNB_SinglePrecCoefs(LVM_UINT16 Fs, + LVEQNB_BandDef_t *pFilterDefinition, + PK_C16_Coefs_t *pCoefficients); + +LVEQNB_ReturnStatus_en LVEQNB_DoublePrecCoefs(LVM_UINT16 Fs, + LVEQNB_BandDef_t *pFilterDefinition, + PK_C32_Coefs_t *pCoefficients); + +LVM_INT32 LVEQNB_BypassMixerCallBack (void* hInstance, void *pGeneralPurpose, LVM_INT16 CallbackParam); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LVEQNB_PRIVATE_H__ */ + diff --git a/media/libeffects/lvm/lib/Eq/src/LVEQNB_Process.c b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Process.c new file mode 100755 index 0000000..e29e881 --- /dev/null +++ b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Process.c @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/********************************************************************************** + + $Author: beq07716 $ + $Revision: 1005 $ + $Date: 2010-06-28 13:58:28 +0200 (Mon, 28 Jun 2010) $ + +***********************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVEQNB.h" +#include "LVEQNB_Private.h" +#include "VectorArithmetic.h" +#include "BIQUAD.h" + + +/****************************************************************************************/ +/* */ +/* Defines */ +/* */ +/****************************************************************************************/ + +#define SHIFT 13 + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_Process */ +/* */ +/* DESCRIPTION: */ +/* Process function for the N-Band Equaliser module. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pInData Pointer to the input data */ +/* pOutData Pointer to the output data */ +/* NumSamples Number of samples in the input buffer */ +/* */ +/* RETURNS: */ +/* LVEQNB_SUCCESS Succeeded */ +/* LVEQNB_NULLADDRESS When hInstance, pInData or pOutData are NULL */ +/* LVEQNB_ALIGNMENTERROR When pInData or pOutData are not 32-bit aligned */ +/* LVEQNB_TOOMANYSAMPLES NumSamples was larger than the maximum block size */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +LVEQNB_ReturnStatus_en LVEQNB_Process(LVEQNB_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 *pOutData, + LVM_UINT16 NumSamples) +{ + + LVM_UINT16 i; + Biquad_Instance_t *pBiquad; + LVEQNB_Instance_t *pInstance = (LVEQNB_Instance_t *)hInstance; + LVM_INT32 *pScratch; + + + /* Check for NULL pointers */ + if((hInstance == LVM_NULL) || (pInData == LVM_NULL) || (pOutData == LVM_NULL)) + { + return LVEQNB_NULLADDRESS; + } + + /* Check if the input and output data buffers are 32-bit aligned */ + if ((((LVM_INT32)pInData % 4) != 0) || (((LVM_INT32)pOutData % 4) != 0)) + { + return LVEQNB_ALIGNMENTERROR; + } + + pScratch = (LVM_INT32 *)pInstance->pFastTemporary; + + /* + * Check the number of samples is not too large + */ + if (NumSamples > pInstance->Capabilities.MaxBlockSize) + { + return(LVEQNB_TOOMANYSAMPLES); + } + + if (pInstance->Params.OperatingMode == LVEQNB_ON) + { + /* + * Convert from 16-bit to 32-bit + */ + Int16LShiftToInt32_16x32((LVM_INT16 *)pInData, /* Source */ + pScratch, /* Destination */ + (LVM_INT16)(2*NumSamples), /* Left and Right */ + SHIFT); /* Scaling shift */ + + /* + * For each section execte the filter unless the gain is 0dB + */ + if (pInstance->NBands != 0) + { + for (i=0; iNBands; i++) + { + /* + * Check if band is non-zero dB gain + */ + if (pInstance->pBandDefinitions[i].Gain != 0) + { + /* + * Get the address of the biquad instance + */ + pBiquad = &pInstance->pEQNB_FilterState[i]; + + + /* + * Select single or double precision as required + */ + switch (pInstance->pBiquadType[i]) + { + case LVEQNB_SinglePrecision: + { + PK_2I_D32F32C14G11_TRC_WRA_01(pBiquad, + (LVM_INT32 *)pScratch, + (LVM_INT32 *)pScratch, + (LVM_INT16)NumSamples); + break; + } + + case LVEQNB_DoublePrecision: + { + PK_2I_D32F32C30G11_TRC_WRA_01(pBiquad, + (LVM_INT32 *)pScratch, + (LVM_INT32 *)pScratch, + (LVM_INT16)NumSamples); + break; + } + default: + break; + } + } + } + } + + + if(pInstance->bInOperatingModeTransition == LVM_TRUE){ + /* + * Convert from 32-bit to 16- bit and saturate + */ + Int32RShiftToInt16_Sat_32x16(pScratch, /* Source */ + (LVM_INT16 *)pScratch, /* Destination */ + (LVM_INT16)(2*NumSamples), /* Left and Right */ + SHIFT); /* Scaling shift */ + + LVC_MixSoft_2St_D16C31_SAT(&pInstance->BypassMixer, + (LVM_INT16 *)pScratch, + (LVM_INT16 *)pInData, + (LVM_INT16 *)pScratch, + (LVM_INT16)(2*NumSamples)); + + Copy_16((LVM_INT16*)pScratch, /* Source */ + pOutData, /* Destination */ + (LVM_INT16)(2*NumSamples)); /* Left and Right samples */ + } + else{ + + /* + * Convert from 32-bit to 16- bit and saturate + */ + Int32RShiftToInt16_Sat_32x16(pScratch, /* Source */ + pOutData, /* Destination */ + (LVM_INT16 )(2*NumSamples), /* Left and Right */ + SHIFT); /* Scaling shift */ + } + } + else + { + /* + * Mode is OFF so copy the data if necessary + */ + if (pInData != pOutData) + { + Copy_16(pInData, /* Source */ + pOutData, /* Destination */ + (LVM_INT16)(2*NumSamples)); /* Left and Right samples */ + } + } + + + + return(LVEQNB_SUCCESS); + +} diff --git a/media/libeffects/lvm/lib/Eq/src/LVEQNB_Tables.c b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Tables.c new file mode 100755 index 0000000..33c07da --- /dev/null +++ b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Tables.c @@ -0,0 +1,203 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1005 $ + $Date: 2010-06-28 13:58:28 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVEQNB.h" +#include "LVEQNB_Coeffs.h" + + +/************************************************************************************/ +/* */ +/* Sample rate table */ +/* */ +/************************************************************************************/ + +/* + * Sample rate table for converting between the enumerated type and the actual + * frequency + */ +const LVM_UINT16 LVEQNB_SampleRateTab[] = {8000, /* 8kS/s */ + 11025, + 12000, + 16000, + 22050, + 24000, + 32000, + 44100, + 48000}; /* 48kS/s */ + + +/************************************************************************************/ +/* */ +/* Coefficient calculation tables */ +/* */ +/************************************************************************************/ + +/* + * Table for 2 * Pi / Fs + */ +const LVM_INT16 LVEQNB_TwoPiOnFsTable[] = {LVEQNB_2PiOn_8000, /* 8kS/s */ + LVEQNB_2PiOn_11025, + LVEQNB_2PiOn_12000, + LVEQNB_2PiOn_16000, + LVEQNB_2PiOn_22050, + LVEQNB_2PiOn_24000, + LVEQNB_2PiOn_32000, + LVEQNB_2PiOn_44100, + LVEQNB_2PiOn_48000}; /* 48kS/s */ + +/* + * Gain table + */ +const LVM_INT16 LVEQNB_GainTable[] = {LVEQNB_Gain_Neg15_dB, /* -15dB gain */ + LVEQNB_Gain_Neg14_dB, + LVEQNB_Gain_Neg13_dB, + LVEQNB_Gain_Neg12_dB, + LVEQNB_Gain_Neg11_dB, + LVEQNB_Gain_Neg10_dB, + LVEQNB_Gain_Neg9_dB, + LVEQNB_Gain_Neg8_dB, + LVEQNB_Gain_Neg7_dB, + LVEQNB_Gain_Neg6_dB, + LVEQNB_Gain_Neg5_dB, + LVEQNB_Gain_Neg4_dB, + LVEQNB_Gain_Neg3_dB, + LVEQNB_Gain_Neg2_dB, + LVEQNB_Gain_Neg1_dB, + LVEQNB_Gain_0_dB, /* 0dB gain */ + LVEQNB_Gain_1_dB, + LVEQNB_Gain_2_dB, + LVEQNB_Gain_3_dB, + LVEQNB_Gain_4_dB, + LVEQNB_Gain_5_dB, + LVEQNB_Gain_6_dB, + LVEQNB_Gain_7_dB, + LVEQNB_Gain_8_dB, + LVEQNB_Gain_9_dB, + LVEQNB_Gain_10_dB, + LVEQNB_Gain_11_dB, + LVEQNB_Gain_12_dB, + LVEQNB_Gain_13_dB, + LVEQNB_Gain_14_dB, + LVEQNB_Gain_15_dB}; /* +15dB gain */ + + +/* + * D table for 100 / (Gain + 1) + */ +const LVM_INT16 LVEQNB_DTable[] = {LVEQNB_100D_Neg15_dB, /* -15dB gain */ + LVEQNB_100D_Neg14_dB, + LVEQNB_100D_Neg13_dB, + LVEQNB_100D_Neg12_dB, + LVEQNB_100D_Neg11_dB, + LVEQNB_100D_Neg10_dB, + LVEQNB_100D_Neg9_dB, + LVEQNB_100D_Neg8_dB, + LVEQNB_100D_Neg7_dB, + LVEQNB_100D_Neg6_dB, + LVEQNB_100D_Neg5_dB, + LVEQNB_100D_Neg4_dB, + LVEQNB_100D_Neg3_dB, + LVEQNB_100D_Neg2_dB, + LVEQNB_100D_Neg1_dB, + LVEQNB_100D_0_dB}; /* 0dB gain */ + + +/************************************************************************************/ +/* */ +/* Filter polynomial coefficients */ +/* */ +/************************************************************************************/ + +/* + * Coefficients for calculating the cosine with the equation: + * + * Cos(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + a5*x^5) + * + * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting + * a range of 0 to Pi. The output is in the range 32767 to -32768 representing the range + * +1.0 to -1.0 + */ +const LVM_INT16 LVEQNB_CosCoef[] = {3, /* Shifts */ + 4096, /* a0 */ + -36, /* a1 */ + -19725, /* a2 */ + -2671, /* a3 */ + 23730, /* a4 */ + -9490}; /* a5 */ + +/* + * Coefficients for calculating the cosine error with the equation: + * + * CosErr(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3) + * + * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting + * a range of 0 to Pi/25. The output is in the range 0 to 32767 representing the range + * 0.0 to 0.0078852986 + * + * This is used to give a double precision cosine over the range 0 to Pi/25 using the + * the equation: + * + * Cos(x) = 1.0 - CosErr(x) + */ +const LVM_INT16 LVEQNB_DPCosCoef[] = {1, /* Shifts */ + 0, /* a0 */ + -6, /* a1 */ + 16586, /* a2 */ + -44}; /* a3 */ + +/************************************************************************************/ +/* */ +/* Bypass mixer time constants (100ms) */ +/* */ +/************************************************************************************/ + +#define LVEQNB_MIX_TC_Fs8000 32580 /* Floating point value 0.994262695 */ +#define LVEQNB_MIX_TC_Fs11025 32632 /* Floating point value 0.995849609 */ +#define LVEQNB_MIX_TC_Fs12000 32643 /* Floating point value 0.996185303 */ +#define LVEQNB_MIX_TC_Fs16000 32674 /* Floating point value 0.997131348 */ +#define LVEQNB_MIX_TC_Fs22050 32700 /* Floating point value 0.997924805 */ +#define LVEQNB_MIX_TC_Fs24000 32705 /* Floating point value 0.998077393 */ +#define LVEQNB_MIX_TC_Fs32000 32721 /* Floating point value 0.998565674 */ +#define LVEQNB_MIX_TC_Fs44100 32734 /* Floating point value 0.998962402 */ +#define LVEQNB_MIX_TC_Fs48000 32737 /* Floating point value 0.999053955 */ + + +const LVM_INT16 LVEQNB_MixerTCTable[] = { + LVEQNB_MIX_TC_Fs8000, + LVEQNB_MIX_TC_Fs11025, + LVEQNB_MIX_TC_Fs12000, + LVEQNB_MIX_TC_Fs16000, + LVEQNB_MIX_TC_Fs22050, + LVEQNB_MIX_TC_Fs24000, + LVEQNB_MIX_TC_Fs32000, + LVEQNB_MIX_TC_Fs44100, + LVEQNB_MIX_TC_Fs48000}; diff --git a/media/libeffects/lvm/lib/SpectrumAnalyzer/lib/LVPSA.h b/media/libeffects/lvm/lib/SpectrumAnalyzer/lib/LVPSA.h new file mode 100755 index 0000000..b9903b2 --- /dev/null +++ b/media/libeffects/lvm/lib/SpectrumAnalyzer/lib/LVPSA.h @@ -0,0 +1,298 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: PSA_01_ARMC_01 */ +/* $Author: beq07716 $*/ +/* $Revision: 1006 $*/ +/* $Date: 2010-06-28 14:01:47 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ +#ifndef _LVPSA_H_ +#define _LVPSA_H_ + + +#include "LVM_Types.h" + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************************/ +/* */ +/* CONSTANTS DEFINITIONS */ +/* */ +/****************************************************************************************/ + +/* Memory table*/ +#define LVPSA_NR_MEMORY_REGIONS 4 /* Number of memory regions */ + +/****************************************************************************************/ +/* */ +/* TYPES DEFINITIONS */ +/* */ +/****************************************************************************************/ +/* Memory Types */ +typedef enum +{ + LVPSA_PERSISTENT = LVM_PERSISTENT, + LVPSA_PERSISTENT_DATA = LVM_PERSISTENT_DATA, + LVPSA_PERSISTENT_COEF = LVM_PERSISTENT_COEF, + LVPSA_SCRATCH = LVM_SCRATCH, + LVPSA_MEMORY_DUMMY = LVM_MAXINT_32 /* Force 32 bits enum, don't use it! */ +} LVPSA_MemoryTypes_en; + +/* Level detection speed control parameters */ +typedef enum +{ + LVPSA_SPEED_LOW, /* Low speed level detection */ + LVPSA_SPEED_MEDIUM, /* Medium speed level detection */ + LVPSA_SPEED_HIGH, /* High speed level detection */ + LVPSA_SPEED_DUMMY = LVM_MAXINT_32 /* Force 32 bits enum, don't use it! */ +} LVPSA_LevelDetectSpeed_en; + +/* Filter control parameters */ +typedef struct +{ + LVM_UINT16 CenterFrequency; /* Center frequency of the band-pass filter (in Hz) */ + LVM_UINT16 QFactor; /* Quality factor of the filter (in 1/100) */ + LVM_INT16 PostGain; /* Postgain to apply after the filtering (in dB Q16.0) */ + +} LVPSA_FilterParam_t; + +/* LVPSA initialization parameters */ +typedef struct +{ + LVM_UINT16 SpectralDataBufferDuration; /* Spectral data buffer duration in time (ms in Q16.0) */ + LVM_UINT16 MaxInputBlockSize; /* Maximum expected input block size (in samples) */ + LVM_UINT16 nBands; /* Number of bands of the SA */ + LVPSA_FilterParam_t *pFiltersParams; /* Points to nBands filter param structures for filters settings */ + +} LVPSA_InitParams_t, *pLVPSA_InitParams_t; + +/* LVPSA control parameters */ +typedef struct +{ + LVM_Fs_en Fs; /* Input sampling rate */ + LVPSA_LevelDetectSpeed_en LevelDetectionSpeed; /* Level detection speed */ + +} LVPSA_ControlParams_t, *pLVPSA_ControlParams_t; + +/* Memory region definition */ +typedef struct +{ + LVM_UINT32 Size; /* Region size in bytes */ + LVPSA_MemoryTypes_en Type; /* Region type */ + void *pBaseAddress; /* Pointer to the region base address */ +} LVPSA_MemoryRegion_t; + +/* Memory table containing the region definitions */ +typedef struct +{ + LVPSA_MemoryRegion_t Region[LVPSA_NR_MEMORY_REGIONS];/* One definition for each region */ +} LVPSA_MemTab_t; + +/* Audio time type */ +typedef LVM_INT32 LVPSA_Time; + +/* Module instance Handle */ +typedef void *pLVPSA_Handle_t; + +/* LVPSA return codes */ +typedef enum +{ + LVPSA_OK, /* The function ran without any problem */ + LVPSA_ERROR_INVALIDPARAM, /* A parameter is incorrect */ + LVPSA_ERROR_WRONGTIME, /* An incorrect AudioTime is used */ + LVPSA_ERROR_NULLADDRESS, /* A pointer has a NULL value */ + LVPSA_RETURN_DUMMY = LVM_MAXINT_32 /* Force 32 bits enum, don't use it! */ +} LVPSA_RETURN; + + + +/********************************************************************************************************************************* + FUNCTIONS PROTOTYPE +**********************************************************************************************************************************/ +/*********************************************************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_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 */ +/* pInitParams Pointer to the instance init parameters */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/*********************************************************************************************************************************/ +LVPSA_RETURN LVPSA_Memory ( pLVPSA_Handle_t hInstance, + LVPSA_MemTab_t *pMemoryTable, + LVPSA_InitParams_t *pInitParams ); + +/*********************************************************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_Init */ +/* */ +/* DESCRIPTION: */ +/* Initializes the LVPSA module. */ +/* */ +/* */ +/* PARAMETERS: */ +/* phInstance Pointer to the instance Handle */ +/* pInitParams Pointer to the instance init parameters */ +/* pControlParams Pointer to the instance control parameters */ +/* pMemoryTable Pointer to the memory definition table */ +/* */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/*********************************************************************************************************************************/ +LVPSA_RETURN LVPSA_Init ( pLVPSA_Handle_t *phInstance, + LVPSA_InitParams_t *pInitParams, + LVPSA_ControlParams_t *pControlParams, + LVPSA_MemTab_t *pMemoryTable ); + +/*********************************************************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_Control */ +/* */ +/* DESCRIPTION: */ +/* Controls the LVPSA module. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pNewParams Pointer to the instance new control parameters */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/*********************************************************************************************************************************/ +LVPSA_RETURN LVPSA_Control ( pLVPSA_Handle_t hInstance, + LVPSA_ControlParams_t *pNewParams ); + +/*********************************************************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_Process */ +/* */ +/* DESCRIPTION: */ +/* The process calculates the levels of the frequency bands. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pLVPSA_InputSamples Pointer to the input samples buffer */ +/* InputBlockSize Number of mono samples to process */ +/* AudioTime Playback time of the first input sample */ +/* */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/*********************************************************************************************************************************/ +LVPSA_RETURN LVPSA_Process ( pLVPSA_Handle_t hInstance, + LVM_INT16 *pLVPSA_InputSamples, + LVM_UINT16 InputBlockSize, + LVPSA_Time AudioTime ); + +/*********************************************************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_GetSpectrum */ +/* */ +/* DESCRIPTION: */ +/* This function is used for memory allocation and free. */ +/* */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* GetSpectrumAudioTime Time to retrieve the values at */ +/* pCurrentValues Pointer to an empty buffer : Current level values output */ +/* pPeakValues Pointer to an empty buffer : Peak level values output */ +/* */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/*********************************************************************************************************************************/ +LVPSA_RETURN LVPSA_GetSpectrum ( pLVPSA_Handle_t hInstance, + LVPSA_Time GetSpectrumAudioTime, + LVM_UINT8 *pCurrentValues, + LVM_UINT8 *pPeakValues ); + +/*********************************************************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_GetControlParams */ +/* */ +/* DESCRIPTION: */ +/* Get the current control parameters of the LVPSA module. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pParams Pointer to an empty control parameters structure */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/*********************************************************************************************************************************/ +LVPSA_RETURN LVPSA_GetControlParams ( pLVPSA_Handle_t hInstance, + LVPSA_ControlParams_t *pParams ); + +/*********************************************************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_GetInitParams */ +/* */ +/* DESCRIPTION: */ +/* Get the initialization parameters of the LVPSA module. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pParams Pointer to an empty init parameters structure */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/*********************************************************************************************************************************/ +LVPSA_RETURN LVPSA_GetInitParams ( pLVPSA_Handle_t hInstance, + LVPSA_InitParams_t *pParams ); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _LVPSA_H */ diff --git a/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Control.c b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Control.c new file mode 100755 index 0000000..1be8ff0 --- /dev/null +++ b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Control.c @@ -0,0 +1,715 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: PSA_01_ARMC_01 */ +/* $Author: beq07716 $*/ +/* $Revision: 1006 $*/ +/* $Date: 2010-06-28 14:01:47 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ +#include "LVPSA.h" +#include "LVPSA_Private.h" +#include "VectorArithmetic.h" + +#define LOW_FREQ 298 /* 32768/110 for low test frequency */ +#define HIGH_FREQ 386 /* 32768/85 for high test frequency */ + +LVPSA_RETURN LVPSA_SetBPFiltersType ( LVPSA_InstancePr_t *pInst, + LVPSA_ControlParams_t *pParams ); + +LVPSA_RETURN LVPSA_SetQPFCoefficients( LVPSA_InstancePr_t *pInst, + LVPSA_ControlParams_t *pParams ); + +LVPSA_RETURN LVPSA_BPSinglePrecCoefs( LVM_UINT16 Fs, + LVPSA_FilterParam_t *pFilterParams, + BP_C16_Coefs_t *pCoefficients); + +LVPSA_RETURN LVPSA_BPDoublePrecCoefs( LVM_UINT16 Fs, + LVPSA_FilterParam_t *pFilterParams, + BP_C32_Coefs_t *pCoefficients); + +LVPSA_RETURN LVPSA_BPDoublePrecCoefs( LVM_UINT16 Fs, + LVPSA_FilterParam_t *pFilterParams, + BP_C32_Coefs_t *pCoefficients); + +LVPSA_RETURN LVPSA_SetBPFCoefficients( LVPSA_InstancePr_t *pInst, + LVPSA_ControlParams_t *pParams ); + +LVPSA_RETURN LVPSA_ClearFilterHistory( LVPSA_InstancePr_t *pInst); + + + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_Control */ +/* */ +/* DESCRIPTION: */ +/* Give some new control parameters to the module. */ +/* */ +/* PARAMETERS: */ +/* hInstance Pointer to the instance */ +/* NewParams Structure that contains the new parameters */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/************************************************************************************/ +LVPSA_RETURN LVPSA_Control ( pLVPSA_Handle_t hInstance, + LVPSA_ControlParams_t *pNewParams ) +{ + + LVPSA_InstancePr_t *pLVPSA_Inst = (LVPSA_InstancePr_t*)hInstance; + + if((hInstance == LVM_NULL) || (pNewParams == LVM_NULL)) + { + return(LVPSA_ERROR_NULLADDRESS); + } + if(pNewParams->Fs >= LVPSA_NR_SUPPORTED_RATE) + { + return(LVPSA_ERROR_INVALIDPARAM); + } + if(pNewParams->LevelDetectionSpeed >= LVPSA_NR_SUPPORTED_SPEED) + { + return(LVPSA_ERROR_INVALIDPARAM); + } + + pLVPSA_Inst->NewParams = *pNewParams; + pLVPSA_Inst->bControlPending = LVM_TRUE; + + return(LVPSA_OK); +} + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_GetControlParams */ +/* */ +/* DESCRIPTION: */ +/* Get the current control parameters of the module */ +/* */ +/* PARAMETERS: */ +/* hInstance Pointer to the instance */ +/* pParams Pointer to an empty control structure */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/************************************************************************************/ +LVPSA_RETURN LVPSA_GetControlParams ( pLVPSA_Handle_t hInstance, + LVPSA_ControlParams_t *pParams ) +{ + LVPSA_InstancePr_t *pLVPSA_Inst = (LVPSA_InstancePr_t*)hInstance; + + if((hInstance == LVM_NULL) || (pParams == LVM_NULL)) + { + return(LVPSA_ERROR_NULLADDRESS); + } + + pParams->Fs = pLVPSA_Inst->CurrentParams.Fs; + pParams->LevelDetectionSpeed = pLVPSA_Inst->CurrentParams.LevelDetectionSpeed; + + return(LVPSA_OK); +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_GetInitParams */ +/* */ +/* DESCRIPTION: */ +/* Get the initialization parameters of the module */ +/* */ +/* PARAMETERS: */ +/* hInstance Pointer to the instance */ +/* pParams Pointer to an empty control structure */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/************************************************************************************/ +LVPSA_RETURN LVPSA_GetInitParams ( pLVPSA_Handle_t hInstance, + LVPSA_InitParams_t *pParams ) +{ + LVPSA_InstancePr_t *pLVPSA_Inst = (LVPSA_InstancePr_t*)hInstance; + + if((hInstance == LVM_NULL) || (pParams == LVM_NULL)) + { + return(LVPSA_ERROR_NULLADDRESS); + } + + pParams->SpectralDataBufferDuration = pLVPSA_Inst->SpectralDataBufferDuration; + pParams->MaxInputBlockSize = pLVPSA_Inst->MaxInputBlockSize; + pParams->nBands = pLVPSA_Inst->nBands; + pParams->pFiltersParams = pLVPSA_Inst->pFiltersParams; + + return(LVPSA_OK); +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_ApplyNewSettings */ +/* */ +/* DESCRIPTION: */ +/* Reinitialize some parameters and changes filters' coefficients if */ +/* some control parameters have changed. */ +/* */ +/* PARAMETERS: */ +/* pInst Pointer to the instance */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/* NOTES: */ +/* */ +/************************************************************************************/ +LVPSA_RETURN LVPSA_ApplyNewSettings (LVPSA_InstancePr_t *pInst) +{ + LVM_UINT16 ii; + LVM_UINT16 Freq; + LVPSA_ControlParams_t Params; + extern LVM_INT16 LVPSA_nSamplesBufferUpdate[]; + extern LVM_UINT16 LVPSA_SampleRateTab[]; + extern LVM_UINT16 LVPSA_DownSamplingFactor[]; + + + if(pInst == 0) + { + return(LVPSA_ERROR_NULLADDRESS); + } + + Params = pInst->NewParams; + + /* Modifies filters types and coefficients, clear the taps and + re-initializes parameters if sample frequency has changed */ + if(Params.Fs != pInst->CurrentParams.Fs) + { + pInst->CurrentParams.Fs = Params.Fs; + + /* Initialize the center freqeuncies as a function of the sample rate */ + Freq = (LVM_UINT16) ((LVPSA_SampleRateTab[pInst->CurrentParams.Fs]>>1) / (pInst->nBands + 1)); + for(ii = pInst->nBands; ii > 0; ii--) + { + pInst->pFiltersParams[ii-1].CenterFrequency = (LVM_UINT16) (Freq * ii); + } + + /* Count the number of relevant filters. If the center frequency of the filter is + bigger than the nyquist frequency, then the filter is not relevant and doesn't + need to be used */ + for(ii = pInst->nBands; ii > 0; ii--) + { + if(pInst->pFiltersParams[ii-1].CenterFrequency < (LVPSA_SampleRateTab[pInst->CurrentParams.Fs]>>1)) + { + pInst->nRelevantFilters = ii; + break; + } + } + LVPSA_SetBPFiltersType(pInst, &Params); + LVPSA_SetBPFCoefficients(pInst, &Params); + LVPSA_SetQPFCoefficients(pInst, &Params); + LVPSA_ClearFilterHistory(pInst); + pInst->nSamplesBufferUpdate = (LVM_UINT16)LVPSA_nSamplesBufferUpdate[Params.Fs]; + pInst->BufferUpdateSamplesCount = 0; + pInst->DownSamplingFactor = LVPSA_DownSamplingFactor[Params.Fs]; + pInst->DownSamplingCount = 0; + for(ii = 0; ii < (pInst->nBands * pInst->SpectralDataBufferLength); ii++) + { + pInst->pSpectralDataBufferStart[ii] = 0; + } + for(ii = 0; ii < pInst->nBands; ii++) + { + pInst->pPreviousPeaks[ii] = 0; + } + } + else + { + if(Params.LevelDetectionSpeed != pInst->CurrentParams.LevelDetectionSpeed) + { + LVPSA_SetQPFCoefficients(pInst, &Params); + } + } + + pInst->CurrentParams = pInst->NewParams; + + return (LVPSA_OK); +} +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_SetBPFiltersType */ +/* */ +/* DESCRIPTION: */ +/* Sets the filter type based on the BPFilterType. */ +/* */ +/* PARAMETERS: */ +/* pInst Pointer to the instance */ +/* pParams Poniter to conrol parameters */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Always succeeds */ +/* */ +/* NOTES: */ +/* 1. To select the biquad type the follow rules are applied: */ +/* Double precision if (fc <= fs/110) */ +/* Double precision if (fs/110 < fc < fs/85) & (Q>3) */ +/* Single precision otherwise */ +/* */ +/************************************************************************************/ +LVPSA_RETURN LVPSA_SetBPFiltersType ( LVPSA_InstancePr_t *pInst, + LVPSA_ControlParams_t *pParams ) +{ + + extern LVM_UINT16 LVPSA_SampleRateTab[]; /* Sample rate table */ + LVM_UINT16 ii; /* Filter band index */ + LVM_UINT32 fs = (LVM_UINT32)LVPSA_SampleRateTab[(LVM_UINT16)pParams->Fs]; /* Sample rate */ + LVM_UINT32 fc; /* Filter centre frequency */ + LVM_INT16 QFactor; /* Filter Q factor */ + + for (ii = 0; ii < pInst->nRelevantFilters; ii++) + { + /* + * Get the filter settings + */ + fc = (LVM_UINT32)pInst->pFiltersParams[ii].CenterFrequency; /* Get the band centre frequency */ + QFactor =(LVM_INT16) pInst->pFiltersParams[ii].QFactor; /* Get the band Q factor */ + + + /* + * For each filter set the type of biquad required + */ + pInst->pBPFiltersPrecision[ii] = LVPSA_SimplePrecisionFilter; /* Default to single precision */ + if ((LOW_FREQ * fs) >= (fc << 15)) + { + /* + * fc <= fs/110 + */ + pInst->pBPFiltersPrecision[ii] = LVPSA_DoublePrecisionFilter; + } + else + { + if (((LOW_FREQ * fs) < (fc << 15)) && ((fc << 15) < (HIGH_FREQ * fs)) && (QFactor > 300)) + { + /* + * (fs/110 < fc < fs/85) & (Q>3) + */ + pInst->pBPFiltersPrecision[ii] = LVPSA_DoublePrecisionFilter; + } + } + } + + return(LVPSA_OK); +} + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_SetBPFCoefficients */ +/* */ +/* DESCRIPTION: */ +/* Sets the band pass filter coefficients. This uses the type to select */ +/* single or double precision coefficients. */ +/* */ +/* PARAMETERS: */ +/* pInst Pointer to the instance */ +/* Params Initialisation parameters */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Always succeeds */ +/* */ +/* NOTES: */ +/* */ +/************************************************************************************/ +LVPSA_RETURN LVPSA_SetBPFCoefficients( LVPSA_InstancePr_t *pInst, + LVPSA_ControlParams_t *pParams) +{ + + LVM_UINT16 ii; + + /* + * Set the coefficients for each band by the init function + */ + for (ii = 0; ii < pInst->nRelevantFilters; ii++) + { + switch (pInst->pBPFiltersPrecision[ii]) + { + case LVPSA_DoublePrecisionFilter: + { + BP_C32_Coefs_t Coefficients; + + /* + * Calculate the double precision coefficients + */ + LVPSA_BPDoublePrecCoefs((LVM_UINT16)pParams->Fs, + &pInst->pFiltersParams[ii], + &Coefficients); + + /* + * Set the coefficients + */ + BP_1I_D16F32Cll_TRC_WRA_01_Init ( &pInst->pBP_Instances[ii], + &pInst->pBP_Taps[ii], + &Coefficients); + break; + } + + case LVPSA_SimplePrecisionFilter: + { + BP_C16_Coefs_t Coefficients; + + /* + * Calculate the single precision coefficients + */ + LVPSA_BPSinglePrecCoefs((LVM_UINT16)pParams->Fs, + &pInst->pFiltersParams[ii], + &Coefficients); + + /* + * Set the coefficients + */ + BP_1I_D16F16Css_TRC_WRA_01_Init ( &pInst->pBP_Instances[ii], + &pInst->pBP_Taps[ii], + &Coefficients); + break; + } + } + } + + return(LVPSA_OK); +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_SetQPFCoefficients */ +/* */ +/* DESCRIPTION: */ +/* Sets the quasi peak filters coefficients. This uses the chosen */ +/* LevelDetectionSpeed from the control parameters. */ +/* */ +/* PARAMETERS: */ +/* pInst Pointer to the instance */ +/* Params Control parameters */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Always succeeds */ +/* */ +/* NOTES: */ +/* */ +/************************************************************************************/ +LVPSA_RETURN LVPSA_SetQPFCoefficients( LVPSA_InstancePr_t *pInst, + LVPSA_ControlParams_t *pParams ) +{ + LVM_UINT16 ii; + LVM_Fs_en Fs = pParams->Fs; + QPD_C32_Coefs *pCoefficients; + extern QPD_C32_Coefs LVPSA_QPD_Coefs[]; + + + pCoefficients = &LVPSA_QPD_Coefs[(pParams->LevelDetectionSpeed * LVPSA_NR_SUPPORTED_RATE) + Fs]; + + + for (ii = 0; ii < pInst->nRelevantFilters; ii++) + { + LVPSA_QPD_Init (&pInst->pQPD_States[ii], + &pInst->pQPD_Taps[ii], + pCoefficients ); + } + + return(LVPSA_OK); + +} + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_BPSinglePrecCoefs */ +/* */ +/* DESCRIPTION: */ +/* Calculate single precision coefficients for a band pass filter */ +/* */ +/* PARAMETERS: */ +/* Fs Sampling frequency index */ +/* pFilterParams Pointer to the filter definition */ +/* pCoefficients Pointer to the coefficients */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Always succeeds */ +/* */ +/* NOTES: */ +/* 1. The equations used are as follows: */ +/* */ +/* t0 = 2 * Pi * Fc / Fs */ +/* */ +/* b2 = -0.5 * (2Q - t0) / (2Q + t0) */ +/* b1 = (0.5 - b2) * cos(t0) */ +/* a0 = (0.5 + b2) / 2 */ +/* */ +/* Where: */ +/* Fc is the centre frequency, DC to Nyquist */ +/* Fs is the sample frequency, 8000 to 48000 in descrete steps */ +/* Q is the Q factor, 0.25 to 12 */ +/* */ +/* 2. This function is entirely based on the LVEQNB_SinglePrecCoefs function */ +/* of the n bands equalizer (LVEQNB */ +/* */ +/****************************************************************************************/ +LVPSA_RETURN LVPSA_BPSinglePrecCoefs( LVM_UINT16 Fs, + LVPSA_FilterParam_t *pFilterParams, + BP_C16_Coefs_t *pCoefficients) +{ + + extern LVM_INT16 LVPSA_TwoPiOnFsTable[]; + extern LVM_INT16 LVPSA_CosCoef[]; + + + /* + * Intermediate variables and temporary values + */ + LVM_INT32 T0; + LVM_INT16 D; + LVM_INT32 A0; + LVM_INT32 B1; + LVM_INT32 B2; + LVM_INT32 Dt0; + LVM_INT32 B2_Den; + LVM_INT32 B2_Num; + LVM_INT32 COS_T0; + LVM_INT16 coef; + LVM_INT32 factor; + LVM_INT16 t0; + LVM_INT16 i; + + + /* + * Get the filter definition + */ + LVM_UINT16 Frequency = pFilterParams->CenterFrequency; + LVM_UINT16 QFactor = pFilterParams->QFactor; + + + /* + * Calculating the intermediate values + */ + T0 = (LVM_INT32)Frequency * LVPSA_TwoPiOnFsTable[Fs]; /* T0 = 2 * Pi * Fc / Fs */ + D = 3200; /* Floating point value 1.000000 (1*100*2^5) */ + /* Force D = 1 : the function was originally used for a peaking filter. + The D parameter do not exist for a BandPass filter coefficients */ + + /* + * Calculate the B2 coefficient + */ + Dt0 = D * (T0 >> 10); + B2_Den = (LVM_INT32)(((LVM_UINT32)QFactor << 19) + (LVM_UINT32)(Dt0 >> 2)); + B2_Num = (LVM_INT32)((LVM_UINT32)(Dt0 >> 3) - ((LVM_UINT32)QFactor << 18)); + B2 = (B2_Num / (B2_Den >> 16)) << 15; + + /* + * Calculate the cosine by a polynomial expansion using the equation: + * + * Cos += coef(n) * t0^n For n = 0 to 6 + */ + T0 = (T0 >> 10) * 20859; /* Scale to 1.0 in 16-bit for range 0 to fs/2 */ + t0 = (LVM_INT16)(T0 >> 16); + factor = 0x7fff; /* Initialise to 1.0 for the a0 coefficient */ + COS_T0 = 0; /* Initialise the error to zero */ + for (i=1; i<7; i++) + { + coef = LVPSA_CosCoef[i]; /* Get the nth coefficient */ + COS_T0 += (factor * coef) >> 5; /* The nth partial sum */ + factor = (factor * t0) >> 15; /* Calculate t0^n */ + } + COS_T0 = COS_T0 << (LVPSA_CosCoef[0]+6); /* Correct the scaling */ + + + B1 = ((0x40000000 - B2) >> 16) * (COS_T0 >> 16); /* B1 = (0.5 - b2) * cos(t0) */ + A0 = (0x40000000 + B2) >> 1; /* A0 = (0.5 + b2) / 2 */ + + /* + * Write coeff into the data structure + */ + pCoefficients->A0 = (LVM_INT16)(A0>>16); + pCoefficients->B1 = (LVM_INT16)(B1>>15); + pCoefficients->B2 = (LVM_INT16)(B2>>16); + + + return(LVPSA_OK); +} + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_BPDoublePrecCoefs */ +/* */ +/* DESCRIPTION: */ +/* Calculate double precision coefficients for a band pass filter */ +/* */ +/* PARAMETERS: */ +/* Fs Sampling frequency index */ +/* pFilterParams Pointer to the filter definition */ +/* pCoefficients Pointer to the coefficients */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Always succeeds */ +/* */ +/* NOTES: */ +/* 1. The equations used are as follows: */ +/* */ +/* t0 = 2 * Pi * Fc / Fs */ +/* */ +/* b2 = -0.5 * (2Q - t0) / (2Q + t0) */ +/* b1 = (0.5 - b2) * (1 - coserr(t0)) */ +/* a0 = (0.5 + b2) / 2 */ +/* */ +/* Where: */ +/* Fc is the centre frequency, DC to Fs/50 */ +/* Fs is the sample frequency, 8000 to 48000 in descrete steps */ +/* Q is the Q factor, 0.25 to 12 (represented by 25 to 1200) */ +/* */ +/* 2. The double precision coefficients are only used when fc is less than fs/85, so */ +/* the cosine of t0 is always close to 1.0. Instead of calculating the cosine */ +/* itself the difference from the value 1.0 is calculated, this can be done with */ +/* lower precision maths. */ +/* */ +/* 3. The value of the B2 coefficient is only calculated as a single precision value, */ +/* small errors in this value have a combined effect on the Q and Gain but not the */ +/* the frequency of the filter. */ +/* */ +/* 4. This function is entirely based on the LVEQNB_DoublePrecCoefs function */ +/* of the n bands equalizer (LVEQNB */ +/* */ +/****************************************************************************************/ +LVPSA_RETURN LVPSA_BPDoublePrecCoefs( LVM_UINT16 Fs, + LVPSA_FilterParam_t *pFilterParams, + BP_C32_Coefs_t *pCoefficients) +{ + + extern LVM_INT16 LVPSA_TwoPiOnFsTable[]; + extern LVM_INT16 LVPSA_DPCosCoef[]; + + /* + * Intermediate variables and temporary values + */ + LVM_INT32 T0; + LVM_INT16 D; + LVM_INT32 A0; + LVM_INT32 B1; + LVM_INT32 B2; + LVM_INT32 Dt0; + LVM_INT32 B2_Den; + LVM_INT32 B2_Num; + LVM_INT32 CosErr; + LVM_INT16 coef; + LVM_INT32 factor; + LVM_INT16 t0; + LVM_INT16 i; + + /* + * Get the filter definition + */ + LVM_UINT16 Frequency = pFilterParams->CenterFrequency; + LVM_UINT16 QFactor = pFilterParams->QFactor; + + + /* + * Calculating the intermediate values + */ + T0 = (LVM_INT32)Frequency * LVPSA_TwoPiOnFsTable[Fs]; /* T0 = 2 * Pi * Fc / Fs */ + D = 3200; /* Floating point value 1.000000 (1*100*2^5) */ + /* Force D = 1 : the function was originally used for a peaking filter. + The D parameter do not exist for a BandPass filter coefficients */ + + /* + * Calculate the B2 coefficient + */ + Dt0 = D * (T0 >> 10); + B2_Den = (LVM_INT32)(((LVM_UINT32)QFactor << 19) + (LVM_UINT32)(Dt0 >> 2)); + B2_Num = (LVM_INT32)((LVM_UINT32)(Dt0 >> 3) - ((LVM_UINT32)QFactor << 18)); + B2 = (B2_Num / (B2_Den >> 16)) << 15; + + /* + * Calculate the cosine error by a polynomial expansion using the equation: + * + * CosErr += coef(n) * t0^n For n = 0 to 4 + */ + T0 = (T0 >> 6) * 0x7f53; /* Scale to 1.0 in 16-bit for range 0 to fs/50 */ + t0 = (LVM_INT16)(T0 >> 16); + factor = 0x7fff; /* Initialise to 1.0 for the a0 coefficient */ + CosErr = 0; /* Initialise the error to zero */ + for (i=1; i<5; i++) + { + coef = LVPSA_DPCosCoef[i]; /* Get the nth coefficient */ + CosErr += (factor * coef) >> 5; /* The nth partial sum */ + factor = (factor * t0) >> 15; /* Calculate t0^n */ + } + CosErr = CosErr << (LVPSA_DPCosCoef[0]); /* Correct the scaling */ + + /* + * Calculate the B1 and A0 coefficients + */ + B1 = (0x40000000 - B2); /* B1 = (0.5 - b2) */ + A0 = ((B1 >> 16) * (CosErr >> 10)) >> 6; /* Temporary storage for (0.5 - b2) * coserr(t0) */ + B1 -= A0; /* B1 = (0.5 - b2) * (1 - coserr(t0)) */ + A0 = (0x40000000 + B2) >> 1; /* A0 = (0.5 + b2) / 2 */ + + /* + * Write coeff into the data structure + */ + pCoefficients->A0 = A0; + pCoefficients->B1 = B1; + pCoefficients->B2 = B2; + + return(LVPSA_OK); +} + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_ClearFilterHistory */ +/* */ +/* DESCRIPTION: */ +/* Clears the filters' data history */ +/* */ +/* PARAMETERS: */ +/* pInst Pointer to the instance */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Always succeeds */ +/* */ +/* NOTES: */ +/* */ +/************************************************************************************/ +LVPSA_RETURN LVPSA_ClearFilterHistory(LVPSA_InstancePr_t *pInst) +{ + LVM_INT8 *pTapAddress; + LVM_UINT32 i; + + /* Band Pass filters taps */ + pTapAddress = (LVM_INT8 *)pInst->pBP_Taps; + for(i = 0; i < pInst->nBands * sizeof(Biquad_1I_Order2_Taps_t); i++) + { + pTapAddress[i] = 0; + } + + /* Quasi-peak filters taps */ + pTapAddress = (LVM_INT8 *)pInst->pQPD_Taps; + for(i = 0; i < pInst->nBands * sizeof(QPD_Taps_t); i++) + { + pTapAddress[i] = 0; + } + + return(LVPSA_OK); +} + diff --git a/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Init.c b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Init.c new file mode 100755 index 0000000..ab45678 --- /dev/null +++ b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Init.c @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: PSA_01_ARMC_01 */ +/* $Author: beq07716 $*/ +/* $Revision: 1006 $*/ +/* $Date: 2010-06-28 14:01:47 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ +#include "LVPSA.h" +#include "LVPSA_Private.h" +#include "InstAlloc.h" + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_Init */ +/* */ +/* DESCRIPTION: */ +/* Initialize the LVPSA module */ +/* */ +/* */ +/* PARAMETERS: */ +/* phInstance Pointer to pointer to the instance */ +/* InitParams Init parameters structure */ +/* ControlParams Control parameters structure */ +/* pMemoryTable Memory table that contains memory areas definition */ +/* */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/************************************************************************************/ +LVPSA_RETURN LVPSA_Init ( pLVPSA_Handle_t *phInstance, + LVPSA_InitParams_t *pInitParams, + LVPSA_ControlParams_t *pControlParams, + LVPSA_MemTab_t *pMemoryTable ) +{ + LVPSA_InstancePr_t *pLVPSA_Inst; + LVPSA_RETURN errorCode = LVPSA_OK; + LVM_UINT32 ii; + extern LVM_INT16 LVPSA_GainTable[]; + LVM_UINT32 BufferLength = 0; + + /* Ints_Alloc instances, needed for memory alignment management */ + INST_ALLOC Instance; + INST_ALLOC Scratch; + INST_ALLOC Data; + INST_ALLOC Coef; + + /* Check parameters */ + if((phInstance == LVM_NULL) || (pInitParams == LVM_NULL) || (pControlParams == LVM_NULL) || (pMemoryTable == LVM_NULL)) + { + return(LVPSA_ERROR_NULLADDRESS); + } + if( (pInitParams->SpectralDataBufferDuration > LVPSA_MAXBUFFERDURATION) || + (pInitParams->SpectralDataBufferDuration == 0) || + (pInitParams->MaxInputBlockSize > LVPSA_MAXINPUTBLOCKSIZE) || + (pInitParams->MaxInputBlockSize == 0) || + (pInitParams->nBands < LVPSA_NBANDSMIN) || + (pInitParams->nBands > LVPSA_NBANDSMAX) || + (pInitParams->pFiltersParams == 0)) + { + return(LVPSA_ERROR_INVALIDPARAM); + } + for(ii = 0; ii < pInitParams->nBands; ii++) + { + if((pInitParams->pFiltersParams[ii].CenterFrequency > LVPSA_MAXCENTERFREQ) || + (pInitParams->pFiltersParams[ii].PostGain > LVPSA_MAXPOSTGAIN) || + (pInitParams->pFiltersParams[ii].PostGain < LVPSA_MINPOSTGAIN) || + (pInitParams->pFiltersParams[ii].QFactor < LVPSA_MINQFACTOR) || + (pInitParams->pFiltersParams[ii].QFactor > LVPSA_MAXQFACTOR)) + { + return(LVPSA_ERROR_INVALIDPARAM); + } + } + + + /*Inst_Alloc instances initialization */ + InstAlloc_Init( &Instance , pMemoryTable->Region[LVPSA_MEMREGION_INSTANCE].pBaseAddress); + InstAlloc_Init( &Scratch , pMemoryTable->Region[LVPSA_MEMREGION_SCRATCH].pBaseAddress); + InstAlloc_Init( &Data , pMemoryTable->Region[LVPSA_MEMREGION_PERSISTENT_DATA].pBaseAddress); + InstAlloc_Init( &Coef , pMemoryTable->Region[LVPSA_MEMREGION_PERSISTENT_COEF].pBaseAddress); + + + /* Set the instance handle if not already initialised */ + if (*phInstance == LVM_NULL) + { + *phInstance = InstAlloc_AddMember( &Instance, sizeof(LVPSA_InstancePr_t) ); + } + pLVPSA_Inst =(LVPSA_InstancePr_t*)*phInstance; + + + /* Check the memory table for NULL pointers */ + for (ii = 0; ii < LVPSA_NR_MEMORY_REGIONS; ii++) + { + if (pMemoryTable->Region[ii].Size!=0) + { + if (pMemoryTable->Region[ii].pBaseAddress==LVM_NULL) + { + return(LVPSA_ERROR_NULLADDRESS); + } + pLVPSA_Inst->MemoryTable.Region[ii] = pMemoryTable->Region[ii]; + } + } + + /* Initialize module's internal parameters */ + pLVPSA_Inst->bControlPending = LVM_FALSE; + pLVPSA_Inst->nBands = pInitParams->nBands; + pLVPSA_Inst->MaxInputBlockSize = pInitParams->MaxInputBlockSize; + pLVPSA_Inst->SpectralDataBufferDuration = pInitParams->SpectralDataBufferDuration; + pLVPSA_Inst->CurrentParams.Fs = LVM_FS_DUMMY; + pLVPSA_Inst->CurrentParams.LevelDetectionSpeed = LVPSA_SPEED_DUMMY; + + { /* for avoiding QAC warnings */ + LVM_INT32 SDBD=(LVM_INT32)pLVPSA_Inst->SpectralDataBufferDuration; + LVM_INT32 IRTI=(LVM_INT32)LVPSA_InternalRefreshTimeInv; + LVM_INT32 BL; + + MUL32x32INTO32(SDBD,IRTI,BL,LVPSA_InternalRefreshTimeShift) + + BufferLength=(LVM_UINT32)BL; + } + + if((BufferLength * LVPSA_InternalRefreshTime) != pLVPSA_Inst->SpectralDataBufferDuration) + { + pLVPSA_Inst->SpectralDataBufferLength = BufferLength + 1; + } + else + { + pLVPSA_Inst->SpectralDataBufferLength = BufferLength; + } + + + /* Assign the pointers */ + + pLVPSA_Inst->pPostGains = InstAlloc_AddMember( &Instance, pInitParams->nBands * sizeof(LVM_UINT16) ); + pLVPSA_Inst->pFiltersParams = InstAlloc_AddMember( &Instance, pInitParams->nBands * sizeof(LVPSA_FilterParam_t) ); + pLVPSA_Inst->pSpectralDataBufferStart = InstAlloc_AddMember( &Instance, pInitParams->nBands * pLVPSA_Inst->SpectralDataBufferLength * sizeof(LVM_UINT8) ); + pLVPSA_Inst->pPreviousPeaks = InstAlloc_AddMember( &Instance, pInitParams->nBands * sizeof(LVM_UINT8) ); + pLVPSA_Inst->pBPFiltersPrecision = InstAlloc_AddMember( &Instance, pInitParams->nBands * sizeof(LVPSA_BPFilterPrecision_en) ); + + pLVPSA_Inst->pBP_Instances = InstAlloc_AddMember( &Coef, pInitParams->nBands * sizeof(Biquad_Instance_t) ); + pLVPSA_Inst->pQPD_States = InstAlloc_AddMember( &Coef, pInitParams->nBands * sizeof(QPD_State_t) ); + + pLVPSA_Inst->pBP_Taps = InstAlloc_AddMember( &Data, pInitParams->nBands * sizeof(Biquad_1I_Order2_Taps_t) ); + pLVPSA_Inst->pQPD_Taps = InstAlloc_AddMember( &Data, pInitParams->nBands * sizeof(QPD_Taps_t) ); + + + /* Copy filters parameters in the private instance */ + for(ii = 0; ii < pLVPSA_Inst->nBands; ii++) + { + pLVPSA_Inst->pFiltersParams[ii] = pInitParams->pFiltersParams[ii]; + } + + /* Set Post filters gains*/ + for(ii = 0; ii < pLVPSA_Inst->nBands; ii++) + { + pLVPSA_Inst->pPostGains[ii] =(LVM_UINT16) LVPSA_GainTable[pInitParams->pFiltersParams[ii].PostGain + 15]; + } + pLVPSA_Inst->pSpectralDataBufferWritePointer = pLVPSA_Inst->pSpectralDataBufferStart; + + + /* Initialize control dependant internal parameters */ + errorCode = LVPSA_Control (*phInstance, pControlParams); + + if(errorCode!=0) + { + return errorCode; + } + + errorCode = LVPSA_ApplyNewSettings (pLVPSA_Inst); + + if(errorCode!=0) + { + return errorCode; + } + + return(errorCode); +} + diff --git a/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Memory.c b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Memory.c new file mode 100755 index 0000000..059cb4e --- /dev/null +++ b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Memory.c @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: PSA_01_ARMC_01 */ +/* $Author: beq07716 $*/ +/* $Revision: 1006 $*/ +/* $Date: 2010-06-28 14:01:47 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ +#include "LVPSA.h" +#include "LVPSA_Private.h" +#include "InstAlloc.h" + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVEQNB_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 */ +/* InitParams Pointer to the instance init parameters */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/****************************************************************************************/ +LVPSA_RETURN LVPSA_Memory ( pLVPSA_Handle_t hInstance, + LVPSA_MemTab_t *pMemoryTable, + LVPSA_InitParams_t *pInitParams ) +{ + LVM_UINT32 ii; + LVM_UINT32 BufferLength; + INST_ALLOC Instance; + INST_ALLOC Scratch; + INST_ALLOC Data; + INST_ALLOC Coef; + LVPSA_InstancePr_t *pLVPSA_Inst = (LVPSA_InstancePr_t*)hInstance; + + + InstAlloc_Init( &Instance , LVM_NULL); + InstAlloc_Init( &Scratch , LVM_NULL); + InstAlloc_Init( &Data , LVM_NULL); + InstAlloc_Init( &Coef , LVM_NULL); + + + if((pMemoryTable == LVM_NULL) || (pInitParams == LVM_NULL)) + { + return(LVPSA_ERROR_NULLADDRESS); + } + + + /* + * Fill in the memory table + */ + if (hInstance == LVM_NULL) + { + + /* Check init parameter */ + if( (pInitParams->SpectralDataBufferDuration > LVPSA_MAXBUFFERDURATION) || + (pInitParams->SpectralDataBufferDuration == 0) || + (pInitParams->MaxInputBlockSize > LVPSA_MAXINPUTBLOCKSIZE) || + (pInitParams->MaxInputBlockSize == 0) || + (pInitParams->nBands < LVPSA_NBANDSMIN) || + (pInitParams->nBands > LVPSA_NBANDSMAX) || + (pInitParams->pFiltersParams == 0)) + { + return(LVPSA_ERROR_INVALIDPARAM); + } + for(ii = 0; ii < pInitParams->nBands; ii++) + { + if((pInitParams->pFiltersParams[ii].CenterFrequency > LVPSA_MAXCENTERFREQ) || + (pInitParams->pFiltersParams[ii].PostGain > LVPSA_MAXPOSTGAIN) || + (pInitParams->pFiltersParams[ii].PostGain < LVPSA_MINPOSTGAIN) || + (pInitParams->pFiltersParams[ii].QFactor < LVPSA_MINQFACTOR) || + (pInitParams->pFiltersParams[ii].QFactor > LVPSA_MAXQFACTOR)) + { + return(LVPSA_ERROR_INVALIDPARAM); + } + } + + /* + * Instance memory + */ + + InstAlloc_AddMember( &Instance, sizeof(LVPSA_InstancePr_t) ); + InstAlloc_AddMember( &Instance, pInitParams->nBands * sizeof(LVM_UINT16) ); + InstAlloc_AddMember( &Instance, pInitParams->nBands * sizeof(LVPSA_FilterParam_t) ); + + { + /* for avoiding QAC warnings as MUL32x32INTO32 works on LVM_INT32 only*/ + LVM_INT32 SDBD=(LVM_INT32)pInitParams->SpectralDataBufferDuration; + LVM_INT32 IRTI=(LVM_INT32)LVPSA_InternalRefreshTimeInv; + LVM_INT32 BL; + + MUL32x32INTO32(SDBD,IRTI,BL,LVPSA_InternalRefreshTimeShift) + BufferLength=(LVM_UINT32)BL; + } + + + if((BufferLength * LVPSA_InternalRefreshTime) != pInitParams->SpectralDataBufferDuration) + { + BufferLength++; + } + InstAlloc_AddMember( &Instance, pInitParams->nBands * BufferLength * sizeof(LVM_UINT8) ); + InstAlloc_AddMember( &Instance, pInitParams->nBands * sizeof(LVM_UINT8) ); + InstAlloc_AddMember( &Instance, pInitParams->nBands * sizeof(LVPSA_BPFilterPrecision_en) ); + pMemoryTable->Region[LVPSA_MEMREGION_INSTANCE].Size = InstAlloc_GetTotal(&Instance); + pMemoryTable->Region[LVPSA_MEMREGION_INSTANCE].Type = LVPSA_PERSISTENT; + pMemoryTable->Region[LVPSA_MEMREGION_INSTANCE].pBaseAddress = LVM_NULL; + + /* + * Scratch memory + */ + InstAlloc_AddMember( &Scratch, 2 * pInitParams->MaxInputBlockSize * sizeof(LVM_INT16) ); + pMemoryTable->Region[LVPSA_MEMREGION_SCRATCH].Size = InstAlloc_GetTotal(&Scratch); + pMemoryTable->Region[LVPSA_MEMREGION_SCRATCH].Type = LVPSA_SCRATCH; + pMemoryTable->Region[LVPSA_MEMREGION_SCRATCH].pBaseAddress = LVM_NULL; + + /* + * Persistent coefficients memory + */ + InstAlloc_AddMember( &Coef, pInitParams->nBands * sizeof(Biquad_Instance_t) ); + InstAlloc_AddMember( &Coef, pInitParams->nBands * sizeof(QPD_State_t) ); + pMemoryTable->Region[LVPSA_MEMREGION_PERSISTENT_COEF].Size = InstAlloc_GetTotal(&Coef); + pMemoryTable->Region[LVPSA_MEMREGION_PERSISTENT_COEF].Type = LVPSA_PERSISTENT_COEF; + pMemoryTable->Region[LVPSA_MEMREGION_PERSISTENT_COEF].pBaseAddress = LVM_NULL; + + /* + * Persistent data memory + */ + InstAlloc_AddMember( &Data, pInitParams->nBands * sizeof(Biquad_1I_Order2_Taps_t) ); + InstAlloc_AddMember( &Data, pInitParams->nBands * sizeof(QPD_Taps_t) ); + pMemoryTable->Region[LVPSA_MEMREGION_PERSISTENT_DATA].Size = InstAlloc_GetTotal(&Data); + pMemoryTable->Region[LVPSA_MEMREGION_PERSISTENT_DATA].Type = LVPSA_PERSISTENT_DATA; + pMemoryTable->Region[LVPSA_MEMREGION_PERSISTENT_DATA].pBaseAddress = LVM_NULL; + + } + else + { + /* Read back memory allocation table */ + *pMemoryTable = pLVPSA_Inst->MemoryTable; + } + + return(LVPSA_OK); +} + diff --git a/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Private.h b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Private.h new file mode 100755 index 0000000..eb9fa8f --- /dev/null +++ b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Private.h @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: PSA_01_ARMC_01 */ +/* $Author: beq07716 $*/ +/* $Revision: 1006 $*/ +/* $Date: 2010-06-28 14:01:47 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ +#ifndef _LVPSA_PRIVATE_H_ +#define _LVPSA_PRIVATE_H_ + +#include "LVPSA.h" +#include "BIQUAD.h" +#include "LVPSA_QPD.h" +#include "LVM_Macros.h" + + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/********************************************************************************** + CONSTANT DEFINITIONS +***********************************************************************************/ + +/* Memory */ +#define LVPSA_INSTANCE_ALIGN 4 /* 32-bit alignment for structures */ +#define LVPSA_SCRATCH_ALIGN 4 /* 32-bit alignment for long data */ +#define LVPSA_COEF_ALIGN 4 /* 32-bit alignment for long words */ +#define LVPSA_DATA_ALIGN 4 /* 32-bit alignment for long data */ + +#define LVPSA_MEMREGION_INSTANCE 0 /* Offset to instance memory region in memory table */ +#define LVPSA_MEMREGION_PERSISTENT_COEF 1 /* Offset to persistent coefficients memory region in memory table */ +#define LVPSA_MEMREGION_PERSISTENT_DATA 2 /* Offset to persistent taps memory region in memory table */ +#define LVPSA_MEMREGION_SCRATCH 3 /* Offset to scratch memory region in memory table */ + +#define LVPSA_NR_SUPPORTED_RATE 9 /* From 8000Hz to 48000Hz */ +#define LVPSA_NR_SUPPORTED_SPEED 3 /* LOW, MEDIUM, HIGH */ + +#define LVPSA_MAXBUFFERDURATION 4000 /* Maximum length in ms of the levels buffer */ +#define LVPSA_MAXINPUTBLOCKSIZE 5000 /* Maximum length in mono samples of the block to process */ +#define LVPSA_NBANDSMIN 1 /* Minimum number of frequency band */ +#define LVPSA_NBANDSMAX 30 /* Maximum number of frequency band */ +#define LVPSA_MAXCENTERFREQ 20000 /* Maximum possible center frequency */ +#define LVPSA_MINPOSTGAIN -15 /* Minimum possible post gain */ +#define LVPSA_MAXPOSTGAIN 15 /* Maximum possible post gain */ +#define LVPSA_MINQFACTOR 25 /* Minimum possible Q factor */ +#define LVPSA_MAXQFACTOR 1200 /* Maximum possible Q factor */ + +#define LVPSA_MAXLEVELDECAYFACTOR 0x4111 /* Decay factor for the maximum values calculation */ +#define LVPSA_MAXLEVELDECAYSHIFT 14 /* Decay shift for the maximum values calculation */ + +#define LVPSA_MAXUNSIGNEDCHAR 0xFF + +#define LVPSA_FsInvertShift 31 +#define LVPSA_GAINSHIFT 11 +#define LVPSA_FREQSHIFT 25 + +/********************************************************************************** + TYPES DEFINITIONS +***********************************************************************************/ + +#define LVPSA_InternalRefreshTime 0x0014 /* 20 ms (50Hz) in Q16.0 */ +#define LVPSA_InternalRefreshTimeInv 0x0666 /* 1/20ms left shifted by 15 */ +#define LVPSA_InternalRefreshTimeShift 15 + + +/* Precision of the filter */ +typedef enum +{ + LVPSA_SimplePrecisionFilter, /* Simple precision */ + LVPSA_DoublePrecisionFilter /* Double precision */ +} LVPSA_BPFilterPrecision_en; + +typedef struct +{ + LVM_CHAR bControlPending; /* Flag incating a change of the control parameters */ + LVM_UINT16 nBands; /* Number of bands of the spectrum analyzer */ + LVM_UINT16 MaxInputBlockSize; /* Maximum input data buffer size */ + + LVPSA_ControlParams_t CurrentParams; /* Current control parameters of the module */ + LVPSA_ControlParams_t NewParams; /* New control parameters given by the user */ + LVPSA_MemTab_t MemoryTable; + + LVPSA_BPFilterPrecision_en *pBPFiltersPrecision; /* Points a nBands elements array that contains the filter precision for each band */ + Biquad_Instance_t *pBP_Instances; /* Points a nBands elements array that contains the band pass filter instance for each band */ + Biquad_1I_Order2_Taps_t *pBP_Taps; /* Points a nBands elements array that contains the band pass filter taps for each band */ + QPD_State_t *pQPD_States; /* Points a nBands elements array that contains the QPD filter instance for each band */ + QPD_Taps_t *pQPD_Taps; /* Points a nBands elements array that contains the QPD filter taps for each band */ + LVM_UINT16 *pPostGains; /* Points a nBands elements array that contains the post-filter gains for each band */ + + LVPSA_FilterParam_t *pFiltersParams; /* Copy of the filters parameters from the input parameters */ + + + LVM_UINT16 nSamplesBufferUpdate; /* Number of samples to make 20ms */ + LVM_INT32 BufferUpdateSamplesCount; /* Counter used to know when to put a new value in the buffer */ + LVM_UINT16 nRelevantFilters; /* Number of relevent filters depending on sampling frequency and bands center frequency */ + LVM_UINT16 LocalSamplesCount; /* Counter used to update the SpectralDataBufferAudioTime */ + + LVM_UINT16 DownSamplingFactor; /* Down sampling factor depending on the sampling frequency */ + LVM_UINT16 DownSamplingCount; /* Counter used for the downsampling handling */ + + LVM_UINT16 SpectralDataBufferDuration; /* Length of the buffer in time (ms) defined by the application */ + LVM_UINT8 *pSpectralDataBufferStart; /* Starting address of the buffer */ + LVM_UINT8 *pSpectralDataBufferWritePointer; /* Current position of the writting pointer of the buffer */ + LVPSA_Time SpectralDataBufferAudioTime; /* AudioTime at which the last value save occured in the buffer */ + LVM_UINT32 SpectralDataBufferLength; /* Number of spectrum data value that the buffer can contain (per band) + = SpectralDataBufferDuration/20ms */ + + LVM_UINT8 *pPreviousPeaks; /* Points to a nBands elements array that contains the previous peak value of the level + detection. Those values are decremented after each call to the GetSpectrum function */ + +}LVPSA_InstancePr_t, *pLVPSA_InstancePr_t; + + + +/********************************************************************************** + FUNCTIONS PROTOTYPE +***********************************************************************************/ +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_ApplyNewSettings */ +/* */ +/* DESCRIPTION: */ +/* Reinitialize some parameters and changes filters' coefficients if */ +/* some control parameters have changed. */ +/* */ +/* PARAMETERS: */ +/* pInst Pointer to the instance */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Always succeeds */ +/* */ +/************************************************************************************/ +LVPSA_RETURN LVPSA_ApplyNewSettings (LVPSA_InstancePr_t *pInst); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _LVPSA_PRIVATE_H */ diff --git a/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Process.c b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Process.c new file mode 100755 index 0000000..d88a751 --- /dev/null +++ b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Process.c @@ -0,0 +1,260 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: PSA_01_ARMC_01 */ +/* $Author: beq07716 $*/ +/* $Revision: 1006 $*/ +/* $Date: 2010-06-28 14:01:47 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ +#include "LVPSA.h" +#include "LVPSA_Private.h" +#include "LVM_Macros.h" +#include "VectorArithmetic.h" + +#define LVM_MININT_32 0x80000000 + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_Process */ +/* */ +/* DESCRIPTION: */ +/* The process applies band pass filters to the signal. Each output */ +/* feeds a quasi peak filter for level detection. */ +/* */ +/* PARAMETERS: */ +/* hInstance Pointer to the instance */ +/* pLVPSA_InputSamples Pointer to the input samples buffer */ +/* InputBlockSize Number of mono samples to process */ +/* AudioTime Playback time of the input samples */ +/* */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/************************************************************************************/ +LVPSA_RETURN LVPSA_Process ( pLVPSA_Handle_t hInstance, + LVM_INT16 *pLVPSA_InputSamples, + LVM_UINT16 InputBlockSize, + LVPSA_Time AudioTime ) + +{ + LVPSA_InstancePr_t *pLVPSA_Inst = (LVPSA_InstancePr_t*)hInstance; + LVM_INT16 *pScratch; + LVM_INT16 ii; + LVM_INT32 AudioTimeInc; + extern LVM_UINT32 LVPSA_SampleRateInvTab[]; + LVM_UINT8 *pWrite_Save; /* Position of the write pointer at the beginning of the process */ + + /****************************************************************************** + CHECK PARAMETERS + *******************************************************************************/ + if(hInstance == LVM_NULL || pLVPSA_InputSamples == LVM_NULL) + { + return(LVPSA_ERROR_NULLADDRESS); + } + if(InputBlockSize == 0 || InputBlockSize > pLVPSA_Inst->MaxInputBlockSize) + { + return(LVPSA_ERROR_INVALIDPARAM); + } + + pScratch = (LVM_INT16*)pLVPSA_Inst->MemoryTable.Region[LVPSA_MEMREGION_SCRATCH].pBaseAddress; + pWrite_Save = pLVPSA_Inst->pSpectralDataBufferWritePointer; + + /****************************************************************************** + APPLY NEW SETTINGS IF NEEDED + *******************************************************************************/ + if (pLVPSA_Inst->bControlPending == LVM_TRUE) + { + pLVPSA_Inst->bControlPending = 0; + LVPSA_ApplyNewSettings( pLVPSA_Inst); + } + + /****************************************************************************** + PROCESS SAMPLES + *******************************************************************************/ + /* Put samples in range [-0.5;0.5[ for BP filters (see Biquads documentation) */ + Copy_16( pLVPSA_InputSamples,pScratch,(LVM_INT16)InputBlockSize); + Shift_Sat_v16xv16(-1,pScratch,pScratch,(LVM_INT16)InputBlockSize); + + for (ii = 0; ii < pLVPSA_Inst->nRelevantFilters; ii++) + { + switch(pLVPSA_Inst->pBPFiltersPrecision[ii]) + { + case LVPSA_SimplePrecisionFilter: + BP_1I_D16F16C14_TRC_WRA_01 ( &pLVPSA_Inst->pBP_Instances[ii], + pScratch, + pScratch + InputBlockSize, + (LVM_INT16)InputBlockSize); + break; + + case LVPSA_DoublePrecisionFilter: + BP_1I_D16F32C30_TRC_WRA_01 ( &pLVPSA_Inst->pBP_Instances[ii], + pScratch, + pScratch + InputBlockSize, + (LVM_INT16)InputBlockSize); + break; + default: + break; + } + + + LVPSA_QPD_Process ( pLVPSA_Inst, + pScratch + InputBlockSize, + (LVM_INT16)InputBlockSize, + ii); + } + + /****************************************************************************** + UPDATE SpectralDataBufferAudioTime + *******************************************************************************/ + + if(pLVPSA_Inst->pSpectralDataBufferWritePointer != pWrite_Save) + { + MUL32x32INTO32((AudioTime + (LVM_INT32)((LVM_INT32)pLVPSA_Inst->LocalSamplesCount*1000)), + (LVM_INT32)LVPSA_SampleRateInvTab[pLVPSA_Inst->CurrentParams.Fs], + AudioTimeInc, + LVPSA_FsInvertShift) + pLVPSA_Inst->SpectralDataBufferAudioTime = AudioTime + AudioTimeInc; + } + + return(LVPSA_OK); +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_GetSpectrum */ +/* */ +/* DESCRIPTION: */ +/* Gets the levels values at a certain point in time */ +/* */ +/* */ +/* PARAMETERS: */ +/* hInstance Pointer to the instance */ +/* GetSpectrumAudioTime Retrieve the values at this time */ +/* pCurrentValues Pointer to a buffer that will contain levels' values */ +/* pMaxValues Pointer to a buffer that will contain max levels' values */ +/* */ +/* */ +/* RETURNS: */ +/* LVPSA_OK Succeeds */ +/* otherwise Error due to bad parameters */ +/* */ +/************************************************************************************/ +LVPSA_RETURN LVPSA_GetSpectrum ( pLVPSA_Handle_t hInstance, + LVPSA_Time GetSpectrumAudioTime, + LVM_UINT8 *pCurrentValues, + LVM_UINT8 *pPeakValues ) + +{ + + LVPSA_InstancePr_t *pLVPSA_Inst = (LVPSA_InstancePr_t*)hInstance; + LVM_INT32 StatusDelta, ii; + LVM_UINT8 *pRead; + + if(hInstance == LVM_NULL || pCurrentValues == LVM_NULL || pPeakValues == LVM_NULL) + { + return(LVPSA_ERROR_NULLADDRESS); + } + + + /* First find the place where to look in the status buffer */ + if(GetSpectrumAudioTime <= pLVPSA_Inst->SpectralDataBufferAudioTime) + { + MUL32x32INTO32((pLVPSA_Inst->SpectralDataBufferAudioTime - GetSpectrumAudioTime),LVPSA_InternalRefreshTimeInv,StatusDelta,LVPSA_InternalRefreshTimeShift); + if((StatusDelta * LVPSA_InternalRefreshTime) != (pLVPSA_Inst->SpectralDataBufferAudioTime - GetSpectrumAudioTime)) + { + StatusDelta += 1; + } + } + else + { + /* This part handles the wrap around */ + MUL32x32INTO32(((pLVPSA_Inst->SpectralDataBufferAudioTime - (LVM_INT32)LVM_MININT_32) + ((LVM_INT32)LVM_MAXINT_32 - GetSpectrumAudioTime)),LVPSA_InternalRefreshTimeInv,StatusDelta,LVPSA_InternalRefreshTimeShift) + if(((LVM_INT32)(StatusDelta * LVPSA_InternalRefreshTime)) != ((LVM_INT32)((pLVPSA_Inst->SpectralDataBufferAudioTime - (LVM_INT32)LVM_MININT_32) + ((LVM_INT32)LVM_MAXINT_32 - GetSpectrumAudioTime)))) + { + StatusDelta += 1; + } + } + /* Check whether the desired level is not too "old" (see 2.10 in LVPSA_DesignNotes.doc)*/ + if( + ((GetSpectrumAudioTime < pLVPSA_Inst->SpectralDataBufferAudioTime)&& + ((GetSpectrumAudioTime<0)&&(pLVPSA_Inst->SpectralDataBufferAudioTime>0))&& + (((LVM_INT32)(-GetSpectrumAudioTime + pLVPSA_Inst->SpectralDataBufferAudioTime))>LVM_MAXINT_32))|| + + ((GetSpectrumAudioTime > pLVPSA_Inst->SpectralDataBufferAudioTime)&& + (((GetSpectrumAudioTime>=0)&&(pLVPSA_Inst->SpectralDataBufferAudioTime>=0))|| + ((GetSpectrumAudioTime<=0)&&(pLVPSA_Inst->SpectralDataBufferAudioTime<=0))|| + (((GetSpectrumAudioTime>=0)&&(pLVPSA_Inst->SpectralDataBufferAudioTime<=0))&& + (((LVM_INT32)(GetSpectrumAudioTime - pLVPSA_Inst->SpectralDataBufferAudioTime)) (LVM_INT32)pLVPSA_Inst->SpectralDataBufferLength) || + (!StatusDelta)) + { + for(ii = 0; ii < pLVPSA_Inst->nBands; ii++) + { + pCurrentValues[ii] = 0; + pPeakValues[ii] = 0; + } + return(LVPSA_OK); + } + /* Set the reading pointer */ + if((LVM_INT32)(StatusDelta * pLVPSA_Inst->nBands) > (pLVPSA_Inst->pSpectralDataBufferWritePointer - pLVPSA_Inst->pSpectralDataBufferStart)) + { + pRead = pLVPSA_Inst->pSpectralDataBufferWritePointer + (pLVPSA_Inst->SpectralDataBufferLength - (LVM_UINT32)StatusDelta) * pLVPSA_Inst->nBands; + } + else + { + pRead = pLVPSA_Inst->pSpectralDataBufferWritePointer - StatusDelta * pLVPSA_Inst->nBands; + } + + + /* Read the status buffer and fill the output buffers */ + for(ii = 0; ii < pLVPSA_Inst->nBands; ii++) + { + pCurrentValues[ii] = pRead[ii]; + if(pLVPSA_Inst->pPreviousPeaks[ii] <= pRead[ii]) + { + pLVPSA_Inst->pPreviousPeaks[ii] = pRead[ii]; + } + else if(pLVPSA_Inst->pPreviousPeaks[ii] != 0) + { + LVM_INT32 temp; + /*Re-compute max values for decay */ + temp = (LVM_INT32)(LVPSA_MAXUNSIGNEDCHAR - pLVPSA_Inst->pPreviousPeaks[ii]); + temp = ((temp * LVPSA_MAXLEVELDECAYFACTOR)>>LVPSA_MAXLEVELDECAYSHIFT); + /* If the gain has no effect, "help" the value to increase */ + if(temp == (LVPSA_MAXUNSIGNEDCHAR - pLVPSA_Inst->pPreviousPeaks[ii])) + { + temp += 1; + } + /* Saturate */ + temp = (temp > LVPSA_MAXUNSIGNEDCHAR) ? LVPSA_MAXUNSIGNEDCHAR : temp; + /* Store new max level */ + pLVPSA_Inst->pPreviousPeaks[ii] = (LVM_UINT8)(LVPSA_MAXUNSIGNEDCHAR - temp); + } + + pPeakValues[ii] = pLVPSA_Inst->pPreviousPeaks[ii]; + } + + return(LVPSA_OK); +} diff --git a/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_QPD.h b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_QPD.h new file mode 100755 index 0000000..641357e --- /dev/null +++ b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_QPD.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: PSA_01_ARMC_01 */ +/* $Author: beq07716 $*/ +/* $Revision: 1006 $*/ +/* $Date: 2010-06-28 14:01:47 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ +#ifndef _LVPSA_QPD_H_ +#define _LVPSA_QPD_H_ + +#include "LVM_Types.h" + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct +{ + LVM_INT32 *pDelay; /* pointer to the delayed samples (data of 32 bits) */ + LVM_INT32 Coefs[2]; /* pointer to the filter coefficients */ +}QPD_State_t, *pQPD_State_t; + +typedef struct +{ + LVM_INT32 KP; /*should store a0*/ + LVM_INT32 KM; /*should store b2*/ + +} QPD_C32_Coefs, *PQPD_C32_Coefs; + +typedef struct +{ + LVM_INT32 Storage[1]; + +} QPD_Taps_t, *pQPD_Taps_t; + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_QPD_Process */ +/* */ +/* DESCRIPTION: */ +/* Apply downsampling, post gain, quasi peak filtering and write the levels values */ +/* in the buffer every 20 ms. */ +/* */ +/* PARAMETERS: */ +/* */ +/* RETURNS: void */ +/* */ +/************************************************************************************/ +void LVPSA_QPD_Process ( void *hInstance, + LVM_INT16 *pInSamps, + LVM_INT16 numSamples, + LVM_INT16 BandIndex); + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_QPD_Init */ +/* */ +/* DESCRIPTION: */ +/* Initialize a quasi peak filter instance. */ +/* */ +/* PARAMETERS: */ +/* pInstance Pointer to the instance */ +/* pTaps Pointer to the filter's taps */ +/* pCoef Pointer to the filter's coefficients */ +/* */ +/* RETURNS: void */ +/* */ +/************************************************************************************/ +void LVPSA_QPD_Init ( QPD_State_t *pInstance, + QPD_Taps_t *pTaps, + QPD_C32_Coefs *pCoef ); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif + diff --git a/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_QPD_Init.c b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_QPD_Init.c new file mode 100755 index 0000000..37abe40 --- /dev/null +++ b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_QPD_Init.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: PSA_01_ARMC_01 */ +/* $Author: beq07716 $*/ +/* $Revision: 1006 $*/ +/* $Date: 2010-06-28 14:01:47 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ +#include "LVPSA_QPD.h" + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_QPD_Init */ +/* */ +/* DESCRIPTION: */ +/* Initialize a quasi peak filter instance. */ +/* */ +/* PARAMETERS: */ +/* pQPD_State Pointer to the filter state */ +/* pTaps Pointer to the filter's taps */ +/* pCoef Pointer to the filter's coefficients */ +/* */ +/* RETURNS: void */ +/* */ +/************************************************************************************/ +void LVPSA_QPD_Init ( pQPD_State_t pQPD_State, + QPD_Taps_t *pTaps, + QPD_C32_Coefs *pCoef ) +{ + pQPD_State->pDelay = pTaps->Storage; + pQPD_State->Coefs[0] = pCoef->KP; + pQPD_State->Coefs[1] = pCoef->KM; +} diff --git a/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_QPD_Process.c b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_QPD_Process.c new file mode 100755 index 0000000..7087475 --- /dev/null +++ b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_QPD_Process.c @@ -0,0 +1,220 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: PSA_01_ARMC_01 */ +/* $Author: beq07716 $*/ +/* $Revision: 1006 $*/ +/* $Date: 2010-06-28 14:01:47 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ +#include "LVPSA_QPD.h" +#include "LVPSA_Private.h" + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_QPD_WritePeak */ +/* */ +/* DESCRIPTION: */ +/* Write a level value in the buffer in the corresponding band. */ +/* */ +/* PARAMETERS: */ +/* pInst Pointer to the LVPSA instance */ +/* ppWrite Pointer to pointer to the buffer */ +/* CallNumber Number of the band the value should be written in */ +/* Value Value to write in the buffer */ +/* */ +/* RETURNS: void */ +/* */ +/************************************************************************************/ +void LVPSA_QPD_WritePeak( pLVPSA_InstancePr_t pLVPSA_Inst, + LVM_UINT8 **ppWrite, + LVM_INT16 BandIndex, + LVM_INT16 Value ); + + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_QPD_Process */ +/* */ +/* DESCRIPTION: */ +/* Apply downsampling, post gain, quasi peak filtering and write the levels values */ +/* in the buffer every 20 ms. */ +/* */ +/* PARAMETERS: */ +/* */ +/* RETURNS: void */ +/* */ +/************************************************************************************/ +void LVPSA_QPD_Process ( void *hInstance, + LVM_INT16 *pInSamps, + LVM_INT16 numSamples, + LVM_INT16 BandIndex) +{ + + /****************************************************************************** + PARAMETERS + *******************************************************************************/ + LVPSA_InstancePr_t *pLVPSA_Inst = (LVPSA_InstancePr_t*)hInstance; + QPD_State_t *pQPDState = (QPD_State_t*)&pLVPSA_Inst->pQPD_States[BandIndex]; + + /* Pointer to taps */ + LVM_INT32* pDelay = pQPDState->pDelay; + + /* Parameters needed during quasi peak calculations */ + LVM_INT32 X0; + LVM_INT32 temp,temp2; + LVM_INT32 accu; + LVM_INT16 Xg0; + LVM_INT16 D0; + LVM_INT16 V0 = (LVM_INT16)(*pDelay); + + /* Filter's coef */ + LVM_INT32 Kp = pQPDState->Coefs[0]; + LVM_INT32 Km = pQPDState->Coefs[1]; + + LVM_INT16 ii = numSamples; + + LVM_UINT8 *pWrite = pLVPSA_Inst->pSpectralDataBufferWritePointer; + LVM_INT32 BufferUpdateSamplesCount = pLVPSA_Inst->BufferUpdateSamplesCount; + LVM_UINT16 DownSamplingFactor = pLVPSA_Inst->DownSamplingFactor; + + /****************************************************************************** + INITIALIZATION + *******************************************************************************/ + /* Correct the pointer to take the first down sampled signal sample */ + pInSamps += pLVPSA_Inst->DownSamplingCount; + /* Correct also the number of samples */ + ii = (LVM_INT16)(ii - (LVM_INT16)pLVPSA_Inst->DownSamplingCount); + + while (ii > 0) + { + /* Apply post gain */ + X0 = ((*pInSamps) * pLVPSA_Inst->pPostGains[BandIndex]) >> (LVPSA_GAINSHIFT-1); /* - 1 to compensate scaling in process function*/ + pInSamps = pInSamps + DownSamplingFactor; + + /* Saturate and take absolute value */ + if(X0 < 0) + X0 = -X0; + if (X0 > 0x7FFF) + Xg0 = 0x7FFF; + else + Xg0 = (LVM_INT16)(X0); + + + /* Quasi peak filter calculation */ + D0 = (LVM_INT16)(Xg0 - V0); + + temp2 = (LVM_INT32)D0; + MUL32x32INTO32(temp2,Kp,accu,31); + + D0 = (LVM_INT16)(D0>>1); + if (D0 < 0){ + D0 = (LVM_INT16)(-D0); + } + + temp2 = (LVM_INT32)D0; + MUL32x32INTO32((LVM_INT32)D0,Km,temp,31); + accu +=temp + Xg0; + + if (accu > 0x7FFF) + accu = 0x7FFF; + else if(accu < 0) + accu = 0x0000; + + V0 = (LVM_INT16)accu; + + if(((pLVPSA_Inst->nSamplesBufferUpdate - BufferUpdateSamplesCount) < DownSamplingFactor)) + { + LVPSA_QPD_WritePeak( pLVPSA_Inst, + &pWrite, + BandIndex, + V0); + BufferUpdateSamplesCount -= pLVPSA_Inst->nSamplesBufferUpdate; + pLVPSA_Inst->LocalSamplesCount = (LVM_UINT16)(numSamples - ii); + } + BufferUpdateSamplesCount+=DownSamplingFactor; + + ii = (LVM_INT16)(ii-DownSamplingFactor); + + } + + /* Store last taps in memory */ + *pDelay = (LVM_INT32)(V0); + + /* If this is the last call to the function after last band processing, + update the parameters. */ + if(BandIndex == (pLVPSA_Inst->nRelevantFilters-1)) + { + pLVPSA_Inst->pSpectralDataBufferWritePointer = pWrite; + /* Adjustment for 11025Hz input, 220,5 is normally + the exact number of samples for 20ms.*/ + if((pLVPSA_Inst->pSpectralDataBufferWritePointer != pWrite)&&(pLVPSA_Inst->CurrentParams.Fs == LVM_FS_11025)) + { + if(pLVPSA_Inst->nSamplesBufferUpdate == 220) + { + pLVPSA_Inst->nSamplesBufferUpdate = 221; + } + else + { + pLVPSA_Inst->nSamplesBufferUpdate = 220; + } + } + pLVPSA_Inst->pSpectralDataBufferWritePointer = pWrite; + pLVPSA_Inst->BufferUpdateSamplesCount = BufferUpdateSamplesCount; + pLVPSA_Inst->DownSamplingCount = (LVM_UINT16)(-ii); + } +} + +/************************************************************************************/ +/* */ +/* FUNCTION: LVPSA_QPD_WritePeak */ +/* */ +/* DESCRIPTION: */ +/* Write a level value in the spectrum data buffer in the corresponding band. */ +/* */ +/* PARAMETERS: */ +/* pLVPSA_Inst Pointer to the LVPSA instance */ +/* ppWrite Pointer to pointer to the buffer */ +/* CallNumber Number of the band the value should be written in */ +/* Value Value to write in the spectrum data buffer */ +/* */ +/* RETURNS: void */ +/* */ +/************************************************************************************/ +void LVPSA_QPD_WritePeak( pLVPSA_InstancePr_t pLVPSA_Inst, + LVM_UINT8 **ppWrite, + LVM_INT16 BandIndex, + LVM_INT16 Value ) +{ + LVM_UINT8 *pWrite = *ppWrite; + + + /* Write the value and update the write pointer */ + *(pWrite + BandIndex) = (LVM_UINT8)(Value>>7); + pWrite += pLVPSA_Inst->nBands; + if (pWrite == (pLVPSA_Inst->pSpectralDataBufferStart + pLVPSA_Inst->nBands * pLVPSA_Inst->SpectralDataBufferLength)) + { + pWrite = pLVPSA_Inst->pSpectralDataBufferStart; + } + + *ppWrite = pWrite; + +} + diff --git a/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Tables.c b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Tables.c new file mode 100755 index 0000000..f4a35c5 --- /dev/null +++ b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Tables.c @@ -0,0 +1,250 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************/ +/* */ +/* Project:: PSA_01_ARMC_01 */ +/* $Author: beq07716 $*/ +/* $Revision: 1006 $*/ +/* $Date: 2010-06-28 14:01:47 +0200 (Mon, 28 Jun 2010) $*/ +/* */ +/************************************************************************/ + + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVPSA.h" +#include "LVPSA_QPD.h" +/************************************************************************************/ +/* */ +/* Sample rate table */ +/* */ +/************************************************************************************/ + +/* + * Sample rate table for converting between the enumerated type and the actual + * frequency + */ +const LVM_UINT16 LVPSA_SampleRateTab[] = { 8000, /* 8kS/s */ + 11025, + 12000, + 16000, + 22050, + 24000, + 32000, + 44100, + 48000}; /* 48kS/s */ + +/************************************************************************************/ +/* */ +/* Sample rate inverse table */ +/* */ +/************************************************************************************/ + +/* + * Sample rate table for converting between the enumerated type and the actual + * frequency + */ +const LVM_UINT32 LVPSA_SampleRateInvTab[] = { 268435, /* 8kS/s */ + 194783, + 178957, + 134218, + 97391, + 89478, + 67109, + 48696, + 44739}; /* 48kS/s */ + + + +/************************************************************************************/ +/* */ +/* Number of samples in 20ms */ +/* */ +/************************************************************************************/ + +/* + * Table for converting between the enumerated type and the number of samples + * during 20ms + */ +const LVM_UINT16 LVPSA_nSamplesBufferUpdate[] = { 160, /* 8kS/s */ + 220, + 240, + 320, + 441, + 480, + 640, + 882, + 960}; /* 48kS/s */ +/************************************************************************************/ +/* */ +/* Down sampling factors */ +/* */ +/************************************************************************************/ + +/* + * Table for converting between the enumerated type and the down sampling factor + */ +const LVM_UINT16 LVPSA_DownSamplingFactor[] = { 5, /* 8000 S/s */ + 7, /* 11025 S/s */ + 8, /* 12000 S/s */ + 10, /* 16000 S/s */ + 15, /* 22050 S/s */ + 16, /* 24000 S/s */ + 21, /* 32000 S/s */ + 30, /* 44100 S/s */ + 32}; /* 48000 S/s */ + + +/************************************************************************************/ +/* */ +/* Coefficient calculation tables */ +/* */ +/************************************************************************************/ + +/* + * Table for 2 * Pi / Fs + */ +const LVM_INT16 LVPSA_TwoPiOnFsTable[] = { 26354, /* 8kS/s */ + 19123, + 17569, + 13177, + 9561, + 8785, + 6588, + 4781, + 4392}; /* 48kS/s */ + +/* + * Gain table + */ +const LVM_INT16 LVPSA_GainTable[] = { 364, /* -15dB gain */ + 408, + 458, + 514, + 577, + 647, + 726, + 815, + 914, + 1026, + 1151, + 1292, + 1449, + 1626, + 1825, + 2048, /* 0dB gain */ + 2297, + 2578, + 2892, + 3245, + 3641, + 4096, + 4584, + 5144, + 5772, + 6476, + 7266, + 8153, + 9148, + 10264, + 11576}; /* +15dB gain */ + +/************************************************************************************/ +/* */ +/* Cosone polynomial coefficients */ +/* */ +/************************************************************************************/ + +/* + * Coefficients for calculating the cosine with the equation: + * + * Cos(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + a5*x^5) + * + * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting + * a range of 0 to Pi. The output is in the range 32767 to -32768 representing the range + * +1.0 to -1.0 + */ +const LVM_INT16 LVPSA_CosCoef[] = { 3, /* Shifts */ + 4096, /* a0 */ + -36, /* a1 */ + -19725, /* a2 */ + -2671, /* a3 */ + 23730, /* a4 */ + -9490}; /* a5 */ + +/* + * Coefficients for calculating the cosine error with the equation: + * + * CosErr(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3) + * + * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting + * a range of 0 to Pi/25. The output is in the range 0 to 32767 representing the range + * 0.0 to 0.0078852986 + * + * This is used to give a double precision cosine over the range 0 to Pi/25 using the + * the equation: + * + * Cos(x) = 1.0 - CosErr(x) + */ +const LVM_INT16 LVPSA_DPCosCoef[] = { 1, /* Shifts */ + 0, /* a0 */ + -6, /* a1 */ + 16586, /* a2 */ + -44}; /* a3 */ + +/************************************************************************************/ +/* */ +/* Quasi peak filter coefficients table */ +/* */ +/************************************************************************************/ +const QPD_C32_Coefs LVPSA_QPD_Coefs[] = { + + {0x80CEFD2B,0x00CB9B17}, /* 8kS/s */ /* LVPSA_SPEED_LOW */ + {0x80D242E7,0x00CED11D}, + {0x80DCBAF5,0x00D91679}, + {0x80CEFD2B,0x00CB9B17}, + {0x80E13739,0x00DD7CD3}, + {0x80DCBAF5,0x00D91679}, + {0x80D94BAF,0x00D5B7E7}, + {0x80E13739,0x00DD7CD3}, + {0x80DCBAF5,0x00D91679}, /* 48kS/s */ + + {0x8587513D,0x055C22CF}, /* 8kS/s */ /* LVPSA_SPEED_MEDIUM */ + {0x859D2967,0x0570F007}, + {0x85E2EFAC,0x05B34D79}, + {0x8587513D,0x055C22CF}, + {0x8600C7B9,0x05CFA6CF}, + {0x85E2EFAC,0x05B34D79}, + {0x85CC1018,0x059D8F69}, + {0x8600C7B9,0x05CFA6CF},//{0x8600C7B9,0x05CFA6CF}, + {0x85E2EFAC,0x05B34D79}, /* 48kS/s */ + + {0xA115EA7A,0x1CDB3F5C}, /* 8kS/s */ /* LVPSA_SPEED_HIGH */ + {0xA18475F0,0x1D2C83A2}, + {0xA2E1E950,0x1E2A532E}, + {0xA115EA7A,0x1CDB3F5C}, + {0xA375B2C6,0x1E943BBC}, + {0xA2E1E950,0x1E2A532E}, + {0xA26FF6BD,0x1DD81530}, + {0xA375B2C6,0x1E943BBC}, + {0xA2E1E950,0x1E2A532E}}; /* 48kS/s */ + diff --git a/media/libeffects/lvm/lib/StereoWidening/lib/LVCS.h b/media/libeffects/lvm/lib/StereoWidening/lib/LVCS.h new file mode 100755 index 0000000..1ab45cc --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/lib/LVCS.h @@ -0,0 +1,396 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************************** + + $Author: beq07716 $ + $Revision: 1001 $ + $Date: 2010-06-28 13:23:02 +0200 (Mon, 28 Jun 2010) $ + +*****************************************************************************************/ + +/****************************************************************************************/ +/* */ +/* Header file for the application layer interface of Concert Sound and Concert */ +/* Sound EX. */ +/* */ +/* This files includes all definitions, types, structures and function */ +/* prototypes required by the calling layer. All other types, structures and */ +/* functions are private. */ +/* */ +/****************************************************************************************/ +/* */ +/* Note: 1 */ +/* ======= */ +/* The algorithm can execute either with separate input and output buffers or with */ +/* a common buffer, i.e. the data is processed in-place. If the buffers are the */ +/* same then the MIPs will be slightly higher and an extra stereo scratch buffer is */ +/* required. */ +/* */ +/****************************************************************************************/ +/* */ +/* Note: 2 */ +/* ======= */ +/* Two data formats are support Stereo and Mono-In-Stereo. The data is interleaved as */ +/* follows: */ +/* Byte Offset Stereo Input Mono-In-Stereo Input */ +/* =========== ============ ==================== */ +/* 0 Left Sample #1 Mono Sample #1 */ +/* 2 Right Sample #1 Mono Sample #1 */ +/* 4 Left Sample #2 Mono Sample #2 */ +/* 6 Right Sample #2 Mono Sample #2 */ +/* . . . */ +/* . . . */ +/* */ +/* Mono format data is not supported, the calling routine must convert a Mono stream */ +/* in to Mono-In-Stereo format. */ +/* */ +/****************************************************************************************/ + +#ifndef LVCS_H +#define LVCS_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/****************************************************************************************/ +/* */ +/* Includes */ +/* */ +/****************************************************************************************/ + +#include "LVM_Types.h" +#include "LVM_Common.h" + + +/****************************************************************************************/ +/* */ +/* Definitions */ +/* */ +/****************************************************************************************/ + +/* Memory table */ +#define LVCS_MEMREGION_PERSISTENT_SLOW_DATA 0 /* Offset to the instance memory region */ +#define LVCS_MEMREGION_PERSISTENT_FAST_DATA 1 /* Offset to the persistent data memory region */ +#define LVCS_MEMREGION_PERSISTENT_FAST_COEF 2 /* Offset to the persistent coefficient memory region */ +#define LVCS_MEMREGION_TEMPORARY_FAST 3 /* Offset to temporary memory region */ +#define LVCS_NR_MEMORY_REGIONS 4 /* Number of memory regions */ + +/* Effect Level */ +#define LVCS_EFFECT_LOW 16384 /* Effect scaling 50% */ +#define LVCS_EFFECT_MEDIUM 24576 /* Effect scaling 75% */ +#define LVCS_EFFECT_HIGH 32767 /* Effect Scaling 100% */ + +/* Callback events */ +#define LVCS_EVENT_NONE 0x0000 /* Not a valid event */ +#define LVCS_EVENT_ALGOFF 0x0001 /* CS has completed switch off */ + + +/****************************************************************************************/ +/* */ +/* Types */ +/* */ +/****************************************************************************************/ + +/* Instance handle */ +typedef void *LVCS_Handle_t; + + +/* Operating modes */ +typedef enum +{ + LVCS_OFF = 0, + LVCS_ON = 15, + LVCS_MAX = LVM_MAXENUM +} LVCS_Modes_en; + + +/* Memory Types */ +typedef enum +{ + LVCS_SCRATCH = 0, + LVCS_DATA = 1, + LVCS_COEFFICIENT = 2, + LVCS_PERSISTENT = 3, + LVCS_MEMORYTYPE_MAX = LVM_MAXENUM +} LVCS_MemoryTypes_en; + + +/* Function return status */ +typedef enum +{ + LVCS_SUCCESS = 0, /* Successful return from a routine */ + LVCS_ALIGNMENTERROR = 1, /* Memory alignment error */ + LVCS_NULLADDRESS = 2, /* NULL allocation address */ + LVCS_TOOMANYSAMPLES = 3, /* Maximum block size exceeded */ + LVCS_INVALIDBUFFER = 4, /* Invalid buffer processing request */ + LVCS_STATUSMAX = LVM_MAXENUM +} LVCS_ReturnStatus_en; + + +/* + * Source data formats + */ +typedef enum +{ + LVCS_STEREO = 0, + LVCS_MONOINSTEREO = 1, + LVCS_SOURCEMAX = LVM_MAXENUM +} LVCS_SourceFormat_en; + + +/* + * Supported output devices + */ +typedef enum +{ + LVCS_HEADPHONES = 0, + LVCS_EX_HEADPHONES = 1, + LVCS_SPEAKERTYPE_MAX = LVM_MAXENUM +} LVCS_SpeakerType_en; + +/* + * Speaker Coefficients Table + */ +typedef struct +{ + void *pTable1; + void *pTable2; + void *pTable3; + void *pTable4; + void *pTable5; + void *pTable6; + void *pTable7; + void *pTable8; +} LVCS_CSMS_Coef_Tables_t; + + +/****************************************************************************************/ +/* */ +/* Structures */ +/* */ +/****************************************************************************************/ + +/* Memory region definition */ +typedef struct +{ + LVM_UINT32 Size; /* Region size in bytes */ + LVCS_MemoryTypes_en Type; /* Region type */ + void *pBaseAddress; /* Pointer to the region base address */ +} LVCS_MemoryRegion_t; + + +/* Memory table containing the region definitions */ +typedef struct +{ + LVCS_MemoryRegion_t Region[LVCS_NR_MEMORY_REGIONS]; /* One definition for each region */ +} LVCS_MemTab_t; + + +/* Concert Sound parameter structure */ +typedef struct +{ + LVCS_Modes_en OperatingMode; /* Algorithm mode */ + LVCS_SpeakerType_en SpeakerType; /* Output device type */ + LVCS_SourceFormat_en SourceFormat; /* Source data format */ + LVM_Mode_en CompressorMode; /* Non-Linear Compressor Mode */ + LVM_Fs_en SampleRate; /* Sampling rate */ + LVM_INT16 EffectLevel; /* Effect level */ + LVM_UINT16 ReverbLevel; /* Reverb level in % */ +} LVCS_Params_t; + + +/* Concert Sound Capability structure */ +typedef struct +{ + /* General parameters */ + LVM_UINT16 MaxBlockSize; /* Maximum block size in sample pairs */ + + /* Callback parameters */ + LVM_Callback CallBack; /* Bundle callback */ + void *pBundleInstance; /* Bundle instance handle */ + +} LVCS_Capabilities_t; + + +/****************************************************************************************/ +/* */ +/* Function Prototypes */ +/* */ +/****************************************************************************************/ + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVCS_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) it is */ +/* passed the default capabilities, of these only the buffer processing setting is */ +/* used. */ +/* */ +/* When called for memory allocation the memory base address pointers are NULL on */ +/* return. */ +/* */ +/* When the function is called for free (hInstance = Instance Handle) the */ +/* capabilities are ignored and 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 default capabilites */ +/* */ +/* RETURNS: */ +/* LVCS_Success Succeeded */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVCS_Process function */ +/* */ +/****************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_Memory(LVCS_Handle_t hInstance, + LVCS_MemTab_t *pMemoryTable, + LVCS_Capabilities_t *pCapabilities); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVCS_Init */ +/* */ +/* DESCRIPTION: */ +/* Create and initialisation function for the Concert Sound 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 */ +/* LVCS_Memory before calling this function. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pMemoryTable Pointer to the memory definition table */ +/* pCapabilities Pointer to the initialisation capabilities */ +/* */ +/* RETURNS: */ +/* LVCS_Success Initialisation succeeded */ +/* LVCS_AlignmentError Instance or scratch memory on incorrect alignment */ +/* LVCS_NullAddress Instance or scratch 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 LVCS_Process function */ +/* */ +/****************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_Init(LVCS_Handle_t *phInstance, + LVCS_MemTab_t *pMemoryTable, + LVCS_Capabilities_t *pCapabilities); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVCS_GetParameters */ +/* */ +/* DESCRIPTION: */ +/* Request the Concert Sound parameters. The current parameter set is returned */ +/* via the parameter pointer. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to an empty parameter structure */ +/* */ +/* RETURNS: */ +/* LVCS_Success Always succeeds */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVCS_Process function */ +/* */ +/****************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_GetParameters(LVCS_Handle_t hInstance, + LVCS_Params_t *pParams); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVCS_Control */ +/* */ +/* DESCRIPTION: */ +/* Sets or changes the Concert Sound parameters. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to a parameter structure */ +/* */ +/* RETURNS: */ +/* LVCS_Success Succeeded */ +/* */ +/* NOTES: */ +/* 1. This function must not be interrupted by the LVCS_Process function */ +/* */ +/****************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_Control(LVCS_Handle_t hInstance, + LVCS_Params_t *pParams); + + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVCS_Process */ +/* */ +/* DESCRIPTION: */ +/* Process function for the Concert Sound module. The implementation supports two */ +/* variants of the algorithm, one for headphones and one for mobile speakers. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pInData Pointer to the input data */ +/* pOutData Pointer to the output data */ +/* NumSamples Number of samples in the input buffer */ +/* */ +/* RETURNS: */ +/* LVCS_Success Succeeded */ +/* LVCS_TooManySamples NumSamples was larger than the maximum block size */ +/* */ +/* NOTES: */ +/* */ +/****************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_Process(LVCS_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 *pOutData, + LVM_UINT16 NumSamples); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LVCS_H */ diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_BypassMix.c b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_BypassMix.c new file mode 100755 index 0000000..2a83e89 --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_BypassMix.c @@ -0,0 +1,303 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: nxp007753 $ + $Revision: 1246 $ + $Date: 2010-07-16 11:07:10 +0200 (Fri, 16 Jul 2010) $ + +*************************************************************************************/ + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVCS.h" +#include "LVCS_Private.h" +#include "LVCS_BypassMix.h" +#include "VectorArithmetic.h" +#include "LVCS_Tables.h" + +/****************************************************************************************/ +/* */ +/* Function Prototypes */ +/* */ +/****************************************************************************************/ +LVM_INT32 LVCS_MixerCallback( LVCS_Handle_t hInstance, + void *pGeneralPurpose, + LVM_INT16 CallbackParam); + +/************************************************************************************/ +/* */ +/* FUNCTION: LVCS_BypassMixInit */ +/* */ +/* DESCRIPTION: */ +/* Initialises the bypass mixer module */ +/* */ +/* The overall gain of the processed path is set by the gains in the individual */ +/* processing blocks and by the effect level gain. */ +/* */ +/* The unprocessed path must have matching gain for the processed path to ensure */ +/* as they are mixed together the correct effect is achieved, this is the value */ +/* UnprocLoss. */ +/* */ +/* The overall gain is corrected by a combination of a shift with saturation and a */ +/* linear scaler, loss. The loss ensures the sum in the mixer does not saturate */ +/* and also corrects for any excess gain in the shift. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pParams Initialisation parameters */ +/* */ +/* RETURNS: */ +/* LVCS_Success Always succeeds */ +/* */ +/* NOTES: */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_BypassMixInit(LVCS_Handle_t hInstance, + LVCS_Params_t *pParams) +{ + + LVM_UINT16 Offset; + LVM_UINT32 Gain; + LVCS_Instance_t *pInstance = (LVCS_Instance_t *)hInstance; + LVCS_BypassMix_t *pConfig = (LVCS_BypassMix_t *)&pInstance->BypassMix; + const Gain_t *pOutputGainTable; + LVM_INT32 Current; + + + /* + * Set the transition gain + */ + if ((pParams->OperatingMode == LVCS_ON) && + (pInstance->bTimerDone == LVM_TRUE) + && (LVC_Mixer_GetTarget(&pInstance->MSBypassMixer.MixerStream[1]) != 0x7FFF) /* this indicates an off->on transtion */ + ) + { + pInstance->TransitionGain = pParams->EffectLevel; + } + else + { + /* Select no effect level */ + pInstance->TransitionGain = 0; + } + + /* + * Calculate the output gain table offset + */ + Offset = (LVM_UINT16)(pParams->SpeakerType + (pParams->SourceFormat*(1+LVCS_EX_HEADPHONES))); + pOutputGainTable = (Gain_t*)&LVCS_OutputGainTable[0]; + + /* + * Setup the mixer gain for the processed path + */ + Gain = (LVM_UINT32)(pOutputGainTable[Offset].Loss * pInstance->TransitionGain); + + pConfig->Mixer_Instance.MixerStream[0].CallbackParam = 0; + pConfig->Mixer_Instance.MixerStream[0].pCallbackHandle = LVM_NULL; + pConfig->Mixer_Instance.MixerStream[0].pCallBack = LVM_NULL; + pConfig->Mixer_Instance.MixerStream[0].CallbackSet=1; + Current = LVC_Mixer_GetCurrent(&pConfig->Mixer_Instance.MixerStream[0]); + LVC_Mixer_Init(&pConfig->Mixer_Instance.MixerStream[0],(LVM_INT32)(Gain >> 15),Current); + LVC_Mixer_VarSlope_SetTimeConstant(&pConfig->Mixer_Instance.MixerStream[0],LVCS_BYPASS_MIXER_TC,pParams->SampleRate,2); + /* + * Setup the mixer gain for the unprocessed path + */ + Gain = (LVM_UINT32)(pOutputGainTable[Offset].Loss * (0x7FFF - pInstance->TransitionGain)); + Gain = (LVM_UINT32)pOutputGainTable[Offset].UnprocLoss * (Gain >> 15); + Current = LVC_Mixer_GetCurrent(&pConfig->Mixer_Instance.MixerStream[1]); + LVC_Mixer_Init(&pConfig->Mixer_Instance.MixerStream[1],(LVM_INT32)(Gain >> 15),Current); + LVC_Mixer_VarSlope_SetTimeConstant(&pConfig->Mixer_Instance.MixerStream[1],LVCS_BYPASS_MIXER_TC,pParams->SampleRate,2); + pConfig->Mixer_Instance.MixerStream[1].CallbackParam = 0; + pConfig->Mixer_Instance.MixerStream[1].pCallbackHandle = hInstance; + pConfig->Mixer_Instance.MixerStream[1].CallbackSet=1; + pConfig->Mixer_Instance.MixerStream[1].pCallBack = LVCS_MixerCallback; + + /* + * Setup the output gain shift + */ + pConfig->Output_Shift = pOutputGainTable[Offset].Shift; + + + /* + * Correct gain for the effect level + */ + { + + LVM_INT16 GainCorrect; + LVM_INT32 Gain1; + LVM_INT32 Gain2; + + Gain1 = LVC_Mixer_GetTarget(&pConfig->Mixer_Instance.MixerStream[0]); + Gain2 = LVC_Mixer_GetTarget(&pConfig->Mixer_Instance.MixerStream[1]); + /* + * Calculate the gain correction + */ + if (pInstance->Params.CompressorMode == LVM_MODE_ON) + { + GainCorrect = (LVM_INT16)( pInstance->VolCorrect.GainMin + - (((LVM_INT32)pInstance->VolCorrect.GainMin * (LVM_INT32)pInstance->TransitionGain) >> 15) + + (((LVM_INT32)pInstance->VolCorrect.GainFull * (LVM_INT32)pInstance->TransitionGain) >> 15) ); + + /* + * Apply the gain correction and shift, note the result is in Q3.13 format + */ + Gain1 = (Gain1 * GainCorrect) << 4; + Gain2 = (Gain2 * GainCorrect) << 4; + } + else + { + Gain1 = Gain1 << 16; + Gain2 = Gain2 << 16; + } + + + + /* + * Set the gain values + */ + pConfig->Output_Shift = pConfig->Output_Shift; + LVC_Mixer_SetTarget(&pConfig->Mixer_Instance.MixerStream[0],Gain1>>16); + LVC_Mixer_VarSlope_SetTimeConstant(&pConfig->Mixer_Instance.MixerStream[0],LVCS_BYPASS_MIXER_TC,pParams->SampleRate,2); + LVC_Mixer_SetTarget(&pConfig->Mixer_Instance.MixerStream[1],Gain2>>16); + LVC_Mixer_VarSlope_SetTimeConstant(&pConfig->Mixer_Instance.MixerStream[1],LVCS_BYPASS_MIXER_TC,pParams->SampleRate,2); + } + + return(LVCS_SUCCESS); + +} + +/************************************************************************************/ +/* */ +/* FUNCTION: LVCS_BypassMixer */ +/* */ +/* DESCRIPTION: */ +/* Apply Bypass Mix. */ +/* */ +/* This mixes the processed and unprocessed data streams together to correct the */ +/* overall system gain and allow progressive control of the Concert Sound effect. */ +/* */ +/* When the bypass mixer is enabled the output is the processed signal only and */ +/* without gain correction. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pProcessed Pointer to the processed data */ +/* pUnprocessed Pointer to the unprocessed data */ +/* pOutData Pointer to the output data */ +/* NumSamples Number of samples to process */ +/* */ +/* RETURNS: */ +/* LVCS_Success Always succeeds */ +/* */ +/* NOTES: */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_BypassMixer(LVCS_Handle_t hInstance, + const LVM_INT16 *pProcessed, + const LVM_INT16 *pUnprocessed, + LVM_INT16 *pOutData, + LVM_UINT16 NumSamples) +{ + + LVCS_Instance_t *pInstance = (LVCS_Instance_t *)hInstance; + LVCS_BypassMix_t *pConfig = (LVCS_BypassMix_t *)&pInstance->BypassMix; + + /* + * Check if the bypass mixer is enabled + */ + if ((pInstance->Params.OperatingMode & LVCS_BYPASSMIXSWITCH) != 0) + { + /* + * Apply the bypass mix + */ + LVC_MixSoft_2St_D16C31_SAT(&pConfig->Mixer_Instance, + pProcessed, + (LVM_INT16 *) pUnprocessed, + pOutData, + (LVM_INT16)(2*NumSamples)); + + /* + * Apply output gain correction shift + */ + Shift_Sat_v16xv16 ((LVM_INT16)pConfig->Output_Shift, + (LVM_INT16*)pOutData, + (LVM_INT16*)pOutData, + (LVM_INT16)(2*NumSamples)); /* Left and right*/ + } + + return(LVCS_SUCCESS); +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVCS_MixerCallback */ +/* */ +/************************************************************************************/ +LVM_INT32 LVCS_MixerCallback(LVCS_Handle_t hInstance, + void *pGeneralPurpose, + LVM_INT16 CallbackParam) +{ + LVCS_Instance_t *pInstance = (LVCS_Instance_t *)hInstance; + LVM_INT32 Target1; + + Target1 = LVC_Mixer_GetTarget(&pInstance->MSBypassMixer.MixerStream[0]); + (void)pGeneralPurpose; + + /* + * Off transition has completed in Headphone mode + */ + if ((pInstance->OutputDevice == LVCS_HEADPHONE) && + (pInstance->bInOperatingModeTransition) && + (Target1 == 0x0000)&& /* this indicates an on->off transition */ + (CallbackParam == 0)) + { + /* Set operating mode to OFF */ + pInstance->Params.OperatingMode = LVCS_OFF; + + /* Exit transition state */ + pInstance->bInOperatingModeTransition = LVM_FALSE; + + /* Signal to the bundle */ + if((*pInstance->Capabilities.CallBack) != LVM_NULL){ + (*pInstance->Capabilities.CallBack)(pInstance->Capabilities.pBundleInstance, + LVM_NULL, + (ALGORITHM_CS_ID | LVCS_EVENT_ALGOFF)); + } + } + + + if ((pInstance->OutputDevice == LVCS_HEADPHONE) && + (Target1 == 1) && + (pInstance->bTimerDone == LVM_TRUE)){ + + /* Exit transition state */ + pInstance->bInOperatingModeTransition = LVM_FALSE; + } + + return 1; +} + + + diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_BypassMix.h b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_BypassMix.h new file mode 100755 index 0000000..79dff41 --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_BypassMix.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1001 $ + $Date: 2010-06-28 13:23:02 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + +#ifndef __LVCS_BYPASSMIX_H__ +#define __LVCS_BYPASSMIX_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVC_Mixer.h" + + +/************************************************************************************/ +/* */ +/* Structures */ +/* */ +/************************************************************************************/ + +/* Bypass mixer structure */ +typedef struct +{ + /* Mixer settings */ + LVMixer3_2St_st Mixer_Instance; /* Mixer instance */ + LVM_UINT16 Output_Shift; /* Correcting gain output shift */ + +} LVCS_BypassMix_t; + + +/* Output gain type */ +typedef struct +{ + /* Output gain settings, Gain = (Loss/32768) * 2^Shift */ + LVM_UINT16 Shift; /* Left shifts required */ + LVM_UINT16 Loss; /* Loss required */ + LVM_UINT16 UnprocLoss; /* Unprocessed path loss */ +} Gain_t; + + +/************************************************************************************/ +/* */ +/* Function prototypes */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_BypassMixInit(LVCS_Handle_t hInstance, + LVCS_Params_t *pParams); + + +LVCS_ReturnStatus_en LVCS_BypassMixer(LVCS_Handle_t hInstance, + const LVM_INT16 *pProcessed, + const LVM_INT16 *unProcessed, + LVM_INT16 *pOutData, + LVM_UINT16 NumSamples); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* BYPASSMIX_H */ diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Control.c b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Control.c new file mode 100755 index 0000000..5dfca25 --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Control.c @@ -0,0 +1,273 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: nxp007753 $ + $Revision: 1246 $ + $Date: 2010-07-16 11:07:10 +0200 (Fri, 16 Jul 2010) $ + +*************************************************************************************/ + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVCS.h" +#include "LVCS_Private.h" +#include "LVCS_Tables.h" + +/************************************************************************************/ +/* */ +/* FUNCTION: LVCS_GetParameters */ +/* */ +/* DESCRIPTION: */ +/* Request the Concert Sound parameters. The current parameter set is returned */ +/* via the parameter pointer. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to an empty parameter structure */ +/* */ +/* RETURNS: */ +/* LVCS_Success Always succeeds */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVCS_Process function */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_GetParameters(LVCS_Handle_t hInstance, + LVCS_Params_t *pParams) +{ + + LVCS_Instance_t *pInstance =(LVCS_Instance_t *)hInstance; + + *pParams = pInstance->Params; + + return(LVCS_SUCCESS); +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVCS_Control */ +/* */ +/* DESCRIPTION: */ +/* Sets or changes the Concert Sound parameters. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pParams Pointer to a parameter structure */ +/* */ +/* RETURNS: */ +/* LVCS_Success Succeeded */ +/* */ +/* NOTES: */ +/* 1. This function must not be interrupted by the LVCS_Process function */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_Control(LVCS_Handle_t hInstance, + LVCS_Params_t *pParams) +{ + LVM_INT16 Offset; + LVCS_Instance_t *pInstance =(LVCS_Instance_t *)hInstance; + LVCS_ReturnStatus_en err; + LVCS_Modes_en OperatingModeSave = pInstance->Params.OperatingMode; + + if (pParams->SampleRate != pInstance->Params.SampleRate) + { + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->MSBypassMixer.MixerStream[0],LVCS_BYPASS_MIXER_TC,pParams->SampleRate,2); + + LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->MSBypassMixer.MixerStream[1],LVCS_BYPASS_MIXER_TC,pParams->SampleRate,2); + pInstance->TimerParams.SamplingRate = LVCS_SampleRateTable[pParams->SampleRate]; + } + + /* + * If the reverb level has changed + */ + if(pInstance->Params.ReverbLevel != pParams->ReverbLevel) + { + err=LVCS_ReverbGeneratorInit(hInstance,pParams); + } + + /* + * If the sample rate or speaker has changed then perform a full re-initialisation + */ + if ((pInstance->Params.SampleRate != pParams->SampleRate) || + (pInstance->Params.SpeakerType != pParams->SpeakerType)) + { + const LVCS_VolCorrect_t *pLVCS_VolCorrectTable; + + /* + * Output device + */ + pInstance->OutputDevice = LVCS_HEADPHONE; + + /* + * Get the volume correction parameters + */ + /* Use internal coefficient table */ + pLVCS_VolCorrectTable = (LVCS_VolCorrect_t*)&LVCS_VolCorrectTable[0]; + Offset = (LVM_INT16)(pParams->SpeakerType + pParams->SourceFormat*(1+LVCS_EX_HEADPHONES)); + + pInstance->VolCorrect = pLVCS_VolCorrectTable[Offset]; + + err=LVCS_SEnhancerInit(hInstance, + pParams); + + err=LVCS_ReverbGeneratorInit(hInstance, + pParams); + + err=LVCS_EqualiserInit(hInstance, + pParams); + + err=LVCS_BypassMixInit(hInstance, + pParams); + + } + + + /* + * Check if the effect level or source format has changed + */ + else if ((pInstance->Params.EffectLevel != pParams->EffectLevel) || + (pInstance->Params.SourceFormat != pParams->SourceFormat)) + { + const LVCS_VolCorrect_t *pLVCS_VolCorrectTable; + + /* + * Get the volume correction parameters + */ + /* Use internal coefficient table */ + pLVCS_VolCorrectTable = (LVCS_VolCorrect_t*)&LVCS_VolCorrectTable[0]; + Offset = (LVM_INT16)(pParams->SpeakerType + pParams->SourceFormat*(1+LVCS_EX_HEADPHONES)); + + pInstance->VolCorrect = pLVCS_VolCorrectTable[Offset]; + + /* Update the effect level and alpha-mixer gains */ + err=LVCS_BypassMixInit(hInstance, + pParams); + + if(err != LVCS_SUCCESS) + { + return err; + } + } + else + { + pInstance->Params = *pParams; + } + + /* + * Update the instance parameters + */ + pInstance->Params = *pParams; + + /* Stay on the current operating mode until the transition is done */ + if((pParams->OperatingMode != OperatingModeSave) || + (pInstance->bInOperatingModeTransition == LVM_TRUE)){ + + /* Set the reverb delay timeout */ + if(pInstance->bInOperatingModeTransition != LVM_TRUE){ + pInstance->bTimerDone = LVM_FALSE; + pInstance->TimerParams.TimeInMs = (LVM_INT16)(((pInstance->Reverberation.DelaySize << 2)/pInstance->TimerParams.SamplingRate) + 1); + LVM_Timer_Init ( &pInstance->TimerInstance, + &pInstance->TimerParams); + } + + /* Update the effect level and alpha-mixer gains */ + err=LVCS_BypassMixInit(hInstance, + pParams); + + /* Change transition bypass mixer settings if needed depending on transition type */ + if(pParams->OperatingMode != LVCS_OFF){ + LVM_INT32 Current1; + LVM_INT32 Current2; + + Current1 = LVC_Mixer_GetCurrent(&pInstance->MSBypassMixer.MixerStream[0]); + Current2 = LVC_Mixer_GetCurrent(&pInstance->MSBypassMixer.MixerStream[1]); + + if(pInstance->bInOperatingModeTransition != LVM_TRUE) + { + Current1 = 0x00000000; + Current2 = LVM_MAXINT_16; + } + pInstance->MSBypassMixer.MixerStream[0].CallbackSet = 1; + pInstance->MSBypassMixer.MixerStream[1].CallbackSet = 1; + + LVC_Mixer_Init(&pInstance->MSBypassMixer.MixerStream[0],LVM_MAXINT_16,Current1); + LVC_Mixer_Init(&pInstance->MSBypassMixer.MixerStream[1],0,Current2); + } + else + { + LVM_INT32 Current1; + LVM_INT32 Current2; + + Current1 = LVC_Mixer_GetCurrent(&pInstance->MSBypassMixer.MixerStream[0]); + Current2 = LVC_Mixer_GetCurrent(&pInstance->MSBypassMixer.MixerStream[1]); + + if(pInstance->bInOperatingModeTransition != LVM_TRUE) + { + Current1 = LVM_MAXINT_16; + Current2 = 0x00000000; + } + pInstance->MSBypassMixer.MixerStream[0].CallbackSet = 1; + pInstance->MSBypassMixer.MixerStream[1].CallbackSet = 1; + pInstance->Params.OperatingMode = OperatingModeSave; + LVC_Mixer_Init(&pInstance->MSBypassMixer.MixerStream[0],0x00000000,Current1); + LVC_Mixer_Init(&pInstance->MSBypassMixer.MixerStream[1],LVM_MAXINT_16,Current2); + } + LVC_Mixer_SetTimeConstant(&pInstance->MSBypassMixer.MixerStream[0],LVCS_BYPASS_MIXER_TC,pParams->SampleRate,2); + LVC_Mixer_SetTimeConstant(&pInstance->MSBypassMixer.MixerStream[1],LVCS_BYPASS_MIXER_TC,pParams->SampleRate,2); + + + /* Set transition flag */ + pInstance->bInOperatingModeTransition = LVM_TRUE; + } + + return(LVCS_SUCCESS); +} + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVCS_TimerCallBack */ +/* */ +/* DESCRIPTION: */ +/* CallBack function of the Timer. */ +/* */ +/****************************************************************************************/ +void LVCS_TimerCallBack (void* hInstance, void* pCallBackParams, LVM_INT32 CallbackParam) +{ + LVCS_Instance_t *pInstance = (LVCS_Instance_t *)hInstance; + + /* Avoid warnings because pCallBackParams and CallbackParam are not used*/ + if((pCallBackParams != LVM_NULL) || (CallbackParam != 0)){ + pCallBackParams = hInstance; + CallbackParam = 0; + return; + } + + pInstance->bTimerDone = LVM_TRUE; + + + return; +} + diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Equaliser.c b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Equaliser.c new file mode 100755 index 0000000..ca615b0 --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Equaliser.c @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1001 $ + $Date: 2010-06-28 13:23:02 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVCS.h" +#include "LVCS_Private.h" +#include "LVCS_Equaliser.h" +#include "BIQUAD.h" +#include "VectorArithmetic.h" +#include "LVCS_Tables.h" + +/************************************************************************************/ +/* */ +/* FUNCTION: LVCS_EqualiserInit */ +/* */ +/* DESCRIPTION: */ +/* Initialises the equaliser module */ +/* */ +/* The function selects the coefficients for the filters and clears the data */ +/* history. It is also used for re-initialisation when one of the system control */ +/* parameters changes but will only change the coefficients and clear the history */ +/* if the sample rate or speaker type has changed. */ +/* */ +/* To avoid excessive testing during the sample processing the biquad type is */ +/* set as a callback function in the init routine. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pParams Initialisation parameters */ +/* */ +/* RETURNS: */ +/* LVCS_Success Always succeeds */ +/* */ +/* NOTES: */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_EqualiserInit(LVCS_Handle_t hInstance, + LVCS_Params_t *pParams) +{ + + LVM_UINT16 Offset; + LVCS_Instance_t *pInstance = (LVCS_Instance_t *)hInstance; + LVCS_Equaliser_t *pConfig = (LVCS_Equaliser_t *)&pInstance->Equaliser; + LVCS_Data_t *pData = (LVCS_Data_t *)pInstance->MemoryTable.Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].pBaseAddress; + LVCS_Coefficient_t *pCoefficients = (LVCS_Coefficient_t *)pInstance->MemoryTable.Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].pBaseAddress; + BQ_C16_Coefs_t Coeffs; + const BiquadA012B12CoefsSP_t *pEqualiserCoefTable; + + /* + * If the sample rate changes re-initialise the filters + */ + if ((pInstance->Params.SampleRate != pParams->SampleRate) || + (pInstance->Params.SpeakerType != pParams->SpeakerType)) + { + /* + * Setup the filter coefficients and clear the history + */ + Offset = (LVM_UINT16)(pParams->SampleRate + (pParams->SpeakerType * (1+LVM_FS_48000))); + pEqualiserCoefTable = (BiquadA012B12CoefsSP_t*)&LVCS_EqualiserCoefTable[0]; + + /* Left and right filters */ + /* Convert incoming coefficients to the required format/ordering */ + Coeffs.A0 = (LVM_INT16) pEqualiserCoefTable[Offset].A0; + Coeffs.A1 = (LVM_INT16) pEqualiserCoefTable[Offset].A1; + Coeffs.A2 = (LVM_INT16) pEqualiserCoefTable[Offset].A2; + Coeffs.B1 = (LVM_INT16)-pEqualiserCoefTable[Offset].B1; + Coeffs.B2 = (LVM_INT16)-pEqualiserCoefTable[Offset].B2; + + LoadConst_16((LVM_INT16)0, /* Value */ + (LVM_INT16 *)&pData->EqualiserBiquadTaps, /* Destination */ + (LVM_UINT16)(sizeof(pData->EqualiserBiquadTaps)/sizeof(LVM_INT16))); /* Number of words */ + + BQ_2I_D16F32Css_TRC_WRA_01_Init(&pCoefficients->EqualiserBiquadInstance, + &pData->EqualiserBiquadTaps, + &Coeffs); + + /* Callbacks */ + switch(pEqualiserCoefTable[Offset].Scale) + { + case 13: + pConfig->pBiquadCallBack = BQ_2I_D16F32C13_TRC_WRA_01; + break; + case 14: + pConfig->pBiquadCallBack = BQ_2I_D16F32C14_TRC_WRA_01; + break; + case 15: + pConfig->pBiquadCallBack = BQ_2I_D16F32C15_TRC_WRA_01; + break; + } + } + + return(LVCS_SUCCESS); +} + +/************************************************************************************/ +/* */ +/* FUNCTION: LVCS_Equaliser */ +/* */ +/* DESCRIPTION: */ +/* Apply the equaliser filter. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pInputOutput Pointer to the input/output buffer */ +/* NumSamples The number of samples to process */ +/* */ +/* RETURNS: */ +/* LVCS_Success Always succeeds */ +/* */ +/* NOTES: */ +/* 1. Always processes in place. */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_Equaliser(LVCS_Handle_t hInstance, + LVM_INT16 *pInputOutput, + LVM_UINT16 NumSamples) +{ + + LVCS_Instance_t *pInstance = (LVCS_Instance_t *)hInstance; + LVCS_Equaliser_t *pConfig = (LVCS_Equaliser_t *)&pInstance->Equaliser; + LVCS_Coefficient_t *pCoefficients = (LVCS_Coefficient_t *)pInstance->MemoryTable.Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].pBaseAddress; + + + /* + * Check if the equaliser is required + */ + if ((pInstance->Params.OperatingMode & LVCS_EQUALISERSWITCH) != 0) + { + /* Apply filter to the left and right channels */ + (pConfig->pBiquadCallBack)((Biquad_Instance_t*)&pCoefficients->EqualiserBiquadInstance, + (LVM_INT16 *)pInputOutput, + (LVM_INT16 *)pInputOutput, + (LVM_INT16)NumSamples); + } + + return(LVCS_SUCCESS); +} + diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Equaliser.h b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Equaliser.h new file mode 100755 index 0000000..10b02cc --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Equaliser.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1001 $ + $Date: 2010-06-28 13:23:02 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + +#ifndef __LVCS_EQUALISER_H__ +#define __LVCS_EQUALISER_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/************************************************************************************/ +/* */ +/* Structures */ +/* */ +/************************************************************************************/ + +/* Equaliser structure */ +typedef struct +{ + void (*pBiquadCallBack) (Biquad_Instance_t*, LVM_INT16*, LVM_INT16*, LVM_INT16); + +} LVCS_Equaliser_t; + + +/************************************************************************************/ +/* */ +/* Function prototypes */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_EqualiserInit(LVCS_Handle_t hInstance, + LVCS_Params_t *pParams); + +LVCS_ReturnStatus_en LVCS_Equaliser(LVCS_Handle_t hInstance, + LVM_INT16 *pInputOutput, + LVM_UINT16 NumSamples); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* EQUALISER_H */ diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Headphone_Coeffs.h b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Headphone_Coeffs.h new file mode 100755 index 0000000..1d55281 --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Headphone_Coeffs.h @@ -0,0 +1,398 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LVCS_HEADPHONE_COEFFS_H__ +#define __LVCS_HEADPHONE_COEFFS_H__ + + +/************************************************************************************/ +/* */ +/* The Stereo Enhancer */ +/* */ +/************************************************************************************/ + +/* Stereo Enhancer coefficients for 8000 Hz sample rate, scaled with 0.161258 */ +#define CS_MIDDLE_8000_A0 7462 /* Floating point value 0.227720 */ +#define CS_MIDDLE_8000_A1 -7049 /* Floating point value -0.215125 */ +#define CS_MIDDLE_8000_A2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_8000_B1 -30209 /* Floating point value -0.921899 */ +#define CS_MIDDLE_8000_B2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_8000_SCALE 15 +#define CS_SIDE_8000_A0 20036 /* Floating point value 0.611441 */ +#define CS_SIDE_8000_A1 -12463 /* Floating point value -0.380344 */ +#define CS_SIDE_8000_A2 -7573 /* Floating point value -0.231097 */ +#define CS_SIDE_8000_B1 -20397 /* Floating point value -0.622470 */ +#define CS_SIDE_8000_B2 -4285 /* Floating point value -0.130759 */ +#define CS_SIDE_8000_SCALE 15 + +/* Stereo Enhancer coefficients for 11025Hz sample rate, scaled with 0.162943 */ +#define CS_MIDDLE_11025_A0 7564 /* Floating point value 0.230838 */ +#define CS_MIDDLE_11025_A1 -7260 /* Floating point value -0.221559 */ +#define CS_MIDDLE_11025_A2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_11025_B1 -30902 /* Floating point value -0.943056 */ +#define CS_MIDDLE_11025_B2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_11025_SCALE 15 +#define CS_SIDE_11025_A0 18264 /* Floating point value 0.557372 */ +#define CS_SIDE_11025_A1 -12828 /* Floating point value -0.391490 */ +#define CS_SIDE_11025_A2 -5436 /* Floating point value -0.165881 */ +#define CS_SIDE_11025_B1 -28856 /* Floating point value -0.880608 */ +#define CS_SIDE_11025_B2 1062 /* Floating point value 0.032397 */ +#define CS_SIDE_11025_SCALE 15 + +/* Stereo Enhancer coefficients for 12000Hz sample rate, scaled with 0.162191 */ +#define CS_MIDDLE_12000_A0 7534 /* Floating point value 0.229932 */ +#define CS_MIDDLE_12000_A1 -7256 /* Floating point value -0.221436 */ +#define CS_MIDDLE_12000_A2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_12000_B1 -31051 /* Floating point value -0.947616 */ +#define CS_MIDDLE_12000_B2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_12000_SCALE 15 +#define CS_SIDE_12000_A0 18298 /* Floating point value 0.558398 */ +#define CS_SIDE_12000_A1 -12852 /* Floating point value -0.392211 */ +#define CS_SIDE_12000_A2 -5446 /* Floating point value -0.166187 */ +#define CS_SIDE_12000_B1 -29247 /* Floating point value -0.892550 */ +#define CS_SIDE_12000_B2 1077 /* Floating point value 0.032856 */ +#define CS_SIDE_12000_SCALE 15 + +/* Stereo Enhancer coefficients for 16000Hz sample rate, scaled with 0.162371 */ +#define CS_MIDDLE_16000_A0 7558 /* Floating point value 0.230638 */ +#define CS_MIDDLE_16000_A1 -7348 /* Floating point value -0.224232 */ +#define CS_MIDDLE_16000_A2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_16000_B1 -31475 /* Floating point value -0.960550 */ +#define CS_MIDDLE_16000_B2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_16000_SCALE 15 +#define CS_SIDE_16000_A0 8187 /* Floating point value 0.499695 */ +#define CS_SIDE_16000_A1 -5825 /* Floating point value -0.355543 */ +#define CS_SIDE_16000_A2 -2362 /* Floating point value -0.144152 */ +#define CS_SIDE_16000_B1 -17216 /* Floating point value -1.050788 */ +#define CS_SIDE_16000_B2 2361 /* Floating point value 0.144104 */ +#define CS_SIDE_16000_SCALE 14 + +/* Stereo Enhancer coefficients for 22050Hz sample rate, scaled with 0.160781 */ +#define CS_MIDDLE_22050_A0 7496 /* Floating point value 0.228749 */ +#define CS_MIDDLE_22050_A1 -7344 /* Floating point value -0.224128 */ +#define CS_MIDDLE_22050_A2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_22050_B1 -31826 /* Floating point value -0.971262 */ +#define CS_MIDDLE_22050_B2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_22050_SCALE 15 +#define CS_SIDE_22050_A0 7211 /* Floating point value 0.440112 */ +#define CS_SIDE_22050_A1 -4278 /* Floating point value -0.261096 */ +#define CS_SIDE_22050_A2 -2933 /* Floating point value -0.179016 */ +#define CS_SIDE_22050_B1 -18297 /* Floating point value -1.116786 */ +#define CS_SIDE_22050_B2 2990 /* Floating point value 0.182507 */ +#define CS_SIDE_22050_SCALE 14 + +/* Stereo Enhancer coefficients for 24000Hz sample rate, scaled with 0.161882 */ +#define CS_MIDDLE_24000_A0 7550 /* Floating point value 0.230395 */ +#define CS_MIDDLE_24000_A1 -7409 /* Floating point value -0.226117 */ +#define CS_MIDDLE_24000_A2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_24000_B1 -31902 /* Floating point value -0.973573 */ +#define CS_MIDDLE_24000_B2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_24000_SCALE 15 +#define CS_SIDE_24000_A0 6796 /* Floating point value 0.414770 */ +#define CS_SIDE_24000_A1 -4705 /* Floating point value -0.287182 */ +#define CS_SIDE_24000_A2 -2090 /* Floating point value -0.127588 */ +#define CS_SIDE_24000_B1 -20147 /* Floating point value -1.229648 */ +#define CS_SIDE_24000_B2 4623 /* Floating point value 0.282177 */ +#define CS_SIDE_24000_SCALE 14 + +/* Stereo Enhancer coefficients for 32000Hz sample rate, scaled with 0.160322 */ +#define CS_MIDDLE_32000_A0 7484 /* Floating point value 0.228400 */ +#define CS_MIDDLE_32000_A1 -7380 /* Floating point value -0.225214 */ +#define CS_MIDDLE_32000_A2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_32000_B1 -32117 /* Floating point value -0.980126 */ +#define CS_MIDDLE_32000_B2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_32000_SCALE 15 +#define CS_SIDE_32000_A0 5973 /* Floating point value 0.364579 */ +#define CS_SIDE_32000_A1 -3397 /* Floating point value -0.207355 */ +#define CS_SIDE_32000_A2 -2576 /* Floating point value -0.157224 */ +#define CS_SIDE_32000_B1 -20877 /* Floating point value -1.274231 */ +#define CS_SIDE_32000_B2 5120 /* Floating point value 0.312495 */ +#define CS_SIDE_32000_SCALE 14 + +/* Stereo Enhancer coefficients for 44100Hz sample rate, scaled with 0.163834 */ +#define CS_MIDDLE_44100_A0 7654 /* Floating point value 0.233593 */ +#define CS_MIDDLE_44100_A1 -7577 /* Floating point value -0.231225 */ +#define CS_MIDDLE_44100_A2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_44100_B1 -32294 /* Floating point value -0.985545 */ +#define CS_MIDDLE_44100_B2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_44100_SCALE 15 +#define CS_SIDE_44100_A0 4662 /* Floating point value 0.284573 */ +#define CS_SIDE_44100_A1 -4242 /* Floating point value -0.258910 */ +#define CS_SIDE_44100_A2 -420 /* Floating point value -0.025662 */ +#define CS_SIDE_44100_B1 -25760 /* Floating point value -1.572248 */ +#define CS_SIDE_44100_B2 9640 /* Floating point value 0.588399 */ +#define CS_SIDE_44100_SCALE 14 + +/* Stereo Enhancer coefficients for 48000Hz sample rate, scaled with 0.164402 */ +#define CS_MIDDLE_48000_A0 7682 /* Floating point value 0.234445 */ +#define CS_MIDDLE_48000_A1 -7611 /* Floating point value -0.232261 */ +#define CS_MIDDLE_48000_A2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_48000_B1 -32333 /* Floating point value -0.986713 */ +#define CS_MIDDLE_48000_B2 0 /* Floating point value 0.000000 */ +#define CS_MIDDLE_48000_SCALE 15 +#define CS_SIDE_48000_A0 4466 /* Floating point value 0.272606 */ +#define CS_SIDE_48000_A1 -4374 /* Floating point value -0.266952 */ +#define CS_SIDE_48000_A2 -93 /* Floating point value -0.005654 */ +#define CS_SIDE_48000_B1 -26495 /* Floating point value -1.617141 */ +#define CS_SIDE_48000_B2 10329 /* Floating point value 0.630405 */ +#define CS_SIDE_48000_SCALE 14 + + +/************************************************************************************/ +/* */ +/* The Reverb Unit */ +/* */ +/************************************************************************************/ + +/* Reverb delay settings in samples */ +#define LVCS_STEREODELAY_CS_8KHZ 93 /* Sample rate 8kS/s */ +#define LVCS_STEREODELAY_CS_11KHZ 128 /* Sample rate 11kS/s */ +#define LVCS_STEREODELAY_CS_12KHZ 139 /* Sample rate 12kS/s */ +#define LVCS_STEREODELAY_CS_16KHZ 186 /* Sample rate 16kS/s */ +#define LVCS_STEREODELAY_CS_22KHZ 256 /* Sample rate 22kS/s */ +#define LVCS_STEREODELAY_CS_24KHZ 279 /* Sample rate 24kS/s */ +#define LVCS_STEREODELAY_CS_32KHZ 372 /* Sample rate 32kS/s */ +#define LVCS_STEREODELAY_CS_44KHZ 512 /* Sample rate 44kS/s */ +#define LVCS_STEREODELAY_CS_48KHZ 512 /* Sample rate 48kS/s */ + +/* Reverb coefficients for 8000 Hz sample rate, scaled with 1.038030 */ +#define CS_REVERB_8000_A0 21865 /* Floating point value 0.667271 */ +#define CS_REVERB_8000_A1 -21865 /* Floating point value -0.667271 */ +#define CS_REVERB_8000_A2 0 /* Floating point value 0.000000 */ +#define CS_REVERB_8000_B1 -21895 /* Floating point value -0.668179 */ +#define CS_REVERB_8000_B2 0 /* Floating point value 0.000000 */ +#define CS_REVERB_8000_SCALE 15 + +/* Reverb coefficients for 11025Hz sample rate, scaled with 1.038030 */ +#define CS_REVERB_11025_A0 22926 /* Floating point value 0.699638 */ +#define CS_REVERB_11025_A1 -22926 /* Floating point value -0.699638 */ +#define CS_REVERB_11025_A2 0 /* Floating point value 0.000000 */ +#define CS_REVERB_11025_B1 -24546 /* Floating point value -0.749096 */ +#define CS_REVERB_11025_B2 0 /* Floating point value 0.000000 */ +#define CS_REVERB_11025_SCALE 15 + +/* Reverb coefficients for 12000Hz sample rate, scaled with 1.038030 */ +#define CS_REVERB_12000_A0 23165 /* Floating point value 0.706931 */ +#define CS_REVERB_12000_A1 -23165 /* Floating point value -0.706931 */ +#define CS_REVERB_12000_A2 0 /* Floating point value 0.000000 */ +#define CS_REVERB_12000_B1 -25144 /* Floating point value -0.767327 */ +#define CS_REVERB_12000_B2 0 /* Floating point value 0.000000 */ +#define CS_REVERB_12000_SCALE 15 + +/* Reverb coefficients for 16000Hz sample rate, scaled with 1.038030 */ +#define CS_REVERB_16000_A0 23864 /* Floating point value 0.728272 */ +#define CS_REVERB_16000_A1 -23864 /* Floating point value -0.728272 */ +#define CS_REVERB_16000_A2 0 /* Floating point value 0.000000 */ +#define CS_REVERB_16000_B1 -26892 /* Floating point value -0.820679 */ +#define CS_REVERB_16000_B2 0 /* Floating point value 0.000000 */ +#define CS_REVERB_16000_SCALE 15 + +/* Reverb coefficients for 22050Hz sample rate, scaled with 1.038030 */ +#define CS_REVERB_22050_A0 16921 /* Floating point value 0.516396 */ +#define CS_REVERB_22050_A1 0 /* Floating point value 0.000000 */ +#define CS_REVERB_22050_A2 -16921 /* Floating point value -0.516396 */ +#define CS_REVERB_22050_B1 -16991 /* Floating point value -0.518512 */ +#define CS_REVERB_22050_B2 -9535 /* Floating point value -0.290990 */ +#define CS_REVERB_22050_SCALE 15 + +/* Reverb coefficients for 24000Hz sample rate, scaled with 1.038030 */ +#define CS_REVERB_24000_A0 15714 /* Floating point value 0.479565 */ +#define CS_REVERB_24000_A1 0 /* Floating point value 0.000000 */ +#define CS_REVERB_24000_A2 -15714 /* Floating point value -0.479565 */ +#define CS_REVERB_24000_B1 -20898 /* Floating point value -0.637745 */ +#define CS_REVERB_24000_B2 -6518 /* Floating point value -0.198912 */ +#define CS_REVERB_24000_SCALE 15 + +/* Reverb coefficients for 32000Hz sample rate, scaled with 1.038030 */ +#define CS_REVERB_32000_A0 12463 /* Floating point value 0.380349 */ +#define CS_REVERB_32000_A1 0 /* Floating point value 0.000000 */ +#define CS_REVERB_32000_A2 -12463 /* Floating point value -0.380349 */ +#define CS_REVERB_32000_B1 -31158 /* Floating point value -0.950873 */ +#define CS_REVERB_32000_B2 1610 /* Floating point value 0.049127 */ +#define CS_REVERB_32000_SCALE 15 + +/* Reverb coefficients for 44100Hz sample rate, scaled with 1.038030 */ +#define CS_REVERB_44100_A0 4872 /* Floating point value 0.297389 */ +#define CS_REVERB_44100_A1 0 /* Floating point value 0.000000 */ +#define CS_REVERB_44100_A2 -4872 /* Floating point value -0.297389 */ +#define CS_REVERB_44100_B1 -19668 /* Floating point value -1.200423 */ +#define CS_REVERB_44100_B2 4203 /* Floating point value 0.256529 */ +#define CS_REVERB_44100_SCALE 14 + +/* Reverb coefficients for 48000Hz sample rate, scaled with 1.038030 */ +#define CS_REVERB_48000_A0 4566 /* Floating point value 0.278661 */ +#define CS_REVERB_48000_A1 0 /* Floating point value 0.000000 */ +#define CS_REVERB_48000_A2 -4566 /* Floating point value -0.278661 */ +#define CS_REVERB_48000_B1 -20562 /* Floating point value -1.254993 */ +#define CS_REVERB_48000_B2 4970 /* Floating point value 0.303347 */ +#define CS_REVERB_48000_SCALE 14 + +/* Reverb Gain Settings */ +#define LVCS_HEADPHONE_DELAYGAIN 0.800000 /* Algorithm delay path gain */ +#define LVCS_HEADPHONE_OUTPUTGAIN 1.000000 /* Algorithm output gain */ +#define LVCS_HEADPHONE_PROCGAIN 18403 /* Processed path gain */ +#define LVCS_HEADPHONE_UNPROCGAIN 18403 /* Unprocessed path gain */ +#define LVCS_HEADPHONE_GAINCORRECT 1.009343 /* Delay mixer gain correction */ + + +/************************************************************************************/ +/* */ +/* The Equaliser */ +/* */ +/************************************************************************************/ + +/* Equaliser coefficients for 8000 Hz sample rate, CS scaled with 1.038497 and CSEX scaled with 0.775480 */ +#define CS_EQUALISER_8000_A0 20698 /* Floating point value 1.263312 */ +#define CS_EQUALISER_8000_A1 -9859 /* Floating point value -0.601748 */ +#define CS_EQUALISER_8000_A2 -4599 /* Floating point value -0.280681 */ +#define CS_EQUALISER_8000_B1 -7797 /* Floating point value -0.475865 */ +#define CS_EQUALISER_8000_B2 -6687 /* Floating point value -0.408154 */ +#define CS_EQUALISER_8000_SCALE 14 +#define CSEX_EQUALISER_8000_A0 30912 /* Floating point value 0.943357 */ +#define CSEX_EQUALISER_8000_A1 -14724 /* Floating point value -0.449345 */ +#define CSEX_EQUALISER_8000_A2 -6868 /* Floating point value -0.209594 */ +#define CSEX_EQUALISER_8000_B1 -15593 /* Floating point value -0.475865 */ +#define CSEX_EQUALISER_8000_B2 -13374 /* Floating point value -0.408154 */ +#define CSEX_EQUALISER_8000_SCALE 15 + +/* Equaliser coefficients for 11025Hz sample rate, CS scaled with 1.027761 and CSEX scaled with 0.767463 */ +#define CS_EQUALISER_11025_A0 18041 /* Floating point value 1.101145 */ +#define CS_EQUALISER_11025_A1 2278 /* Floating point value 0.139020 */ +#define CS_EQUALISER_11025_A2 -14163 /* Floating point value -0.864423 */ +#define CS_EQUALISER_11025_B1 402 /* Floating point value 0.024541 */ +#define CS_EQUALISER_11025_B2 -14892 /* Floating point value -0.908930 */ +#define CS_EQUALISER_11025_SCALE 14 +#define CSEX_EQUALISER_11025_A0 31983 /* Floating point value 0.976058 */ +#define CSEX_EQUALISER_11025_A1 -22784 /* Floating point value -0.695326 */ +#define CSEX_EQUALISER_11025_A2 -2976 /* Floating point value -0.090809 */ +#define CSEX_EQUALISER_11025_B1 -20008 /* Floating point value -0.610594 */ +#define CSEX_EQUALISER_11025_B2 -10196 /* Floating point value -0.311149 */ +#define CSEX_EQUALISER_11025_SCALE 15 + +/* Equaliser coefficients for 12000Hz sample rate, CS scaled with 1.032521 and CSEX scaled with 0.771017 */ +#define CS_EQUALISER_12000_A0 20917 /* Floating point value 1.276661 */ +#define CS_EQUALISER_12000_A1 -16671 /* Floating point value -1.017519 */ +#define CS_EQUALISER_12000_A2 -723 /* Floating point value -0.044128 */ +#define CS_EQUALISER_12000_B1 -11954 /* Floating point value -0.729616 */ +#define CS_EQUALISER_12000_B2 -3351 /* Floating point value -0.204532 */ +#define CS_EQUALISER_12000_SCALE 14 +#define CSEX_EQUALISER_12000_A0 16500 /* Floating point value 1.007095 */ +#define CSEX_EQUALISER_12000_A1 -14285 /* Floating point value -0.871912 */ +#define CSEX_EQUALISER_12000_A2 381 /* Floating point value 0.023232 */ +#define CSEX_EQUALISER_12000_B1 -12220 /* Floating point value -0.745857 */ +#define CSEX_EQUALISER_12000_B2 -3099 /* Floating point value -0.189171 */ +#define CSEX_EQUALISER_12000_SCALE 14 + +/* Equaliser coefficients for 16000Hz sample rate, CS scaled with 1.031378 and CSEX scaled with 0.770164 */ +#define CS_EQUALISER_16000_A0 20998 /* Floating point value 1.281629 */ +#define CS_EQUALISER_16000_A1 -17627 /* Floating point value -1.075872 */ +#define CS_EQUALISER_16000_A2 -678 /* Floating point value -0.041365 */ +#define CS_EQUALISER_16000_B1 -11882 /* Floating point value -0.725239 */ +#define CS_EQUALISER_16000_B2 -3676 /* Floating point value -0.224358 */ +#define CS_EQUALISER_16000_SCALE 14 +#define CSEX_EQUALISER_16000_A0 17713 /* Floating point value 1.081091 */ +#define CSEX_EQUALISER_16000_A1 -14208 /* Floating point value -0.867183 */ +#define CSEX_EQUALISER_16000_A2 -1151 /* Floating point value -0.070247 */ +#define CSEX_EQUALISER_16000_B1 -8440 /* Floating point value -0.515121 */ +#define CSEX_EQUALISER_16000_B2 -6978 /* Floating point value -0.425893 */ +#define CSEX_EQUALISER_16000_SCALE 14 + +/* Equaliser coefficients for 22050Hz sample rate, CS scaled with 1.041576 and CSEX scaled with 0.777779 */ +#define CS_EQUALISER_22050_A0 22751 /* Floating point value 1.388605 */ +#define CS_EQUALISER_22050_A1 -21394 /* Floating point value -1.305799 */ +#define CS_EQUALISER_22050_A2 654 /* Floating point value 0.039922 */ +#define CS_EQUALISER_22050_B1 -11788 /* Floating point value -0.719494 */ +#define CS_EQUALISER_22050_B2 -3985 /* Floating point value -0.243245 */ +#define CS_EQUALISER_22050_SCALE 14 +#define CSEX_EQUALISER_22050_A0 20855 /* Floating point value 1.272910 */ +#define CSEX_EQUALISER_22050_A1 -21971 /* Floating point value -1.341014 */ +#define CSEX_EQUALISER_22050_A2 2744 /* Floating point value 0.167462 */ +#define CSEX_EQUALISER_22050_B1 -10063 /* Floating point value -0.614219 */ +#define CSEX_EQUALISER_22050_B2 -5659 /* Floating point value -0.345384 */ +#define CSEX_EQUALISER_22050_SCALE 14 + +/* Equaliser coefficients for 24000Hz sample rate, CS scaled with 1.034495 and CSEX scaled with 0.772491 */ +#define CS_EQUALISER_24000_A0 23099 /* Floating point value 1.409832 */ +#define CS_EQUALISER_24000_A1 -23863 /* Floating point value -1.456506 */ +#define CS_EQUALISER_24000_A2 2481 /* Floating point value 0.151410 */ +#define CS_EQUALISER_24000_B1 -13176 /* Floating point value -0.804201 */ +#define CS_EQUALISER_24000_B2 -2683 /* Floating point value -0.163783 */ +#define CS_EQUALISER_24000_SCALE 14 +#define CSEX_EQUALISER_24000_A0 21286 /* Floating point value 1.299198 */ +#define CSEX_EQUALISER_24000_A1 -23797 /* Floating point value -1.452447 */ +#define CSEX_EQUALISER_24000_A2 3940 /* Floating point value 0.240489 */ +#define CSEX_EQUALISER_24000_B1 -10966 /* Floating point value -0.669303 */ +#define CSEX_EQUALISER_24000_B2 -4833 /* Floating point value -0.294984 */ +#define CSEX_EQUALISER_24000_SCALE 14 + +/* Equaliser coefficients for 32000Hz sample rate, CS scaled with 1.044559 and CSEX scaled with 0.780006 */ +#define CS_EQUALISER_32000_A0 25575 /* Floating point value 1.560988 */ +#define CS_EQUALISER_32000_A1 -30765 /* Floating point value -1.877724 */ +#define CS_EQUALISER_32000_A2 6386 /* Floating point value 0.389741 */ +#define CS_EQUALISER_32000_B1 -14867 /* Floating point value -0.907410 */ +#define CS_EQUALISER_32000_B2 -1155 /* Floating point value -0.070489 */ +#define CS_EQUALISER_32000_SCALE 14 +#define CSEX_EQUALISER_32000_A0 14623 /* Floating point value 1.785049 */ +#define CSEX_EQUALISER_32000_A1 -18297 /* Floating point value -2.233497 */ +#define CSEX_EQUALISER_32000_A2 4313 /* Floating point value 0.526431 */ +#define CSEX_EQUALISER_32000_B1 -3653 /* Floating point value -0.445939 */ +#define CSEX_EQUALISER_32000_B2 -4280 /* Floating point value -0.522446 */ +#define CSEX_EQUALISER_32000_SCALE 13 + +/* Equaliser coefficients for 44100Hz sample rate, CS scaled with 1.022170 and CSEX scaled with 0.763288 */ +#define CS_EQUALISER_44100_A0 13304 /* Floating point value 1.623993 */ +#define CS_EQUALISER_44100_A1 -18602 /* Floating point value -2.270743 */ +#define CS_EQUALISER_44100_A2 5643 /* Floating point value 0.688829 */ +#define CS_EQUALISER_44100_B1 -9152 /* Floating point value -1.117190 */ +#define CS_EQUALISER_44100_B2 1067 /* Floating point value 0.130208 */ +#define CS_EQUALISER_44100_SCALE 13 +#define CSEX_EQUALISER_44100_A0 16616 /* Floating point value 2.028315 */ +#define CSEX_EQUALISER_44100_A1 -23613 /* Floating point value -2.882459 */ +#define CSEX_EQUALISER_44100_A2 7410 /* Floating point value 0.904535 */ +#define CSEX_EQUALISER_44100_B1 -4860 /* Floating point value -0.593308 */ +#define CSEX_EQUALISER_44100_B2 -3161 /* Floating point value -0.385816 */ +#define CSEX_EQUALISER_44100_SCALE 13 + +/* Equaliser coefficients for 48000Hz sample rate, CS scaled with 1.018635 and CSEX scaled with 0.760648 */ +#define CS_EQUALISER_48000_A0 13445 /* Floating point value 1.641177 */ +#define CS_EQUALISER_48000_A1 -19372 /* Floating point value -2.364687 */ +#define CS_EQUALISER_48000_A2 6225 /* Floating point value 0.759910 */ +#define CS_EQUALISER_48000_B1 -9558 /* Floating point value -1.166774 */ +#define CS_EQUALISER_48000_B2 1459 /* Floating point value 0.178074 */ +#define CS_EQUALISER_48000_SCALE 13 +#define CSEX_EQUALISER_48000_A0 17200 /* Floating point value 2.099655 */ +#define CSEX_EQUALISER_48000_A1 -25110 /* Floating point value -3.065220 */ +#define CSEX_EQUALISER_48000_A2 8277 /* Floating point value 1.010417 */ +#define CSEX_EQUALISER_48000_B1 -5194 /* Floating point value -0.634021 */ +#define CSEX_EQUALISER_48000_B2 -2845 /* Floating point value -0.347332 */ +#define CSEX_EQUALISER_48000_SCALE 13 + + +/************************************************************************************/ +/* */ +/* The Output Gain Correction */ +/* */ +/************************************************************************************/ + +#define LVCS_HEADPHONE_SHIFT 2 /* Output Shift */ +#define LVCS_HEADPHONE_SHIFTLOSS 27779 /* Output Shift loss */ +#define LVCS_HEADPHONE_GAIN 6840 /* Unprocessed path gain */ +#define LVCS_EX_HEADPHONE_SHIFT 3 /* EX Output Shift */ +#define LVCS_EX_HEADPHONE_SHIFTLOSS 18600 /* EX Output Shift loss */ +#define LVCS_EX_HEADPHONE_GAIN 5108 /* EX Unprocessed path gain */ + +#endif diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Init.c b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Init.c new file mode 100755 index 0000000..4aa95d3 --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Init.c @@ -0,0 +1,233 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1001 $ + $Date: 2010-06-28 13:23:02 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVCS.h" +#include "LVCS_Private.h" +#include "LVCS_Tables.h" + +/****************************************************************************************/ +/* */ +/* FUNCTION: LVCS_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) it is */ +/* passed the default capabilities. */ +/* */ +/* When called for memory allocation the memory base address pointers are NULL on */ +/* return. */ +/* */ +/* When the function is called for free (hInstance = Instance Handle) the */ +/* capabilities are ignored and 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 default capabilites */ +/* */ +/* RETURNS: */ +/* LVCS_Success Succeeded */ +/* */ +/* NOTES: */ +/* 1. This function may be interrupted by the LVCS_Process function */ +/* */ +/****************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_Memory(LVCS_Handle_t hInstance, + LVCS_MemTab_t *pMemoryTable, + LVCS_Capabilities_t *pCapabilities) +{ + + LVM_UINT32 ScratchSize; + LVCS_Instance_t *pInstance = (LVCS_Instance_t *)hInstance; + + + /* + * Fill in the memory table + */ + if (hInstance == LVM_NULL) + { + /* + * Instance memory + */ + pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_SLOW_DATA].Size = (LVM_UINT32)sizeof(LVCS_Instance_t); + pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_SLOW_DATA].Type = LVCS_PERSISTENT; + pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_SLOW_DATA].pBaseAddress = LVM_NULL; + + /* + * Data memory + */ + pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].Size = (LVM_UINT32)sizeof(LVCS_Data_t); + pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].Type = LVCS_DATA; + pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].pBaseAddress = LVM_NULL; + + /* + * Coefficient memory + */ + pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].Size = (LVM_UINT32)sizeof(LVCS_Coefficient_t); + pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].Type = LVCS_COEFFICIENT; + pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].pBaseAddress = LVM_NULL; + + /* + * Scratch memory + */ + ScratchSize = (LVM_UINT32)(LVCS_SCRATCHBUFFERS*sizeof(LVM_INT16)*pCapabilities->MaxBlockSize); /* Inplace processing */ + pMemoryTable->Region[LVCS_MEMREGION_TEMPORARY_FAST].Size = ScratchSize; + pMemoryTable->Region[LVCS_MEMREGION_TEMPORARY_FAST].Type = LVCS_SCRATCH; + pMemoryTable->Region[LVCS_MEMREGION_TEMPORARY_FAST].pBaseAddress = LVM_NULL; + } + else + { + /* Read back memory allocation table */ + *pMemoryTable = pInstance->MemoryTable; + } + + return(LVCS_SUCCESS); +} + + +/************************************************************************************/ +/* */ +/* FUNCTION: LVCS_Init */ +/* */ +/* DESCRIPTION: */ +/* Create and initialisation function for the Concert Sound module */ +/* */ +/* This function can be used to create an algorithm instance by calling with */ +/* hInstance set to LVM_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 */ +/* LVCS_Memory before calling this function. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pMemoryTable Pointer to the memory definition table */ +/* pCapabilities Pointer to the capabilities structure */ +/* */ +/* RETURNS: */ +/* LVCS_Success Initialisation succeeded */ +/* */ +/* 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 LVCS_Process function */ +/* 3. This function must be called with the same capabilities as used for the */ +/* call to the memory function */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_Init(LVCS_Handle_t *phInstance, + LVCS_MemTab_t *pMemoryTable, + LVCS_Capabilities_t *pCapabilities) +{ + + LVM_INT16 Offset; + LVCS_Instance_t *pInstance; + LVCS_VolCorrect_t *pLVCS_VolCorrectTable; + + + /* + * Set the instance handle if not already initialised + */ + if (*phInstance == LVM_NULL) + { + *phInstance = (LVCS_Handle_t)pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_SLOW_DATA].pBaseAddress; + } + pInstance =(LVCS_Instance_t *)*phInstance; + + + /* + * Save the capabilities in the instance structure + */ + pInstance->Capabilities = *pCapabilities; + + /* + * Save the memory table in the instance structure + */ + pInstance->MemoryTable = *pMemoryTable; + + + /* + * Set all initial parameters to invalid to force a full initialisation + */ + pInstance->Params.OperatingMode = LVCS_OFF; + pInstance->Params.SpeakerType = LVCS_SPEAKERTYPE_MAX; + pInstance->OutputDevice = LVCS_HEADPHONE; + pInstance->Params.SourceFormat = LVCS_SOURCEMAX; + pInstance->Params.CompressorMode = LVM_MODE_OFF; + pInstance->Params.SampleRate = LVM_FS_INVALID; + pInstance->Params.EffectLevel = 0; + pInstance->Params.ReverbLevel = (LVM_UINT16)0x8000; + pLVCS_VolCorrectTable = (LVCS_VolCorrect_t*)&LVCS_VolCorrectTable[0]; + Offset = (LVM_INT16)(pInstance->Params.SpeakerType + (pInstance->Params.SourceFormat*(1+LVCS_EX_HEADPHONES))); + pInstance->VolCorrect = pLVCS_VolCorrectTable[Offset]; + pInstance->TransitionGain = 0; + LVC_Mixer_Init(&pInstance->BypassMix.Mixer_Instance.MixerStream[0],0,0); + LVC_Mixer_Init(&pInstance->BypassMix.Mixer_Instance.MixerStream[1],0,0); + + /* + * Initialise the bypass variables + */ + pInstance->MSBypassMixer.MixerStream[0].CallbackParam = 0; + pInstance->MSBypassMixer.MixerStream[0].pCallbackHandle = LVM_NULL; + pInstance->MSBypassMixer.MixerStream[0].pCallBack = LVM_NULL; + pInstance->MSBypassMixer.MixerStream[0].CallbackSet = 0; + LVC_Mixer_Init(&pInstance->MSBypassMixer.MixerStream[0],0,0); + LVC_Mixer_SetTimeConstant(&pInstance->MSBypassMixer.MixerStream[0],0,LVM_FS_44100,2); + + + pInstance->MSBypassMixer.MixerStream[1].CallbackParam = 0; + pInstance->MSBypassMixer.MixerStream[1].pCallbackHandle = LVM_NULL; + pInstance->MSBypassMixer.MixerStream[1].pCallBack = LVM_NULL; + pInstance->MSBypassMixer.MixerStream[1].CallbackSet = 0; + LVC_Mixer_Init(&pInstance->MSBypassMixer.MixerStream[1],0,0); + LVC_Mixer_SetTimeConstant(&pInstance->MSBypassMixer.MixerStream[1],0,LVM_FS_44100,2); + + pInstance->bInOperatingModeTransition = LVM_FALSE; + pInstance->bTimerDone = LVM_FALSE; + pInstance->TimerParams.CallBackParam = 0; + pInstance->TimerParams.pCallBack = LVCS_TimerCallBack; + pInstance->TimerParams.pCallbackInstance = pInstance; + pInstance->TimerParams.pCallBackParams = LVM_NULL; + + return(LVCS_SUCCESS); +} + diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Private.h b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Private.h new file mode 100755 index 0000000..be30829 --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Private.h @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1001 $ + $Date: 2010-06-28 13:23:02 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + +/************************************************************************************/ +/* */ +/* Header file for the private layer interface of concert sound. */ +/* */ +/* This files includes all definitions, types, structures and function */ +/* prototypes required by the execution layer. */ +/* */ +/************************************************************************************/ + +#ifndef __LVCS_PRIVATE_H__ +#define __LVCS_PRIVATE_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVCS.h" /* Calling or Application layer definitions */ +#include "LVCS_StereoEnhancer.h" /* Stereo enhancer module definitions */ +#include "LVCS_ReverbGenerator.h" /* Reverberation module definitions */ +#include "LVCS_Equaliser.h" /* Equaliser module definitions */ +#include "LVCS_BypassMix.h" /* Bypass Mixer module definitions */ +#include "LVM_Timer.h" + + +/************************************************************************************/ +/* */ +/* Defines */ +/* */ +/************************************************************************************/ + +/* Configuration switch controls */ +#define LVCS_STEREOENHANCESWITCH 0x0001 /* Stereo enhancement enable control */ +#define LVCS_REVERBSWITCH 0x0002 /* Reverberation enable control */ +#define LVCS_EQUALISERSWITCH 0x0004 /* Equaliser enable control */ +#define LVCS_BYPASSMIXSWITCH 0x0008 /* Bypass mixer enable control */ + +/* Memory */ +#define LVCS_SCRATCHBUFFERS 6 /* Number of buffers required for inplace processing */ + +/* General */ +#define LVCS_INVALID 0xFFFF /* Invalid init parameter */ +#define LVCS_BYPASS_MIXER_TC 100 /* Bypass mixer time */ + +/* Access to external coefficients table */ +#define LVCS_NR_OF_FS 9 +#define LVCS_NR_OF_CHAN_CFG 2 + + +/************************************************************************************/ +/* */ +/* Types */ +/* */ +/************************************************************************************/ + +typedef LVM_UINT16 LVCS_Configuration_t; /* Internal algorithm configuration */ + +typedef enum +{ + LVCS_HEADPHONE = 0, + LVCS_DEVICE_MAX = LVM_MAXENUM +} LVCS_OutputDevice_en; + + +/************************************************************************************/ +/* */ +/* Structures */ +/* */ +/************************************************************************************/ + +/* Volume correction structure */ +typedef struct +{ + LVM_INT16 CompFull; /* Post CS compression 100% effect */ + LVM_INT16 CompMin; /* Post CS compression 0% effect */ + LVM_INT16 GainFull; /* CS gain correct 100% effect */ + LVM_INT16 GainMin; /* CS gain correct 0% effect */ +} LVCS_VolCorrect_t; + +/* Instance structure */ +typedef struct +{ + /* Public parameters */ + LVCS_MemTab_t MemoryTable; /* Instance memory allocation table */ + LVCS_Params_t Params; /* Instance parameters */ + LVCS_Capabilities_t Capabilities; /* Initialisation capabilities */ + + /* Private parameters */ + LVCS_OutputDevice_en OutputDevice; /* Selected output device type */ + LVCS_VolCorrect_t VolCorrect; /* Volume correction settings */ + LVM_INT16 TransitionGain; /* Transition gain */ + + /* Sub-block configurations */ + LVCS_StereoEnhancer_t StereoEnhancer; /* Stereo enhancer configuration */ + LVCS_ReverbGenerator_t Reverberation; /* Reverberation configuration */ + LVCS_Equaliser_t Equaliser; /* Equaliser configuration */ + LVCS_BypassMix_t BypassMix; /* Bypass mixer configuration */ + + /* Bypass variable */ + LVMixer3_2St_st MSBypassMixer; /* Bypass mixer used in transitions in MS mode */ + LVM_INT16 bInOperatingModeTransition; /* Operating mode transition flag */ + LVM_INT16 bTimerDone; /* Timer completion flag */ + LVM_Timer_Params_t TimerParams; /* Timer parameters */ + LVM_Timer_Instance_t TimerInstance; /* Timer instance */ + +} LVCS_Instance_t; + +/* Coefficient Structure */ +typedef struct +{ + Biquad_Instance_t EqualiserBiquadInstance; + Biquad_Instance_t ReverbBiquadInstance; + Biquad_Instance_t SEBiquadInstanceMid; + Biquad_Instance_t SEBiquadInstanceSide; + +} LVCS_Coefficient_t; + +/* Data Structure */ +typedef struct +{ + Biquad_2I_Order2_Taps_t EqualiserBiquadTaps; + Biquad_2I_Order2_Taps_t ReverbBiquadTaps; + Biquad_1I_Order1_Taps_t SEBiquadTapsMid; + Biquad_1I_Order2_Taps_t SEBiquadTapsSide; + +} LVCS_Data_t; + + +void LVCS_TimerCallBack ( void* hInstance, + void* pCallBackParams, + LVM_INT32 CallbackParam); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* PRIVATE_H */ + + diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Process.c b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Process.c new file mode 100755 index 0000000..999b8bb --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Process.c @@ -0,0 +1,271 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1001 $ + $Date: 2010-06-28 13:23:02 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVCS.h" +#include "LVCS_Private.h" +#include "VectorArithmetic.h" +#include "CompLim.h" + +/************************************************************************************/ +/* */ +/* FUNCTION: LVCS_Process_CS */ +/* */ +/* DESCRIPTION: */ +/* Process function for the Concert Sound module based on the following block */ +/* diagram: */ +/* _________ ________ _____ _______ ___ ______ */ +/* | | | | | | | | | | | | */ +/* ----->| Stereo |->| Reverb |->| Equ |->| Alpha |-->| + |-| Gain |----> */ +/* | | Enhance | |________| |_____| |_______| |___| |______| */ +/* | |_________| | */ +/* | ___________ | */ +/* | | | | */ +/* |------------------------------->| 1 - Alpha |-----| */ +/* |___________| */ +/* */ +/* The Stereo Enhancer, Reverb and Equaliser blocks are each configured to have */ +/* their gain to give a near peak to peak output (-0.1dBFS) with a worst case */ +/* input signal. The gains of these blocks are re-combined in the Alpha mixer and */ +/* the gain block folloing the sum. */ +/* */ +/* The processing uses the output buffer for data storage after each processing */ +/* block. When processing is inplace a copy of the input signal is made in scratch */ +/* memory for the 1-Alpha path. */ +/* */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pInData Pointer to the input data */ +/* pOutData Pointer to the output data */ +/* NumSamples Number of samples in the input buffer */ +/* */ +/* RETURNS: */ +/* LVCS_Success Succeeded */ +/* */ +/* NOTES: */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_Process_CS(LVCS_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 *pOutData, + LVM_UINT16 NumSamples) +{ + const LVM_INT16 *pInput; + LVCS_Instance_t *pInstance = (LVCS_Instance_t *)hInstance; + LVM_INT16 *pScratch = (LVM_INT16 *)pInstance->MemoryTable.Region[LVCS_MEMREGION_TEMPORARY_FAST].pBaseAddress; + LVCS_ReturnStatus_en err; + + /* + * Check if the processing is inplace + */ + if (pInData == pOutData) + { + /* Processing inplace */ + pInput = pScratch + (2*NumSamples); + Copy_16((LVM_INT16 *)pInData, /* Source */ + (LVM_INT16 *)pInput, /* Destination */ + (LVM_INT16)(2*NumSamples)); /* Left and right */ + } + else + { + /* Processing outplace */ + pInput = pInData; + } + + /* + * Call the stereo enhancer + */ + err=LVCS_StereoEnhancer(hInstance, /* Instance handle */ + pInData, /* Pointer to the input data */ + pOutData, /* Pointer to the output data */ + NumSamples); /* Number of samples to process */ + + /* + * Call the reverb generator + */ + err=LVCS_ReverbGenerator(hInstance, /* Instance handle */ + pOutData, /* Pointer to the input data */ + pOutData, /* Pointer to the output data */ + NumSamples); /* Number of samples to process */ + + /* + * Call the equaliser + */ + err=LVCS_Equaliser(hInstance, /* Instance handle */ + pOutData, /* Pointer to the input data */ + NumSamples); /* Number of samples to process */ + + /* + * Call the bypass mixer + */ + err=LVCS_BypassMixer(hInstance, /* Instance handle */ + pOutData, /* Pointer to the processed data */ + pInput, /* Pointer to the input (unprocessed) data */ + pOutData, /* Pointer to the output data */ + NumSamples); /* Number of samples to process */ + + if(err !=LVCS_SUCCESS) + { + return err; + } + + return(LVCS_SUCCESS); +} + +/************************************************************************************/ +/* */ +/* FUNCTION: LVCS_Process */ +/* */ +/* DESCRIPTION: */ +/* Process function for the Concert Sound module. The implementation supports two */ +/* variants of the algorithm, one for headphones and one for mobile speakers. */ +/* */ +/* Data can be processed in two formats, stereo or mono-in-stereo. Data in mono */ +/* format is not supported, the calling routine must convert the mono stream to */ +/* mono-in-stereo. */ +/* */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance handle */ +/* pInData Pointer to the input data */ +/* pOutData Pointer to the output data */ +/* NumSamples Number of samples in the input buffer */ +/* */ +/* RETURNS: */ +/* LVCS_Success Succeeded */ +/* LVCS_TooManySamples NumSamples was larger than the maximum block size */ +/* */ +/* NOTES: */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_Process(LVCS_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 *pOutData, + LVM_UINT16 NumSamples) +{ + + LVCS_Instance_t *pInstance =(LVCS_Instance_t *)hInstance; + LVCS_ReturnStatus_en err; + + /* + * Check the number of samples is not too large + */ + if (NumSamples > pInstance->Capabilities.MaxBlockSize) + { + return(LVCS_TOOMANYSAMPLES); + } + + /* + * Check if the algorithm is enabled + */ + if (pInstance->Params.OperatingMode != LVCS_OFF) + { + /* + * Call CS process function + */ + err=LVCS_Process_CS(hInstance, + pInData, + pOutData, + NumSamples); + + /* + * Compress to reduce expansion effect of Concert Sound and correct volume + * differences for difference settings. Not applied in test modes + */ + if ((pInstance->Params.OperatingMode == LVCS_ON)&&(pInstance->Params.CompressorMode == LVM_MODE_ON)) + { + LVM_INT16 Gain = pInstance->VolCorrect.CompMin; + LVM_INT32 Current1; + + Current1 = LVC_Mixer_GetCurrent(&pInstance->BypassMix.Mixer_Instance.MixerStream[0]); + Gain = (LVM_INT16)( pInstance->VolCorrect.CompMin + - (((LVM_INT32)pInstance->VolCorrect.CompMin * (Current1)) >> 15) + + (((LVM_INT32)pInstance->VolCorrect.CompFull * (Current1)) >> 15) ); + + NonLinComp_D16(Gain, /* Compressor gain setting */ + pOutData, + pOutData, + (LVM_INT32)(2*NumSamples)); + } + + + if(pInstance->bInOperatingModeTransition == LVM_TRUE){ + + /* + * Re-init bypass mix when timer has completed + */ + if ((pInstance->bTimerDone == LVM_TRUE) && + (pInstance->BypassMix.Mixer_Instance.MixerStream[1].CallbackSet == 0)) + { + err=LVCS_BypassMixInit(hInstance, + &pInstance->Params); + + if(err != LVCS_SUCCESS) + { + return err; + } + + } + else{ + LVM_Timer ( &pInstance->TimerInstance, + (LVM_INT16)NumSamples); + } + } + } + else + { + if (pInData != pOutData) + { + /* + * The algorithm is disabled so just copy the data + */ + Copy_16((LVM_INT16 *)pInData, /* Source */ + (LVM_INT16 *)pOutData, /* Destination */ + (LVM_INT16)(2*NumSamples)); /* Left and right */ + } + } + + + return(LVCS_SUCCESS); +} + + + + + + + + + + diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_ReverbGenerator.c b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_ReverbGenerator.c new file mode 100755 index 0000000..2efef84 --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_ReverbGenerator.c @@ -0,0 +1,272 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1001 $ + $Date: 2010-06-28 13:23:02 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVCS.h" +#include "LVCS_Private.h" +#include "LVCS_ReverbGenerator.h" +#include "LVC_Mixer.h" +#include "VectorArithmetic.h" +#include "BIQUAD.h" +#include "LVCS_Tables.h" + +/************************************************************************************/ +/* */ +/* FUNCTION: LVCS_ReverbGeneratorInit */ +/* */ +/* DESCRIPTION: */ +/* Initialises the reverb module. The delay buffer size is configured for the */ +/* sample rate and the speaker type. */ +/* */ +/* The routine may also be called for re-initialisation, i.e. when one of the */ +/* control parameters has changed. In this case the delay and filters are only */ +/* re-initialised if one of the following two conditions is met: */ +/* - the sample rate has changed */ +/* - the speaker type changes to/from the mobile speaker */ +/* */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pParams Pointer to the inialisation parameters */ +/* */ +/* RETURNS: */ +/* LVCS_Success Always succeeds */ +/* */ +/* NOTES: */ +/* 1. In the delay settings 'Samples' is the number of samples to the end of the */ +/* buffer. */ +/* 2. The numerator coefficients of the filter are negated to cause an inversion. */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_ReverbGeneratorInit(LVCS_Handle_t hInstance, + LVCS_Params_t *pParams) +{ + + LVM_UINT16 Delay; + LVM_UINT16 Offset; + LVCS_Instance_t *pInstance = (LVCS_Instance_t *)hInstance; + LVCS_ReverbGenerator_t *pConfig = (LVCS_ReverbGenerator_t *)&pInstance->Reverberation; + LVCS_Data_t *pData = (LVCS_Data_t *)pInstance->MemoryTable.Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].pBaseAddress; + LVCS_Coefficient_t *pCoefficients = (LVCS_Coefficient_t *)pInstance->MemoryTable.Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].pBaseAddress; + BQ_C16_Coefs_t Coeffs; + const BiquadA012B12CoefsSP_t *pReverbCoefTable; + + /* + * Initialise the delay and filters if: + * - the sample rate has changed + * - the speaker type has changed to or from the mobile speaker + */ + if(pInstance->Params.SampleRate != pParams->SampleRate ) /* Sample rate change test */ + + { + /* + * Setup the delay + */ + Delay = (LVM_UINT16)LVCS_StereoDelayCS[(LVM_UINT16)pParams->SampleRate]; + + + pConfig->DelaySize = (LVM_INT16)(2 * Delay); + pConfig->DelayOffset = 0; + LoadConst_16(0, /* Value */ + (LVM_INT16 *)&pConfig->StereoSamples[0], /* Destination */ + (LVM_UINT16)(sizeof(pConfig->StereoSamples)/sizeof(LVM_INT16))); /* Number of words */ + + /* + * Setup the filters + */ + Offset = (LVM_UINT16)pParams->SampleRate; + pReverbCoefTable = (BiquadA012B12CoefsSP_t*)&LVCS_ReverbCoefTable[0]; + + /* Convert incoming coefficients to the required format/ordering */ + Coeffs.A0 = (LVM_INT16)pReverbCoefTable[Offset].A0; + Coeffs.A1 = (LVM_INT16)pReverbCoefTable[Offset].A1; + Coeffs.A2 = (LVM_INT16)pReverbCoefTable[Offset].A2; + Coeffs.B1 = (LVM_INT16)-pReverbCoefTable[Offset].B1; + Coeffs.B2 = (LVM_INT16)-pReverbCoefTable[Offset].B2; + + LoadConst_16(0, /* Value */ + (LVM_INT16 *)&pData->ReverbBiquadTaps, /* Destination */ + (LVM_UINT16)(sizeof(pData->ReverbBiquadTaps)/sizeof(LVM_INT16))); /* Number of words */ + + BQ_2I_D16F16Css_TRC_WRA_01_Init(&pCoefficients->ReverbBiquadInstance, + &pData->ReverbBiquadTaps, + &Coeffs); + + /* Callbacks */ + switch(pReverbCoefTable[Offset].Scale) + { + case 14: + pConfig->pBiquadCallBack = BQ_2I_D16F16C14_TRC_WRA_01; + break; + case 15: + pConfig->pBiquadCallBack = BQ_2I_D16F16C15_TRC_WRA_01; + break; + } + + + /* + * Setup the mixer + */ + pConfig->ProcGain = (LVM_UINT16)(HEADPHONEGAINPROC); + pConfig->UnprocGain = (LVM_UINT16)(HEADPHONEGAINUNPROC); + } + + if(pInstance->Params.ReverbLevel != pParams->ReverbLevel) + { + LVM_INT32 ReverbPercentage=83886; // 1 Percent Reverb i.e 1/100 in Q 23 format + ReverbPercentage*=pParams->ReverbLevel; // Actual Reverb Level in Q 23 format + pConfig->ReverbLevel=(LVM_INT16)(ReverbPercentage>>8); // Reverb Level in Q 15 format + } + + return(LVCS_SUCCESS); +} + +/************************************************************************************/ +/* */ +/* FUNCTION: LVCS_Reverb */ +/* */ +/* DESCRIPTION: */ +/* Create reverb using the block of input samples based on the following block */ +/* diagram: */ +/* ________ ________ */ +/* | | | | */ +/* _____ _______ | |----------->| | ______ ___ */ +/* | | | | | Stereo | | L & R | | | | | */ +/* -->| LPF |-->| Delay |-->| to | ____ | to |-->| Gain |-->| + |--> */ +/* | |_____| |_______| | L & R | | | | Stereo | |______| |___| */ +/* | | |-->| -1 |-->| | | */ +/* | |________| |____| |________| | */ +/* | | */ +/* |-----------------------------------------------------------------------| */ +/* */ +/* The input buffer is broken in to sub-blocks of the size of the delay or less. */ +/* This allows the delay buffer to be treated as a circular buffer but processed */ +/* as a linear buffer. */ +/* */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pInData Pointer to the input buffer */ +/* pOutData Pointer to the output buffer */ +/* NumSamples Number of samples to process */ +/* */ +/* RETURNS: */ +/* LVCS_Success Always succeeds */ +/* */ +/* NOTES: */ +/* 1. Process in blocks of samples the size of the delay where possible, if not */ +/* the number of samples left over */ +/* 2. The Gain is combined with the LPF and incorporated in to the coefficients */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_ReverbGenerator(LVCS_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 *pOutData, + LVM_UINT16 NumSamples) +{ + + LVCS_Instance_t *pInstance = (LVCS_Instance_t *)hInstance; + LVCS_ReverbGenerator_t *pConfig = (LVCS_ReverbGenerator_t *)&pInstance->Reverberation; + LVCS_Coefficient_t *pCoefficients = (LVCS_Coefficient_t *)pInstance->MemoryTable.Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].pBaseAddress; + LVM_INT16 *pScratch = (LVM_INT16 *)pInstance->MemoryTable.Region[LVCS_MEMREGION_TEMPORARY_FAST].pBaseAddress; + + + /* + * Copy the data to the output in outplace processing + */ + if (pInData != pOutData) + { + /* + * Reverb not required so just copy the data + */ + Copy_16((LVM_INT16 *)pInData, /* Source */ + (LVM_INT16 *)pOutData, /* Destination */ + (LVM_INT16)(2*NumSamples)); /* Left and right */ + } + + + /* + * Check if the reverb is required + */ + if (((pInstance->Params.SpeakerType == LVCS_HEADPHONE) || /* Disable when CS4MS in stereo mode */ + (pInstance->Params.SpeakerType == LVCS_EX_HEADPHONES) || + (pInstance->Params.SourceFormat != LVCS_STEREO)) && + ((pInstance->Params.OperatingMode & LVCS_REVERBSWITCH) !=0)) /* For validation testing */ + { + /********************************************************************************/ + /* */ + /* Copy the input data to scratch memory and filter it */ + /* */ + /********************************************************************************/ + + /* + * Copy the input data to the scratch memory + */ + Copy_16((LVM_INT16 *)pInData, /* Source */ + (LVM_INT16 *)pScratch, /* Destination */ + (LVM_INT16)(2*NumSamples)); /* Left and right */ + + + /* + * Filter the data + */ + (pConfig->pBiquadCallBack)((Biquad_Instance_t*)&pCoefficients->ReverbBiquadInstance, + (LVM_INT16 *)pScratch, + (LVM_INT16 *)pScratch, + (LVM_INT16)NumSamples); + + Mult3s_16x16( (LVM_INT16 *)pScratch, + pConfig->ReverbLevel, + (LVM_INT16 *)pScratch, + (LVM_INT16)(2*NumSamples)); + + + /* + * Apply the delay mix + */ + DelayMix_16x16((LVM_INT16 *)pScratch, + &pConfig->StereoSamples[0], + pConfig->DelaySize, + pOutData, + &pConfig->DelayOffset, + (LVM_INT16)NumSamples); + + + } + + return(LVCS_SUCCESS); +} + + + + + diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_ReverbGenerator.h b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_ReverbGenerator.h new file mode 100755 index 0000000..1164bce --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_ReverbGenerator.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1001 $ + $Date: 2010-06-28 13:23:02 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + +#ifndef __LVCS_REVERBGENERATOR_H__ +#define __LVCS_REVERBGENERATOR_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVC_Mixer.h" + + +/************************************************************************************/ +/* */ +/* Defines */ +/* */ +/************************************************************************************/ + +#define HEADPHONEGAINPROC LVCS_HEADPHONE_PROCGAIN +#define HEADPHONEGAINUNPROC LVCS_HEADPHONE_UNPROCGAIN + + +/************************************************************************************/ +/* */ +/* Structures */ +/* */ +/************************************************************************************/ + + +/* Reverberation module structure */ +typedef struct +{ + + /* Stereo delay */ + LVM_INT16 DelaySize; + LVM_INT16 DelayOffset; + LVM_INT16 ProcGain; + LVM_INT16 UnprocGain; + LVM_INT16 StereoSamples[2*LVCS_STEREODELAY_CS_48KHZ]; + + /* Reverb Level */ + LVM_INT16 ReverbLevel; + + /* Filter */ + void (*pBiquadCallBack) (Biquad_Instance_t*, LVM_INT16*, LVM_INT16*, LVM_INT16); + +} LVCS_ReverbGenerator_t; + + +/************************************************************************************/ +/* */ +/* Function prototypes */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_ReverbGeneratorInit(LVCS_Handle_t hInstance, + LVCS_Params_t *pParams); + +LVCS_ReturnStatus_en LVCS_ReverbGenerator(LVCS_Handle_t hInstance, + const LVM_INT16 *pInput, + LVM_INT16 *pOutput, + LVM_UINT16 NumSamples); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* REVERB_H */ diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_StereoEnhancer.c b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_StereoEnhancer.c new file mode 100755 index 0000000..4ff4716 --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_StereoEnhancer.c @@ -0,0 +1,266 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1001 $ + $Date: 2010-06-28 13:23:02 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVCS.h" +#include "LVCS_Private.h" +#include "LVCS_StereoEnhancer.h" +#include "VectorArithmetic.h" +#include "LVCS_Tables.h" + +/************************************************************************************/ +/* */ +/* FUNCTION: LVCS_StereoEnhanceInit */ +/* */ +/* DESCRIPTION: */ +/* Initialises the stereo enhancement module based on the sample rate. */ +/* */ +/* The function selects the coefficients for the filters and clears the data */ +/* history. It is also used for re-initialisation when one of the system control */ +/* parameters changes but will only change the coefficients and clear the history */ +/* if the sample rate or speaker type has changed. */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pParams Initialisation parameters */ +/* */ +/* RETURNS: */ +/* LVCS_Success Always succeeds */ +/* */ +/* NOTES: */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_SEnhancerInit(LVCS_Handle_t hInstance, + LVCS_Params_t *pParams) +{ + + LVM_UINT16 Offset; + LVCS_Instance_t *pInstance = (LVCS_Instance_t *)hInstance; + LVCS_StereoEnhancer_t *pConfig = (LVCS_StereoEnhancer_t *)&pInstance->StereoEnhancer; + LVCS_Data_t *pData = (LVCS_Data_t *)pInstance->MemoryTable.Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].pBaseAddress; + LVCS_Coefficient_t *pCoefficient = (LVCS_Coefficient_t *)pInstance->MemoryTable.Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].pBaseAddress; + FO_C16_Coefs_t CoeffsMid; + BQ_C16_Coefs_t CoeffsSide; + const BiquadA012B12CoefsSP_t *pSESideCoefs; + + /* + * If the sample rate or speaker type has changed update the filters + */ + if ((pInstance->Params.SampleRate != pParams->SampleRate) || + (pInstance->Params.SpeakerType != pParams->SpeakerType)) + { + /* + * Set the filter coefficients based on the sample rate + */ + /* Mid filter */ + Offset = (LVM_UINT16)pParams->SampleRate; + + /* Convert incoming coefficients to the required format/ordering */ + CoeffsMid.A0 = (LVM_INT16) LVCS_SEMidCoefTable[Offset].A0; + CoeffsMid.A1 = (LVM_INT16) LVCS_SEMidCoefTable[Offset].A1; + CoeffsMid.B1 = (LVM_INT16)-LVCS_SEMidCoefTable[Offset].B1; + + /* Clear the taps */ + LoadConst_16(0, /* Value */ + (LVM_INT16 *)&pData->SEBiquadTapsMid, /* Destination */ + (LVM_UINT16)(sizeof(pData->SEBiquadTapsMid)/sizeof(LVM_UINT16))); /* Number of words */ + + FO_1I_D16F16Css_TRC_WRA_01_Init(&pCoefficient->SEBiquadInstanceMid, + &pData->SEBiquadTapsMid, + &CoeffsMid); + + /* Callbacks */ + if(LVCS_SEMidCoefTable[Offset].Scale==15) + { + pConfig->pBiquadCallBack_Mid = FO_1I_D16F16C15_TRC_WRA_01; + } + + Offset = (LVM_UINT16)(pParams->SampleRate); + pSESideCoefs = (BiquadA012B12CoefsSP_t*)&LVCS_SESideCoefTable[0]; + + /* Side filter */ + /* Convert incoming coefficients to the required format/ordering */ + CoeffsSide.A0 = (LVM_INT16) pSESideCoefs[Offset].A0; + CoeffsSide.A1 = (LVM_INT16) pSESideCoefs[Offset].A1; + CoeffsSide.A2 = (LVM_INT16) pSESideCoefs[Offset].A2; + CoeffsSide.B1 = (LVM_INT16)-pSESideCoefs[Offset].B1; + CoeffsSide.B2 = (LVM_INT16)-pSESideCoefs[Offset].B2; + + /* Clear the taps */ + LoadConst_16(0, /* Value */ + (LVM_INT16 *)&pData->SEBiquadTapsSide, /* Destination */ + (LVM_UINT16)(sizeof(pData->SEBiquadTapsSide)/sizeof(LVM_UINT16))); /* Number of words */ + + + /* Callbacks */ + switch(pSESideCoefs[Offset].Scale) + { + case 14: + BQ_1I_D16F32Css_TRC_WRA_01_Init(&pCoefficient->SEBiquadInstanceSide, + &pData->SEBiquadTapsSide, + &CoeffsSide); + + pConfig->pBiquadCallBack_Side = BQ_1I_D16F32C14_TRC_WRA_01; + break; + case 15: + BQ_1I_D16F16Css_TRC_WRA_01_Init(&pCoefficient->SEBiquadInstanceSide, + &pData->SEBiquadTapsSide, + &CoeffsSide); + + pConfig->pBiquadCallBack_Side = BQ_1I_D16F16C15_TRC_WRA_01; + break; + } + + } + + + return(LVCS_SUCCESS); +} + +/************************************************************************************/ +/* */ +/* FUNCTION: LVCS_StereoEnhance */ +/* */ +/* DESCRIPTION: */ +/* Enhance the stereo image in the input samples based on the following block */ +/* diagram: */ +/* */ +/* ________ */ +/* ________ | | ________ */ +/* | | Middle | Treble | | | */ +/* | |---------->| Boost |-------->| | */ +/* | Stereo | |________| | M & S | */ +/* -->| to | ________ | to |--> */ +/* | M & S | Side | | | Stereo | */ +/* | |---------->| Side |-------->| | */ +/* |________| | Boost | |________| */ +/* |________| */ +/* */ +/* */ +/* If the input signal is a mono signal there will be no side signal and hence */ +/* the side filter will not be run. In mobile speaker mode the middle filter is */ +/* not required and the Trebble boost filter is replaced by a simple gain block. */ +/* */ +/* */ +/* PARAMETERS: */ +/* hInstance Instance Handle */ +/* pInData Pointer to the input data */ +/* pOutData Pointer to the output data */ +/* NumSamples Number of samples to process */ +/* */ +/* RETURNS: */ +/* LVCS_Success Always succeeds */ +/* */ +/* NOTES: */ +/* 1. The side filter is not used in Mobile Speaker mode */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_StereoEnhancer(LVCS_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 *pOutData, + LVM_UINT16 NumSamples) +{ + + LVCS_Instance_t *pInstance = (LVCS_Instance_t *)hInstance; + LVCS_StereoEnhancer_t *pConfig = (LVCS_StereoEnhancer_t *)&pInstance->StereoEnhancer; + LVCS_Coefficient_t *pCoefficient = (LVCS_Coefficient_t *)pInstance->MemoryTable.Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].pBaseAddress; + LVM_INT16 *pScratch = (LVM_INT16 *)pInstance->MemoryTable.Region[LVCS_MEMREGION_TEMPORARY_FAST].pBaseAddress; + + /* + * Check if the Stereo Enhancer is enabled + */ + if ((pInstance->Params.OperatingMode & LVCS_STEREOENHANCESWITCH) != 0) + { + /* + * Convert from stereo to middle and side + */ + From2iToMS_16x16(pInData, + pScratch, + pScratch+NumSamples, + (LVM_INT16)NumSamples); + + /* + * Apply filter to the middle signal + */ + if (pInstance->OutputDevice == LVCS_HEADPHONE) + { + (pConfig->pBiquadCallBack_Mid)((Biquad_Instance_t*)&pCoefficient->SEBiquadInstanceMid, + (LVM_INT16 *)pScratch, + (LVM_INT16 *)pScratch, + (LVM_INT16)NumSamples); + } + else + { + Mult3s_16x16(pScratch, /* Source */ + (LVM_INT16)pConfig->MidGain, /* Gain */ + pScratch, /* Destination */ + (LVM_INT16)NumSamples); /* Number of samples */ + } + + /* + * Apply the filter the side signal only in stereo mode for headphones + * and in all modes for mobile speakers + */ + if (pInstance->Params.SourceFormat == LVCS_STEREO) + { + (pConfig->pBiquadCallBack_Side)((Biquad_Instance_t*)&pCoefficient->SEBiquadInstanceSide, + (LVM_INT16 *)(pScratch + NumSamples), + (LVM_INT16 *)(pScratch + NumSamples), + (LVM_INT16)NumSamples); + } + + /* + * Convert from middle and side to stereo + */ + MSTo2i_Sat_16x16(pScratch, + pScratch+NumSamples, + pOutData, + (LVM_INT16)NumSamples); + + } + else + { + /* + * The stereo enhancer is disabled so just copy the data + */ + Copy_16((LVM_INT16 *)pInData, /* Source */ + (LVM_INT16 *)pOutData, /* Destination */ + (LVM_INT16)(2*NumSamples)); /* Left and right */ + + } + + return(LVCS_SUCCESS); +} + + + + diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_StereoEnhancer.h b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_StereoEnhancer.h new file mode 100755 index 0000000..c3f6296 --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_StereoEnhancer.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1001 $ + $Date: 2010-06-28 13:23:02 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + +#ifndef __LVCS_STEREOENHANCER_H__ +#define __LVCS_STEREOENHANCER_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "Filters.h" /* Filter definitions */ +#include "LVCS_Headphone_Coeffs.h" /* Headphone coefficients */ +#include "BIQUAD.h" + + +/************************************************************************************/ +/* */ +/* Structures */ +/* */ +/************************************************************************************/ + +/* Stereo enhancer structure */ +typedef struct +{ + /* + * Middle filter + */ + void (*pBiquadCallBack_Mid)(Biquad_Instance_t*, LVM_INT16*, LVM_INT16*, LVM_INT16); + + /* + * Side filter + */ + void (*pBiquadCallBack_Side)(Biquad_Instance_t*, LVM_INT16*, LVM_INT16*, LVM_INT16); + + LVM_UINT16 MidGain; /* Middle gain in mobile speaker mode */ + +} LVCS_StereoEnhancer_t; + + +/************************************************************************************/ +/* */ +/* Function prototypes */ +/* */ +/************************************************************************************/ + +LVCS_ReturnStatus_en LVCS_SEnhancerInit(LVCS_Handle_t hInstance, + LVCS_Params_t *pParams); + +LVCS_ReturnStatus_en LVCS_StereoEnhancer(LVCS_Handle_t hInstance, + const LVM_INT16 *pInData, + LVM_INT16 *pOutData, + LVM_UINT16 NumSamples); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* STEREOENHANCE_H */ diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Tables.c b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Tables.c new file mode 100755 index 0000000..ad4eb1e --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Tables.c @@ -0,0 +1,456 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: beq07716 $ + $Revision: 1001 $ + $Date: 2010-06-28 13:23:02 +0200 (Mon, 28 Jun 2010) $ + +*************************************************************************************/ + + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "LVCS_Private.h" +#include "Filters.h" /* Filter definitions */ +#include "BIQUAD.h" /* Biquad definitions */ +#include "LVCS_Headphone_Coeffs.h" /* Headphone coefficients */ + + +/************************************************************************************/ +/* */ +/* Stereo Enhancer coefficient constant tables */ +/* */ +/************************************************************************************/ + +/* Coefficient table for the middle filter */ +const BiquadA01B1CoefsSP_t LVCS_SEMidCoefTable[] = { + {CS_MIDDLE_8000_A0, /* 8kS/s coefficients */ + CS_MIDDLE_8000_A1, + CS_MIDDLE_8000_B1, + (LVM_UINT16 )CS_MIDDLE_8000_SCALE}, + {CS_MIDDLE_11025_A0, /* 11kS/s coefficients */ + CS_MIDDLE_11025_A1, + CS_MIDDLE_11025_B1, + (LVM_UINT16 )CS_MIDDLE_11025_SCALE}, + {CS_MIDDLE_12000_A0, /* 12kS/s coefficients */ + CS_MIDDLE_12000_A1, + CS_MIDDLE_12000_B1, + (LVM_UINT16 )CS_MIDDLE_12000_SCALE}, + {CS_MIDDLE_16000_A0, /* 16kS/s coefficients */ + CS_MIDDLE_16000_A1, + CS_MIDDLE_16000_B1, + (LVM_UINT16 )CS_MIDDLE_16000_SCALE}, + {CS_MIDDLE_22050_A0, /* 22kS/s coefficients */ + CS_MIDDLE_22050_A1, + CS_MIDDLE_22050_B1, + (LVM_UINT16 )CS_MIDDLE_22050_SCALE}, + {CS_MIDDLE_24000_A0, /* 24kS/s coefficients */ + CS_MIDDLE_24000_A1, + CS_MIDDLE_24000_B1, + (LVM_UINT16 )CS_MIDDLE_24000_SCALE}, + {CS_MIDDLE_32000_A0, /* 32kS/s coefficients */ + CS_MIDDLE_32000_A1, + CS_MIDDLE_32000_B1, + (LVM_UINT16 )CS_MIDDLE_32000_SCALE}, + {CS_MIDDLE_44100_A0, /* 44kS/s coefficients */ + CS_MIDDLE_44100_A1, + CS_MIDDLE_44100_B1, + (LVM_UINT16 )CS_MIDDLE_44100_SCALE}, + {CS_MIDDLE_48000_A0, /* 48kS/s coefficients */ + CS_MIDDLE_48000_A1, + CS_MIDDLE_48000_B1, + (LVM_UINT16 )CS_MIDDLE_48000_SCALE}}; + +/* Coefficient table for the side filter */ +const BiquadA012B12CoefsSP_t LVCS_SESideCoefTable[] = { + /* Headphone Side coefficients */ + {CS_SIDE_8000_A0, /* 8kS/s coefficients */ + CS_SIDE_8000_A1, + CS_SIDE_8000_A2, + CS_SIDE_8000_B1, + CS_SIDE_8000_B2, + (LVM_UINT16 )CS_SIDE_8000_SCALE}, + {CS_SIDE_11025_A0, /* 11kS/s coefficients */ + CS_SIDE_11025_A1, + CS_SIDE_11025_A2, + CS_SIDE_11025_B1, + CS_SIDE_11025_B2, + (LVM_UINT16 )CS_SIDE_11025_SCALE}, + {CS_SIDE_12000_A0, /* 12kS/s coefficients */ + CS_SIDE_12000_A1, + CS_SIDE_12000_A2, + CS_SIDE_12000_B1, + CS_SIDE_12000_B2, + (LVM_UINT16 )CS_SIDE_12000_SCALE}, + {CS_SIDE_16000_A0, /* 16kS/s coefficients */ + CS_SIDE_16000_A1, + CS_SIDE_16000_A2, + CS_SIDE_16000_B1, + CS_SIDE_16000_B2, + (LVM_UINT16 )CS_SIDE_16000_SCALE}, + {CS_SIDE_22050_A0, /* 22kS/s coefficients */ + CS_SIDE_22050_A1, + CS_SIDE_22050_A2, + CS_SIDE_22050_B1, + CS_SIDE_22050_B2, + (LVM_UINT16 )CS_SIDE_22050_SCALE}, + {CS_SIDE_24000_A0, /* 24kS/s coefficients */ + CS_SIDE_24000_A1, + CS_SIDE_24000_A2, + CS_SIDE_24000_B1, + CS_SIDE_24000_B2, + (LVM_UINT16 )CS_SIDE_24000_SCALE}, + {CS_SIDE_32000_A0, /* 32kS/s coefficients */ + CS_SIDE_32000_A1, + CS_SIDE_32000_A2, + CS_SIDE_32000_B1, + CS_SIDE_32000_B2, + (LVM_UINT16 )CS_SIDE_32000_SCALE}, + {CS_SIDE_44100_A0, /* 44kS/s coefficients */ + CS_SIDE_44100_A1, + CS_SIDE_44100_A2, + CS_SIDE_44100_B1, + CS_SIDE_44100_B2, + (LVM_UINT16 )CS_SIDE_44100_SCALE}, + {CS_SIDE_48000_A0, /* 48kS/s coefficients */ + CS_SIDE_48000_A1, + CS_SIDE_48000_A2, + CS_SIDE_48000_B1, + CS_SIDE_48000_B2, + (LVM_UINT16 )CS_SIDE_48000_SCALE} +}; + + +/************************************************************************************/ +/* */ +/* Equaliser coefficient constant tables */ +/* */ +/************************************************************************************/ + +const BiquadA012B12CoefsSP_t LVCS_EqualiserCoefTable[] = { + /* Headphone coefficients */ + {CS_EQUALISER_8000_A0, /* 8kS/s coefficients */ + CS_EQUALISER_8000_A1, + CS_EQUALISER_8000_A2, + CS_EQUALISER_8000_B1, + CS_EQUALISER_8000_B2, + (LVM_UINT16 )CS_EQUALISER_8000_SCALE}, + {CS_EQUALISER_11025_A0, /* 11kS/s coefficients */ + CS_EQUALISER_11025_A1, + CS_EQUALISER_11025_A2, + CS_EQUALISER_11025_B1, + CS_EQUALISER_11025_B2, + (LVM_UINT16 )CS_EQUALISER_11025_SCALE}, + {CS_EQUALISER_12000_A0, /* 12kS/s coefficients */ + CS_EQUALISER_12000_A1, + CS_EQUALISER_12000_A2, + CS_EQUALISER_12000_B1, + CS_EQUALISER_12000_B2, + (LVM_UINT16 )CS_EQUALISER_12000_SCALE}, + {CS_EQUALISER_16000_A0, /* 16kS/s coefficients */ + CS_EQUALISER_16000_A1, + CS_EQUALISER_16000_A2, + CS_EQUALISER_16000_B1, + CS_EQUALISER_16000_B2, + (LVM_UINT16 )CS_EQUALISER_16000_SCALE}, + {CS_EQUALISER_22050_A0, /* 22kS/s coefficients */ + CS_EQUALISER_22050_A1, + CS_EQUALISER_22050_A2, + CS_EQUALISER_22050_B1, + CS_EQUALISER_22050_B2, + (LVM_UINT16 )CS_EQUALISER_22050_SCALE}, + {CS_EQUALISER_24000_A0, /* 24kS/s coefficients */ + CS_EQUALISER_24000_A1, + CS_EQUALISER_24000_A2, + CS_EQUALISER_24000_B1, + CS_EQUALISER_24000_B2, + (LVM_UINT16 )CS_EQUALISER_24000_SCALE}, + {CS_EQUALISER_32000_A0, /* 32kS/s coefficients */ + CS_EQUALISER_32000_A1, + CS_EQUALISER_32000_A2, + CS_EQUALISER_32000_B1, + CS_EQUALISER_32000_B2, + (LVM_UINT16 )CS_EQUALISER_32000_SCALE}, + {CS_EQUALISER_44100_A0, /* 44kS/s coefficients */ + CS_EQUALISER_44100_A1, + CS_EQUALISER_44100_A2, + CS_EQUALISER_44100_B1, + CS_EQUALISER_44100_B2, + (LVM_UINT16 )CS_EQUALISER_44100_SCALE}, + {CS_EQUALISER_48000_A0, /* 48kS/s coefficients */ + CS_EQUALISER_48000_A1, + CS_EQUALISER_48000_A2, + CS_EQUALISER_48000_B1, + CS_EQUALISER_48000_B2, + (LVM_UINT16 )CS_EQUALISER_48000_SCALE}, + + /* Concert Sound EX Headphone coefficients */ + {CSEX_EQUALISER_8000_A0, /* 8kS/s coefficients */ + CSEX_EQUALISER_8000_A1, + CSEX_EQUALISER_8000_A2, + CSEX_EQUALISER_8000_B1, + CSEX_EQUALISER_8000_B2, + (LVM_UINT16 )CSEX_EQUALISER_8000_SCALE}, + {CSEX_EQUALISER_11025_A0, /* 11kS/s coefficients */ + CSEX_EQUALISER_11025_A1, + CSEX_EQUALISER_11025_A2, + CSEX_EQUALISER_11025_B1, + CSEX_EQUALISER_11025_B2, + (LVM_UINT16 )CSEX_EQUALISER_11025_SCALE}, + {CSEX_EQUALISER_12000_A0, /* 12kS/s coefficients */ + CSEX_EQUALISER_12000_A1, + CSEX_EQUALISER_12000_A2, + CSEX_EQUALISER_12000_B1, + CSEX_EQUALISER_12000_B2, + (LVM_UINT16 )CSEX_EQUALISER_12000_SCALE}, + {CSEX_EQUALISER_16000_A0, /* 16kS/s coefficients */ + CSEX_EQUALISER_16000_A1, + CSEX_EQUALISER_16000_A2, + CSEX_EQUALISER_16000_B1, + CSEX_EQUALISER_16000_B2, + (LVM_UINT16 )CSEX_EQUALISER_16000_SCALE}, + {CSEX_EQUALISER_22050_A0, /* 22kS/s coefficients */ + CSEX_EQUALISER_22050_A1, + CSEX_EQUALISER_22050_A2, + CSEX_EQUALISER_22050_B1, + CSEX_EQUALISER_22050_B2, + (LVM_UINT16 )CSEX_EQUALISER_22050_SCALE}, + {CSEX_EQUALISER_24000_A0, /* 24kS/s coefficients */ + CSEX_EQUALISER_24000_A1, + CSEX_EQUALISER_24000_A2, + CSEX_EQUALISER_24000_B1, + CSEX_EQUALISER_24000_B2, + (LVM_UINT16 )CSEX_EQUALISER_24000_SCALE}, + {CSEX_EQUALISER_32000_A0, /* 32kS/s coefficients */ + CSEX_EQUALISER_32000_A1, + CSEX_EQUALISER_32000_A2, + CSEX_EQUALISER_32000_B1, + CSEX_EQUALISER_32000_B2, + (LVM_UINT16 )CSEX_EQUALISER_32000_SCALE}, + {CSEX_EQUALISER_44100_A0, /* 44kS/s coefficients */ + CSEX_EQUALISER_44100_A1, + CSEX_EQUALISER_44100_A2, + CSEX_EQUALISER_44100_B1, + CSEX_EQUALISER_44100_B2, + (LVM_UINT16 )CSEX_EQUALISER_44100_SCALE}, + {CSEX_EQUALISER_48000_A0, /* 48kS/s coefficients */ + CSEX_EQUALISER_48000_A1, + CSEX_EQUALISER_48000_A2, + CSEX_EQUALISER_48000_B1, + CSEX_EQUALISER_48000_B2, + (LVM_UINT16 )CSEX_EQUALISER_48000_SCALE} +}; + + +/************************************************************************************/ +/* */ +/* Reverb delay constant tables */ +/* */ +/************************************************************************************/ + +/* Stereo delay table for Concert Sound */ +const LVM_UINT16 LVCS_StereoDelayCS[] = { + LVCS_STEREODELAY_CS_8KHZ, + LVCS_STEREODELAY_CS_11KHZ, + LVCS_STEREODELAY_CS_12KHZ, + LVCS_STEREODELAY_CS_16KHZ, + LVCS_STEREODELAY_CS_22KHZ, + LVCS_STEREODELAY_CS_24KHZ, + LVCS_STEREODELAY_CS_32KHZ, + LVCS_STEREODELAY_CS_44KHZ, + LVCS_STEREODELAY_CS_48KHZ}; + +/************************************************************************************/ +/* */ +/* Reverb coefficients constant table */ +/* */ +/************************************************************************************/ + +const BiquadA012B12CoefsSP_t LVCS_ReverbCoefTable[] = { + /* Headphone coefficients */ + {CS_REVERB_8000_A0, /* 8kS/s coefficients */ + CS_REVERB_8000_A1, + CS_REVERB_8000_A2, + CS_REVERB_8000_B1, + CS_REVERB_8000_B2, + (LVM_UINT16 )CS_REVERB_8000_SCALE}, + {CS_REVERB_11025_A0, /* 11kS/s coefficients */ + CS_REVERB_11025_A1, + CS_REVERB_11025_A2, + CS_REVERB_11025_B1, + CS_REVERB_11025_B2, + (LVM_UINT16 )CS_REVERB_11025_SCALE}, + {CS_REVERB_12000_A0, /* 12kS/s coefficients */ + CS_REVERB_12000_A1, + CS_REVERB_12000_A2, + CS_REVERB_12000_B1, + CS_REVERB_12000_B2, + (LVM_UINT16 )CS_REVERB_12000_SCALE}, + {CS_REVERB_16000_A0, /* 16kS/s coefficients */ + CS_REVERB_16000_A1, + CS_REVERB_16000_A2, + CS_REVERB_16000_B1, + CS_REVERB_16000_B2, + (LVM_UINT16 )CS_REVERB_16000_SCALE}, + {CS_REVERB_22050_A0, /* 22kS/s coefficients */ + CS_REVERB_22050_A1, + CS_REVERB_22050_A2, + CS_REVERB_22050_B1, + CS_REVERB_22050_B2, + (LVM_UINT16 )CS_REVERB_22050_SCALE}, + {CS_REVERB_24000_A0, /* 24kS/s coefficients */ + CS_REVERB_24000_A1, + CS_REVERB_24000_A2, + CS_REVERB_24000_B1, + CS_REVERB_24000_B2, + (LVM_UINT16 )CS_REVERB_24000_SCALE}, + {CS_REVERB_32000_A0, /* 32kS/s coefficients */ + CS_REVERB_32000_A1, + CS_REVERB_32000_A2, + CS_REVERB_32000_B1, + CS_REVERB_32000_B2, + (LVM_UINT16 )CS_REVERB_32000_SCALE}, + {CS_REVERB_44100_A0, /* 44kS/s coefficients */ + CS_REVERB_44100_A1, + CS_REVERB_44100_A2, + CS_REVERB_44100_B1, + CS_REVERB_44100_B2, + (LVM_UINT16 )CS_REVERB_44100_SCALE}, + {CS_REVERB_48000_A0, /* 48kS/s coefficients */ + CS_REVERB_48000_A1, + CS_REVERB_48000_A2, + CS_REVERB_48000_B1, + CS_REVERB_48000_B2, + (LVM_UINT16 )CS_REVERB_48000_SCALE} +}; + + +/************************************************************************************/ +/* */ +/* Bypass mixer constant tables */ +/* */ +/************************************************************************************/ + +const Gain_t LVCS_OutputGainTable[] = { + {LVCS_HEADPHONE_SHIFT, /* Headphone, stereo mode */ + LVCS_HEADPHONE_SHIFTLOSS, + LVCS_HEADPHONE_GAIN}, + {LVCS_EX_HEADPHONE_SHIFT, /* EX Headphone, stereo mode */ + LVCS_EX_HEADPHONE_SHIFTLOSS, + LVCS_EX_HEADPHONE_GAIN}, + {LVCS_HEADPHONE_SHIFT, /* Headphone, mono mode */ + LVCS_HEADPHONE_SHIFTLOSS, + LVCS_HEADPHONE_GAIN}, + {LVCS_EX_HEADPHONE_SHIFT, /* EX Headphone, mono mode */ + LVCS_EX_HEADPHONE_SHIFTLOSS, + LVCS_EX_HEADPHONE_GAIN} +}; + + +/************************************************************************************/ +/* */ +/* Volume correction table */ +/* */ +/* Coefficient order: */ +/* Compression 100% effect */ +/* Compression 0% effect */ +/* Gain 100% effect */ +/* Gain 0% effect */ +/* */ +/* The Compression gain is represented by a Q1.15 number to give a range of 0dB */ +/* to +6dB, E.g.: */ +/* 0 is 0dB compression (no effect) */ +/* 5461 is 1dB compression gain */ +/* 10923 is 2dB compression gain */ +/* 32767 is 6dB compression gain */ +/* */ +/* The Gain is represented as a Q3.13 number to give a range of +8 to -infinity */ +/* E.g.: */ +/* 0 is -infinity */ +/* 32767 is +18dB (x8) gain */ +/* 4096 is 0dB gain */ +/* 1024 is -12dB gain */ +/* */ +/************************************************************************************/ +const LVCS_VolCorrect_t LVCS_VolCorrectTable[] = { + {14200, /* Headphone, stereo mode */ + 0, + 4096, + 5786}, + {14200, /* EX Headphone, stereo mode */ + 0, + 4096, + 5786}, + {32767, /* Headphone, mono mode */ + 0, + 4096, + 5786}, + {32767, /* EX Headphone, mono mode */ + 0, + 4096, + 5786} +}; + +/************************************************************************************/ +/* */ +/* Mixer time constants, 100ms */ +/* */ +/************************************************************************************/ + +#define LVCS_VOL_TC_Fs8000 32580 /* Floating point value 0.994262695 */ +#define LVCS_VOL_TC_Fs11025 32632 /* Floating point value 0.995849609 */ +#define LVCS_VOL_TC_Fs12000 32643 /* Floating point value 0.996185303 */ +#define LVCS_VOL_TC_Fs16000 32674 /* Floating point value 0.997131348 */ +#define LVCS_VOL_TC_Fs22050 32700 /* Floating point value 0.997924805 */ +#define LVCS_VOL_TC_Fs24000 32705 /* Floating point value 0.998077393 */ +#define LVCS_VOL_TC_Fs32000 32721 /* Floating point value 0.998565674 */ +#define LVCS_VOL_TC_Fs44100 32734 /* Floating point value 0.998962402 */ +#define LVCS_VOL_TC_Fs48000 32737 /* Floating point value 0.999053955 */ + + +const LVM_INT16 LVCS_VolumeTCTable[9] = {LVCS_VOL_TC_Fs8000, + LVCS_VOL_TC_Fs11025, + LVCS_VOL_TC_Fs12000, + LVCS_VOL_TC_Fs16000, + LVCS_VOL_TC_Fs22050, + LVCS_VOL_TC_Fs24000, + LVCS_VOL_TC_Fs32000, + LVCS_VOL_TC_Fs44100, + LVCS_VOL_TC_Fs48000}; + +/************************************************************************************/ +/* */ +/* Sample rate table */ +/* */ +/************************************************************************************/ + +const LVM_INT32 LVCS_SampleRateTable[9] = {8000, + 11025, + 12000, + 16000, + 22050, + 24000, + 32000, + 44100, + 48000}; + diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Tables.h b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Tables.h new file mode 100755 index 0000000..72d6855 --- /dev/null +++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Tables.h @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2004-2010 NXP Software + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/************************************************************************************ + + $Author: nxp27078 $ + $Revision: 672 $ + $Date: 2010-06-08 19:39:38 +0200 (Tue, 08 Jun 2010) $ + +*************************************************************************************/ +#ifndef __LVCS_TABLES_H__ +#define __LVCS_TABLES_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/************************************************************************************/ +/* */ +/* Includes */ +/* */ +/************************************************************************************/ + +#include "BIQUAD.h" /* Biquad definitions */ + +/************************************************************************************/ +/* */ +/* Stereo Enhancer coefficient constant tables */ +/* */ +/************************************************************************************/ + +/* Coefficient table for the middle filter */ +extern const BiquadA01B1CoefsSP_t LVCS_SEMidCoefTable[]; + +/* Coefficient table for the side filter */ +extern const BiquadA012B12CoefsSP_t LVCS_SESideCoefTable[]; + +/************************************************************************************/ +/* */ +/* Equaliser coefficient constant tables */ +/* */ +/************************************************************************************/ + +extern const BiquadA012B12CoefsSP_t LVCS_EqualiserCoefTable[]; + +/************************************************************************************/ +/* */ +/* Reverb delay constant tables */ +/* */ +/************************************************************************************/ + +/* Stereo delay table for Concert Sound */ +extern const LVM_UINT16 LVCS_StereoDelayCS[]; + +/************************************************************************************/ +/* */ +/* Reverb coefficients constant table */ +/* */ +/************************************************************************************/ + +extern const BiquadA012B12CoefsSP_t LVCS_ReverbCoefTable[]; + +/************************************************************************************/ +/* */ +/* Bypass mixer constant tables */ +/* */ +/************************************************************************************/ + +extern const Gain_t LVCS_OutputGainTable[]; + +/************************************************************************************/ +/* */ +/* Volume correction table */ +/* */ +/* Coefficient order: */ +/* Compression 100% effect */ +/* Compression 0% effect */ +/* Gain 100% effect */ +/* Gain 0% effect */ +/* */ +/* The Compression gain is represented by a Q1.15 number to give a range of 0dB */ +/* to +6dB, E.g.: */ +/* 0 is 0dB compression (no effect) */ +/* 5461 is 1dB compression gain */ +/* 10923 is 2dB compression gain */ +/* 32767 is 6dB compression gain */ +/* */ +/* The Gain is represented as a Q3.13 number to give a range of +8 to -infinity */ +/* E.g.: */ +/* 0 is -infinity */ +/* 32767 is +18dB (x8) gain */ +/* 4096 is 0dB gain */ +/* 1024 is -12dB gain */ +/* */ +/************************************************************************************/ + +extern const LVCS_VolCorrect_t LVCS_VolCorrectTable[]; +extern const LVM_INT16 LVCS_VolumeTCTable[]; + + +/************************************************************************************/ +/* */ +/* Sample rates */ +/* */ +/************************************************************************************/ + +extern LVM_INT32 LVCS_SampleRateTable[]; + + +/*Speaker coeffient tables*/ +extern LVM_UINT16 LVCS_MS_Small_SEMiddleGainTable[]; +extern BiquadA012B12CoefsSP_t LVCS_MS_Small_SESideCoefTable[]; +extern BiquadA012B12CoefsSP_t LVCS_MS_Small_EqualiserCoefTable[]; +extern BiquadA012B12CoefsSP_t LVCS_MS_Small_ReverbCoefTable[] ; +extern LVM_UINT16 LVCS_MS_Small_StereoDelayCS4MS[]; +extern Gain_t LVCS_MS_Small_OutputGainTable[]; +extern LVCS_VolCorrect_t LVCS_MS_Small_VolCorrectTable[]; +extern LVM_UINT16 LVCS_MS_Small_ReverbGainTable[]; + +extern LVM_UINT16 LVCS_MS_Medium_SEMiddleGainTable[]; +extern BiquadA012B12CoefsSP_t LVCS_MS_Medium_SESideCoefTable[]; +extern BiquadA012B12CoefsSP_t LVCS_MS_Medium_EqualiserCoefTable[]; +extern BiquadA012B12CoefsSP_t LVCS_MS_Medium_ReverbCoefTable[] ; +extern LVM_UINT16 LVCS_MS_Medium_StereoDelayCS4MS[]; +extern Gain_t LVCS_MS_Medium_OutputGainTable[]; +extern LVCS_VolCorrect_t LVCS_MS_Medium_VolCorrectTable[]; +extern LVM_UINT16 LVCS_MS_Medium_ReverbGainTable[]; + +extern LVM_UINT16 LVCS_MS_Large_SEMiddleGainTable[]; +extern BiquadA012B12CoefsSP_t LVCS_MS_Large_SESideCoefTable[]; +extern BiquadA012B12CoefsSP_t LVCS_MS_Large_EqualiserCoefTable[]; +extern BiquadA012B12CoefsSP_t LVCS_MS_Large_ReverbCoefTable[] ; +extern LVM_UINT16 LVCS_MS_Large_StereoDelayCS4MS[]; +extern Gain_t LVCS_MS_Large_OutputGainTable[]; +extern LVCS_VolCorrect_t LVCS_MS_Large_VolCorrectTable[]; +extern LVM_UINT16 LVCS_MS_Large_ReverbGainTable[]; + + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LVCS_TABLES_H__ */ + diff --git a/media/libeffects/lvm/wrapper/Android.mk b/media/libeffects/lvm/wrapper/Android.mk new file mode 100644 index 0000000..4ebc443 --- /dev/null +++ b/media/libeffects/lvm/wrapper/Android.mk @@ -0,0 +1,30 @@ +LOCAL_PATH:= $(call my-dir) + +# music bundle wrapper +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_ARM_MODE := arm + +LOCAL_SRC_FILES:= \ + Bundle/EffectBundle.cpp + +LOCAL_MODULE:= libbundlewrapper + +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/soundfx + +LOCAL_PRELINK_MODULE := false + +LOCAL_STATIC_LIBRARIES += libmusicbundle + +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + libdl + +LOCAL_C_INCLUDES += \ + $(LOCAL_PATH)/Bundle \ + $(LOCAL_PATH)/../lib/Common/lib/ \ + $(LOCAL_PATH)/../lib/Bundle/lib/ + + +include $(BUILD_SHARED_LIBRARY) diff --git a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp new file mode 100644 index 0000000..3bbcf55 --- /dev/null +++ b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp @@ -0,0 +1,2609 @@ +/* + * Copyright (C) 2010-2010 NXP Software + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "Bundle" +#define ARRAY_SIZE(array) (sizeof array / sizeof array[0]) +#define LVM_BUNDLE // Include all the bundle code +#define LOG_NDEBUG 0 + +#include +#include +#include +#include +#include +#include + +#ifdef LVM_BUNDLE +#define LVM_MAX_SESSIONS 32 +#define MAX_NUM_BANDS 5 +#define MAX_CALL_SIZE 256 +#endif /* end LVM_BUNDLE */ + + +int framecountag = 0; +// effect_interface_t interface implementation for bass boost +extern "C" const struct effect_interface_s gLvmEffectInterface; + +#define LVM_ERROR_CHECK(LvmStatus, callingFunc, calledFunc){\ + if (LvmStatus == LVM_NULLADDRESS){\ + LOGV("\tLVM_ERROR : Parameter error - "\ + "null pointer returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\ + }\ + if (LvmStatus == LVM_ALIGNMENTERROR){\ + LOGV("\tLVM_ERROR : Parameter error - "\ + "bad alignment returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\ + }\ + if (LvmStatus == LVM_INVALIDNUMSAMPLES){\ + LOGV("\tLVM_ERROR : Parameter error - "\ + "bad number of samples returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\ + }\ + if (LvmStatus == LVM_OUTOFRANGE){\ + LOGV("\tLVM_ERROR : Parameter error - "\ + "out of range returned by %s in %s\n", callingFunc, calledFunc);\ + }\ + } + + + + + +// Namespaces +namespace android { +namespace { + +/* local functions */ +#define CHECK_ARG(cond) { \ + if (!(cond)) { \ + LOGV("\tLVM_ERROR : Invalid argument: "#cond); \ + return -EINVAL; \ + } \ +} + +int LvmInitFlag = LVM_FALSE; +SessionContext GlobalSessionMemory[32]; + +// NXP SW BassBoost UUID +const effect_descriptor_t gBassBoostDescriptor = { + {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, + {0x8631f300, 0x72e2, 0x11df, 0xb57e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid + EFFECT_API_VERSION, + (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST), + 0, // TODO + 1, + "Dynamic Bass Boost", + "NXP Software Ltd.", +}; + +// NXP SW Virtualizer UUID +const effect_descriptor_t gVirtualizerDescriptor = { + {0x37cc2c00, 0xdddd, 0x11db, 0x8577, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // Virtualizer ID + {0x1d4033c0, 0x8557, 0x11df, 0x9f2d, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // NXP SW UUID gen july 01 2010 + EFFECT_API_VERSION, + (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST), + 0, // TODO + 1, + "Virtualizer", + "NXP Software Ltd.", +}; + +// NXP SW Equalizer UUID +const effect_descriptor_t gEqualizerDescriptor = { + {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type + {0xce772f20, 0x847d, 0x11df, 0xbb17, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid Eq NXP + EFFECT_API_VERSION, + (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST), + 0, // TODO + 1, + "Equalizer", + "NXP Software Ltd.", +}; + +// NXP SW Volume UUID +const effect_descriptor_t gVolumeDescriptor = { + {0x09e8ede0, 0xddde, 0x11db, 0xb4f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, + //{0x8631f300, 0x72e2, 0x11df, 0xb57e, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, // uuid + {0x119341a0, 0x8469, 0x11df, 0x81f9, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, //uuid VOL NXP + EFFECT_API_VERSION, + (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST), + 0, // TODO + 1, + "Volume", + "NXP Software Ltd.", +}; + +//--- local function prototypes +void LvmGlobalBundle_init (void); +int LvmBundle_init (EffectContext *pContext); +int LvmEffect_enable (EffectContext *pContext); +int LvmEffect_disable (EffectContext *pContext); +void LvmEffect_free (EffectContext *pContext); +int Effect_configure (EffectContext *pContext, effect_config_t *pConfig); +int BassBoost_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue); +int BassBoost_getParameter (EffectContext *pContext, + int32_t *pParam, + size_t *pValueSize, + void *pValue); +int Virtualizer_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue); +int Virtualizer_getParameter (EffectContext *pContext, + int32_t *pParam, + size_t *pValueSize, + void *pValue); +int Equalizer_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue); +int Equalizer_getParameter (EffectContext *pContext, + int32_t *pParam, + size_t *pValueSize, + void *pValue); +int Volume_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue); +int Volume_getParameter (EffectContext *pContext, + int32_t *pParam, + size_t *pValueSize, + void *pValue); + + + + + + + + + + + + + + + + +/* Effect Library Interface Implementation */ +extern "C" int EffectQueryNumberEffects(uint32_t *pNumEffects){ + LOGV("\n\tEffectQueryNumberEffects start"); + *pNumEffects = 4; + LOGV("\tEffectQueryNumberEffects creating %d effects", *pNumEffects); + LOGV("\tEffectQueryNumberEffects end\n"); + return 0; +} /* end EffectQueryNumberEffects */ + + +extern "C" int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor){ + LOGV("\n\tEffectQueryEffect start"); + LOGV("\tEffectQueryEffect processing index %d", index); + + if (pDescriptor == NULL){ + LOGV("\tLVM_ERROR : EffectQueryEffect was passed NULL pointer"); + return -EINVAL; + } + if (index > 3){ + LOGV("\tLVM_ERROR : EffectQueryEffect index out of range %d", index); + return -ENOENT; + } + if(index == LVM_BASS_BOOST){ + LOGV("\tEffectQueryEffect processing LVM_BASS_BOOST"); + memcpy(pDescriptor, &gBassBoostDescriptor, sizeof(effect_descriptor_t)); + }else if(index == LVM_VIRTUALIZER){ + LOGV("\tEffectQueryEffect processing LVM_VIRTUALIZER"); + memcpy(pDescriptor, &gVirtualizerDescriptor, sizeof(effect_descriptor_t)); + } else if(index == LVM_EQUALIZER){ + LOGV("\tEffectQueryEffect processing LVM_EQUALIZER"); + memcpy(pDescriptor, &gEqualizerDescriptor, sizeof(effect_descriptor_t)); + } else if(index == LVM_VOLUME){ + LOGV("\tEffectQueryEffect processing LVM_VOLUME"); + memcpy(pDescriptor, &gVolumeDescriptor, sizeof(effect_descriptor_t)); + } + LOGV("\tEffectQueryEffect end\n"); + return 0; +} /* end EffectQueryEffect */ + + +extern "C" int EffectCreate(effect_uuid_t *uuid, + int32_t sessionId, + int32_t ioId, + effect_interface_t *pInterface){ + int ret; + int i; + EffectContext *pContext = new EffectContext; + + LOGV("\n\tEffectCreate start session %d", sessionId); + + if (pInterface == NULL || uuid == NULL){ + LOGV("\tLVM_ERROR : EffectCreate() called with NULL pointer"); + return -EINVAL; + } + + if((sessionId < 0)||(sessionId >= LVM_MAX_SESSIONS)){ + LOGV("\tLVM_ERROR : EffectCreate sessionId is less than 0"); + return -EINVAL; + } + + if(LvmInitFlag == LVM_FALSE){ + LvmInitFlag = LVM_TRUE; + LOGV("\tEffectCreate - Initializing all global memory"); + LvmGlobalBundle_init(); + } + + // If this is the first create in this session + if(GlobalSessionMemory[sessionId].bBundledEffectsEnabled == LVM_FALSE){ + LOGV("\tEffectCreate - This is the first effect in current session %d", sessionId); + LOGV("\tEffectCreate - Setting up Bundled Effects Instance for session %d", sessionId); + GlobalSessionMemory[sessionId].bBundledEffectsEnabled = LVM_TRUE; + GlobalSessionMemory[sessionId].pBundledContext = new BundledEffectContext; + + pContext->pBundledContext = GlobalSessionMemory[sessionId].pBundledContext; + pContext->pBundledContext->SessionNo = sessionId; + pContext->pBundledContext->hInstance = NULL; + pContext->pBundledContext->bVolumeEnabled = LVM_FALSE; + pContext->pBundledContext->bEqualizerEnabled = LVM_FALSE; + pContext->pBundledContext->bBassEnabled = LVM_FALSE; + pContext->pBundledContext->bVirtualizerEnabled = LVM_FALSE; + pContext->pBundledContext->NumberEffectsEnabled = 0; + pContext->pBundledContext->NumberEffectsCalled = 0; + + /* Saved strength is used to return the exact strength that was used in the set to the get + * because we map the original strength range of 0:1000 to 1:15, and this will avoid + * quantisation like effect when returning + */ + pContext->pBundledContext->BassStrengthSaved = 0; + pContext->pBundledContext->VirtStrengthSaved = 0; + pContext->pBundledContext->CurPreset = PRESET_CUSTOM; + pContext->pBundledContext->levelSaved = 0; + pContext->pBundledContext->bMuteEnabled = LVM_FALSE; + + LOGV("\tEffectCreate - Calling LvmBundle_init"); + ret = LvmBundle_init(pContext); + + if (ret < 0){ + LOGV("\tLVM_ERROR : EffectCreate() Bundle init failed"); + delete pContext->pBundledContext; + delete pContext; + return ret; + } + } + else{ + pContext->pBundledContext = GlobalSessionMemory[sessionId].pBundledContext; + } + + LOGV("\tEffectCreate - pBundledContext is %p", pContext->pBundledContext); + + // Create each Effect + if (memcmp(uuid, &gBassBoostDescriptor.uuid, sizeof(effect_uuid_t)) == 0){ + // Create Bass Boost + LOGV("\tEffectCreate - Effect to be created is LVM_BASS_BOOST"); + GlobalSessionMemory[sessionId].bBassInstantiated = LVM_TRUE; + + pContext->itfe = &gLvmEffectInterface; + pContext->EffectType = LVM_BASS_BOOST; + } else if (memcmp(uuid, &gVirtualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){ + // Create Virtualizer + LOGV("\tEffectCreate - Effect to be created is LVM_VIRTUALIZER"); + GlobalSessionMemory[sessionId].bVirtualizerInstantiated = LVM_TRUE; + + pContext->itfe = &gLvmEffectInterface; + pContext->EffectType = LVM_VIRTUALIZER; + } else if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){ + // Create Equalizer + LOGV("\tEffectCreate - Effect to be created is LVM_EQUALIZER"); + GlobalSessionMemory[sessionId].bEqualizerInstantiated = LVM_TRUE; + + pContext->itfe = &gLvmEffectInterface; + pContext->EffectType = LVM_EQUALIZER; + } else if (memcmp(uuid, &gVolumeDescriptor.uuid, sizeof(effect_uuid_t)) == 0){ + // Create Volume + LOGV("\tEffectCreate - Effect to be created is LVM_VOLUME"); + GlobalSessionMemory[sessionId].bVolumeInstantiated = LVM_TRUE; + + pContext->itfe = &gLvmEffectInterface; + pContext->EffectType = LVM_VOLUME; + } + else{ + LOGV("\tLVM_ERROR : EffectCreate() invalid UUID"); + return -EINVAL; + } + + *pInterface = (effect_interface_t)pContext; + LOGV("\tEffectCreate end..\n\n"); + return 0; +} /* end EffectCreate */ + + + +extern "C" int EffectRelease(effect_interface_t interface){ + LOGV("\n\tEffectRelease start %p", interface); + EffectContext * pContext = (EffectContext *)interface; + + if (pContext == NULL){ + LOGV("\tLVM_ERROR : EffectRelease called with NULL pointer"); + return -EINVAL; + } + + // Clear the instantiated flag for the effect + if(pContext->EffectType == LVM_BASS_BOOST) { + LOGV("\tEffectRelease LVM_BASS_BOOST Clearing global intstantiated flag"); + GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBassInstantiated = LVM_FALSE; + } else if(pContext->EffectType == LVM_VIRTUALIZER) { + LOGV("\tEffectRelease LVM_VIRTUALIZER Clearing global intstantiated flag"); + GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVirtualizerInstantiated = LVM_FALSE; + } else if(pContext->EffectType == LVM_EQUALIZER) { + LOGV("\tEffectRelease LVM_EQUALIZER Clearing global intstantiated flag"); + GlobalSessionMemory[pContext->pBundledContext->SessionNo].bEqualizerInstantiated = LVM_FALSE; + } else if(pContext->EffectType == LVM_VOLUME) { + LOGV("\tEffectRelease LVM_VOLUME Clearing global intstantiated flag"); + GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVolumeInstantiated = LVM_FALSE; + } else { + LOGV("\tLVM_ERROR : EffectRelease : Unsupported effect\n\n\n\n\n\n\n"); + } + + // if all effects are no longer instantiaed free the lvm memory and delete BundledEffectContext + if((GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBassInstantiated == LVM_FALSE)&& + (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVolumeInstantiated == LVM_FALSE)&& + (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bEqualizerInstantiated == LVM_FALSE)&& + (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVirtualizerInstantiated == LVM_FALSE)) + { + LOGV("\tEffectRelease: All effects are no longer instantiated\n"); + GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBundledEffectsEnabled = LVM_FALSE; + GlobalSessionMemory[pContext->pBundledContext->SessionNo].pBundledContext = LVM_NULL; + LOGV("\tEffectRelease: Freeing LVM Bundle memory\n"); + LvmEffect_free(pContext); + LOGV("\tEffectRelease: Deleting LVM Bundle context\n"); + delete pContext->pBundledContext; + } + + // free the effect context for current effect + delete pContext; + + LOGV("\tEffectRelease end\n"); + return 0; + +} /* end EffectRelease */ + + + + + + + + + + + + + + + + +void LvmGlobalBundle_init(){ + LOGV("\tLvmGlobalBundle_init start"); + for(int i=0; iconfig.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; + pContext->config.inputCfg.channels = CHANNEL_STEREO; + pContext->config.inputCfg.format = SAMPLE_FORMAT_PCM_S15; + pContext->config.inputCfg.samplingRate = 44100; + pContext->config.inputCfg.bufferProvider.getBuffer = NULL; + pContext->config.inputCfg.bufferProvider.releaseBuffer = NULL; + pContext->config.inputCfg.bufferProvider.cookie = NULL; + pContext->config.inputCfg.mask = EFFECT_CONFIG_ALL; + pContext->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; + pContext->config.outputCfg.channels = CHANNEL_STEREO; + pContext->config.outputCfg.format = SAMPLE_FORMAT_PCM_S15; + pContext->config.outputCfg.samplingRate = 44100; + pContext->config.outputCfg.bufferProvider.getBuffer = NULL; + pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL; + pContext->config.outputCfg.bufferProvider.cookie = NULL; + pContext->config.outputCfg.mask = EFFECT_CONFIG_ALL; + + CHECK_ARG(pContext != NULL); + + if (pContext->pBundledContext->hInstance != NULL){ + LOGV("\tLvmBundle_init pContext->pBassBoost != NULL " + "-> Calling pContext->pBassBoost->free()"); + + LvmEffect_free(pContext); + + LOGV("\tLvmBundle_init pContext->pBassBoost != NULL " + "-> Called pContext->pBassBoost->free()"); + } + + #ifdef LVM_BUNDLE + LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ + LVM_ControlParams_t params; /* Control Parameters */ + LVM_InstParams_t InstParams; /* Instance parameters */ + LVM_EQNB_BandDef_t BandDefs[MAX_NUM_BANDS]; /* Equaliser band definitions */ + LVM_HeadroomParams_t HeadroomParams; /* Headroom parameters */ + LVM_HeadroomBandDef_t HeadroomBandDef[LVM_HEADROOM_MAX_NBANDS]; + LVM_MemTab_t MemTab; /* Memory allocation table */ + bool bMallocFailure = LVM_FALSE; + + /* Set the capabilities */ + InstParams.BufferMode = LVM_MANAGED_BUFFERS; + InstParams.MaxBlockSize = MAX_CALL_SIZE; + InstParams.EQNB_NumBands = MAX_NUM_BANDS; + InstParams.PSA_Included = LVM_PSA_ON; + + /* Allocate memory, forcing alignment */ + LvmStatus = LVM_GetMemoryTable(LVM_NULL, + &MemTab, + &InstParams); + + LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmBundle_init") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + + LOGV("\tCreateInstance Succesfully called LVM_GetMemoryTable\n"); + + /* Allocate memory */ + for (int i=0; ipBundledContext->hInstance = LVM_NULL; /* Initialise to NULL */ + + LvmStatus = LVM_GetInstanceHandle(&pContext->pBundledContext->hInstance,/* Init sets the instance handle */ + &MemTab, + &InstParams); + + LVM_ERROR_CHECK(LvmStatus, "LVM_GetInstanceHandle", "LvmBundle_init") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + + LOGV("\tCreateInstance Succesfully called LVM_GetInstanceHandle\n"); + + /* Set the initial process parameters */ + /* General parameters */ + params.OperatingMode = LVM_MODE_ON; + params.SampleRate = LVM_FS_44100; + params.SourceFormat = LVM_STEREO; + params.SpeakerType = LVM_HEADPHONES; + + /* Concert Sound parameters */ + params.VirtualizerOperatingMode = LVM_MODE_OFF; + params.VirtualizerType = LVM_CONCERTSOUND; + params.VirtualizerReverbLevel = 100; + params.CS_EffectLevel = LVM_CS_EFFECT_HIGH; + + /* N-Band Equaliser parameters */ + params.EQNB_OperatingMode = LVM_EQNB_OFF; + params.EQNB_NBands = FIVEBAND_NUMBANDS; + params.pEQNB_BandDefinition = &BandDefs[0]; + for (int i=0; ipBundledContext->hInstance, /* Activate the initial settings */ + ¶ms); + + LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmBundle_init") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + + LOGV("\tCreateInstance Succesfully called LVM_SetControlParameters\n"); + + /* Set the headroom parameters */ + HeadroomBandDef[0].Limit_Low = 20; + HeadroomBandDef[0].Limit_High = 4999; + HeadroomBandDef[0].Headroom_Offset = 3; + HeadroomBandDef[1].Limit_Low = 5000; + HeadroomBandDef[1].Limit_High = 24000; + HeadroomBandDef[1].Headroom_Offset = 4; + HeadroomParams.pHeadroomDefinition = &HeadroomBandDef[0]; + HeadroomParams.Headroom_OperatingMode = LVM_HEADROOM_ON; + HeadroomParams.NHeadroomBands = 2; + + LvmStatus = LVM_SetHeadroomParams(pContext->pBundledContext->hInstance, + &HeadroomParams); + + LVM_ERROR_CHECK(LvmStatus, "LVM_SetHeadroomParams", "LvmBundle_init") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + + LOGV("\tCreateInstance Succesfully called LVM_SetHeadroomParams\n"); + #endif /* end LVM_BUNDLE */ + + LOGV("\tLvmBundle_init End"); + return 0; +} /* end LvmBundle_init */ + + + +//---------------------------------------------------------------------------- +// LvmBundle_process() +//---------------------------------------------------------------------------- +// Purpose: +// Apply LVM Bundle effects +// +// Inputs: +// pIn: pointer to stereo 16 bit input data +// pOut: pointer to stereo 16 bit output data +// frameCount: Frames to process +// pContext: effect engine context +// strength strength to be applied +// +// Outputs: +// pOut: pointer to updated stereo 16 bit output data +// +//---------------------------------------------------------------------------- + +int LvmBundle_process(LVM_INT16 *pIn, + LVM_INT16 *pOut, + int frameCount, + EffectContext *pContext){ + + LVM_ControlParams_t ActiveParams; /* Current control Parameters */ + LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ + + + #ifdef LVM_BUNDLE + LVM_INT16 *pOutTmp; + if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE){ + //LOGV("\tprocess: mBehavior is EFFECT_BUFFER_ACCESS_WRITE %d\n", + // pContext->config.outputCfg.accessMode); + pOutTmp = pOut; + }else if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){ + //LOGV("\tprocess: mBehavior is EFFECT_BUFFER_ACCESS_ACCUMULATE %d\n", + // pContext->config.outputCfg.accessMode); + pOutTmp = (LVM_INT16 *)malloc(frameCount * sizeof(LVM_INT16) * 2); + if(pOutTmp == NULL){ + LOGV("\tLVM_ERROR : LvmBundle_process failed to allocate memory for EFFECT_BUFFER_ACCESS_ACCUMULATE mode"); + return -EINVAL; + } + }else{ + LOGV("LVM_ERROR : LvmBundle_process invalid access mode"); + return -EINVAL; + } + + /* Process the samples */ + LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, /* Get the current settings */ + &ActiveParams); + + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_enable") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + LOGV("\t%d %d %d\n",ActiveParams.BE_OperatingMode, ActiveParams.VirtualizerOperatingMode, ActiveParams.EQNB_OperatingMode); + + + LvmStatus = LVM_Process(pContext->pBundledContext->hInstance, /* Instance handle */ + pIn, /* Input buffer */ + pOutTmp, /* Output buffer */ + (LVM_UINT16)frameCount, /* Number of samples to read */ + 0); /* Audo Time */ + LVM_ERROR_CHECK(LvmStatus, "LVM_Process", "LvmBundle_process") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + + if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){ + for (int i=0; ipBundledContext->hInstance, /* Get the current settings */ + &ActiveParams); + + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_enable") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + LOGV("\tLvmEffect_enable Succesfully called LVM_GetControlParameters\n"); + + if(pContext->EffectType == LVM_BASS_BOOST) { + LOGV("\tLvmEffect_enable : Enabling LVM_BASS_BOOST"); + ActiveParams.BE_OperatingMode = LVM_BE_ON; + } + if(pContext->EffectType == LVM_VIRTUALIZER) { + LOGV("\tLvmEffect_enable : Enabling LVM_VIRTUALIZER"); + ActiveParams.VirtualizerOperatingMode = LVM_MODE_ON; + } + if(pContext->EffectType == LVM_EQUALIZER) { + LOGV("\tLvmEffect_enable : Enabling LVM_EQUALIZER"); + ActiveParams.EQNB_OperatingMode = LVM_EQNB_ON; + } + if(pContext->EffectType == LVM_VOLUME) { + LOGV("\tLvmEffect_enable : Enabling LVM_VOLUME"); + } + + LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); + LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_enable") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + LOGV("\tLvmEffect_enable Succesfully called LVM_SetControlParameters\n"); + #endif /* end LVM_BUNDLE */ + + LOGV("\tLvmEffect_enable end"); + return 0; +} + + +//---------------------------------------------------------------------------- +// LvmEffect_disable() +//---------------------------------------------------------------------------- +// Purpose: Disable the effect in the bundle +// +// Inputs: +// pContext: effect engine context +// +// Outputs: +// +//---------------------------------------------------------------------------- + +int LvmEffect_disable(EffectContext *pContext){ + LOGV("\tLvmEffect_disable start"); + + #ifdef LVM_BUNDLE + LVM_ControlParams_t ActiveParams; /* Current control Parameters */ + LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ + + LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, /* Get the current settings */ + &ActiveParams); + + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_disable") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + LOGV("\tLvmEffect_disable Succesfully called LVM_GetControlParameters\n"); + + if(pContext->EffectType == LVM_BASS_BOOST) { + LOGV("\tLvmEffect_disable : Disabling LVM_BASS_BOOST"); + ActiveParams.BE_OperatingMode = LVM_BE_OFF; + } + if(pContext->EffectType == LVM_VIRTUALIZER) { + LOGV("\tLvmEffect_enable : Enabling LVM_VIRTUALIZER"); + ActiveParams.VirtualizerOperatingMode = LVM_MODE_OFF; + } + if(pContext->EffectType == LVM_EQUALIZER) { + LOGV("\tLvmEffect_enable : Enabling LVM_EQUALIZER"); + ActiveParams.EQNB_OperatingMode = LVM_EQNB_OFF; + } + if(pContext->EffectType == LVM_VOLUME) { + LOGV("\tLvmEffect_enable : Enabling LVM_VOLUME"); + } + + LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); + LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_disable") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + LOGV("\tLvmEffect_enable Succesfully called LVM_SetControlParameters\n"); + #endif /* end LVM_BUNDLE */ + + LOGV("\tLvmEffect_enable end"); + return 0; +} + + +//---------------------------------------------------------------------------- +// LvmEffect_free() +//---------------------------------------------------------------------------- +// Purpose: Free all memory associated with the Bundle. +// +// Inputs: +// pContext: effect engine context +// +// Outputs: +// +//---------------------------------------------------------------------------- + +void LvmEffect_free(EffectContext *pContext){ + #ifdef LVM_BUNDLE + LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ + LVM_ControlParams_t params; /* Control Parameters */ + LVM_MemTab_t MemTab; + + /* Free the algorithm memory */ + LvmStatus = LVM_GetMemoryTable(pContext->pBundledContext->hInstance, + &MemTab, + LVM_NULL); + + LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmEffect_free") + + for (int i=0; iinputCfg.samplingRate == pConfig->outputCfg.samplingRate); + CHECK_ARG(pConfig->inputCfg.channels == pConfig->outputCfg.channels); + CHECK_ARG(pConfig->inputCfg.format == pConfig->outputCfg.format); + CHECK_ARG(pConfig->inputCfg.channels == CHANNEL_STEREO); + CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE + || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE); + CHECK_ARG(pConfig->inputCfg.format == SAMPLE_FORMAT_PCM_S15); + + LOGV("\tEffect_configure calling memcpy"); + memcpy(&pContext->config, pConfig, sizeof(effect_config_t)); + LOGV("\tEffect_configure End"); + return 0; +} /* end Effect_configure */ + + + + + + + + + + + + + + + + + + + + + + + + + +//---------------------------------------------------------------------------- +// BassGetStrength() +//---------------------------------------------------------------------------- +// Purpose: +// get the effect strength currently being used, what is actually returned is the strengh that was +// previously used in the set, this is because the app uses a strength in the range 0-1000 while +// the bassboost uses 1-15, so to avoid a quantisation the original set value is used. However the +// actual used value is checked to make sure it corresponds to the one being returned +// +// Inputs: +// pContext: effect engine context +// +//---------------------------------------------------------------------------- + +uint32_t BassGetStrength(EffectContext *pContext){ + LOGV("\tBassGetStrength() (0-1000) -> %d\n", pContext->pBundledContext->BassStrengthSaved); + + #ifdef LVM_BUNDLE + LVM_ControlParams_t ActiveParams; /* Current control Parameters */ + LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ + + LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, /* Get the current settings */ + &ActiveParams); + + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassGetStrength") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + + LOGV("\tBassGetStrength Succesfully returned from LVM_GetControlParameters\n"); + + /* Check that the strength returned matches the strength that was set earlier */ + if(ActiveParams.BE_EffectLevel != (LVM_INT16)((15*pContext->pBundledContext->BassStrengthSaved)/1000)){ + LOGV("\tLVM_ERROR : BassGetStrength module strength does not match savedStrength %d %d\n", + ActiveParams.BE_EffectLevel, pContext->pBundledContext->BassStrengthSaved); + return -EINVAL; + } + + LOGV("\tBassGetStrength() (0-15) -> %d\n", ActiveParams.BE_EffectLevel ); + #endif /* end LVM_BUNDLE */ + + LOGV("\tBassGetStrength() (saved) -> %d\n", pContext->pBundledContext->BassStrengthSaved ); + return pContext->pBundledContext->BassStrengthSaved; +} /* end BassGetStrength */ + +//---------------------------------------------------------------------------- +// BassSetStrength() +//---------------------------------------------------------------------------- +// Purpose: +// Apply the strength to the BassBosst. Must first be converted from the range 0-1000 to 1-15 +// +// Inputs: +// pContext: effect engine context +// strength strength to be applied +// +//---------------------------------------------------------------------------- + +void BassSetStrength(EffectContext *pContext, uint32_t strength){ + LOGV("\tBassSetStrength(%d)", strength); + + pContext->pBundledContext->BassStrengthSaved = (int)strength; + + #ifdef LVM_BUNDLE + LVM_ControlParams_t ActiveParams; /* Current control Parameters */ + LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ + + /* Get the current settings */ + LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, + &ActiveParams); + + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassSetStrength") + LOGV("\tsetStrength Succesfully returned from LVM_GetControlParameters\n"); + + /* Bass Enhancement parameters */ +// ActiveParams.BE_OperatingMode = LVM_BE_ON; + ActiveParams.BE_EffectLevel = (LVM_INT16)((15*strength)/1000); + ActiveParams.BE_CentreFreq = LVM_BE_CENTRE_90Hz; + + LOGV("\tBassSetStrength() (0-15) -> %d\n", ActiveParams.BE_EffectLevel ); + + /* Activate the initial settings */ + LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); + + LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "BassSetStrength") + LOGV("\tBassSetStrength Succesfully called LVM_SetControlParameters\n"); + #endif /* end LVM_BUNDLE */ +} /* end BassSetStrength */ + +//---------------------------------------------------------------------------- +// VirtualizerGetStrength() +//---------------------------------------------------------------------------- +// Purpose: +// get the effect strength currently being used, what is actually returned is the strengh that was +// previously used in the set, this is because the app uses a strength in the range 0-1000 while +// the Virtualizer uses 1-100, so to avoid a quantisation the original set value is used. However the +// actual used value is checked to make sure it corresponds to the one being returned +// +// Inputs: +// pContext: effect engine context +// +//---------------------------------------------------------------------------- + +uint32_t VirtualizerGetStrength(EffectContext *pContext){ + LOGV("\tVirtualizerGetStrength() (0-1000) -> %d\n", pContext->pBundledContext->VirtStrengthSaved ); + + #ifdef LVM_BUNDLE + LVM_ControlParams_t ActiveParams; /* Current control Parameters */ + LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ + + LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); + + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerGetStrength") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + + LOGV("\tVirtualizerGetStrength Succesfully returned from LVM_GetControlParameters\n"); + LOGV("\tVirtualizerGetStrength() (0-100) -> %d\n", ActiveParams.VirtualizerReverbLevel*10); + #endif /* end LVM_BUNDLE */ + + return ActiveParams.VirtualizerReverbLevel*10; +} /* end getStrength */ + +//---------------------------------------------------------------------------- +// VirtualizerSetStrength() +//---------------------------------------------------------------------------- +// Purpose: +// Apply the strength to the Virtualizer. Must first be converted from the range 0-1000 to 1-15 +// +// Inputs: +// pContext: effect engine context +// strength strength to be applied +// +//---------------------------------------------------------------------------- + +void VirtualizerSetStrength(EffectContext *pContext, uint32_t strength){ + LOGV("\tVirtualizerSetStrength(%d)", strength); + + pContext->pBundledContext->VirtStrengthSaved = (int)strength; + + #ifdef LVM_BUNDLE + LVM_ControlParams_t ActiveParams; /* Current control Parameters */ + LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ + + /* Get the current settings */ + LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams); + + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerSetStrength") + LOGV("\tVirtualizerSetStrength Succesfully returned from LVM_GetControlParameters\n"); + + /* Virtualizer parameters */ + ActiveParams.VirtualizerReverbLevel = (LVM_INT16)(strength/10); + + LOGV("\tVirtualizerSetStrength() (0-1000) -> %d\n", strength ); + LOGV("\tVirtualizerSetStrength() (0- 100) -> %d\n", ActiveParams.VirtualizerReverbLevel ); + + /* Activate the initial settings */ + LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); + LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VirtualizerSetStrength") + LOGV("\tVirtualizerSetStrength Succesfully called LVM_SetControlParameters\n"); + #endif /* end LVM_BUNDLE */ +} /* end setStrength */ + +//---------------------------------------------------------------------------- +// EqualizerGetBandLevel() +//---------------------------------------------------------------------------- +// Purpose: Retrieve the gain currently being used for the band passed in +// +// Inputs: +// band: band number +// pContext: effect engine context +// +// Outputs: +// +//---------------------------------------------------------------------------- +int32_t EqualizerGetBandLevel(EffectContext *pContext, int32_t band){ + + int32_t Gain =0; + + #ifdef LVM_BUNDLE + LVM_ControlParams_t ActiveParams; /* Current control Parameters */ + LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ + LVM_EQNB_BandDef_t *BandDef; + + LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, /* Get the current settings */ + &ActiveParams); + + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "getBandLevel") + + BandDef = ActiveParams.pEQNB_BandDefinition; + Gain = (int32_t)BandDef[band].Gain*100; // Convert to millibels + + LOGV("\tgetBandLevel() -> %d\n", Gain ); + LOGV("\tgetBandLevel Succesfully returned from LVM_GetControlParameters\n"); + #endif /* end LVM_BUNDLE */ + + return Gain; +} + +//---------------------------------------------------------------------------- +// EqualizerSetBandLevel() +//---------------------------------------------------------------------------- +// Purpose: +// Sets gain value for the given band. +// +// Inputs: +// band: band number +// Gain: Gain to be applied in millibels +// pContext: effect engine context +// +// Outputs: +// +//--------------------------------------------------------------------------- +void EqualizerSetBandLevel(EffectContext *pContext, int band, int Gain){ + int gainRounded; + if(Gain > 0){ + gainRounded = (int)((Gain+50)/100); + }else{ + gainRounded = (int)((Gain-50)/100); + } + LOGV("\tsetBandLevel(%d)->(%d)", Gain, gainRounded); + + #ifdef LVM_BUNDLE + LVM_ControlParams_t ActiveParams; /* Current control Parameters */ + LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ + LVM_EQNB_BandDef_t *BandDef; + + /* Get the current settings */ + LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "setBandLevel") + LOGV("\tsetBandLevel Succesfully returned from LVM_GetControlParameters\n"); + LOGV("\tsetBandLevel() just Got -> %d\n", ActiveParams.pEQNB_BandDefinition[band].Gain); + + /* Set local EQ parameters */ + BandDef = ActiveParams.pEQNB_BandDefinition; + ActiveParams.pEQNB_BandDefinition[band].Gain = gainRounded; + + /* Activate the initial settings */ + LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); + LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "setBandLevel") + LOGV("\tsetBandLevel() just Set -> %d\n", ActiveParams.pEQNB_BandDefinition[band].Gain); + + /* Get the current settings to check they were applied ok, might not work as process not called*/ + LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "setBandLevel") + LOGV("\tLVM_ERROR : remove this test setBandLevel Succesfully returned from LVM_GetControlParameters\n"); + LOGV("\tsetBandLevel() just Got -> %d\n", ActiveParams.pEQNB_BandDefinition[band].Gain); + LOGV("\tsetBandLevel Succesfully called LVM_SetControlParameters\n"); + #endif /* end LVM_BUNDLE */ + + pContext->pBundledContext->CurPreset = PRESET_CUSTOM; + return; +} +//---------------------------------------------------------------------------- +// EqualizerGetCentreFrequency() +//---------------------------------------------------------------------------- +// Purpose: Retrieve the frequency being used for the band passed in +// +// Inputs: +// band: band number +// pContext: effect engine context +// +// Outputs: +// +//---------------------------------------------------------------------------- +int32_t EqualizerGetCentreFrequency(EffectContext *pContext, int32_t band){ + int32_t Frequency =0; + + #ifdef LVM_BUNDLE + LVM_ControlParams_t ActiveParams; /* Current control Parameters */ + LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ + LVM_EQNB_BandDef_t *BandDef; + + LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, /* Get the current settings */ + &ActiveParams); + + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "getCentreFrequency") + + BandDef = ActiveParams.pEQNB_BandDefinition; + Frequency = (int32_t)BandDef[band].Frequency*1000; // Convert to millibels + + LOGV("\tgetCentreFrequency() -> %d\n", Frequency ); + LOGV("\tgetCentreFrequency Succesfully returned from LVM_GetControlParameters\n"); + #endif /* end LVM_BUNDLE */ + + return Frequency; +} + +//---------------------------------------------------------------------------- +// EqualizerGetBandFreqRange( +//---------------------------------------------------------------------------- +// Purpose: +// +// Gets lower and upper boundaries of a band. +// For the high shelf, the low bound is the band frequency and the high +// bound is Nyquist. +// For the peaking filters, they are the gain[dB]/2 points. +// +// Inputs: +// band: band number +// pContext: effect engine context +// +// Outputs: +// pLow: lower band range +// pLow: upper band range +//---------------------------------------------------------------------------- +int32_t EqualizerGetBandFreqRange(EffectContext *pContext, int32_t band, uint32_t *pLow, uint32_t *pHi){ + *pLow = bandFreqRange[band][0]; + *pHi = bandFreqRange[band][1]; + return 0; +} + +//---------------------------------------------------------------------------- +// EqualizerGetBand( +//---------------------------------------------------------------------------- +// Purpose: +// +// Returns the band with the maximum influence on a given frequency. +// Result is unaffected by whether EQ is enabled or not, or by whether +// changes have been committed or not. +// +// Inputs: +// targetFreq The target frequency, in millihertz. +// pContext: effect engine context +// +// Outputs: +// pLow: lower band range +// pLow: upper band range +//---------------------------------------------------------------------------- +int32_t EqualizerGetBand(EffectContext *pContext, uint32_t targetFreq){ + int band = 0; + + if(targetFreq < bandFreqRange[0][0]){ + return -EINVAL; + }else if(targetFreq == bandFreqRange[0][0]){ + return 0; + } + for(int i=0; i bandFreqRange[i][0])&&(targetFreq <= bandFreqRange[i][1])){ + band = i; + } + } + return band; +} + +//---------------------------------------------------------------------------- +// EqualizerGetPreset( +//---------------------------------------------------------------------------- +// Purpose: +// +// Gets the currently set preset ID. +// Will return PRESET_CUSTOM in case the EQ parameters have been modified +// manually since a preset was set. +// +// Inputs: +// pContext: effect engine context +// +//---------------------------------------------------------------------------- +int32_t EqualizerGetPreset(EffectContext *pContext){ + return pContext->pBundledContext->CurPreset; +} + +//---------------------------------------------------------------------------- +// EqualizerSetPreset( +//---------------------------------------------------------------------------- +// Purpose: +// +// Sets the current preset by ID. +// All the band parameters will be overridden. +// +// Inputs: +// pContext: effect engine context +// preset The preset ID. +// +//---------------------------------------------------------------------------- +void EqualizerSetPreset(EffectContext *pContext, int preset){ + + LOGV("\tsetPreset(%d)", preset); + pContext->pBundledContext->CurPreset = preset; + + #ifdef LVM_BUNDLE + LVM_ControlParams_t ActiveParams; /* Current control Parameters */ + LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ + + /* Get the current settings */ + LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "setPreset") + LOGV("\tsetPreset Succesfully returned from LVM_GetControlParameters\n"); + + //ActiveParams.pEQNB_BandDefinition = &BandDefs[0]; + for (int i=0; ipBundledContext->hInstance, &ActiveParams); + LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "setPreset") + LOGV("\tsetPreset Succesfully called LVM_SetControlParameters\n"); + #endif /* end LVM_BUNDLE */ + + return; +} +int32_t EqualizerGetNumPresets(){ + return 10; +} + +//---------------------------------------------------------------------------- +// EqualizerGetPresetName( +//---------------------------------------------------------------------------- +// Purpose: +// Gets a human-readable name for a preset ID. Will return "Custom" if +// PRESET_CUSTOM is passed. +// +// Inputs: +// preset The preset ID. Must be less than number of presets. +// +//------------------------------------------------------------------------- +const char * EqualizerGetPresetName(int32_t preset){ + LOGV("\tEqualizerGetPresetName start(%d)", preset); + if (preset == PRESET_CUSTOM) { + return "Custom"; + } else { + return gEqualizerPresets[preset].name; + } + LOGV("\tEqualizerGetPresetName end(%d)", preset); + return 0; +} + +//---------------------------------------------------------------------------- +// VolumeSetVolumeLevel() +//---------------------------------------------------------------------------- +// Purpose: +// +// Inputs: +// pContext: effect engine context +// level level to be applied +// +//---------------------------------------------------------------------------- + +int VolumeSetVolumeLevel(EffectContext *pContext, int16_t level){ + LOGV("\tVolumeSetVolumeLevel start(%d)", level); + + #ifdef LVM_BUNDLE + LVM_ControlParams_t ActiveParams; /* Current control Parameters */ + LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ + + /* Get the current settings */ + LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + LOGV("\tVolumeSetVolumeLevel Succesfully returned from LVM_GetControlParameters\n"); + + /* Volume parameters */ + ActiveParams.VC_EffectLevel = (LVM_INT16)(level/100); + LOGV("\tVolumeSetVolumeLevel() (-96dB -> 0dB) -> %d\n", ActiveParams.VC_EffectLevel ); + + /* Activate the initial settings */ + LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); + LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetVolumeLevel") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + + LOGV("\tVolumeSetVolumeLevel Succesfully called LVM_SetControlParameters\n"); + LOGV("\tVolumeSetVolumeLevel end"); + #endif /* end LVM_BUNDLE */ + return 0; +} /* end setVolumeLevel */ + +//---------------------------------------------------------------------------- +// VolumeGetVolumeLevel() +//---------------------------------------------------------------------------- +// Purpose: +// +// Inputs: +// pContext: effect engine context +// +//---------------------------------------------------------------------------- + +int VolumeGetVolumeLevel(EffectContext *pContext, int16_t *level){ + + LOGV("\tVolumeGetVolumeLevel start"); + #ifdef LVM_BUNDLE + LVM_ControlParams_t ActiveParams; /* Current control Parameters */ + LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ + + LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetVolumeLevel") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + + LOGV("\tVolumeGetVolumeLevel() (-96dB -> 0dB) -> %d\n", ActiveParams.VC_EffectLevel ); + LOGV("\tVolumeGetVolumeLevel Succesfully returned from LVM_GetControlParameters\n"); + #endif /* end LVM_BUNDLE */ + + *level = ActiveParams.VC_EffectLevel*100; // Convert dB to millibels + LOGV("\tVolumeGetVolumeLevel end"); + return 0; +} /* end VolumeGetVolumeLevel */ + +//---------------------------------------------------------------------------- +// VolumeSetMute() +//---------------------------------------------------------------------------- +// Purpose: +// +// Inputs: +// pContext: effect engine context +// mute: enable/disable flag +// +//---------------------------------------------------------------------------- + +int32_t VolumeSetMute(EffectContext *pContext, uint32_t mute){ + LOGV("\tVolumeSetMute start()"); + + pContext->pBundledContext->bMuteEnabled = mute; + + #ifdef LVM_BUNDLE + LVM_ControlParams_t ActiveParams; /* Current control Parameters */ + LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ + + /* Get the current settings */ + LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); + LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetMute") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + + LOGV("\tVolumeSetMute Succesfully returned from LVM_GetControlParameters\n"); + LOGV("\tVolumeSetMute() to %d, level was %d\n", mute, ActiveParams.BE_EffectLevel ); + + /* Set appropriate volume level */ + if(pContext->pBundledContext->bMuteEnabled == LVM_TRUE){ + pContext->pBundledContext->levelSaved = ActiveParams.VC_EffectLevel; + ActiveParams.VC_EffectLevel = -96; + }else{ + ActiveParams.VC_EffectLevel = pContext->pBundledContext->levelSaved; + } + + /* Activate the initial settings */ + LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); + LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetMute") + if(LvmStatus != LVM_SUCCESS) return -EINVAL; + + LOGV("\tVolumeSetMute Succesfully called LVM_SetControlParameters\n"); + #endif /* end LVM_BUNDLE */ + LOGV("\tVolumeSetMute start()"); + return 0; +} /* end setMute */ + +//---------------------------------------------------------------------------- +// VolumeSetMute() +//---------------------------------------------------------------------------- +// Purpose: +// +// Inputs: +// pContext: effect engine context +// +// Ourputs: +// mute: enable/disable flag +//---------------------------------------------------------------------------- + +int32_t VolumeGetMute(EffectContext *pContext, uint32_t *mute){ + LOGV("\tVolumeGetMute start"); + if((pContext->pBundledContext->bMuteEnabled == LVM_FALSE)||(pContext->pBundledContext->bMuteEnabled == LVM_TRUE)){ + *mute = pContext->pBundledContext->bMuteEnabled; + return 0; + }else{ + LOGV("\tLVM_ERROR : VolumeGetMute read an invalid value from context %d", pContext->pBundledContext->bMuteEnabled); + return -EINVAL; + } + LOGV("\tVolumeGetMute start"); +} /* end getMute */ + + + + + + + + + + + + + + + + +//---------------------------------------------------------------------------- +// BassBoost_getParameter() +//---------------------------------------------------------------------------- +// Purpose: +// Get a BassBoost parameter +// +// Inputs: +// pBassBoost - handle to instance data +// pParam - pointer to parameter +// pValue - pointer to variable to hold retrieved value +// pValueSize - pointer to value size: maximum size as input +// +// Outputs: +// *pValue updated with parameter value +// *pValueSize updated with actual value size +// +// +// Side Effects: +// +//---------------------------------------------------------------------------- + +int BassBoost_getParameter(EffectContext *pContext, + int32_t *pParam, + size_t *pValueSize, + void *pValue){ + int status = 0; + int32_t param = *pParam++; + int32_t param2; + char *name; + + LOGV("\tBassBoost_getParameter start"); + + switch (param){ + case BASSBOOST_PARAM_STRENGTH_SUP: + //if (*pValueSize != sizeof(uint32_t)){ + // LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize1 %d", *pValueSize); + // return -EINVAL; + //} + //*pValueSize = sizeof(uint32_t); + //break; + case BASSBOOST_PARAM_STRENGTH: + if (*pValueSize != sizeof(int16_t)){ + LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize2 %d", *pValueSize); + return -EINVAL; + } + *pValueSize = sizeof(int16_t); + break; + + default: + LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param); + return -EINVAL; + } + + switch (param){ + case BASSBOOST_PARAM_STRENGTH_SUP: + *(uint32_t *)pValue = 1; + + LOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH_SUP Value is %d", + *(uint32_t *)pValue); + break; + + case BASSBOOST_PARAM_STRENGTH: + *(int16_t *)pValue = BassGetStrength(pContext); + + LOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH Value is %d", + *(int16_t *)pValue); + break; + + default: + LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param); + status = -EINVAL; + break; + } + + LOGV("\tBassBoost_getParameter end"); + return status; +} /* end BassBoost_getParameter */ + + +//---------------------------------------------------------------------------- +// BassBoost_setParameter() +//---------------------------------------------------------------------------- +// Purpose: +// Set a BassBoost parameter +// +// Inputs: +// pBassBoost - handle to instance data +// pParam - pointer to parameter +// pValue - pointer to value +// +// Outputs: +// +//---------------------------------------------------------------------------- + +int BassBoost_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue){ + int status = 0; + int16_t strength; + + LOGV("\tBassBoost_setParameter start"); + + switch (*pParam){ + case BASSBOOST_PARAM_STRENGTH: + strength = *(int16_t *)pValue; + LOGV("\tBassBoost_setParameter() BASSBOOST_PARAM_STRENGTH value is %d", strength); + LOGV("\tBassBoost_setParameter() Calling pBassBoost->BassSetStrength"); + BassSetStrength(pContext, (int32_t)strength); + LOGV("\tBassBoost_setParameter() Called pBassBoost->BassSetStrength"); + break; + default: + LOGV("\tLVM_ERROR : BassBoost_setParameter() invalid param %d", *pParam); + break; + } + + LOGV("\tBassBoost_setParameter end"); + return status; +} /* end BassBoost_setParameter */ + +//---------------------------------------------------------------------------- +// Virtualizer_getParameter() +//---------------------------------------------------------------------------- +// Purpose: +// Get a Virtualizer parameter +// +// Inputs: +// pVirtualizer - handle to instance data +// pParam - pointer to parameter +// pValue - pointer to variable to hold retrieved value +// pValueSize - pointer to value size: maximum size as input +// +// Outputs: +// *pValue updated with parameter value +// *pValueSize updated with actual value size +// +// +// Side Effects: +// +//---------------------------------------------------------------------------- + +int Virtualizer_getParameter(EffectContext *pContext, + int32_t *pParam, + size_t *pValueSize, + void *pValue){ + int status = 0; + int32_t param = *pParam++; + int32_t param2; + char *name; + + LOGV("\tVirtualizer_getParameter start"); + + switch (param){ + case VIRTUALIZER_PARAM_STRENGTH_SUP: + //if (*pValueSize != sizeof(uint32_t)){ + // LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize1 %d", *pValueSize); + // return -EINVAL; + //} + //*pValueSize = sizeof(uint32_t); + //break; + case VIRTUALIZER_PARAM_STRENGTH: + if (*pValueSize != sizeof(int16_t)){ + LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize2 %d", *pValueSize); + return -EINVAL; + } + *pValueSize = sizeof(int16_t); + break; + + default: + LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param); + return -EINVAL; + } + + switch (param){ + case VIRTUALIZER_PARAM_STRENGTH_SUP: + *(uint32_t *)pValue = 1; + + LOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH_SUP Value is %d", + *(uint32_t *)pValue); + break; + + case VIRTUALIZER_PARAM_STRENGTH: + *(int16_t *)pValue = VirtualizerGetStrength(pContext); + + LOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH Value is %d", + *(int16_t *)pValue); + break; + + default: + LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param); + status = -EINVAL; + break; + } + + LOGV("\tVirtualizer_getParameter end"); + return status; +} /* end Virtualizer_getParameter */ + + +//---------------------------------------------------------------------------- +// Virtualizer_setParameter() +//---------------------------------------------------------------------------- +// Purpose: +// Set a Virtualizer parameter +// +// Inputs: +// pVirtualizer - handle to instance data +// pParam - pointer to parameter +// pValue - pointer to value +// +// Outputs: +// +//---------------------------------------------------------------------------- + +int Virtualizer_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue){ + int status = 0; + int16_t strength; + + LOGV("\tVirtualizer_setParameter start"); + + switch (*pParam){ + case VIRTUALIZER_PARAM_STRENGTH: + strength = *(int16_t *)pValue; + LOGV("\tVirtualizer_setParameter() VIRTUALIZER_PARAM_STRENGTH value is %d", strength); + LOGV("\tVirtualizer_setParameter() Calling pVirtualizer->setStrength"); + VirtualizerSetStrength(pContext, (int32_t)strength); + LOGV("\tVirtualizer_setParameter() Called pVirtualizer->setStrength"); + break; + default: + LOGV("\tLVM_ERROR : Virtualizer_setParameter() invalid param %d", *pParam); + break; + } + + LOGV("\tVirtualizer_setParameter end"); + return status; +} /* end Virtualizer_setParameter */ + +//---------------------------------------------------------------------------- +// Equalizer_getParameter() +//---------------------------------------------------------------------------- +// Purpose: +// Get a Equalizer parameter +// +// Inputs: +// pEqualizer - handle to instance data +// pParam - pointer to parameter +// pValue - pointer to variable to hold retrieved value +// pValueSize - pointer to value size: maximum size as input +// +// Outputs: +// *pValue updated with parameter value +// *pValueSize updated with actual value size +// +// +// Side Effects: +// +//---------------------------------------------------------------------------- +int Equalizer_getParameter(EffectContext *pContext, + int32_t *pParam, + size_t *pValueSize, + void *pValue){ + int status = 0; + int bMute = 0; + int32_t param = *pParam++; + int32_t param2; + char *name; + + LOGV("\tEqualizer_getParameter start"); + + switch (param) { + case EQ_PARAM_NUM_BANDS: + case EQ_PARAM_CUR_PRESET: + case EQ_PARAM_GET_NUM_OF_PRESETS: + if (*pValueSize < sizeof(int16_t)) { + LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1 %d", *pValueSize); + return -EINVAL; + } + *pValueSize = sizeof(int16_t); + break; + + case EQ_PARAM_LEVEL_RANGE: + case EQ_PARAM_BAND_FREQ_RANGE: + if (*pValueSize < 2 * sizeof(int32_t)) { + LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2 %d", *pValueSize); + return -EINVAL; + } + *pValueSize = 2 * sizeof(int32_t); + break; + case EQ_PARAM_BAND_LEVEL: + case EQ_PARAM_GET_BAND: + case EQ_PARAM_CENTER_FREQ: + if (*pValueSize < sizeof(int32_t)) { + LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1 %d", *pValueSize); + return -EINVAL; + } + *pValueSize = sizeof(int32_t); + break; + + case EQ_PARAM_GET_PRESET_NAME: + break; + + default: + LOGV("\tLVM_ERROR : Equalizer_getParameter unknown param %d", param); + return -EINVAL; + } + + switch (param) { + case EQ_PARAM_NUM_BANDS: + *(int16_t *)pValue = FIVEBAND_NUMBANDS; + LOGV("\tEqualizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue); + break; + + case EQ_PARAM_LEVEL_RANGE: + *(int32_t *)pValue = -1500; + *((int32_t *)pValue + 1) = 1500; + LOGV("\tEqualizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d", *(int32_t *)pValue, *((int32_t *)pValue + 1)); + break; + + case EQ_PARAM_BAND_LEVEL: + param2 = *pParam; + if (param2 >= FIVEBAND_NUMBANDS) { + status = -EINVAL; + break; + } + *(int32_t *)pValue = EqualizerGetBandLevel(pContext, param2); + LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", param2, *(int32_t *)pValue); + break; + + case EQ_PARAM_CENTER_FREQ: + param2 = *pParam; + if (param2 >= FIVEBAND_NUMBANDS) { + status = -EINVAL; + break; + } + *(int32_t *)pValue = EqualizerGetCentreFrequency(pContext, param2); + LOGV("\tEqualizer_getParameter() EQ_PARAM_CENTER_FREQ band %d, frequency %d", param2, *(int32_t *)pValue); + break; + + case EQ_PARAM_BAND_FREQ_RANGE: + param2 = *pParam; + if (param2 >= FIVEBAND_NUMBANDS) { + status = -EINVAL; + break; + } + EqualizerGetBandFreqRange(pContext, param2, (uint32_t *)pValue, ((uint32_t *)pValue + 1)); + LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_FREQ_RANGE band %d, min %d, max %d", param2, *(int32_t *)pValue, *((int32_t *)pValue + 1)); + break; + + case EQ_PARAM_GET_BAND: + param2 = *pParam; + *(int32_t *)pValue = EqualizerGetBand(pContext, param2); + LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d", param2, *(int32_t *)pValue); + break; + + case EQ_PARAM_CUR_PRESET: + *(int16_t *)pValue = EqualizerGetPreset(pContext); + LOGV("\tEqualizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue); + break; + + case EQ_PARAM_GET_NUM_OF_PRESETS: + *(int16_t *)pValue = EqualizerGetNumPresets(); + LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue); + break; + + case EQ_PARAM_GET_PRESET_NAME: + param2 = *pParam; + if (param2 >= EqualizerGetNumPresets()) { + //if (param2 >= 20) { // AGO FIX + status = -EINVAL; + break; + } + name = (char *)pValue; + strncpy(name, EqualizerGetPresetName(param2), *pValueSize - 1); + name[*pValueSize - 1] = 0; + *pValueSize = strlen(name) + 1; + LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_PRESET_NAME preset %d, name %s len %d", param2, gEqualizerPresets[param2].name, *pValueSize); + break; + + default: + LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid param %d", param); + status = -EINVAL; + break; + } + + LOGV("\tEqualizer_getParameter end"); + return status; +} /* end Equalizer_getParameter */ + +//---------------------------------------------------------------------------- +// Equalizer_setParameter() +//---------------------------------------------------------------------------- +// Purpose: +// Set a Equalizer parameter +// +// Inputs: +// pEqualizer - handle to instance data +// pParam - pointer to parameter +// pValue - pointer to value +// +// Outputs: +// +//---------------------------------------------------------------------------- +int Equalizer_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue){ + int status = 0; + int32_t preset; + int32_t band; + int32_t level; + int32_t param = *pParam++; + + LOGV("\tEqualizer_setParameter start"); + switch (param) { + case EQ_PARAM_CUR_PRESET: + preset = *(int16_t *)pValue; + + LOGV("\tEqualizer_setParameter() EQ_PARAM_CUR_PRESET %d", preset); + if ((preset >= EqualizerGetNumPresets())||(preset < 0)) { + status = -EINVAL; + break; + } + EqualizerSetPreset(pContext, preset); + break; + case EQ_PARAM_BAND_LEVEL: + band = *pParam; + level = *(int32_t *)pValue; + LOGV("\tEqualizer_setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level); + if (band >= FIVEBAND_NUMBANDS) { + status = -EINVAL; + break; + } + EqualizerSetBandLevel(pContext, band, level); + break; + default: + LOGV("\tLVM_ERROR : setParameter() invalid param %d", param); + break; + } + + LOGV("\tEqualizer_setParameter end"); + return status; +} /* end Equalizer_setParameter */ + +//---------------------------------------------------------------------------- +// Volume_getParameter() +//---------------------------------------------------------------------------- +// Purpose: +// Get a Volume parameter +// +// Inputs: +// pVolume - handle to instance data +// pParam - pointer to parameter +// pValue - pointer to variable to hold retrieved value +// pValueSize - pointer to value size: maximum size as input +// +// Outputs: +// *pValue updated with parameter value +// *pValueSize updated with actual value size +// +// +// Side Effects: +// +//---------------------------------------------------------------------------- + +int Volume_getParameter(EffectContext *pContext, + int32_t *pParam, + size_t *pValueSize, + void *pValue){ + int status = 0; + int bMute = 0; + int32_t param = *pParam++; + int32_t param2; + char *name; + + LOGV("\tVolume_getParameter start"); + + switch (param){ + case VOLUME_PARAM_LEVEL: + case VOLUME_PARAM_MAXLEVEL: + case VOLUME_PARAM_STEREOPOSITION: + if (*pValueSize < sizeof(int16_t)){ + LOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 1 %d", *pValueSize); + return -EINVAL; + } + *pValueSize = sizeof(int16_t); + break; + + case VOLUME_PARAM_MUTE: + case VOLUME_PARAM_ENABLESTEREOPOSITION: + if (*pValueSize < sizeof(int32_t)){ + LOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 2 %d", *pValueSize); + return -EINVAL; + } + *pValueSize = sizeof(int32_t); + break; + + default: + LOGV("\tLVM_ERROR : EVolume_getParameter unknown param %d", param); + return -EINVAL; + } + + switch (param){ + case VOLUME_PARAM_LEVEL: + status = VolumeGetVolumeLevel(pContext, (int16_t *)(pValue)); + LOGV("\tVolume_getParameter() VOLUME_PARAM_LEVEL Value is %d", + *(int16_t *)pValue); + break; + + case VOLUME_PARAM_MAXLEVEL: + *(int16_t *)pValue = 0; + LOGV("\tVolume_getParameter() VOLUME_PARAM_MAXLEVEL Value is %d", + *(int16_t *)pValue); + break; + + case VOLUME_PARAM_STEREOPOSITION: + *(int16_t *)pValue = 0; + LOGV("\tVolume_getParameter() VOLUME_PARAM_STEREOPOSITION Value is %d", + *(int16_t *)pValue); + break; + + case VOLUME_PARAM_MUTE: + status = VolumeGetMute(pContext, (uint32_t *)pValue); + LOGV("\tVolume_getParameter() VOLUME_PARAM_MUTE Value is %d", + *(uint32_t *)pValue); + break; + + case VOLUME_PARAM_ENABLESTEREOPOSITION: + *(int32_t *)pValue = 0; + LOGV("\tVolume_getParameter() VOLUME_PARAM_ENABLESTEREOPOSITION Value is %d", + *(uint32_t *)pValue); + break; + + default: + LOGV("\tLVM_ERROR : Volume_getParameter() invalid param %d", param); + status = -EINVAL; + break; + } + + LOGV("\tVolume_getParameter end"); + return status; +} /* end Volume_getParameter */ + + +//---------------------------------------------------------------------------- +// Volume_setParameter() +//---------------------------------------------------------------------------- +// Purpose: +// Set a Volume parameter +// +// Inputs: +// pVolume - handle to instance data +// pParam - pointer to parameter +// pValue - pointer to value +// +// Outputs: +// +//---------------------------------------------------------------------------- + +int Volume_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue){ + int status = 0; + int16_t level; + uint32_t mute; + + LOGV("\tVolume_setParameter start"); + + switch (*pParam){ + case VOLUME_PARAM_LEVEL: + level = *(int16_t *)pValue; + LOGV("\tVolume_setParameter() VOLUME_PARAM_LEVEL value is %d", level); + LOGV("\tVolume_setParameter() Calling pVolume->setVolumeLevel"); + status = VolumeSetVolumeLevel(pContext, (int16_t)level); + LOGV("\tVolume_setParameter() Called pVolume->setVolumeLevel"); + break; + + case VOLUME_PARAM_MUTE: + mute = *(uint32_t *)pValue; + LOGV("\tVolume_setParameter() Calling pVolume->setMute, mute is %d", mute); + LOGV("\tVolume_setParameter() Calling pVolume->setMute"); + status = VolumeSetMute(pContext, mute); + LOGV("\tVolume_setParameter() Called pVolume->setMute"); + break; + + case VOLUME_PARAM_ENABLESTEREOPOSITION: + LOGV("\tVolume_setParameter() VOLUME_PARAM_ENABLESTEREOPOSITION called"); + break; + + case VOLUME_PARAM_STEREOPOSITION: + LOGV("\tVolume_setParameter() VOLUME_PARAM_STEREOPOSITION called"); + break; + + default: + LOGV("\tLVM_ERROR : Volume_setParameter() invalid param %d", *pParam); + break; + } + + LOGV("\tVolume_setParameter end"); + return status; +} /* end Volume_setParameter */ +} // namespace +} // namespace + + + + + + + + + + + + + + + + + + + + + +/* Effect Control Interface Implementation: Process */ +extern "C" int Effect_process(effect_interface_t self, + audio_buffer_t *inBuffer, + audio_buffer_t *outBuffer){ + EffectContext * pContext = (EffectContext *) self; + int status = 0; + + //LOGV("\tIn Effect_process"); + + if (pContext == NULL){ + LOGV("\tLVM_ERROR : Effect_process() ERROR pContext == NULL"); + return -EINVAL; + } + if (inBuffer == NULL || inBuffer->raw == NULL || + outBuffer == NULL || outBuffer->raw == NULL || + inBuffer->frameCount != outBuffer->frameCount){ + LOGV("\tLVM_ERROR : Effect_process() ERROR NULL INPUT POINTER OR FRAME COUNT IS WRONG"); + return -EINVAL; + } + + if ((pContext->pBundledContext->bBassEnabled == LVM_FALSE)&&(pContext->EffectType == LVM_BASS_BOOST)){ + LOGV("\tLVM_ERROR : Effect_process() ERROR LVM_BASS_BOOST Effect is not enabled"); + return -ENODATA; + } + if ((pContext->pBundledContext->bVolumeEnabled == LVM_FALSE)&&(pContext->EffectType == LVM_VOLUME)){ + LOGV("\tLVM_ERROR : Effect_process() ERROR LVM_VOLUME Effect is not enabled"); + return -ENODATA; + } + if ((pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE)&&(pContext->EffectType == LVM_EQUALIZER)){ + LOGV("\tLVM_ERROR : Effect_process() ERROR LVM_EQUALIZER Effect is not enabled"); + return -ENODATA; + } + if ((pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE)&&(pContext->EffectType == LVM_VIRTUALIZER)){ + LOGV("\tLVM_ERROR : Effect_process() ERROR LVM_VIRTUALIZER Effect is not enabled"); + return -ENODATA; + } + + pContext->pBundledContext->NumberEffectsCalled++; + + if(pContext->pBundledContext->NumberEffectsCalled == pContext->pBundledContext->NumberEffectsEnabled){ + LOGV("\tEffect_process() Calling process with %d frames, %d effects enabled, %d called: Effect %d", outBuffer->frameCount, pContext->pBundledContext->NumberEffectsEnabled, pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType); + pContext->pBundledContext->NumberEffectsCalled = 0; + /* Process all the available frames, block processing is handled internalLY by the LVM bundle */ + status = android::LvmBundle_process( (LVM_INT16 *)inBuffer->raw, + (LVM_INT16 *)outBuffer->raw, + outBuffer->frameCount, + pContext); + //LOGV("\tEffect_process() Called process with %d frames, %d effects enabled, %d called: Effect %d", outBuffer->frameCount, pContext->pBundledContext->NumberEffectsEnabled, pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType); + }else{ + LOGV("\tEffect_process() Not Calling process with %d frames, %d effects enabled, %d called: Effect %d", outBuffer->frameCount, pContext->pBundledContext->NumberEffectsEnabled, pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType); + memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount*sizeof(LVM_INT16)*2); // 2 is for stereo input + } + return status; +} /* end Effect_process */ + +/* Effect Control Interface Implementation: Command */ +extern "C" int Effect_command(effect_interface_t self, + int cmdCode, + int cmdSize, + void *pCmdData, + int *replySize, + void *pReplyData){ + EffectContext * pContext = (EffectContext *) self; + int retsize; + int status = 0; + + LOGV("\t\nEffect_command start"); + + if(pContext->EffectType == LVM_BASS_BOOST){ + LOGV("\tEffect_command setting command for LVM_BASS_BOOST"); + } + if(pContext->EffectType == LVM_VIRTUALIZER){ + LOGV("\tEffect_command setting command for LVM_VIRTUALIZER"); + } + if(pContext->EffectType == LVM_EQUALIZER){ + LOGV("\tEffect_command setting command for LVM_EQUALIZER"); + } + if(pContext->EffectType == LVM_VOLUME){ + LOGV("\tEffect_command setting command for LVM_VOLUME"); + } + + if (pContext == NULL){ + LOGV("\tLVM_ERROR : Effect_command ERROR pContext == NULL"); + return -EINVAL; + } + + LOGV("\tEffect_command INPUTS are: command %d cmdSize %d",cmdCode, cmdSize); + + // Incase we disable an effect, next time process is called the number of effect called could be greater + pContext->pBundledContext->NumberEffectsCalled = 0; + + LOGV("\tEffect_command NumberEffectsCalled = %d, NumberEffectsEnabled = %d", pContext->pBundledContext->NumberEffectsCalled, pContext->pBundledContext->NumberEffectsEnabled); + + switch (cmdCode){ + case EFFECT_CMD_INIT: + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT start"); + if(pContext->EffectType == LVM_BASS_BOOST){ + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_BASS_BOOST"); + + if (pReplyData == NULL || *replySize != sizeof(int)){ + LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: " + "EFFECT_CMD_INIT: ERROR"); + return -EINVAL; + } + + android::BassSetStrength(pContext, 0); + } + if(pContext->EffectType == LVM_VIRTUALIZER){ + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VIRTUALIZER"); + + if (pReplyData == NULL || *replySize != sizeof(int)){ + LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: " + "EFFECT_CMD_INIT: ERROR"); + return -EINVAL; + } + + android::VirtualizerSetStrength(pContext, 0); + } + if(pContext->EffectType == LVM_EQUALIZER){ + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_EQUALIZER"); + + if (pReplyData == NULL || *replySize != sizeof(int)){ + LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: " + "EFFECT_CMD_INIT: ERROR"); + return -EINVAL; + } + + android::EqualizerSetPreset(pContext, 0); + } + if(pContext->EffectType == LVM_VOLUME){ + LOGV("\tEffect_command cmdCode Case: " + "EFFECT_CMD_INIT start"); + + if (pReplyData == NULL || *replySize != sizeof(int)){ + LOGV("\tLVM_ERROR : Volume_command cmdCode Case: " + "EFFECT_CMD_INIT: ERROR"); + return -EINVAL; + } + + status = android::VolumeSetVolumeLevel(pContext, 0); + if(status == -EINVAL){ + return -EINVAL; + } + } + break; + + case EFFECT_CMD_CONFIGURE: + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE start"); + if (pCmdData == NULL|| + cmdSize != sizeof(effect_config_t)|| + pReplyData == NULL|| + *replySize != sizeof(int)){ + LOGV("\tLVM_ERROR : Effect_command cmdCode Case: " + "EFFECT_CMD_CONFIGURE: ERROR"); + return -EINVAL; + } + *(int *) pReplyData = android::Effect_configure(pContext, (effect_config_t *) pCmdData); + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE end"); + break; + + case EFFECT_CMD_RESET: + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET start"); + android::Effect_configure(pContext, &pContext->config); + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET end"); + break; + + case EFFECT_CMD_GET_PARAM:{ + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM start"); + + if(pContext->EffectType == LVM_BASS_BOOST){ + if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || + pReplyData == NULL ||*replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){ + LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: " + "EFFECT_CMD_GET_PARAM: ERROR"); + return -EINVAL; + } + effect_param_t *p = (effect_param_t *)pCmdData; + + memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); + + p = (effect_param_t *)pReplyData; + + int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); + + p->status = android::BassBoost_getParameter(pContext, + (int32_t *)p->data, + (size_t *)&p->vsize, + p->data + voffset); + + *replySize = sizeof(effect_param_t) + voffset + p->vsize; + + LOGV("\tBassBoost_command EFFECT_CMD_GET_PARAM " + "*pCmdData %d, *replySize %d, *pReplyData %d ", + *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), + *replySize, + *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset)); + } + + if(pContext->EffectType == LVM_VIRTUALIZER){ + if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || + pReplyData == NULL ||*replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){ + LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: " + "EFFECT_CMD_GET_PARAM: ERROR"); + return -EINVAL; + } + effect_param_t *p = (effect_param_t *)pCmdData; + + memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); + + p = (effect_param_t *)pReplyData; + + int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); + + p->status = android::Virtualizer_getParameter(pContext, + (int32_t *)p->data, + (size_t *)&p->vsize, + p->data + voffset); + + *replySize = sizeof(effect_param_t) + voffset + p->vsize; + + LOGV("\tVirtualizer_command EFFECT_CMD_GET_PARAM " + "*pCmdData %d, *replySize %d, *pReplyData %d ", + *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), + *replySize, + *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset)); + } + if(pContext->EffectType == LVM_EQUALIZER){ + LOGV("\tEqualizer_command cmdCode Case: " + "EFFECT_CMD_GET_PARAM start"); + if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || + pReplyData == NULL || *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))) { + LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: " + "EFFECT_CMD_GET_PARAM"); + return -EINVAL; + } + effect_param_t *p = (effect_param_t *)pCmdData; + + memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); + + p = (effect_param_t *)pReplyData; + + int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); + + p->status = android::Equalizer_getParameter(pContext, (int32_t *)p->data, &p->vsize, + p->data + voffset); + + *replySize = sizeof(effect_param_t) + voffset + p->vsize; + + LOGV("\tEqualizer_command EFFECT_CMD_GET_PARAM *pCmdData %d, *replySize %d, *pReplyData %08x %08x", + *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), *replySize, + *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset), + *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset + sizeof(int32_t))); + } + if(pContext->EffectType == LVM_VOLUME){ + LOGV("\tVolume_command cmdCode Case: " + "EFFECT_CMD_GET_PARAM start"); + if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || + pReplyData == NULL ||*replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){ + LOGV("\tLVM_ERROR : Volume_command cmdCode Case: " + "EFFECT_CMD_GET_PARAM: ERROR"); + return -EINVAL; + } + effect_param_t *p = (effect_param_t *)pCmdData; + + memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); + + p = (effect_param_t *)pReplyData; + + int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); + + p->status = android::Volume_getParameter(pContext, + (int32_t *)p->data, + (size_t *)&p->vsize, + p->data + voffset); + + *replySize = sizeof(effect_param_t) + voffset + p->vsize; + + LOGV("\tVolume_command EFFECT_CMD_GET_PARAM " + "*pCmdData %d, *replySize %d, *pReplyData %d ", + *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), + *replySize, + *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset)); + } + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM end"); + } break; + case EFFECT_CMD_SET_PARAM:{ + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM start"); + if(pContext->EffectType == LVM_BASS_BOOST){ + LOGV("\tBassBoost_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ", + *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), + *replySize, + *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t))); + + if ( pCmdData == NULL|| + cmdSize != (int)(sizeof(effect_param_t) + sizeof(int32_t) + sizeof(int16_t))|| + pReplyData == NULL|| + *replySize != sizeof(int32_t)){ + LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: " + "EFFECT_CMD_SET_PARAM: ERROR"); + return -EINVAL; + } + effect_param_t *p = (effect_param_t *) pCmdData; + + if (p->psize != sizeof(int32_t)){ + LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: " + "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)"); + return -EINVAL; + } + + LOGV("\tnBassBoost_command cmdSize is %d\n" + "\tsizeof(effect_param_t) is %d\n" + "\tp->psize is %d\n" + "\tp->vsize is %d" + "\n", + cmdSize, sizeof(effect_param_t), p->psize, p->vsize ); + + *(int *)pReplyData = android::BassBoost_setParameter(pContext, + (int32_t *)p->data, + p->data + p->psize); + } + if(pContext->EffectType == LVM_VIRTUALIZER){ + LOGV("\tVirtualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ", + *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), + *replySize, + *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t))); + + if ( pCmdData == NULL|| + cmdSize != (int)(sizeof(effect_param_t) + sizeof(int32_t) + sizeof(int16_t))|| + pReplyData == NULL|| + *replySize != sizeof(int32_t)){ + LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: " + "EFFECT_CMD_SET_PARAM: ERROR"); + return -EINVAL; + } + effect_param_t *p = (effect_param_t *) pCmdData; + + if (p->psize != sizeof(int32_t)){ + LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: " + "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)"); + return -EINVAL; + } + + LOGV("\tnVirtualizer_command cmdSize is %d\n" + "\tsizeof(effect_param_t) is %d\n" + "\tp->psize is %d\n" + "\tp->vsize is %d" + "\n", + cmdSize, sizeof(effect_param_t), p->psize, p->vsize ); + + *(int *)pReplyData = android::Virtualizer_setParameter(pContext, + (int32_t *)p->data, + p->data + p->psize); + } + if(pContext->EffectType == LVM_EQUALIZER){ + LOGV("\tEqualizer_command cmdCode Case: " + "EFFECT_CMD_SET_PARAM start"); + LOGV("\tEqualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ", + *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), + *replySize, + *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t))); + + if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || + pReplyData == NULL || *replySize != sizeof(int32_t)) { + LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: " + "EFFECT_CMD_SET_PARAM: ERROR"); + return -EINVAL; + } + effect_param_t *p = (effect_param_t *) pCmdData; + + *(int *)pReplyData = android::Equalizer_setParameter(pContext, + (int32_t *)p->data, + p->data + p->psize); + } + if(pContext->EffectType == LVM_VOLUME){ + LOGV("\tVolume_command cmdCode Case: " + "EFFECT_CMD_SET_PARAM start"); + LOGV("\tVolume_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ", + *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), + *replySize, + *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t))); + + if ( pCmdData == NULL|| + cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t))|| + pReplyData == NULL|| + *replySize != sizeof(int32_t)){ + LOGV("\tLVM_ERROR : Volume_command cmdCode Case: " + "EFFECT_CMD_SET_PARAM: ERROR"); + return -EINVAL; + } + effect_param_t *p = (effect_param_t *) pCmdData; + + *(int *)pReplyData = android::Volume_setParameter(pContext, + (int32_t *)p->data, + p->data + p->psize); + } + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM end"); + } break; + + case EFFECT_CMD_ENABLE: + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE start"); + if (pReplyData == NULL || *replySize != sizeof(int)){ + LOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_ENABLE: ERROR"); + return -EINVAL; + } + switch (pContext->EffectType){ + case LVM_BASS_BOOST: + if(pContext->pBundledContext->bBassEnabled == LVM_TRUE){ + LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: " + "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled"); + return -EINVAL; + } + pContext->pBundledContext->bBassEnabled = LVM_TRUE; + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_BASS_BOOST enabled"); + break; + case LVM_EQUALIZER: + if(pContext->pBundledContext->bEqualizerEnabled == LVM_TRUE){ + LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: " + "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled"); + return -EINVAL; + } + pContext->pBundledContext->bEqualizerEnabled = LVM_TRUE; + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_EQUALIZER enabled"); + break; + case LVM_VIRTUALIZER: + if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){ + LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: " + "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled"); + return -EINVAL; + } + pContext->pBundledContext->bVirtualizerEnabled = LVM_TRUE; + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_VIRTUALIZER enabled"); + break; + case LVM_VOLUME: + if(pContext->pBundledContext->bVolumeEnabled == LVM_TRUE){ + LOGV("\tLVM_ERROR : Volume_command cmdCode Case: " + "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled"); + return -EINVAL; + } + pContext->pBundledContext->bVolumeEnabled = LVM_TRUE; + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_VOLUME enabled"); + break; + default: + LOGV("\tLVM_ERROR : Effect_command cmdCode Case: " + "EFFECT_CMD_ENABLE: ERROR, invalid Effect Type"); + return -EINVAL; + } + *(int *)pReplyData = 0; + pContext->pBundledContext->NumberEffectsEnabled++; + android::LvmEffect_enable(pContext); + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE NumberEffectsEnabled = %d", pContext->pBundledContext->NumberEffectsEnabled); + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE end"); + break; + + case EFFECT_CMD_DISABLE: + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE start"); + if (pReplyData == NULL || *replySize != sizeof(int)){ + LOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_DISABLE: ERROR"); + return -EINVAL; + } + switch (pContext->EffectType){ + case LVM_BASS_BOOST: + if(pContext->pBundledContext->bBassEnabled == LVM_FALSE){ + LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: " + "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled"); + return -EINVAL; + } + pContext->pBundledContext->bBassEnabled = LVM_FALSE; + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE LVM_BASS_BOOST disabled"); + break; + case LVM_EQUALIZER: + if(pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE){ + LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: " + "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled"); + return -EINVAL; + } + pContext->pBundledContext->bEqualizerEnabled = LVM_FALSE; + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE LVM_EQUALIZER disabled"); + break; + case LVM_VIRTUALIZER: + if(pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE){ + LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: " + "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled"); + return -EINVAL; + } + pContext->pBundledContext->bVirtualizerEnabled = LVM_FALSE; + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE LVM_VIRTUALIZER disabled"); + break; + case LVM_VOLUME: + if(pContext->pBundledContext->bVolumeEnabled == LVM_FALSE){ + LOGV("\tLVM_ERROR : Volume_command cmdCode Case: " + "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled"); + return -EINVAL; + } + pContext->pBundledContext->bVolumeEnabled = LVM_FALSE; + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE LVM_VOLUME disabled"); + break; + break; + default: + LOGV("\tLVM_ERROR : Effect_command cmdCode Case: " + "EFFECT_CMD_DISABLE: ERROR, invalid Effect Type"); + return -EINVAL; + } + *(int *)pReplyData = 0; + pContext->pBundledContext->NumberEffectsEnabled--; + android::LvmEffect_disable(pContext); + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE NumberEffectsEnabled = %d", pContext->pBundledContext->NumberEffectsEnabled); + LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE end"); + break; + + case EFFECT_CMD_SET_DEVICE: + case EFFECT_CMD_SET_VOLUME: +// case EFFECT_CMD_SET_AUDIO_MODE:// AGO add this + LOGV("\tEffect_command cmdCode Case: " + "EFFECT_CMD_SET_DEVICE/EFFECT_CMD_SET_VOLUME/EFFECT_CMD_SET_AUDIO_MODE start"); + break; + + default: + LOGV("\tLVM_ERROR : Effect_command cmdCode Case: DEFAULT start %d ERROR",cmdCode); + return -EINVAL; + } + + LOGV("\tEffect_command end...\n\n"); + return 0; +} /* end Effect_command */ + +// effect_interface_t interface implementation for effect +const struct effect_interface_s gLvmEffectInterface = { + Effect_process, + Effect_command +}; /* end gLvmEffectInterface */ + + diff --git a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.h b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.h new file mode 100644 index 0000000..6818dd6 --- /dev/null +++ b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.h @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EFFECTBUNDLE_H_ +#define ANDROID_EFFECTBUNDLE_H_ + +#include +#include + +#if __cplusplus +extern "C" { +#endif + +#define FIVEBAND_NUMBANDS 5 +#define MAX_NUM_BANDS 5 +#define MAX_CALL_SIZE 256 + +//TODO: this should be included from each effect API include +static const effect_uuid_t SL_IID_BASSBOOST_ = { 0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }; +const effect_uuid_t * const SL_IID_BASSBOOST = &SL_IID_BASSBOOST_; + +static const effect_uuid_t SL_IID_EQUALIZER_ = { 0x0bed4300, 0xddd6, 0x11db, 0x8f34, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }; +const effect_uuid_t * const SL_IID_EQUALIZER = &SL_IID_EQUALIZER_; + +static const effect_uuid_t SL_IID_VIRTUALIZER_ = { 0x37cc2c00, 0xdddd, 0x11db, 0x8577, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }; // updated mon 28th june 2010 +const effect_uuid_t * const SL_IID_VIRTUALIZER = &SL_IID_VIRTUALIZER_; + +static const effect_uuid_t SL_IID_VOLUME_ = { 0x09e8ede0, 0xddde, 0x11db, 0xb4f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }; // updated mon 28th june 2010 +const effect_uuid_t * const SL_IID_VOLUME = &SL_IID_VOLUME_; + +typedef enum +{ + LVM_BASS_BOOST, + LVM_VIRTUALIZER, + LVM_EQUALIZER, + LVM_VOLUME +} lvm_effect_en; + +// Preset configuration. +struct PresetConfig { + // Human-readable name. + const char * name; + // An array of size nBands where each element is a configuration for the + // corresponding band. + //const BandConfig * bandConfigs; +}; + +/* BundledEffectContext : One per session */ +struct BundledEffectContext{ + LVM_Handle_t hInstance; /* Instance handle */ + int SessionNo; /* Current session number */ + bool bVolumeEnabled; /* Flag for Volume */ + bool bEqualizerEnabled; /* Flag for EQ */ + bool bBassEnabled; /* Flag for Bass */ + bool bVirtualizerEnabled; /* Flag for Virtualizer */ + int NumberEffectsEnabled; /* Effects in this session */ + int NumberEffectsCalled; /* Effects called so far */ + // Saved parameters for each effect */ + // Bass Boost + int BassStrengthSaved; /* Conversion between Get/Set */ + // Equalizer + int CurPreset; /* Current preset being used */ + // Virtualzer + int VirtStrengthSaved; /* Conversion between Get/Set */ + // Volume + int levelSaved; /* for when mute is set, level must be saved */ + bool bMuteEnabled; /* Must store as mute = -96dB level */ +}; + +/* SessionContext : One session */ +struct SessionContext{ + bool bBundledEffectsEnabled; + bool bVolumeInstantiated; + bool bEqualizerInstantiated; + bool bBassInstantiated; + bool bVirtualizerInstantiated; + BundledEffectContext *pBundledContext; +}; + +struct EffectContext{ + const struct effect_interface_s *itfe; + effect_config_t config; + lvm_effect_en EffectType; + BundledEffectContext *pBundledContext; +}; + +//TODO: this should be included from each effect API include +/* enumerated parameter settings for BassBoost effect */ +typedef enum +{ + BASSBOOST_PARAM_STRENGTH_SUP, // type SLboolean = typedef SLuint32 + BASSBOOST_PARAM_STRENGTH // type SLpermille = typedef SLuint16 +} t_bassboost_params; + +/* enumerated parameter settings for Virtualizer effect */ +typedef enum +{ + VIRTUALIZER_PARAM_STRENGTH_SUP, // type SLboolean = typedef SLuint32 + VIRTUALIZER_PARAM_STRENGTH // type SLpermille = typedef SLuint16 +} t_virtualizer_params; + +/* enumerated parameter settings for Equalizer effect */ +typedef enum +{ + EQ_PARAM_NUM_BANDS, // Gets the number of frequency bands that the equalizer supports. + EQ_PARAM_LEVEL_RANGE, // Returns the minimum and maximum band levels supported. + EQ_PARAM_BAND_LEVEL, // Gets/Sets the gain set for the given equalizer band. + EQ_PARAM_CENTER_FREQ, // Gets the center frequency of the given band. + EQ_PARAM_BAND_FREQ_RANGE, // Gets the frequency range of the given frequency band. + EQ_PARAM_GET_BAND, // Gets the band that has the most effect on the given frequency. + EQ_PARAM_CUR_PRESET, // Gets/Sets the current preset. + EQ_PARAM_GET_NUM_OF_PRESETS, // Gets the total number of presets the equalizer supports. + EQ_PARAM_GET_PRESET_NAME // Gets the preset name based on the index. +} t_equalizer_params; + +/* enumerated parameter settings for Volume effect */ +typedef enum +{ + VOLUME_PARAM_LEVEL, // type SLmillibel = typedef SLuint16 (set & get) + VOLUME_PARAM_MAXLEVEL, // type SLmillibel = typedef SLuint16 (get) + VOLUME_PARAM_MUTE, // type SLboolean = typedef SLuint32 (set & get) + VOLUME_PARAM_ENABLESTEREOPOSITION, // type SLboolean = typedef SLuint32 (set & get) + VOLUME_PARAM_STEREOPOSITION, // type SLpermille = typedef SLuint16 (set & get) +} t_volume_params; + +static const int PRESET_CUSTOM = -1; + +static const uint32_t bandFreqRange[FIVEBAND_NUMBANDS][2] = { + {30000, 120000}, + {12000, 460000}, + {46000, 1800000}, + {180000, 7000000}, + {700000, 1} + }; + +static const LVM_UINT16 EQNB_5BandPresetsFrequencies[] = { + 60, /* Frequencies in Hz */ + 230, + 910, + 3600, + 14000}; + +static const LVM_UINT16 EQNB_5BandPresetsQFactors[] = { + 96, /* Q factor multiplied by 100 */ + 96, + 96, + 96, + 96}; + +static const LVM_INT16 EQNB_5BandNormalPresets[] = { + 3, 0, 0, 0, 3, /* Normal Preset */ + 8, 5, -3, 5, 6, /* Classical Preset */ + 15, -6, 7, 13, 10, /* Dance Preset */ + 0, 0, 0, 0, 0, /* Flat Preset */ + 6, -2, -2, 6, -3, /* Folk Preset */ + 8, -8, 13, -1, -4, /* Heavy Metal Preset */ + 10, 6, -4, 5, 8, /* Hip Hop Preset */ + 8, 5, -4, 5, 9, /* Jazz Preset */ + -6, 4, 9, 4, -5, /* Pop Preset */ + 10, 6, -1, 8, 10}; /* Rock Preset */ + +static const PresetConfig gEqualizerPresets[] = { + {"Normal"}, + {"Classical"}, + {"Dance"}, + {"Flat"}, + {"Folk"}, + {"Heavy Metal"}, + {"Hip Hop"}, + {"Jazz"}, + {"Pop"}, + {"Rock"} + }; + +#if __cplusplus +} // extern "C" +#endif + + +#endif /*ANDROID_EFFECTBUNDLE_H_*/ diff --git a/media/libeffects/testlibs/Android.mk_ b/media/libeffects/testlibs/Android.mk_ new file mode 100644 index 0000000..9ba71ed --- /dev/null +++ b/media/libeffects/testlibs/Android.mk_ @@ -0,0 +1,66 @@ +LOCAL_PATH:= $(call my-dir) + +# Test Reverb library +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + EffectReverb.c.arm \ + EffectsMath.c.arm +LOCAL_CFLAGS+= -O2 + +LOCAL_SHARED_LIBRARIES := \ + libcutils + +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/soundfx +LOCAL_MODULE:= libreverbtest + +ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true) +LOCAL_LDLIBS += -ldl +endif + +ifneq ($(TARGET_SIMULATOR),true) +LOCAL_SHARED_LIBRARIES += libdl +endif + +LOCAL_C_INCLUDES := \ + $(call include-path-for, graphics corecg) + +LOCAL_PRELINK_MODULE := false + +include $(BUILD_SHARED_LIBRARY) + +# Test Equalizer library +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + EffectsMath.c.arm \ + EffectEqualizer.cpp \ + AudioBiquadFilter.cpp.arm \ + AudioCoefInterpolator.cpp.arm \ + AudioPeakingFilter.cpp.arm \ + AudioShelvingFilter.cpp.arm \ + AudioEqualizer.cpp.arm + +LOCAL_CFLAGS+= -O2 + +LOCAL_SHARED_LIBRARIES := \ + libcutils + +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/soundfx +LOCAL_MODULE:= libequalizertest + +ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true) +LOCAL_LDLIBS += -ldl +endif + +ifneq ($(TARGET_SIMULATOR),true) +LOCAL_SHARED_LIBRARIES += libdl +endif + +LOCAL_C_INCLUDES := \ + $(call include-path-for, graphics corecg) + +LOCAL_PRELINK_MODULE := false + +include $(BUILD_SHARED_LIBRARY) + diff --git a/media/libeffects/testlibs/AudioBiquadFilter.cpp b/media/libeffects/testlibs/AudioBiquadFilter.cpp new file mode 100644 index 0000000..72917a3 --- /dev/null +++ b/media/libeffects/testlibs/AudioBiquadFilter.cpp @@ -0,0 +1,260 @@ +/* //device/servers/AudioFlinger/AudioBiquadFilter.cpp +** +** Copyright 2009, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +#include +#include + +#include "AudioBiquadFilter.h" + +#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) +#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) + +namespace android { + +const audio_coef_t AudioBiquadFilter::IDENTITY_COEFS[AudioBiquadFilter::NUM_COEFS] = { AUDIO_COEF_ONE, 0, 0, 0, 0 }; + +AudioBiquadFilter::AudioBiquadFilter(int nChannels, int sampleRate) { + configure(nChannels, sampleRate); + reset(); +} + +void AudioBiquadFilter::configure(int nChannels, int sampleRate) { + assert(nChannels > 0 && nChannels <= MAX_CHANNELS); + assert(sampleRate > 0); + mNumChannels = nChannels; + mMaxDelta = static_cast(MAX_DELTA_PER_SEC) + * AUDIO_COEF_ONE + / sampleRate; + clear(); +} + +void AudioBiquadFilter::reset() { + memcpy(mCoefs, IDENTITY_COEFS, sizeof(mCoefs)); + mCoefDirtyBits = 0; + setState(STATE_BYPASS); +} + +void AudioBiquadFilter::clear() { + memset(mDelays, 0, sizeof(mDelays)); +} + +void AudioBiquadFilter::setCoefs(const audio_coef_t coefs[NUM_COEFS], bool immediate) { + memcpy(mTargetCoefs, coefs, sizeof(mTargetCoefs)); + if (mState & STATE_ENABLED_MASK) { + if (UNLIKELY(immediate)) { + memcpy(mCoefs, coefs, sizeof(mCoefs)); + setState(STATE_NORMAL); + } else { + setState(STATE_TRANSITION_TO_NORMAL); + } + } +} + +void AudioBiquadFilter::process(const audio_sample_t in[], audio_sample_t out[], + int frameCount) { + (this->*mCurProcessFunc)(in, out, frameCount); +} + +void AudioBiquadFilter::enable(bool immediate) { + if (UNLIKELY(immediate)) { + memcpy(mCoefs, mTargetCoefs, sizeof(mCoefs)); + setState(STATE_NORMAL); + } else { + setState(STATE_TRANSITION_TO_NORMAL); + } +} + +void AudioBiquadFilter::disable(bool immediate) { + if (UNLIKELY(immediate)) { + memcpy(mCoefs, IDENTITY_COEFS, sizeof(mCoefs)); + setState(STATE_BYPASS); + } else { + setState(STATE_TRANSITION_TO_BYPASS); + } +} + +void AudioBiquadFilter::setState(state_t state) { + switch (state) { + case STATE_BYPASS: + mCurProcessFunc = &AudioBiquadFilter::process_bypass; + break; + case STATE_TRANSITION_TO_BYPASS: + if (mNumChannels == 1) { + mCurProcessFunc = &AudioBiquadFilter::process_transition_bypass_mono; + } else { + mCurProcessFunc = &AudioBiquadFilter::process_transition_bypass_multi; + } + mCoefDirtyBits = (1 << NUM_COEFS) - 1; + break; + case STATE_TRANSITION_TO_NORMAL: + if (mNumChannels == 1) { + mCurProcessFunc = &AudioBiquadFilter::process_transition_normal_mono; + } else { + mCurProcessFunc = &AudioBiquadFilter::process_transition_normal_multi; + } + mCoefDirtyBits = (1 << NUM_COEFS) - 1; + break; + case STATE_NORMAL: + if (mNumChannels == 1) { + mCurProcessFunc = &AudioBiquadFilter::process_normal_mono; + } else { + mCurProcessFunc = &AudioBiquadFilter::process_normal_multi; + } + break; + } + mState = state; +} + +bool AudioBiquadFilter::updateCoefs(const audio_coef_t coefs[NUM_COEFS], + int frameCount) { + int64_t maxDelta = mMaxDelta * frameCount; + for (int i = 0; i < NUM_COEFS; ++i) { + if (mCoefDirtyBits & (1< maxDelta) { + mCoefs[i] += maxDelta; + } else if (diff < -maxDelta) { + mCoefs[i] -= maxDelta; + } else { + mCoefs[i] = coefs[i]; + mCoefDirtyBits ^= (1< 0) { + audio_sample_t x0 = *(in++); + audio_coef_sample_acc_t acc; + acc = mul_coef_sample(b0, x0); + acc = mac_coef_sample(b1, x1, acc); + acc = mac_coef_sample(b2, x2, acc); + acc = mac_coef_sample(a1, y1, acc); + acc = mac_coef_sample(a2, y2, acc); + audio_sample_t y0 = coef_sample_acc_to_sample(acc); + y2 = y1; + y1 = y0; + x2 = x1; + x1 = x0; + (*out++) = y0; + } + mDelays[0][0] = x1; + mDelays[0][1] = x2; + mDelays[0][2] = y1; + mDelays[0][3] = y2; +} + +void AudioBiquadFilter::process_transition_normal_mono(const audio_sample_t * in, + audio_sample_t * out, + int frameCount) { + if (updateCoefs(mTargetCoefs, frameCount)) { + setState(STATE_NORMAL); + } + process_normal_mono(in, out, frameCount); +} + +void AudioBiquadFilter::process_transition_bypass_mono(const audio_sample_t * in, + audio_sample_t * out, + int frameCount) { + if (updateCoefs(IDENTITY_COEFS, frameCount)) { + setState(STATE_NORMAL); + } + process_normal_mono(in, out, frameCount); +} + +void AudioBiquadFilter::process_normal_multi(const audio_sample_t * in, + audio_sample_t * out, + int frameCount) { + const audio_coef_t b0 = mCoefs[0]; + const audio_coef_t b1 = mCoefs[1]; + const audio_coef_t b2 = mCoefs[2]; + const audio_coef_t a1 = mCoefs[3]; + const audio_coef_t a2 = mCoefs[4]; + for (int ch = 0; ch < mNumChannels; ++ch) { + size_t nFrames = frameCount; + audio_sample_t x1 = mDelays[ch][0]; + audio_sample_t x2 = mDelays[ch][1]; + audio_sample_t y1 = mDelays[ch][2]; + audio_sample_t y2 = mDelays[ch][3]; + while (nFrames-- > 0) { + audio_sample_t x0 = *in; + audio_coef_sample_acc_t acc; + acc = mul_coef_sample(b0, x0); + acc = mac_coef_sample(b1, x1, acc); + acc = mac_coef_sample(b2, x2, acc); + acc = mac_coef_sample(a1, y1, acc); + acc = mac_coef_sample(a2, y2, acc); + audio_sample_t y0 = coef_sample_acc_to_sample(acc); + y2 = y1; + y1 = y0; + x2 = x1; + x1 = x0; + *out = y0; + in += mNumChannels; + out += mNumChannels; + } + mDelays[ch][0] = x1; + mDelays[ch][1] = x2; + mDelays[ch][2] = y1; + mDelays[ch][3] = y2; + in -= frameCount * mNumChannels - 1; + out -= frameCount * mNumChannels - 1; + } +} + +void AudioBiquadFilter::process_transition_normal_multi(const audio_sample_t * in, + audio_sample_t * out, + int frameCount) { + if (updateCoefs(mTargetCoefs, frameCount)) { + setState(STATE_NORMAL); + } + process_normal_multi(in, out, frameCount); +} + +void AudioBiquadFilter::process_transition_bypass_multi(const audio_sample_t * in, + audio_sample_t * out, + int frameCount) { + if (updateCoefs(IDENTITY_COEFS, frameCount)) { + setState(STATE_NORMAL); + } + process_normal_multi(in, out, frameCount); +} + +} diff --git a/media/libeffects/testlibs/AudioBiquadFilter.h b/media/libeffects/testlibs/AudioBiquadFilter.h new file mode 100644 index 0000000..2b0e2d6 --- /dev/null +++ b/media/libeffects/testlibs/AudioBiquadFilter.h @@ -0,0 +1,180 @@ +/* //device/include/server/AudioFlinger/AudioBiquadFilter.h +** +** Copyright 2007, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +#ifndef ANDROID_AUDIO_BIQUAD_FILTER_H +#define ANDROID_AUDIO_BIQUAD_FILTER_H + +#include "AudioCommon.h" + +namespace android { +// A biquad filter. +// Implements the recursion y[n]=a0*y[n-1]+a1*y[n-2]+b0*x[n]+b1*x[n-1]+b2*x[n-2] +// (the a0 and a1 coefficients have an opposite sign to the common convention) +// The filter works on fixed sized blocks of data (frameCount multi-channel +// samples, as defined during construction). An arbitrary number of interlaced +// channels is supported. +// Filter can operate in an enabled (active) or disabled (bypassed) states. +// A mechanism for suppression of artifacts caused by abrupt coefficient changes +// is implemented: normally, when the enable(), disable() and setCoefs() methods +// are called without the immediate flag set, the filter smoothly transitions +// from its current state to the desired state. +class AudioBiquadFilter { +public: + // Max number of channels (can be changed here, and everything should work). + static const int MAX_CHANNELS = 2; + // Number of coefficients. + static const int NUM_COEFS = 5; + + // Constructor. + // nChannels Number of input/output channels. + // sampleRate Sample rate, in Hz. + AudioBiquadFilter(int nChannels, int sampleRate); + + // Reconfiguration of the filter. Implies clear(). + // nChannels Number of input/output channels. + // sampleRate Sample rate, in Hz. + void configure(int nChannels, int sampleRate); + + // Resets the internal state of the filter. + // Coefficients are reset to identity, state becomes disabled. This change + // happens immediately and might cause discontinuities in the output. + // Delay lines are not cleared. + void reset(); + + // Clears the delay lines. + // This change happens immediately and might cause discontinuities in the + // output. + void clear(); + + // Sets the coefficients. + // If called when filter is disabled, will have no immediate effect, but the + // new coefficients will be set and used next time the filter is enabled. + // coefs The new coefficients. + // immediate If true, transitions to new coefficients smoothly, without + // introducing discontinuities in the output. Otherwise, + // transitions immediately. + void setCoefs(const audio_coef_t coefs[NUM_COEFS], bool immediate = false); + + // Process a buffer of data. Always processes frameCount multi-channel + // samples. Processing can be done in-place, by passing the same buffer as + // both arguments. + // in The input buffer. Should be of size frameCount * nChannels. + // out The output buffer. Should be of size frameCount * nChannels. + // frameCount Number of multi-channel samples to process. + void process(const audio_sample_t in[], audio_sample_t out[], + int frameCount); + + // Enables (activates) the filter. + // immediate If true, transitions to new state smoothly, without + // introducing discontinuities in the output. Otherwise, + // transitions immediately. + void enable(bool immediate = false); + + // Disables (bypasses) the filter. + // immediate If true, transitions to new state smoothly, without + // introducing discontinuities in the output. Otherwise, + // transitions immediately. + void disable(bool immediate = false); + +private: + // A prototype of the actual processing function. Has the same semantics as + // the process() method. + typedef void (AudioBiquadFilter::*process_func)(const audio_sample_t[], + audio_sample_t[], + int frameCount); + + // The maximum rate of coefficient change, measured in coefficient units per + // second. + static const audio_coef_t MAX_DELTA_PER_SEC = 2000; + + // Coefficients of identity transformation. + static const audio_coef_t IDENTITY_COEFS[NUM_COEFS]; + + // Filter state. + enum state_t { + // Bypass. + STATE_BYPASS = 0x01, + // In the process of smooth transition to bypass state. + STATE_TRANSITION_TO_BYPASS = 0x02, + // In the process of smooth transition to normal (enabled) state. + STATE_TRANSITION_TO_NORMAL = 0x04, + // In normal (enabled) state. + STATE_NORMAL = 0x05, + // A bit-mask for determining whether the filter is enabled or disabled + // in the eyes of the client. + STATE_ENABLED_MASK = 0x04 + }; + + // Number of channels. + int mNumChannels; + // Current state. + state_t mState; + // Maximum coefficient delta per sample. + audio_coef_t mMaxDelta; + + // A bit-mask designating for which coefficients the current value is not + // necessarily identical to the target value (since we're in transition + // state). + uint32_t mCoefDirtyBits; + // The current coefficients. + audio_coef_t mCoefs[NUM_COEFS]; + // The target coefficients. Will not be identical to mCoefs if we are in a + // transition state. + audio_coef_t mTargetCoefs[NUM_COEFS]; + + // The delay lines. + audio_sample_t mDelays[MAX_CHANNELS][4]; + + // Current processing function (determines according to current state and + // number of channels). + process_func mCurProcessFunc; + + // Sets a new state. Updates the processing function accordingly, and sets + // the dirty bits if changing to a transition state. + void setState(state_t state); + + // In a transition state, modifies the current coefs towards the passed + // coefs, while keeping a smooth change rate. Whenever a coef reaches its + // target value, the dirty bit is cleared. If all are clear, the function + // returns true, and we can then change to our target state. + bool updateCoefs(const audio_coef_t coefs[NUM_COEFS], int frameCount); + + // Processing function when in disabled state. + void process_bypass(const audio_sample_t * in, audio_sample_t * out, + int frameCount); + // Processing function when in normal state, mono. + void process_normal_mono(const audio_sample_t * in, audio_sample_t * out, + int frameCount); + // Processing function when transitioning to normal state, mono. + void process_transition_normal_mono(const audio_sample_t * in, + audio_sample_t * out, int frameCount); + // Processing function when transitioning to bypass state, mono. + void process_transition_bypass_mono(const audio_sample_t * in, + audio_sample_t * out, int frameCount); + // Processing function when in normal state, multi-channel. + void process_normal_multi(const audio_sample_t * in, audio_sample_t * out, + int frameCount); + // Processing function when transitioning to normal state, multi-channel. + void process_transition_normal_multi(const audio_sample_t * in, + audio_sample_t * out, int frameCount); + // Processing function when transitioning to bypass state, multi-channel. + void process_transition_bypass_multi(const audio_sample_t * in, + audio_sample_t * out, int frameCount); +}; +} + +#endif // ANDROID_AUDIO_BIQUAD_FILTER_H diff --git a/media/libeffects/testlibs/AudioCoefInterpolator.cpp b/media/libeffects/testlibs/AudioCoefInterpolator.cpp new file mode 100644 index 0000000..039ab9f --- /dev/null +++ b/media/libeffects/testlibs/AudioCoefInterpolator.cpp @@ -0,0 +1,84 @@ +/* //device/servers/AudioFlinger/AudioCoefInterpolator.cpp + ** + ** Copyright 2008, The Android Open Source Project + ** + ** Licensed under the Apache License, Version 2.0 (the "License"); + ** you may not use this file except in compliance with the License. + ** You may obtain a copy of the License at + ** + ** http://www.apache.org/licenses/LICENSE-2.0 + ** + ** Unless required by applicable law or agreed to in writing, software + ** distributed under the License is distributed on an "AS IS" BASIS, + ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ** See the License for the specific language governing permissions and + ** limitations under the License. + */ + +#include +#include "AudioCoefInterpolator.h" + +#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) +#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) + +namespace android { + +AudioCoefInterpolator::AudioCoefInterpolator(size_t nInDims, + const size_t inDims[], + size_t nOutDims, + const audio_coef_t * table) { + mNumInDims = nInDims; + memcpy(mInDims, inDims, nInDims * sizeof(size_t)); + mNumOutDims = nOutDims; + mTable = table; + // Initialize offsets array + size_t dim = nInDims - 1; + mInDimOffsets[nInDims - 1] = nOutDims; + while (dim-- > 0) { + mInDimOffsets[dim] = mInDimOffsets[dim + 1] * mInDims[dim + 1]; + } +} + +void AudioCoefInterpolator::getCoef(const int intCoord[], uint32_t fracCoord[], + audio_coef_t out[]) { + size_t index = 0; + size_t dim = mNumInDims; + while (dim-- > 0) { + if (UNLIKELY(intCoord[dim] < 0)) { + fracCoord[dim] = 0; + } else if (UNLIKELY(intCoord[dim] >= (int)mInDims[dim] - 1)) { + fracCoord[dim] = 0; + index += mInDimOffsets[dim] * (mInDims[dim] - 1); + } else { + index += mInDimOffsets[dim] * intCoord[dim]; + } + } + getCoefRecurse(index, fracCoord, out, 0); +} + +void AudioCoefInterpolator::getCoefRecurse(size_t index, + const uint32_t fracCoord[], + audio_coef_t out[], size_t dim) { + if (dim == mNumInDims) { + memcpy(out, mTable + index, mNumOutDims * sizeof(audio_coef_t)); + } else { + getCoefRecurse(index, fracCoord, out, dim + 1); + if (LIKELY(fracCoord != 0)) { + audio_coef_t tempCoef[MAX_OUT_DIMS]; + getCoefRecurse(index + mInDimOffsets[dim], fracCoord, tempCoef, + dim + 1); + size_t d = mNumOutDims; + while (d-- > 0) { + out[d] = interp(out[d], tempCoef[d], fracCoord[dim]); + } + } + } +} + +audio_coef_t AudioCoefInterpolator::interp(audio_coef_t lo, audio_coef_t hi, + uint32_t frac) { + int64_t delta = static_cast(hi-lo) * frac; + return lo + static_cast (delta >> 32); +} + +} diff --git a/media/libeffects/testlibs/AudioCoefInterpolator.h b/media/libeffects/testlibs/AudioCoefInterpolator.h new file mode 100644 index 0000000..13e5697 --- /dev/null +++ b/media/libeffects/testlibs/AudioCoefInterpolator.h @@ -0,0 +1,98 @@ +/* //device/include/server/AudioFlinger/AudioCoefInterpolator.h + ** + ** Copyright 2007, The Android Open Source Project + ** + ** Licensed under the Apache License, Version 2.0 (the "License"); + ** you may not use this file except in compliance with the License. + ** You may obtain a copy of the License at + ** + ** http://www.apache.org/licenses/LICENSE-2.0 + ** + ** Unless required by applicable law or agreed to in writing, software + ** distributed under the License is distributed on an "AS IS" BASIS, + ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ** See the License for the specific language governing permissions and + ** limitations under the License. + */ + +#ifndef ANDROID_AUDIO_COEF_INTERPOLATOR_H +#define ANDROID_AUDIO_COEF_INTERPOLATOR_H + +#include "AudioCommon.h" + +namespace android { + +// A helper class for linear interpolation of N-D -> M-D coefficient tables. +// This class provides support for out-of-range indexes. +// Details: +// The purpose is efficient approximation of a N-dimensional vector to +// M-dimensional function. The approximation is based on a table of output +// values on a uniform grid of the input values. Values not on the grid are +// linearly interpolated. +// Access to values are done by specifying input values in table index units, +// having an integer and a fractional part, e.g. retrieving a value from index +// 1.4 will result in linear interpolation between index 1 and index 2. +class AudioCoefInterpolator { +public: + // Constructor. + // nInDims Number of input dimensions (limited to MAX_IN_DIMS). + // inDims An array of size nInDims with the size of the table on each + // respective dimension. + // nOutDims Number of output dimensions (limited to MAX_OUT_DIMS). + // table The coefficient table. Should be of size: + // inDims[0]*inDims[1]*...*inDims[nInDims-1]*nOutDims, where + // func([i,j,k]) = table(i,j,k,:) + AudioCoefInterpolator(size_t nInDims, const size_t inDims[], + size_t nOutDims, const audio_coef_t * table); + + // Get the value of the approximated function at a given point. + // intCoord The integer part of the input value. Should be an array of + // size nInDims. + // fracCoord The fractional part of the input value. Should be an array + // of size nInDims. This value is in 32-bit precision. + // out An array for the output value. Should be of size nOutDims. + void getCoef(const int intCoord[], uint32_t fracCoord[], audio_coef_t out[]); + +private: + // Maximum allowed number of input dimensions. + static const size_t MAX_IN_DIMS = 8; + // Maximum allowed number of output dimensions. + static const size_t MAX_OUT_DIMS = 8; + + // Number of input dimensions. + size_t mNumInDims; + // Number of input dimensions. + size_t mInDims[MAX_IN_DIMS]; + // The offset between two consecutive indexes of each dimension. This is in + // fact a cumulative product of mInDims (done in reverse). + size_t mInDimOffsets[MAX_IN_DIMS]; + // Number of output dimensions. + size_t mNumOutDims; + // The coefficient table. + const audio_coef_t * mTable; + + // A recursive function for getting an interpolated coefficient value. + // The recursion depth is the number of input dimensions. + // At each step, we fetch two interpolated values of the current dimension, + // by two recursive calls to this method for the next dimensions. We then + // linearly interpolate these values over the current dimension. + // index The linear integer index of the value we need to interpolate. + // fracCoord A vector of fractional coordinates for each of the input + // dimensions. + // out Where the output should be written. Needs to be of size + // mNumOutDims. + // dim The input dimensions we are currently interpolating. This + // value will be increased on recursive calls. + void getCoefRecurse(size_t index, const uint32_t fracCoord[], + audio_coef_t out[], size_t dim); + + // Scalar interpolation of two data points. + // lo The first data point. + // hi The second data point. + // frac A 32-bit fraction designating the weight of the second point. + static audio_coef_t interp(audio_coef_t lo, audio_coef_t hi, uint32_t frac); +}; + +} + +#endif // ANDROID_AUDIO_COEF_INTERPOLATOR_H diff --git a/media/libeffects/testlibs/AudioCommon.h b/media/libeffects/testlibs/AudioCommon.h new file mode 100644 index 0000000..444f93a --- /dev/null +++ b/media/libeffects/testlibs/AudioCommon.h @@ -0,0 +1,92 @@ +/* +** +** Copyright 2009, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +#ifndef ANDROID_AUDIO_COMMON_H +#define ANDROID_AUDIO_COMMON_H + +#include +#include + +namespace android { + +// Audio coefficient type. +typedef int32_t audio_coef_t; +// Audio sample type. +typedef int32_t audio_sample_t; +// Accumulator type for coef x sample. +typedef int64_t audio_coef_sample_acc_t; + +// Number of fraction bits for audio coefficient. +static const int AUDIO_COEF_PRECISION = 24; +// Audio coefficient with the value of 1.0 +static const audio_coef_t AUDIO_COEF_ONE = 1 << AUDIO_COEF_PRECISION; +// Audio coefficient with the value of 0.5 +static const audio_coef_t AUDIO_COEF_HALF = 1 << (AUDIO_COEF_PRECISION - 1); +// Number of fraction bits for audio sample. +static const int AUDIO_SAMPLE_PRECISION = 24; +// Audio sample with the value of 1.0 +static const audio_sample_t AUDIO_SAMPLE_ONE = 1 << AUDIO_SAMPLE_PRECISION; + +// TODO: These are just temporary naive implementations of the necessary +// arithmetic operations needed for the filter. They should be moved to a more +// generic location and implemented more efficiently. + +// Multiply a sample by a coefficient to return an accumulator. +inline audio_coef_sample_acc_t mul_coef_sample(audio_coef_t x, audio_sample_t y) { + return ((audio_coef_sample_acc_t) (x)) * y; +} + +// Multiply and accumulate sample by a coefficient to return an accumulator. +inline audio_coef_sample_acc_t mac_coef_sample(audio_coef_t x, audio_sample_t y, audio_coef_sample_acc_t acc) { + return acc + ((audio_coef_sample_acc_t) (x)) * y; +} + +// Convert a sample-coefficient accumulator to a sample. +inline audio_sample_t coef_sample_acc_to_sample(audio_coef_sample_acc_t acc) { + if (acc < 0) { + acc += AUDIO_COEF_ONE - 1; + } + return (audio_sample_t) (acc >> AUDIO_COEF_PRECISION); +} + +// Convert a S15 sample to audio_sample_t +inline audio_sample_t s15_to_audio_sample_t(int16_t s15) { + return audio_sample_t(s15) << 9; +} + +// Convert a audio_sample_t sample to S15 (no clipping) +inline int16_t audio_sample_t_to_s15(audio_sample_t sample) { + return int16_t((sample + (1 << 8)) >> 9); +} + +// Convert a audio_sample_t sample to S15 (with clipping) +inline int16_t audio_sample_t_to_s15_clip(audio_sample_t sample) { + // TODO: optimize for targets supporting this as an atomic operation. + if (__builtin_expect(sample >= (0x7FFF << 9), 0)) { + return 0x7FFF; + } else if (__builtin_expect(sample <= -(0x8000 << 9), 0)) { + return 0x8000; + } else { + return audio_sample_t_to_s15(sample); + } +} + +//////////////////////////////////////////////////////////////////////////////// + +} + +#endif // ANDROID_AUDIO_COMMON_H diff --git a/media/libeffects/testlibs/AudioEqualizer.cpp b/media/libeffects/testlibs/AudioEqualizer.cpp new file mode 100644 index 0000000..44c9476 --- /dev/null +++ b/media/libeffects/testlibs/AudioEqualizer.cpp @@ -0,0 +1,315 @@ +/* + * Copyright 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "AudioEqualizer" + +#include +#include +#include +#include + +#include "AudioEqualizer.h" +#include "AudioPeakingFilter.h" +#include "AudioShelvingFilter.h" +#include "EffectsMath.h" + +namespace android { + +size_t AudioEqualizer::GetInstanceSize(int nBands) { + assert(nBands >= 2); + return sizeof(AudioEqualizer) + + sizeof(AudioShelvingFilter) * 2 + + sizeof(AudioPeakingFilter) * (nBands - 2); +} + +AudioEqualizer * AudioEqualizer::CreateInstance(void * pMem, int nBands, + int nChannels, int sampleRate, + const PresetConfig * presets, + int nPresets) { + LOGV("AudioEqualizer::CreateInstance(pMem=%p, nBands=%d, nChannels=%d, " + "sampleRate=%d, nPresets=%d)", + pMem, nBands, nChannels, sampleRate, nPresets); + assert(nBands >= 2); + bool ownMem = false; + if (pMem == NULL) { + pMem = malloc(GetInstanceSize(nBands)); + if (pMem == NULL) { + return NULL; + } + ownMem = true; + } + return new (pMem) AudioEqualizer(pMem, nBands, nChannels, sampleRate, + ownMem, presets, nPresets); +} + +void AudioEqualizer::configure(int nChannels, int sampleRate) { + LOGV("AudioEqualizer::configure(nChannels=%d, sampleRate=%d)", nChannels, + sampleRate); + mpLowShelf->configure(nChannels, sampleRate); + for (int i = 0; i < mNumPeaking; ++i) { + mpPeakingFilters[i].configure(nChannels, sampleRate); + } + mpHighShelf->configure(nChannels, sampleRate); +} + +void AudioEqualizer::clear() { + LOGV("AudioEqualizer::clear()"); + mpLowShelf->clear(); + for (int i = 0; i < mNumPeaking; ++i) { + mpPeakingFilters[i].clear(); + } + mpHighShelf->clear(); +} + +void AudioEqualizer::free() { + LOGV("AudioEqualizer::free()"); + if (mpMem != NULL) { + ::free(mpMem); + } +} + +void AudioEqualizer::reset() { + LOGV("AudioEqualizer::reset()"); + const int32_t bottom = Effects_log2(kMinFreq); + const int32_t top = Effects_log2(mSampleRate * 500); + const int32_t jump = (top - bottom) / (mNumPeaking + 2); + int32_t centerFreq = bottom + jump/2; + + mpLowShelf->reset(); + mpLowShelf->setFrequency(Effects_exp2(centerFreq)); + centerFreq += jump; + for (int i = 0; i < mNumPeaking; ++i) { + mpPeakingFilters[i].reset(); + mpPeakingFilters[i].setFrequency(Effects_exp2(centerFreq)); + centerFreq += jump; + } + mpHighShelf->reset(); + mpHighShelf->setFrequency(Effects_exp2(centerFreq)); + commit(true); + mCurPreset = PRESET_CUSTOM; +} + +void AudioEqualizer::setGain(int band, int32_t millibel) { + LOGV("AudioEqualizer::setGain(band=%d, millibel=%d)", band, millibel); + assert(band >= 0 && band < mNumPeaking + 2); + if (band == 0) { + mpLowShelf->setGain(millibel); + } else if (band == mNumPeaking + 1) { + mpHighShelf->setGain(millibel); + } else { + mpPeakingFilters[band - 1].setGain(millibel); + } + mCurPreset = PRESET_CUSTOM; +} + +void AudioEqualizer::setFrequency(int band, uint32_t millihertz) { + LOGV("AudioEqualizer::setFrequency(band=%d, millihertz=%d)", band, + millihertz); + assert(band >= 0 && band < mNumPeaking + 2); + if (band == 0) { + mpLowShelf->setFrequency(millihertz); + } else if (band == mNumPeaking + 1) { + mpHighShelf->setFrequency(millihertz); + } else { + mpPeakingFilters[band - 1].setFrequency(millihertz); + } + mCurPreset = PRESET_CUSTOM; +} + +void AudioEqualizer::setBandwidth(int band, uint32_t cents) { + LOGV("AudioEqualizer::setBandwidth(band=%d, cents=%d)", band, cents); + assert(band >= 0 && band < mNumPeaking + 2); + if (band > 0 && band < mNumPeaking + 1) { + mpPeakingFilters[band - 1].setBandwidth(cents); + mCurPreset = PRESET_CUSTOM; + } +} + +int32_t AudioEqualizer::getGain(int band) const { + assert(band >= 0 && band < mNumPeaking + 2); + if (band == 0) { + return mpLowShelf->getGain(); + } else if (band == mNumPeaking + 1) { + return mpHighShelf->getGain(); + } else { + return mpPeakingFilters[band - 1].getGain(); + } +} + +uint32_t AudioEqualizer::getFrequency(int band) const { + assert(band >= 0 && band < mNumPeaking + 2); + if (band == 0) { + return mpLowShelf->getFrequency(); + } else if (band == mNumPeaking + 1) { + return mpHighShelf->getFrequency(); + } else { + return mpPeakingFilters[band - 1].getFrequency(); + } +} + +uint32_t AudioEqualizer::getBandwidth(int band) const { + assert(band >= 0 && band < mNumPeaking + 2); + if (band == 0 || band == mNumPeaking + 1) { + return 0; + } else { + return mpPeakingFilters[band - 1].getBandwidth(); + } +} + +void AudioEqualizer::getBandRange(int band, uint32_t & low, + uint32_t & high) const { + assert(band >= 0 && band < mNumPeaking + 2); + if (band == 0) { + low = 0; + high = mpLowShelf->getFrequency(); + } else if (band == mNumPeaking + 1) { + low = mpHighShelf->getFrequency(); + high = mSampleRate * 500; + } else { + mpPeakingFilters[band - 1].getBandRange(low, high); + } +} + +const char * AudioEqualizer::getPresetName(int preset) const { + assert(preset < mNumPresets && preset >= PRESET_CUSTOM); + if (preset == PRESET_CUSTOM) { + return "Custom"; + } else { + return mpPresets[preset].name; + } +} + +int AudioEqualizer::getNumPresets() const { + return mNumPresets; +} + +int AudioEqualizer::getPreset() const { + return mCurPreset; +} + +void AudioEqualizer::setPreset(int preset) { + LOGV("AudioEqualizer::setPreset(preset=%d)", preset); + assert(preset < mNumPresets && preset >= 0); + const PresetConfig &presetCfg = mpPresets[preset]; + for (int band = 0; band < (mNumPeaking + 2); ++band) { + const BandConfig & bandCfg = presetCfg.bandConfigs[band]; + setGain(band, bandCfg.gain); + setFrequency(band, bandCfg.freq); + setBandwidth(band, bandCfg.bandwidth); + } + mCurPreset = preset; +} + +void AudioEqualizer::commit(bool immediate) { + LOGV("AudioEqualizer::commit(immediate=%d)", immediate); + mpLowShelf->commit(immediate); + for (int i = 0; i < mNumPeaking; ++i) { + mpPeakingFilters[i].commit(immediate); + } + mpHighShelf->commit(immediate); +} + +void AudioEqualizer::process(const audio_sample_t * pIn, + audio_sample_t * pOut, + int frameCount) { +// LOGV("AudioEqualizer::process(frameCount=%d)", frameCount); + mpLowShelf->process(pIn, pOut, frameCount); + for (int i = 0; i < mNumPeaking; ++i) { + mpPeakingFilters[i].process(pIn, pOut, frameCount); + } + mpHighShelf->process(pIn, pOut, frameCount); +} + +void AudioEqualizer::enable(bool immediate) { + LOGV("AudioEqualizer::enable(immediate=%d)", immediate); + mpLowShelf->enable(immediate); + for (int i = 0; i < mNumPeaking; ++i) { + mpPeakingFilters[i].enable(immediate); + } + mpHighShelf->enable(immediate); +} + +void AudioEqualizer::disable(bool immediate) { + LOGV("AudioEqualizer::disable(immediate=%d)", immediate); + mpLowShelf->disable(immediate); + for (int i = 0; i < mNumPeaking; ++i) { + mpPeakingFilters[i].disable(immediate); + } + mpHighShelf->disable(immediate); +} + +int AudioEqualizer::getMostRelevantBand(uint32_t targetFreq) const { + // First, find the two bands that the target frequency is between. + uint32_t low = mpLowShelf->getFrequency(); + if (targetFreq <= low) { + return 0; + } + uint32_t high = mpHighShelf->getFrequency(); + if (targetFreq >= high) { + return mNumPeaking + 1; + } + int band = mNumPeaking; + for (int i = 0; i < mNumPeaking; ++i) { + uint32_t freq = mpPeakingFilters[i].getFrequency(); + if (freq >= targetFreq) { + high = freq; + band = i; + break; + } + low = freq; + } + // Now, low is right below the target and high is right above. See which one + // is closer on a log scale. + low = Effects_log2(low); + high = Effects_log2(high); + targetFreq = Effects_log2(targetFreq); + if (high - targetFreq < targetFreq - low) { + return band + 1; + } else { + return band; + } +} + + +AudioEqualizer::AudioEqualizer(void * pMem, int nBands, int nChannels, + int sampleRate, bool ownMem, + const PresetConfig * presets, int nPresets) + : mSampleRate(sampleRate) + , mpPresets(presets) + , mNumPresets(nPresets) { + assert(pMem != NULL); + assert(nPresets == 0 || nPresets > 0 && presets != NULL); + mpMem = ownMem ? pMem : NULL; + + pMem = (char *) pMem + sizeof(AudioEqualizer); + mpLowShelf = new (pMem) AudioShelvingFilter(AudioShelvingFilter::kLowShelf, + nChannels, sampleRate); + pMem = (char *) pMem + sizeof(AudioShelvingFilter); + mpHighShelf = new (pMem) AudioShelvingFilter(AudioShelvingFilter::kHighShelf, + nChannels, sampleRate); + pMem = (char *) pMem + sizeof(AudioShelvingFilter); + mNumPeaking = nBands - 2; + if (mNumPeaking > 0) { + mpPeakingFilters = reinterpret_cast(pMem); + for (int i = 0; i < mNumPeaking; ++i) { + new (&mpPeakingFilters[i]) AudioPeakingFilter(nChannels, + sampleRate); + } + } + reset(); +} + +} diff --git a/media/libeffects/testlibs/AudioEqualizer.h b/media/libeffects/testlibs/AudioEqualizer.h new file mode 100644 index 0000000..4028462 --- /dev/null +++ b/media/libeffects/testlibs/AudioEqualizer.h @@ -0,0 +1,246 @@ +/* + * Copyright 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AUDIOEQUALIZER_H_ +#define AUDIOEQUALIZER_H_ + +#include "AudioCommon.h" + +namespace android { + +class AudioShelvingFilter; +class AudioPeakingFilter; + +// A parametric audio equalizer. Supports an arbitrary number of bands and +// presets. +// The EQ is composed of a low-shelf, zero or more peaking filters and a high +// shelf, where each band has frequency and gain controls, and the peaking +// filters have an additional bandwidth control. +class AudioEqualizer { +public: + // Configuration of a single band. + struct BandConfig { + // Gain in millibel. + int32_t gain; + // Frequency in millihertz. + uint32_t freq; + // Bandwidth in cents (ignored on shelving filters). + uint32_t bandwidth; + }; + + // Preset configuration. + struct PresetConfig { + // Human-readable name. + const char * name; + // An array of size nBands where each element is a configuration for the + // corresponding band. + const BandConfig * bandConfigs; + }; + + // This value is used when requesting current preset, and EQ is not using a + // preset. + static const int PRESET_CUSTOM = -1; + + // Get the required memory size for an instance of this class. + // nBands Number of bands required in the instance. + static size_t GetInstanceSize(int nBands); + + // Create an instance of this class. + // If succeeds, a respective call is expected to freeInstance(), regardless + // of who owns the context memory. + // pMem A memory buffer of at least the size returned by + // GetInstanceSize(), where the instance context is to be + // stored. If NULL, it will be automatically allocated (using + // malloc). + // nBands Number of bands. Must be >= 2. + // nChannels Number of input/output channels (interlaced). + // sampleRate The input/output sample rate, in Hz. + // presets The presets configuration. May be NULL, but in that case the + // client is required not to call preset-related functions. + // This array is owned by the client and is not copied. It + // must be kept valid by the client as long as the instance is + // alive. + // nPresets Number of elements in the presets array. + // returns The instance if success. NULL if pMem is NULL and allocation + // failed. + static AudioEqualizer * CreateInstance(void * pMem, int nBands, + int nChannels, + int sampleRate, + const PresetConfig * presets, + int nPresets); + + // Reconfiguration of the filter. Changes input/output format, but does not + // alter current parameter values. Causes reset of the delay lines. + // nChannels Number of input/output channels (interlaced). + // sampleRate The input/output sample rate, in Hz. + void configure(int nChannels, int sampleRate); + + // Resets the filter parameters to the following values: + // frequency: 0 + // gain: 0 + // bandwidth: 1200 cents. + // It also disables the filter. Does not clear the delay lines. + void reset(); + + // Clears delay lines. Does not alter parameter values. + void clear(); + + // Frees the object. Will free the memory if the object owned it, i.e. if + // a NULL pointer was passed to CreateInstance as pMem. + void free(); + + // Sets gain value. Actual change will only take place upon commit(). + // This value will be remembered even if the filter is in disabled() state. + // band The band to set the gain for. + // millibel Gain value in millibel (1/100 of decibel). + void setGain(int band, int32_t millibel); + + // Gets gain of a certain band. This is always the last value set (or + // default value after reset). + // band The band to get the gain for. + // returns Gain value in millibel (1/100 of decibel). + int32_t getGain(int band) const; + + // Sets cutoff frequency value. Actual change will only take place upon + // commit(). + // This value will be remembered even if the filter is in disabled() state. + // band The band to set the frequency for. + // millihertz Frequency value in mHz. + void setFrequency(int band, uint32_t millihertz); + + // Gets frequency of a certain band. This is always the last value set (or + // default value after reset). + // band The band to get the frequency for. + // returns Frequency value in mHz. + uint32_t getFrequency(int band) const; + + // Sets bandwidth value. Actual change will only take place upon commit(). + // This value will be remembered even if the filter is in disabled() state. + // If called on the first or last band, this call is ignored. + // band The band to set the frequency for. + // cents Bandwidth value in cents (1/1200 octave). + void setBandwidth(int band, uint32_t cents); + + // Gets bandwidth of a certain band. This is always the last value set (or + // default value after reset). For the first and last bands, 0 is always + // returned. + // band The band to get the bandwidth for. + // returns Bandwidth value in cents (1/1200 octave). + uint32_t getBandwidth(int band) const; + + // Gets lower and upper boundaries of a band. + // For the low shelf, the low bound is 0 and the high bound is the band + // frequency. + // For the high shelf, the low bound is the band frequency and the high + // bound is Nyquist. + // For the peaking filters, they are the gain[dB]/2 points. + void getBandRange(int band, uint32_t & low, uint32_t & high) const; + + // Gets a human-readable name for a preset ID. Will return "Custom" if + // PRESET_CUSTOM is passed. + // preset The preset ID. Must be less than number of presets. + const char * getPresetName(int preset) const; + + // Gets the number of presets. + int getNumPresets() const; + + // Gets the currently set preset ID. + // Will return PRESET_CUSTOM in case the EQ parameters have been modified + // manually since a preset was set. + int getPreset() const; + + // Sets the current preset by ID. + // All the band parameters will be overridden. + // Change will not be applied until commit() is called. + // preset The preset ID. Must be less than number of presets. + // PRESET_CUSTOM is NOT a valid value here. + void setPreset(int preset); + + // Applies all parameter changes done to this point in time. + // If the filter is disabled, the new parameters will take place when it is + // enabled again. Does not introduce artifacts, unless immediate is set. + // immediate Whether to apply change abruptly (ignored if filter is + // disabled). + void commit(bool immediate = false); + + // Process a buffer of input data. The input and output should contain + // frameCount * nChannels interlaced samples. Processing can be done + // in-place, by passing the same buffer as both arguments. + // pIn Input buffer. + // pOut Output buffer. + // frameCount Number of frames to produce on each call to process(). + void process(const audio_sample_t * pIn, audio_sample_t * pOut, + int frameCount); + + // Enables the filter, so it would start processing input. Does not + // introduce artifacts, unless immediate is set. + // immediate Whether to apply change abruptly. + void enable(bool immediate = false); + + // Disabled (bypasses) the filter. Does not introduce artifacts, unless + // immediate is set. + // immediate Whether to apply change abruptly. + void disable(bool immediate = false); + + // Returns the band with the maximum influence on a given frequency. + // Result is unaffected by whether EQ is enabled or not, or by whether + // changes have been committed or not. + // targetFreq The target frequency, in millihertz. + int getMostRelevantBand(uint32_t targetFreq) const; + +private: + // Bottom frequency, in mHz. + static const int kMinFreq = 20000; + // Sample rate, in Hz. + int mSampleRate; + // Number of peaking filters. Total number of bands is +2. + int mNumPeaking; + // Preset configurations. + const PresetConfig * mpPresets; + // Number of elements in mpPresets; + int mNumPresets; + // Current preset. + int mCurPreset; + + // Memory space to free when instance is deleted, or NULL if no memory is + // owned. + void * mpMem; + // The low-shelving filter. + AudioShelvingFilter * mpLowShelf; + // The high-shelving filter. + AudioShelvingFilter * mpHighShelf; + // An array of size mNumPeaking of peaking filters. + AudioPeakingFilter * mpPeakingFilters; + + // Constructor. Resets the filter (see reset()). Must call init() doing + // anything else. + // pMem Memory buffer for bands. + // nChannels Number of input/output channels (interlaced). + // sampleRate The input/output sample rate, in Hz. + // ownMem Whether pMem is owned by me. + // presets The presets configuration. May be NULL, but in that case the + // client is required not to call preset-related functions. + // This array is owned by the client and is not copied. It + // must be kept valid by the client as long as the instance is + // alive. + // nPresets Number of elements in the presets array. + AudioEqualizer(void * pMem, int nBands, int nChannels, int sampleRate, + bool ownMem, const PresetConfig * presets, int nPresets); +}; + +} + +#endif // AUDIOEQUALIZER_H_ diff --git a/media/libeffects/testlibs/AudioFormatAdapter.h b/media/libeffects/testlibs/AudioFormatAdapter.h new file mode 100644 index 0000000..d93ebe9 --- /dev/null +++ b/media/libeffects/testlibs/AudioFormatAdapter.h @@ -0,0 +1,184 @@ +/* /android/src/frameworks/base/media/libeffects/AudioFormatAdapter.h +** +** Copyright 2009, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +#ifndef AUDIOFORMATADAPTER_H_ +#define AUDIOFORMATADAPTER_H_ + +#include + + +#define min(x,y) (((x) < (y)) ? (x) : (y)) + +namespace android { + +// An adapter for an audio processor working on audio_sample_t samples with a +// buffer override behavior to arbitrary sample formats and buffer behaviors. +// The adapter may work on any processing class which has a processing function +// with the following signature: +// void process(const audio_sample_t * pIn, +// audio_sample_t * pOut, +// int frameCount); +// It is assumed that the underlying processor works in S7.24 format and an +// overwrite behavior. +// +// Usage is simple: just work with the processor normally, but instead of +// calling its process() function directly, work with the process() function of +// the adapter. +// The adapter supports re-configuration to a different format on the fly. +// +// T The processor class. +// bufSize The maximum number of samples (single channel) to process on a +// single call to the underlying processor. Setting this to a small +// number will save a little memory, but will cost function call +// overhead, resulting from multiple calls to the underlying process() +// per a single call to this class's process(). +template +class AudioFormatAdapter { +public: + // Configure the adapter. + // processor The underlying audio processor. + // nChannels Number of input and output channels. The adapter does not do + // channel conversion - this parameter must be in sync with the + // actual processor. + // pcmFormat The desired input/output sample format. + // behavior The desired behavior (overwrite or accumulate). + void configure(T & processor, int nChannels, uint8_t pcmFormat, + uint32_t behavior) { + mpProcessor = &processor; + mNumChannels = nChannels; + mPcmFormat = pcmFormat; + mBehavior = behavior; + mMaxSamplesPerCall = bufSize / nChannels; + } + + // Process a block of samples. + // pIn A buffer of samples with the format specified on + // configure(). + // pOut A buffer of samples with the format specified on + // configure(). May be the same as pIn. + // numSamples The number of multi-channel samples to process. + void process(const void * pIn, void * pOut, uint32_t numSamples) { + while (numSamples > 0) { + uint32_t numSamplesIter = min(numSamples, mMaxSamplesPerCall); + uint32_t nSamplesChannels = numSamplesIter * mNumChannels; + if (mPcmFormat == SAMPLE_FORMAT_PCM_S7_24) { + if (mBehavior == EFFECT_BUFFER_ACCESS_WRITE) { + mpProcessor->process( + reinterpret_cast (pIn), + reinterpret_cast (pOut), + numSamplesIter); + } else if (mBehavior == EFFECT_BUFFER_ACCESS_ACCUMULATE) { + mpProcessor->process( + reinterpret_cast (pIn), + mBuffer, numSamplesIter); + MixOutput(pOut, numSamplesIter); + } else { + assert(false); + } + pIn = reinterpret_cast (pIn) + + nSamplesChannels; + pOut = reinterpret_cast (pOut) + + nSamplesChannels; + } else { + ConvertInput(pIn, nSamplesChannels); + mpProcessor->process(mBuffer, mBuffer, numSamplesIter); + ConvertOutput(pOut, nSamplesChannels); + } + numSamples -= numSamplesIter; + } + } + +private: + // The underlying processor. + T * mpProcessor; + // The number of input/output channels. + int mNumChannels; + // The desired PCM format. + uint8_t mPcmFormat; + // The desired buffer behavior. + uint32_t mBehavior; + // An intermediate buffer for processing. + audio_sample_t mBuffer[bufSize]; + // The buffer size, divided by the number of channels - represents the + // maximum number of multi-channel samples that can be stored in the + // intermediate buffer. + size_t mMaxSamplesPerCall; + + // Converts a buffer of input samples to audio_sample_t format. + // Output is written to the intermediate buffer. + // pIn The input buffer with the format designated in configure(). + // When function exist will point to the next unread input + // sample. + // numSamples The number of single-channel samples to process. + void ConvertInput(const void *& pIn, uint32_t numSamples) { + if (mPcmFormat == SAMPLE_FORMAT_PCM_S15) { + const int16_t * pIn16 = reinterpret_cast(pIn); + audio_sample_t * pOut = mBuffer; + while (numSamples-- > 0) { + *(pOut++) = s15_to_audio_sample_t(*(pIn16++)); + } + pIn = pIn16; + } else { + assert(false); + } + } + + // Converts audio_sample_t samples from the intermediate buffer to the + // output buffer, converting to the desired format and buffer behavior. + // pOut The buffer to write the output to. + // When function exist will point to the next output sample. + // numSamples The number of single-channel samples to process. + void ConvertOutput(void *& pOut, uint32_t numSamples) { + if (mPcmFormat == SAMPLE_FORMAT_PCM_S15) { + const audio_sample_t * pIn = mBuffer; + int16_t * pOut16 = reinterpret_cast(pOut); + if (mBehavior == EFFECT_BUFFER_ACCESS_WRITE) { + while (numSamples-- > 0) { + *(pOut16++) = audio_sample_t_to_s15_clip(*(pIn++)); + } + } else if (mBehavior == EFFECT_BUFFER_ACCESS_ACCUMULATE) { + while (numSamples-- > 0) { + *(pOut16++) += audio_sample_t_to_s15_clip(*(pIn++)); + } + } else { + assert(false); + } + pOut = pOut16; + } else { + assert(false); + } + } + + // Accumulate data from the intermediate buffer to the output. Output is + // assumed to be of audio_sample_t type. + // pOut The buffer to mix the output to. + // When function exist will point to the next output sample. + // numSamples The number of single-channel samples to process. + void MixOutput(void *& pOut, uint32_t numSamples) { + const audio_sample_t * pIn = mBuffer; + audio_sample_t * pOut24 = reinterpret_cast(pOut); + numSamples *= mNumChannels; + while (numSamples-- > 0) { + *(pOut24++) += *(pIn++); + } + pOut = pOut24; + } +}; + +} + +#endif // AUDIOFORMATADAPTER_H_ diff --git a/media/libeffects/testlibs/AudioHighShelfFilterCoef.inl b/media/libeffects/testlibs/AudioHighShelfFilterCoef.inl new file mode 100644 index 0000000..ebba139 --- /dev/null +++ b/media/libeffects/testlibs/AudioHighShelfFilterCoef.inl @@ -0,0 +1,225 @@ +13679, +21575, +8921, +32315056, +-15582015, +26172, +37678, +14797, +31891096, +-15192527, +51020, +64449, +23945, +31322988, +-14685186, +101817, +106144, +37744, +30562882, +-14031372, +208996, +162163, +58536, +29548538, +-13201017, +442996, +207459, +93300, +28200792, +-12167331, +971423, +128786, +169690, +26422744, +-10915428, +2200461, +-465686, +394986, +24103317, +-9455862, +5119991, +-2777199, +1147245, +21129473, +-7842294, +12120379, +-10198160, +3631544, +17411837, +-6188384, +28834234, +-31647135, +11337795, +12924960, +-4672638, +68037766, +-88974388, +33477255, +7752680, +-3516098, +157369944, +-232063160, +92282129, +2113926, +-2925624, +353720112, +-567427144, +237164112, +-3659993, +-3019871, +769091151, +-1309871949, +570539430, +-9202114, +-3779302, +66791, +121706, +55888, +30571245, +-14038415, +120426, +212178, +94820, +29559679, +-13209886, +217130, +365165, +157610, +28215554, +-12178243, +391489, +617016, +255010, +26442131, +-10928431, +705862, +1015147, +398457, +24128430, +-9470680, +1272682, +1605251, +596102, +21161334, +-7858153, +2294668, +2386833, +848523, +17451072, +-6203880, +4137327, +3198789, +1155536, +12971362, +-4685798, +7459675, +3470266, +1567219, +7804818, +-3524761, +13449926, +1738911, +2347406, +2169089, +-2928116, +24250455, +-5211241, +4358971, +-3605298, +-3015671, +43724001, +-23849570, +9823315, +-9151253, +-3769277, +78835150, +-66542375, +23686373, +-14161143, +-5040790, +142141173, +-156324261, +56024234, +-18451275, +-6612656, +256283057, +-335606326, +126341244, +-21970004, +-8270755, +16777216, +33554432, +16777216, +-33554432, +-16777216, +16777216, +33554432, +16777216, +-33554432, +-16777216, +16777216, +33554432, +16777216, +-33554432, +-16777216, +16777216, +33554432, +16777216, +-33554432, +-16777216, +16777216, +33554432, +16777216, +-33554432, +-16777216, +16777216, +33554432, +16777216, +-33554432, +-16777216, +16777216, +33554432, +16777216, +-33554432, +-16777216, +16777216, +33554432, +16777216, +-33554432, +-16777216, +16777216, +33554432, +16777216, +-33554432, +-16777216, +16777216, +33554432, +16777216, +-33554432, +-16777216, +16777216, +33554432, +16777216, +-33554432, +-16777216, +16777216, +33554432, +16777216, +-33554432, +-16777216, +16777216, +33554432, +16777216, +-33554432, +-16777216, +16777216, +33554432, +16777216, +-33554432, +-16777216, +16777216, +33554432, +16777216, +-33554432, +-16777216, diff --git a/media/libeffects/testlibs/AudioLowShelfFilterCoef.inl b/media/libeffects/testlibs/AudioLowShelfFilterCoef.inl new file mode 100644 index 0000000..b57deb4 --- /dev/null +++ b/media/libeffects/testlibs/AudioLowShelfFilterCoef.inl @@ -0,0 +1,375 @@ +16212506, +-32420574, +16208068, +32401411, +-15662521, +16356129, +-32706246, +16350118, +32695525, +-15939752, +16464399, +-32920670, +16456274, +32914686, +-16149441, +16546128, +-33081289, +16535165, +33077955, +-16307411, +16608101, +-33201422, +16593328, +33199569, +-16426067, +16655539, +-33291174, +16635647, +33290147, +-16514997, +16692478, +-33358171, +16665715, +33357608, +-16581540, +16722089, +-33408149, +16686099, +33407850, +-16631271, +16746930, +-33445409, +16698549, +33445267, +-16668405, +16769156, +-33473168, +16704138, +33473133, +-16696114, +16790706, +-33493827, +16703348, +33493886, +-16716779, +16813466, +-33509166, +16696111, +33509342, +-16732186, +16839437, +-33520498, +16681802, +33520852, +-16743669, +16870911, +-33528765, +16659191, +33529424, +-16752226, +16910681, +-33534607, +16626337, +33535807, +-16758602, +15667401, +-31326224, +15658825, +31252161, +-14623074, +15945865, +-31880007, +15934146, +31838205, +-15144597, +16157521, +-32299091, +16141578, +32275604, +-15545369, +16318267, +-32614903, +16296651, +32601755, +-15850850, +16440710, +-32852157, +16411473, +32844820, +-16082303, +16534751, +-33029985, +16495281, +33025910, +-16256891, +16608171, +-33163043, +16554957, +33160803, +-16388152, +16667145, +-33262468, +16595477, +33261275, +-16486599, +16716699, +-33336671, +16620252, +33336105, +-16560301, +16761100, +-33391976, +16631379, +33391836, +-16615404, +16804207, +-33433103, +16629806, +33433341, +-16656560, +16849794, +-33463551, +16615399, +33464251, +-16687277, +16901887, +-33485857, +16586933, +33487271, +-16710189, +16965125, +-33501781, +16542000, +33504415, +-16727274, +17045198, +-33512384, +16476824, +33517183, +-16740008, +14635201, +-29254376, +14619184, +28977711, +-12753834, +15157556, +-30292825, +15135285, +30133938, +-13674513, +15561511, +-31092298, +15530817, +31001860, +-14405551, +15872211, +-31702342, +15830187, +31651218, +-14976306, +16111094, +-32164834, +16053843, +32136101, +-15416453, +16295848, +-32513802, +16218140, +32497757, +-15752817, +16440852, +-32776179, +16335665, +32767326, +-16008155, +16557804, +-32972907, +16415715, +32968179, +-16201031, +16656403, +-33120052, +16464758, +33117802, +-16346195, +16745001, +-33229805, +16486810, +33229247, +-16455153, +16831240, +-33311306, +16483692, +33312252, +-16536771, +16922682, +-33371278, +16455145, +33374070, +-16597819, +17027472, +-33414465, +16398818, +33420110, +-16643430, +17155108, +-33443875, +16310110, +33454398, +-16677479, +17317384, +-33460760, +16181887, +33479933, +-16702882, +12792703, +-25557388, +12764716, +24590507, +-9747085, +13706465, +-27372621, +13666215, +26798296, +-11169790, +14439425, +-28821830, +14382518, +28486469, +-12380088, +15018453, +-29957273, +14939030, +29764018, +-13373522, +15472460, +-30834757, +15362688, +30724568, +-14168120, +15828725, +-31506123, +15678118, +31443928, +-14791822, +16111406, +-32015988, +15905901, +31981391, +-15274688, +16341329, +-32400984, +16062061, +32382398, +-15644761, +16536484, +-32690238, +16158133, +32681354, +-15926286, +16712853, +-32906337, +16201432, +32904128, +-16139278, +16885430, +-33066336, +16195306, +33070090, +-16299767, +17069377, +-33182599, +16139282, +33193711, +-16420332, +17281371, +-33263294, +16029039, +33285785, +-16510702, +17541271, +-33312390, +15856243, +33354359, +-16578329, +17874330, +-33328902, +15608287, +33405430, +-16628873, +9881279, +-19719268, +9838084, +16734303, +-5927111, +11264857, +-22463447, +11198784, +20577584, +-7572288, +12460736, +-24823046, +12362697, +23667359, +-9201903, +13459805, +-26776851, +13317799, +26085683, +-10691555, +14276287, +-28349256, +14074406, +27943899, +-11978834, +14936943, +-29588248, +14654011, +29354533, +-13047453, +15473300, +-30549299, +15081036, +30417203, +-13909216, +15917271, +-31285788, +15377817, +31213972, +-14589687, +16299384, +-31844320, +15562006, +31809683, +-15118811, +16648774, +-32262999, +15645414, +32254329, +-15525641, +16994277, +-32571090, +15633607, +32585895, +-15835862, +17366374, +-32789019, +15525801, +32833003, +-16070975, +17799955, +-32927834, +15314895, +33017107, +-16248361, +18338206, +-32987318, +14987686, +33154246, +-16381747, +19038270, +-32951545, +14525592, +33256392, +-16481800, diff --git a/media/libeffects/testlibs/AudioPeakingFilter.cpp b/media/libeffects/testlibs/AudioPeakingFilter.cpp new file mode 100644 index 0000000..60fefe6 --- /dev/null +++ b/media/libeffects/testlibs/AudioPeakingFilter.cpp @@ -0,0 +1,121 @@ +/* //device/include/server/AudioFlinger/AudioPeakingFilter.cpp + ** + ** Copyright 2007, The Android Open Source Project + ** + ** Licensed under the Apache License, Version 2.0 (the "License"); + ** you may not use this file except in compliance with the License. + ** You may obtain a copy of the License at + ** + ** http://www.apache.org/licenses/LICENSE-2.0 + ** + ** Unless required by applicable law or agreed to in writing, software + ** distributed under the License is distributed on an "AS IS" BASIS, + ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ** See the License for the specific language governing permissions and + ** limitations under the License. + */ + +#include "AudioPeakingFilter.h" +#include "AudioCommon.h" +#include "EffectsMath.h" + +#include +#include + +#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) +#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) + +namespace android { +// Format of the coefficient table: +// kCoefTable[freq][gain][bw][coef] +// freq - peak frequency, in octaves below Nyquist,from -9 to -1. +// gain - gain, in millibel, starting at -9600, jumps of 1024, to 4736 millibel. +// bw - bandwidth, starting at 1 cent, jumps of 1024, to 3073 cents. +// coef - 0: b0 +// 1: b1 +// 2: b2 +// 3: -a1 +// 4: -a2 +static const size_t kInDims[3] = {9, 15, 4}; +static const audio_coef_t kCoefTable[9*15*4*5] = { +#include "AudioPeakingFilterCoef.inl" +}; + +AudioCoefInterpolator AudioPeakingFilter::mCoefInterp(3, kInDims, 5, (const audio_coef_t*) kCoefTable); + +AudioPeakingFilter::AudioPeakingFilter(int nChannels, int sampleRate) + : mBiquad(nChannels, sampleRate) { + configure(nChannels, sampleRate); + reset(); +} + +void AudioPeakingFilter::configure(int nChannels, int sampleRate) { + mNiquistFreq = sampleRate * 500; + mFrequencyFactor = ((1ull) << 42) / mNiquistFreq; + mBiquad.configure(nChannels, sampleRate); + setFrequency(mNominalFrequency); + commit(true); +} + +void AudioPeakingFilter::reset() { + setGain(0); + setFrequency(0); + setBandwidth(2400); + commit(true); +} + +void AudioPeakingFilter::setFrequency(uint32_t millihertz) { + mNominalFrequency = millihertz; + if (UNLIKELY(millihertz > mNiquistFreq / 2)) { + millihertz = mNiquistFreq / 2; + } + uint32_t normFreq = static_cast( + (static_cast(millihertz) * mFrequencyFactor) >> 10); + if (LIKELY(normFreq > (1 << 23))) { + mFrequency = (Effects_log2(normFreq) - ((32-9) << 15)) << (FREQ_PRECISION_BITS - 15); + } else { + mFrequency = 0; + } +} + +void AudioPeakingFilter::setGain(int32_t millibel) { + mGain = millibel + 9600; +} + +void AudioPeakingFilter::setBandwidth(uint32_t cents) { + mBandwidth = cents - 1; +} + +void AudioPeakingFilter::commit(bool immediate) { + audio_coef_t coefs[5]; + int intCoord[3] = { + mFrequency >> FREQ_PRECISION_BITS, + mGain >> GAIN_PRECISION_BITS, + mBandwidth >> BANDWIDTH_PRECISION_BITS + }; + uint32_t fracCoord[3] = { + mFrequency << (32 - FREQ_PRECISION_BITS), + static_cast(mGain) << (32 - GAIN_PRECISION_BITS), + mBandwidth << (32 - BANDWIDTH_PRECISION_BITS) + }; + mCoefInterp.getCoef(intCoord, fracCoord, coefs); + mBiquad.setCoefs(coefs, immediate); +} + +void AudioPeakingFilter::getBandRange(uint32_t & low, uint32_t & high) const { + // Half bandwidth, in octaves, 15-bit precision + int32_t halfBW = (((mBandwidth + 1) / 2) << 15) / 1200; + + low = static_cast((static_cast(mNominalFrequency) * Effects_exp2(-halfBW + (16 << 15))) >> 16); + if (UNLIKELY(halfBW >= (16 << 15))) { + high = mNiquistFreq; + } else { + high = static_cast((static_cast(mNominalFrequency) * Effects_exp2(halfBW + (16 << 15))) >> 16); + if (UNLIKELY(high > mNiquistFreq)) { + high = mNiquistFreq; + } + } +} + +} + diff --git a/media/libeffects/testlibs/AudioPeakingFilter.h b/media/libeffects/testlibs/AudioPeakingFilter.h new file mode 100644 index 0000000..d0f49c9 --- /dev/null +++ b/media/libeffects/testlibs/AudioPeakingFilter.h @@ -0,0 +1,151 @@ +/* //device/include/server/AudioFlinger/AudioPeakingFilter.h +** +** Copyright 2009, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +#ifndef ANDROID_AUDIO_PEAKING_FILTER_H +#define ANDROID_AUDIO_PEAKING_FILTER_H + +#include "AudioBiquadFilter.h" +#include "AudioCoefInterpolator.h" + +namespace android { + +// A peaking audio filter, with unity skirt gain, and controllable peak +// frequency, gain and bandwidth. +// This filter is able to suppress introduce discontinuities and other artifacts +// in the output, even when changing parameters abruptly. +// Parameters can be set to any value - this class will make sure to clip them +// when they are out of supported range. +// +// Implementation notes: +// This class uses an underlying biquad filter whose parameters are determined +// using a linear interpolation from a coefficient table, using a +// AudioCoefInterpolator. +// All is left for this class to do is mapping between high-level parameters to +// fractional indices into the coefficient table. +class AudioPeakingFilter { +public: + // Constructor. Resets the filter (see reset()). + // nChannels Number of input/output channels (interlaced). + // sampleRate The input/output sample rate, in Hz. + AudioPeakingFilter(int nChannels, int sampleRate); + + // Reconfiguration of the filter. Changes input/output format, but does not + // alter current parameter values. Clears delay lines. + // nChannels Number of input/output channels (interlaced). + // sampleRate The input/output sample rate, in Hz. + void configure(int nChannels, int sampleRate); + + // Resets the filter parameters to the following values: + // frequency: 0 + // gain: 0 + // bandwidth: 1200 cents. + // It also disables the filter. Does not clear the delay lines. + void reset(); + + // Clears delay lines. Does not alter parameter values. + void clear() { mBiquad.clear(); } + + // Sets gain value. Actual change will only take place upon commit(). + // This value will be remembered even if the filter is in disabled() state. + // millibel Gain value in millibel (1/100 of decibel). + void setGain(int32_t millibel); + + // Gets the gain, in millibel, as set. + int32_t getGain() const { return mGain - 9600; } + + // Sets bandwidth value. Actual change will only take place upon commit(). + // This value will be remembered even if the filter is in disabled() state. + // cents Bandwidth value in cents (1/1200 octave). + void setBandwidth(uint32_t cents); + + // Gets the gain, in cents, as set. + uint32_t getBandwidth() const { return mBandwidth + 1; } + + // Sets frequency value. Actual change will only take place upon commit(). + // This value will be remembered even if the filter is in disabled() state. + // millihertz Frequency value in mHz. + void setFrequency(uint32_t millihertz); + + // Gets the frequency, in mHz, as set. + uint32_t getFrequency() const { return mNominalFrequency; } + + // Gets gain[dB]/2 points. + // Results in mHz, and are computed based on the nominal values set, not on + // possibly rounded or truncated actual values. + void getBandRange(uint32_t & low, uint32_t & high) const; + + // Applies all parameter changes done to this point in time. + // If the filter is disabled, the new parameters will take place when it is + // enabled again. Does not introduce artifacts, unless immediate is set. + // immediate Whether to apply change abruptly (ignored if filter is + // disabled). + void commit(bool immediate = false); + + // Process a buffer of input data. The input and output should contain + // frameCount * nChannels interlaced samples. Processing can be done + // in-place, by passing the same buffer as both arguments. + // in Input buffer. + // out Output buffer. + // frameCount Number of frames to produce. + void process(const audio_sample_t in[], audio_sample_t out[], + int frameCount) { mBiquad.process(in, out, frameCount); } + + // Enables the filter, so it would start processing input. Does not + // introduce artifacts, unless immediate is set. + // immediate Whether to apply change abruptly. + void enable(bool immediate = false) { mBiquad.enable(immediate); } + + // Disabled (bypasses) the filter. Does not introduce artifacts, unless + // immediate is set. + // immediate Whether to apply change abruptly. + void disable(bool immediate = false) { mBiquad.disable(immediate); } + +private: + // Precision for the mFrequency member. + static const int FREQ_PRECISION_BITS = 26; + // Precision for the mGain member. + static const int GAIN_PRECISION_BITS = 10; + // Precision for the mBandwidth member. + static const int BANDWIDTH_PRECISION_BITS = 10; + + // Nyquist, in mHz. + uint32_t mNiquistFreq; + // Fractional index into the gain dimension of the coef table in + // GAIN_PRECISION_BITS precision. + int32_t mGain; + // Fractional index into the bandwidth dimension of the coef table in + // BANDWIDTH_PRECISION_BITS precision. + uint32_t mBandwidth; + // Fractional index into the frequency dimension of the coef table in + // FREQ_PRECISION_BITS precision. + uint32_t mFrequency; + // Nominal value of frequency, as set. + uint32_t mNominalFrequency; + // 1/Nyquist[mHz], in 42-bit precision (very small). + // Used for scaling the frequency. + uint32_t mFrequencyFactor; + + // A biquad filter, used for the actual processing. + AudioBiquadFilter mBiquad; + // A coefficient interpolator, used for mapping the high level parameters to + // the low-level biquad coefficients. + static AudioCoefInterpolator mCoefInterp; +}; + +} + +#endif // ANDROID_AUDIO_PEAKING_FILTER_H diff --git a/media/libeffects/testlibs/AudioPeakingFilterCoef.inl b/media/libeffects/testlibs/AudioPeakingFilterCoef.inl new file mode 100644 index 0000000..374c6e1 --- /dev/null +++ b/media/libeffects/testlibs/AudioPeakingFilterCoef.inl @@ -0,0 +1,2700 @@ +16769751, +-33538871, +16769751, +33538871, +-16762286, +11468083, +-22935566, +11467915, +22935566, +-6158781, +8532673, +-17064763, +8532412, +17064763, +-287869, +6567366, +-13134160, +6567042, +13134160, +3642808, +16773075, +-33545518, +16773075, +33545518, +-16768934, +13349658, +-26698459, +13349304, +26698459, +-9921746, +10923581, +-21846147, +10922977, +21846147, +-5069342, +9009390, +-18017641, +9008590, +18017641, +-1240764, +16774919, +-33549207, +16774919, +33549207, +-16772622, +14686150, +-29371047, +14685450, +29371047, +-12594384, +12933736, +-25865697, +12932448, +25865697, +-9088968, +11350364, +-22698482, +11348545, +22698482, +-5921693, +16775943, +-33551252, +16775941, +33551252, +-16774668, +15549746, +-31097569, +15548408, +31097569, +-14320938, +14404163, +-28805197, +14401577, +28805197, +-12028524, +13261978, +-26519626, +13258147, +26519626, +-9742909, +16776511, +-33552387, +16776508, +33552387, +-16775803, +16074349, +-32145600, +16071856, +32145600, +-15368989, +15374244, +-30742933, +15369268, +30742933, +-13966296, +14629431, +-29250695, +14621814, +29250695, +-12474030, +16776826, +-33553017, +16776822, +33553017, +-16776432, +16381548, +-32757900, +16376968, +32757900, +-15981300, +15972161, +-31934402, +15962842, +31934402, +-15157787, +15518882, +-31022614, +15504316, +31022614, +-14245982, +16777003, +-33553366, +16776995, +33553366, +-16776781, +16558315, +-33107660, +16549969, +33107660, +-16331067, +16326848, +-32635910, +16309677, +32635910, +-15859308, +16064456, +-32101133, +16037281, +32101133, +-15324521, +16777103, +-33553559, +16777088, +33553559, +-16776975, +16660325, +-33304885, +16645187, +33304885, +-16528296, +16535200, +-33038436, +16503858, +33038436, +-16261842, +16391425, +-32732273, +16341464, +32732273, +-15955673, +16777162, +-33553667, +16777136, +33553667, +-16777082, +16721651, +-33415288, +16694267, +33415288, +-16638701, +16661761, +-33265997, +16604862, +33265997, +-16489407, +16592417, +-33093137, +16501343, +33093137, +-16316544, +16777203, +-33553726, +16777155, +33553726, +-16777142, +16763466, +-33476836, +16714001, +33476836, +-16700251, +16748588, +-33393565, +16645605, +33393565, +-16616978, +16731288, +-33296733, +16566071, +33296733, +-16520144, +16777238, +-33553759, +16777152, +33553759, +-16777175, +16800489, +-33511071, +16711212, +33511071, +-16734485, +16825723, +-33464740, +16639647, +33464740, +-16688154, +16855137, +-33410736, +16556228, +33410736, +-16634149, +16777282, +-33553778, +16777127, +33553778, +-16777193, +16845889, +-33530088, +16684830, +33530088, +-16753503, +16920437, +-33504347, +16584541, +33504347, +-16727762, +17007449, +-33474302, +16467484, +33474302, +-16697716, +16777349, +-33553788, +16777070, +33553788, +-16777203, +16915880, +-33540645, +16625396, +33540645, +-16764060, +17066504, +-33526354, +16460481, +33526354, +-16749769, +17242444, +-33509662, +16267849, +33509662, +-16733077, +16777464, +-33553793, +16776961, +33553793, +-16777209, +17035487, +-33546503, +16511647, +33546503, +-16769918, +17316137, +-33538572, +16223067, +33538572, +-16761988, +17644089, +-33529306, +15885848, +33529306, +-16752721, +16777668, +-33553796, +16776760, +33553796, +-16777212, +17247484, +-33549752, +16302900, +33549752, +-16773168, +17758603, +-33545353, +15787381, +33545353, +-16768768, +18356007, +-33540211, +15184835, +33540211, +-16763626, +16762293, +-33522062, +16762293, +33522062, +-16747370, +8711405, +-17421242, +8711149, +17421242, +-645338, +5721250, +-11441288, +5720900, +11441288, +5335066, +4082836, +-8164655, +4082434, +8164655, +8611946, +16768936, +-33535347, +16768936, +33535347, +-16760656, +11085056, +-22167856, +11084469, +22167856, +-5392309, +8098223, +-16194333, +8097329, +16194333, +581664, +6158323, +-12314623, +6157228, +12314623, +4461665, +16772623, +-33542719, +16772622, +33542719, +-16768029, +13058634, +-26114055, +13057388, +26114055, +-9338806, +10523211, +-21042742, +10521116, +21042742, +-4267110, +8576560, +-17149081, +8573812, +17149081, +-373156, +16774670, +-33546810, +16774667, +33546810, +-16772120, +14489725, +-28974776, +14487233, +28974776, +-12199742, +12619509, +-25232587, +12614979, +25232587, +-8457271, +10965151, +-21922319, +10958818, +21922319, +-5146753, +16775805, +-33549079, +16775800, +33549079, +-16774390, +15428102, +-30849095, +15423317, +30849095, +-14074202, +14188157, +-28364996, +14178975, +28364996, +-11589916, +12969900, +-25924346, +12956398, +25924346, +-9149082, +16776437, +-33550338, +16776428, +33550338, +-16775648, +16004216, +-31997074, +15995268, +31997074, +-15222267, +15241233, +-30462393, +15223454, +30462393, +-13687471, +14437070, +-28844880, +14409982, +28844880, +-12069836, +16776789, +-33551036, +16776773, +33551036, +-16776347, +16345158, +-32671383, +16328685, +32671383, +-15896627, +15900462, +-31765104, +15867034, +31765104, +-14990280, +15410846, +-30767279, +15358750, +30767279, +-13992380, +16776990, +-33551423, +16776960, +33551423, +-16776734, +16545156, +-33057769, +16515103, +33057769, +-16283043, +16300504, +-32536823, +16238769, +32536823, +-15762058, +16024071, +-31948201, +15926537, +31948201, +-15173391, +16777109, +-33551638, +16777056, +33551638, +-16776949, +16666542, +-33276035, +16611999, +33276035, +-16501325, +16548270, +-32981225, +16435439, +32981225, +-16206493, +16412621, +-32643103, +16232940, +32643103, +-15868346, +16777189, +-33551757, +16777094, +33551757, +-16777068, +16749778, +-33398338, +16651075, +33398338, +-16623637, +16720233, +-33232976, +16515245, +33232976, +-16458262, +16686059, +-33041706, +16358135, +33041706, +-16266978, +16777261, +-33551823, +16777089, +33551823, +-16777134, +16823703, +-33466559, +16645376, +33466559, +-16691863, +16873974, +-33374267, +16502806, +33374267, +-16599564, +16932398, +-33267006, +16337114, +33267006, +-16492295, +16777348, +-33551860, +16777038, +33551860, +-16777170, +16914465, +-33504517, +16592574, +33504517, +-16729824, +17063236, +-33453150, +16392432, +33453150, +-16678453, +17236595, +-33393293, +16159213, +33393293, +-16618592, +16777483, +-33551880, +16776924, +33551880, +-16777191, +17054436, +-33525606, +16473695, +33525606, +-16750914, +17355321, +-33497061, +16144262, +33497061, +-16722367, +17706453, +-33463749, +15759816, +33463749, +-16689053, +16777713, +-33551891, +16776705, +33551891, +-16777202, +17293646, +-33537314, +16246194, +33537314, +-16762623, +17854571, +-33521465, +15669419, +33521465, +-16746773, +18509706, +-33502954, +14995772, +33502954, +-16728261, +16778120, +-33551898, +16776304, +33551898, +-16777208, +17717639, +-33543811, +15828698, +33543811, +-16769121, +18739501, +-33535016, +14798040, +33535016, +-16760325, +19933534, +-33524738, +13593729, +33524738, +-16750047, +16747397, +-33484705, +16747396, +33484705, +-16717577, +5883112, +-11762335, +5882767, +11762335, +5011337, +3448701, +-6894903, +3448279, +6894903, +9880236, +2324286, +-4646714, +2323828, +4646714, +12129102, +16760665, +-33511232, +16760663, +33511232, +-16744112, +8276984, +-16548106, +8276108, +16548106, +224124, +5337400, +-10670406, +5336221, +10670406, +6103596, +3771525, +-7539439, +3770185, +7539439, +9235506, +16768033, +-33525963, +16768030, +33525963, +-16758848, +10689564, +-21370649, +10687524, +21370649, +-4599872, +7666068, +-15324466, +7663015, +15324466, +1448133, +5761266, +-11515371, +5757575, +11515371, +5258376, +16772124, +-33534139, +16772118, +33534139, +-16767026, +12751423, +-25490780, +12747036, +25490780, +-8721243, +10113942, +-20214533, +10106682, +20214533, +-3443407, +8145025, +-16275741, +8135620, +16275741, +496571, +16774395, +-33538675, +16774385, +33538675, +-16771564, +14280137, +-28542819, +14271281, +28542819, +-11774202, +12292391, +-24561476, +12276485, +24561476, +-7791660, +10572949, +-21117532, +10550945, +21117532, +-4346678, +16775657, +-33541192, +16775639, +33541192, +-16774081, +15299683, +-30573051, +15282579, +30573051, +-13805046, +13964251, +-27887539, +13931690, +27887539, +-11118724, +12672686, +-25290241, +12625174, +25290241, +-8520644, +16776363, +-33542588, +16776330, +33542588, +-16775477, +15935196, +-31828699, +15903092, +31828699, +-15061072, +15112356, +-30152153, +15048881, +30152153, +-13384021, +14253857, +-28402950, +14157649, +28402950, +-11634291, +16776763, +-33543362, +16776704, +33543362, +-16776252, +16319830, +-32570615, +16260598, +32570615, +-15803212, +15851783, +-31574208, +15731938, +31574208, +-14806505, +15339614, +-30483871, +15153441, +30483871, +-13715838, +16777001, +-33543791, +16776896, +33543791, +-16776681, +16557673, +-32997208, +16449476, +32997208, +-16229933, +16326977, +-32422299, +16105089, +32422299, +-15654851, +16067244, +-31775024, +15717353, +31775024, +-15007381, +16777163, +-33544029, +16776972, +33544029, +-16776919, +16722590, +-33238660, +16526083, +33238660, +-16471458, +16664322, +-32912610, +16258203, +32912610, +-16145310, +16597629, +-32539419, +15951593, +32539419, +-15772007, +16777306, +-33544162, +16776962, +33544162, +-16777051, +16869955, +-33374105, +16514205, +33374105, +-16606944, +16969714, +-33190996, +16231282, +33190996, +-16423780, +17084972, +-32979442, +15904406, +32979442, +-16212162, +16777480, +-33544235, +16776860, +33544235, +-16777125, +17051328, +-33449703, +16408452, +33449703, +-16682565, +17347583, +-33347437, +16009901, +33347437, +-16580267, +17691668, +-33228659, +15547002, +33228659, +-16461454, +16777750, +-33544275, +16776632, +33544275, +-16777165, +17331222, +-33491780, +16170648, +33491780, +-16724654, +17931550, +-33434840, +15513363, +33434840, +-16667697, +18630855, +-33368512, +14747710, +33368512, +-16601349, +16778210, +-33544298, +16776194, +33544298, +-16777188, +17809628, +-33515162, +15715631, +33515162, +-16748043, +18929991, +-33483514, +14563611, +33483514, +-16716385, +20237212, +-33446587, +13219451, +33446587, +-16679448, +16779025, +-33544310, +16775392, +33544310, +-16777200, +18657612, +-33528145, +14880634, +33528145, +-16761030, +20699844, +-33510571, +12820822, +33510571, +-16743451, +23084863, +-33490047, +10415274, +33490047, +-16722921, +16717684, +-33395091, +16717682, +33395091, +-16658149, +3567009, +-7125006, +3566590, +7125006, +9643617, +1921926, +-3838751, +1921455, +3838751, +12933835, +1248662, +-2493824, +1248170, +2493824, +14280384, +16744147, +-33447952, +16744143, +33447952, +-16711074, +5493785, +-10973174, +5492622, +10973174, +5790808, +3173694, +-6338342, +3172292, +6338342, +10431230, +2124754, +-4242881, +2123244, +4242881, +12529218, +16758861, +-33477342, +16758855, +33477342, +-16740500, +7843885, +-15665884, +7840892, +15665884, +1092439, +4968649, +-9921376, +4964692, +9921376, +6843875, +3478437, +-6944043, +3473981, +6944043, +9824798, +16767035, +-33493665, +16767024, +33493665, +-16756842, +10284421, +-20536999, +10277346, +20536999, +-3784550, +7240254, +-14452686, +7229862, +14452686, +2307100, +5379798, +-10734231, +5367379, +10734231, +6030039, +16771575, +-33502725, +16771555, +33502725, +-16765913, +12431046, +-24816749, +12415632, +24816749, +-8069462, +9702049, +-19355664, +9676957, +19355664, +-2601790, +7722611, +-15394544, +7690499, +15394544, +1364106, +16774099, +-33507752, +16774063, +33507752, +-16770946, +14062583, +-28059903, +14031160, +28059903, +-11316527, +11962999, +-23841519, +11907273, +23841519, +-7093056, +10188929, +-20277142, +10112667, +20277142, +-3524380, +16775510, +-33510541, +16775445, +33510541, +-16773738, +15175102, +-30252637, +15114019, +30252637, +-13511905, +13753207, +-27358123, +13637911, +27358123, +-10613901, +12400971, +-24605416, +12234119, +24605416, +-7857874, +16776310, +-33512088, +16776193, +33512088, +-16775287, +15888242, +-31623221, +15773117, +31623221, +-14884143, +15028972, +-29795608, +14802570, +29795608, +-13054325, +14142237, +-27909578, +13801000, +27909578, +-11166021, +16776787, +-33512946, +16776575, +33512946, +-16776146, +16345172, +-32438302, +16132251, +32438302, +-15700207, +15905856, +-31344484, +15476429, +31344484, +-14605069, +15428324, +-30155514, +14763558, +30155514, +-13414665, +16777110, +-33513422, +16776729, +33513422, +-16776623, +16668950, +-32908744, +16279482, +32908744, +-16171216, +16555594, +-32275015, +15758344, +32275015, +-15536722, +16428465, +-31564284, +15173886, +31564284, +-14825134, +16777395, +-33513686, +16776708, +33513686, +-16776887, +16961758, +-33175594, +16253845, +33175594, +-16438387, +17158212, +-32815329, +15696692, +32815329, +-16077688, +17382578, +-32403880, +15060381, +32403880, +-15665743, +16777745, +-33513832, +16776505, +33513832, +-16777033, +17323903, +-33325470, +16041757, +33325470, +-16588444, +17911332, +-33122874, +15251488, +33122874, +-16385604, +18589203, +-32889086, +14339546, +32889086, +-16151534, +16778283, +-33513913, +16776048, +33513913, +-16777115, +17883505, +-33409180, +15565966, +33409180, +-16672255, +19078451, +-33295944, +14257648, +33295944, +-16558883, +20465440, +-33164510, +12739067, +33164510, +-16427290, +16779203, +-33513958, +16775173, +33513958, +-16777160, +18840265, +-33455789, +14655871, +33455789, +-16718921, +21075121, +-33392715, +12357866, +33392715, +-16655771, +23677621, +-33319266, +9681828, +33319266, +-16582233, +16780834, +-33513983, +16773567, +33513983, +-16777185, +20536227, +-33481696, +12985848, +33481696, +-16744859, +24614855, +-33446630, +8872112, +33446630, +-16709751, +29373075, +-33405721, +4072934, +33405721, +-16668793, +16658572, +-33156710, +16658568, +33156710, +-16539925, +1995694, +-3971702, +1995225, +3971702, +12786296, +1019334, +-2028355, +1018835, +2028355, +14739047, +648397, +-1290041, +647886, +1290041, +15480933, +16711208, +-33261470, +16711201, +33261470, +-16645192, +3284873, +-6536727, +3283483, +6536727, +10208860, +1752746, +-3487071, +1751198, +3487071, +13273272, +1134254, +-2255981, +1132642, +2255981, +14510319, +16740546, +-33319859, +16740534, +33319859, +-16703864, +5119019, +-10184853, +5115113, +10184853, +6543083, +2916766, +-5800820, +2912122, +5800820, +10948329, +1940950, +-3858260, +1935979, +3858260, +12900288, +16756866, +-33352332, +16756844, +33352332, +-16736493, +7416141, +-14750709, +7405941, +14750709, +1955134, +4618132, +-9178604, +4604884, +9178604, +7554200, +3205731, +-6365873, +3190944, +6365873, +10380541, +16765937, +-33370369, +16765897, +33370369, +-16754618, +9875714, +-19631961, +9851238, +19631961, +-2949736, +6828874, +-13556870, +6793592, +13556870, +3154751, +5021920, +-9953987, +4980230, +9953987, +6775066, +16770983, +-33380381, +16770911, +33380381, +-16764679, +12107731, +-24045066, +12053679, +24045066, +-7384194, +9304697, +-18433704, +9218200, +18433704, +-1745681, +7330173, +-14480925, +7220819, +14480925, +2226224, +16773804, +-33385937, +16773674, +33385937, +-16770261, +13857067, +-27469883, +13745731, +27469883, +-10825583, +11667230, +-23028209, +11472403, +23028209, +-6362417, +9861509, +-19365642, +9597835, +19365642, +-2682128, +16775405, +-33389019, +16775170, +33389019, +-16773358, +15094166, +-29826057, +14876207, +29826057, +-13193157, +13629575, +-26722225, +13221948, +26722225, +-10074307, +12261304, +-23822520, +11676482, +23822520, +-7160571, +16776358, +-33390729, +16775935, +33390729, +-16775076, +15939973, +-31315809, +15527360, +31315809, +-14690117, +15140254, +-29331850, +14333520, +29331850, +-12696558, +14324552, +-27308240, +13115821, +27308240, +-10663157, +16777004, +-33391677, +16776241, +33391677, +-16776029, +16564519, +-32208051, +15799374, +32208051, +-15586676, +16349720, +-31011538, +14811870, +31011538, +-14384374, +16117884, +-29720119, +13746038, +29720119, +-13086705, +16777574, +-33392203, +16776199, +33392203, +-16776558, +17142623, +-32725183, +15740903, +32725183, +-16106310, +17523746, +-32028793, +14660021, +32028793, +-15406551, +17949452, +-31250941, +13452699, +31250941, +-14624935, +16778273, +-33392495, +16775794, +33392495, +-16776851, +17864511, +-33019221, +15314476, +33019221, +-16401771, +19019582, +-32622294, +13760557, +32622294, +-16002923, +20335886, +-32169961, +11989731, +32169961, +-15548401, +16779350, +-33392657, +16774879, +33392657, +-16777014, +18982972, +-33184592, +14362186, +33184592, +-16567942, +21350554, +-32961046, +11769976, +32961046, +-16343314, +24079688, +-32703362, +8781912, +32703362, +-16084383, +16781190, +-33392746, +16773130, +33392746, +-16777104, +20896303, +-33277026, +12541737, +33277026, +-16660824, +25343199, +-33151977, +7969185, +33151977, +-16535169, +30502384, +-33006896, +2664219, +33006896, +-16389387, +16784451, +-33392796, +16769918, +33392796, +-16777154, +24288258, +-33328516, +9201520, +33328516, +-16712562, +32423187, +-33258828, +996567, +33258828, +-16642538, +41895320, +-33177686, +-8557101, +33177686, +-16561003, +16541595, +-32447498, +16541587, +32447498, +-16305966, +1060925, +-2080590, +1060426, +2080590, +14655865, +525478, +-1030256, +524962, +1030256, +15726776, +330321, +-647437, +329800, +647437, +16117095, +16645717, +-32651734, +16645703, +32651734, +-16514203, +1820789, +-3570095, +1819248, +3570095, +13137179, +924575, +-1812018, +922942, +1812018, +14929699, +586684, +-1149186, +585016, +1149186, +15605516, +16704036, +-32766121, +16704011, +32766121, +-16630831, +3020875, +-5921138, +3016266, +5921138, +10740076, +1597573, +-3128764, +1592487, +3128764, +13587156, +1030124, +-2015487, +1024848, +2015487, +14722244, +16736565, +-32829909, +16736521, +32829909, +-16695869, +4762013, +-9328185, +4748922, +9328185, +7266281, +2679566, +-5241091, +2664205, +5241091, +11433446, +1773912, +-3463620, +1757564, +3463620, +13245740, +16754673, +-32865395, +16754593, +32865395, +-16732050, +7001772, +-13700468, +6967104, +13700468, +2808340, +4293363, +-8378312, +4249089, +8378312, +8234764, +2960061, +-5758307, +2911058, +5758307, +10906097, +16764756, +-32885110, +16764611, +32885110, +-16752151, +9480188, +-18513215, +9395722, +18513215, +-2098694, +6453693, +-12542171, +6334194, +12542171, +3989330, +4710641, +-9103264, +4570966, +9103264, +7495609, +16770393, +-32896054, +16770133, +32896054, +-16763310, +11816276, +-22992949, +11627131, +22992949, +-6666191, +8975726, +-17314789, +8678280, +17314789, +-876790, +7032408, +-13430164, +6660869, +13430164, +3083940, +16773593, +-32902127, +16773124, +32902127, +-16769502, +13735615, +-26557052, +13341720, +26557052, +-10300120, +11528165, +-21946606, +10848400, +21946606, +-5599349, +9752563, +-18238110, +8842853, +18238110, +-1818200, +16775499, +-32905496, +16774654, +32905496, +-16772937, +15200588, +-29054957, +14423589, +29054957, +-12846961, +13857004, +-25769995, +12417855, +25769995, +-9497643, +12624453, +-22756500, +10577873, +22756500, +-6425111, +16776792, +-32907365, +16775267, +32907365, +-16774843, +16366344, +-30654089, +14888294, +30654089, +-14477422, +15978753, +-28526295, +13106406, +28526295, +-12307942, +15588057, +-26381456, +11310242, +26381456, +-10121083, +16777933, +-32908402, +16775183, +32908402, +-16775900, +17493802, +-31619287, +14744943, +31619287, +-15461529, +18212414, +-30325234, +12706927, +30325234, +-14142124, +18982725, +-28938081, +10522286, +28938081, +-12727795, +16779330, +-32908977, +16774372, +32908977, +-16776486, +18928041, +-32181280, +13883707, +32181280, +-16034532, +21163118, +-31424334, +10876855, +31424334, +-15262757, +23650871, +-30581814, +7530076, +30581814, +-14403731, +16781484, +-32909296, +16772543, +32909296, +-16776811, +21161996, +-32501674, +11976424, +32501674, +-16361204, +25812009, +-32068975, +6885234, +32068975, +-15920027, +31103385, +-31576594, +1091831, +31576594, +-15418000, +16785164, +-32909473, +16769043, +32909473, +-16776991, +24988064, +-32682139, +8334356, +32682139, +-16545204, +33795794, +-32438043, +-722252, +32438043, +-16296325, +43946128, +-32156738, +-11159403, +32156738, +-16009510, +16791687, +-32909571, +16762620, +32909571, +-16777091, +31772521, +-32783096, +1652834, +32783096, +-16648139, +47961229, +-32646423, +-14675225, +32646423, +-16508788, +66751682, +-32487785, +-33627423, +32487785, +-16347043, +16312500, +-30141556, +16312485, +30141556, +-15847769, +547598, +-1011354, +547084, +1011354, +15682534, +266448, +-491849, +265925, +491849, +16244843, +166111, +-306446, +165584, +306446, +16445521, +16516262, +-30518049, +16516236, +30518049, +-16255282, +962487, +-1776938, +960857, +1776938, +14853872, +474742, +-875656, +473062, +875656, +15829413, +297520, +-548176, +295821, +548176, +16183875, +16631492, +-30730944, +16631443, +30730944, +-16485719, +1660146, +-3062870, +1655081, +3062870, +13461989, +838172, +-1543806, +832831, +1543806, +15106213, +530135, +-974532, +524691, +974532, +15722390, +16696110, +-30850307, +16696022, +30850307, +-16614916, +2776642, +-5116472, +2761387, +5116472, +11239187, +1456845, +-2676477, +1440152, +2676477, +13880219, +936151, +-1713835, +918891, +1713835, +14922174, +16732191, +-30916910, +16732031, +30916910, +-16687006, +4430219, +-8145523, +4386431, +8145523, +7960566, +2467715, +-4512857, +2416966, +4512857, +11892535, +1628113, +-2958725, +1574387, +2958725, +13574716, +16752314, +-30953973, +16752025, +30953973, +-16727123, +6622193, +-12127616, +6504644, +12127616, +3650379, +4016541, +-7285135, +3868831, +7285135, +8891843, +2762675, +-4954883, +2600451, +4954883, +11414089, +16763575, +-30974568, +16763055, +30974568, +-16749415, +9150431, +-16639142, +8859646, +16639142, +-1232861, +6182181, +-11049974, +5778225, +11049974, +4816810, +4518629, +-7917532, +4051247, +7917532, +8207341, +16769973, +-30986002, +16769034, +30986002, +-16761791, +11676269, +-20964630, +11015683, +20964630, +-5914736, +8893418, +-15489638, +7872446, +15489638, +11352, +7041383, +-11845939, +5780568, +11845939, +3955265, +16773783, +-30992347, +16772092, +30992347, +-16768659, +13953280, +-24496534, +12561577, +24496534, +-9737641, +11970921, +-19931025, +9602265, +19931025, +-4795970, +10413172, +-16343421, +7276820, +16343421, +-912775, +16776368, +-30995868, +16773318, +30995868, +-16772470, +16007790, +-27021343, +13239901, +27021343, +-12470475, +15365527, +-23700024, +10287194, +23700024, +-8875505, +14785947, +-20702857, +7622664, +20702857, +-5631395, +16778650, +-30997821, +16773150, +30997821, +-16774583, +18157056, +-28659649, +12863925, +28659649, +-14243764, +19443806, +-26476950, +9214638, +26476950, +-11881228, +20728681, +-24297433, +5570671, +24297433, +-9522136, +16781445, +-30998904, +16771527, +30998904, +-16775756, +20988060, +-29656921, +11112361, +29656921, +-15323204, +25187743, +-28317150, +5462520, +28317150, +-13873047, +29672124, +-26886556, +-570326, +26886556, +-12324582, +16785752, +-30999505, +16767870, +30999505, +-16776406, +25444300, +-30240545, +7287830, +30240545, +-15954914, +34434980, +-29452472, +-2555854, +29452472, +-15101910, +44441242, +-28575379, +-13511474, +28575379, +-14152552, +16793112, +-30999838, +16760871, +30999838, +-16776767, +33095506, +-30574250, +-2177, +30574250, +-16316113, +50408034, +-30122291, +-17803902, +30122291, +-15826917, +70153765, +-29606811, +-38107583, +29606811, +-15268966, +16806158, +-31000023, +16748025, +31000023, +-16776967, +46670155, +-30762526, +-13373037, +30762526, +-16519902, +78789544, +-30507092, +-45768905, +30507092, +-16243423, +115942747, +-30211627, +-83241918, +30211627, +-15923613, +15872835, +-22447559, +15872807, +22447559, +-14968426, +277754, +-392434, +277231, +392434, +16222231, +133061, +-187804, +132533, +187804, +16511622, +81763, +-115256, +81233, +115256, +16614220, +16263303, +-22999746, +16263250, +22999746, +-15749337, +494605, +-698290, +492927, +698290, +15789685, +238776, +-336475, +237071, +336475, +16301369, +147228, +-207000, +145514, +207000, +16484473, +16488278, +-23317877, +16488181, +23317877, +-16199242, +872378, +-1229961, +867049, +1229961, +15037788, +426889, +-599839, +421411, +599839, +15928916, +264840, +-370629, +259308, +370629, +16253068, +16615785, +-23498145, +16615609, +23498145, +-16454179, +1513757, +-2129016, +1497126, +2129016, +13766333, +758261, +-1060001, +740806, +1060001, +15278149, +475551, +-659971, +457789, +659971, +15843875, +16687407, +-23599332, +16687089, +23599332, +-16597280, +2557116, +-3580647, +2506684, +3580647, +11713416, +1332007, +-1845009, +1277230, +1845009, +14167979, +851272, +-1163942, +794791, +1163942, +15131154, +16727486, +-23655830, +16726910, +23655830, +-16677180, +4144749, +-5758163, +3998523, +5758163, +8633944, +2297803, +-3131069, +2130198, +3131069, +12349216, +1516025, +-2019070, +1339371, +2019070, +13921820, +16749957, +-23687282, +16748918, +23687282, +-16721660, +6342807, +-8688774, +5944975, +8688774, +4489434, +3855722, +-5104454, +3363066, +5104454, +9558428, +2678286, +-3407564, +2140738, +3407564, +11958192, +16762736, +-23704762, +16760861, +23704762, +-16746380, +9059948, +-12106014, +8060542, +12106014, +-343274, +6231959, +-7847669, +4866322, +7847669, +5678936, +4678573, +-5508603, +3111768, +5508603, +8986875, +16770353, +-23714468, +16766970, +23714468, +-16760107, +12100768, +-15483427, +9796104, +15483427, +-5119656, +9659401, +-11180047, +6151573, +11180047, +966242, +8066003, +-8371376, +3772911, +8371376, +4938302, +16775520, +-23719855, +16769420, +23719855, +-16767725, +15410647, +-18317794, +10494626, +18317794, +-9128056, +14477439, +-14624233, +6204350, +14624233, +-3904573, +13754127, +-11761419, +2879032, +11761419, +144058, +16780083, +-23722844, +16769084, +23722844, +-16771951, +19348947, +-20387735, +9483664, +20387735, +-12055395, +21467038, +-17637855, +3476656, +17637855, +-8166478, +23369301, +-15168181, +-1918253, +15168181, +-4673832, +16785673, +-23724501, +16765839, +23724501, +-16774296, +24868547, +-21750945, +5891934, +21750945, +-13983265, +32392543, +-19913847, +-4230110, +19913847, +-11385217, +39938641, +-18071353, +-14381888, +18071353, +-8779537, +16794288, +-23725421, +16758525, +23725421, +-16775596, +33739025, +-22588636, +-1793870, +22588636, +-15167940, +50727371, +-21448926, +-20394010, +21448926, +-13556146, +69082218, +-20217540, +-40490298, +20217540, +-11814703, +16809008, +-23725931, +16744526, +23725931, +-16776318, +49053594, +-23081666, +-16411189, +23081666, +-15865189, +82824296, +-22406908, +-51136143, +22406908, +-14910937, +121049915, +-21643138, +-90441895, +21643138, +-13830803, +16835099, +-23726214, +16718835, +23726214, +-16776718, +76261468, +-23364505, +-43219068, +23364505, +-16265184, +140080603, +-22976059, +-107587549, +22976059, +-15715838, +214348557, +-22524014, +-182494791, +22524014, +-15076550, +15060971, +0, +15060916, +0, +-13344671, +137715, +0, +137188, +0, +16502313, +62494, +0, +61964, +0, +16652757, +35499, +0, +34969, +0, +16706748, +15779939, +0, +15779837, +0, +-14782560, +247059, +0, +245356, +0, +16284801, +112726, +0, +111009, +0, +16553481, +64282, +0, +62560, +0, +16650375, +16209124, +0, +16208934, +0, +-15640842, +441483, +0, +436010, +0, +15899723, +203401, +0, +197848, +0, +16375967, +116794, +0, +111212, +0, +16549211, +16457433, +0, +16457085, +0, +-16137302, +783510, +0, +766083, +0, +15227623, +367229, +0, +349349, +0, +16060638, +213457, +0, +195409, +0, +16368349, +16598556, +0, +16597923, +0, +-16419263, +1374332, +0, +1319705, +0, +14083179, +663683, +0, +606536, +0, +15506996, +394077, +0, +335974, +0, +16047166, +16678051, +0, +16676903, +0, +-16577738, +2365010, +0, +2198183, +0, +12214023, +1201479, +0, +1021183, +0, +14554554, +739666, +0, +554025, +0, +15483525, +16722789, +0, +16720714, +0, +-16666287, +3953214, +0, +3464275, +0, +9359728, +2180807, +0, +1624291, +0, +12972118, +1423936, +0, +838564, +0, +14514716, +16748282, +0, +16744535, +0, +-16715601, +6353786, +0, +5003926, +0, +5419504, +3973108, +0, +2314944, +0, +10489165, +2837511, +0, +1032284, +0, +12907421, +16763496, +0, +16756735, +0, +-16743015, +9775978, +0, +6325602, +0, +675636, +7269959, +0, +2584558, +0, +6922698, +5878520, +0, +507384, +0, +10391313, +16773826, +0, +16761629, +0, +-16758239, +14526462, +0, +6429723, +0, +-4178968, +13351086, +0, +1026117, +0, +2400012, +12566846, +0, +-2579306, +0, +6789676, +16782950, +0, +16760954, +0, +-16766688, +21346996, +0, +3817102, +0, +-8386881, +24548257, +0, +-5261828, +0, +-2509212, +27136746, +0, +-12602908, +0, +2243378, +16794129, +0, +16754463, +0, +-16771376, +31942756, +0, +-3625011, +0, +-11540529, +45048673, +0, +-21256423, +0, +-7015034, +57646140, +0, +-38203817, +0, +-2665107, +16811358, +0, +16739835, +0, +-16773977, +49676415, +0, +-19243342, +0, +-13655857, +82339984, +0, +-55005915, +0, +-10556853, +118287496, +0, +-94363999, +0, +-7146281, +16840799, +0, +16711837, +0, +-16775419, +80691383, +0, +-48942961, +0, +-14971206, +149858505, +0, +-120064524, +0, +-13016765, +233520652, +0, +-206090695, +0, +-10652741, +16892981, +0, +16660455, +0, +-16776220, +136000868, +0, +-103472696, +0, +-15750956, +271801469, +0, +-240442250, +0, +-14582003, +446309601, +0, +-416452524, +0, +-13079862, diff --git a/media/libeffects/testlibs/AudioShelvingFilter.cpp b/media/libeffects/testlibs/AudioShelvingFilter.cpp new file mode 100644 index 0000000..b8650ba --- /dev/null +++ b/media/libeffects/testlibs/AudioShelvingFilter.cpp @@ -0,0 +1,109 @@ +/* /android/src/frameworks/base/libs/audioflinger/AudioShelvingFilter.cpp +** +** Copyright 2009, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +#include "AudioShelvingFilter.h" +#include "AudioCommon.h" +#include "EffectsMath.h" + +#include +#include + +#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) +#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) + +namespace android { +// Format of the coefficient tables: +// kCoefTable[freq][gain][coef] +// freq - cutoff frequency, in octaves below Nyquist,from -10 to -6 in low +// shelf, -2 to 0 in high shelf. +// gain - gain, in millibel, starting at -9600, jumps of 1024, to 4736 millibel. +// coef - 0: b0 +// 1: b1 +// 2: b2 +// 3: -a1 +// 4: -a2 +static const size_t kHiInDims[2] = {3, 15}; +static const audio_coef_t kHiCoefTable[3*15*5] = { +#include "AudioHighShelfFilterCoef.inl" +}; +static const size_t kLoInDims[2] = {5, 15}; +static const audio_coef_t kLoCoefTable[5*15*5] = { +#include "AudioLowShelfFilterCoef.inl" +}; + +AudioCoefInterpolator AudioShelvingFilter::mHiCoefInterp(2, kHiInDims, 5, (const audio_coef_t*) kHiCoefTable); +AudioCoefInterpolator AudioShelvingFilter::mLoCoefInterp(2, kLoInDims, 5, (const audio_coef_t*) kLoCoefTable); + +AudioShelvingFilter::AudioShelvingFilter(ShelfType type, int nChannels, + int sampleRate) + : mType(type), + mBiquad(nChannels, sampleRate) { + configure(nChannels, sampleRate); +} + +void AudioShelvingFilter::configure(int nChannels, int sampleRate) { + mNiquistFreq = sampleRate * 500; + mFrequencyFactor = ((1ull) << 42) / mNiquistFreq; + mBiquad.configure(nChannels, sampleRate); + setFrequency(mNominalFrequency); + commit(true); +} + +void AudioShelvingFilter::reset() { + setGain(0); + setFrequency(mType == kLowShelf ? 0 : mNiquistFreq); + commit(true); +} + +void AudioShelvingFilter::setFrequency(uint32_t millihertz) { + mNominalFrequency = millihertz; + if (UNLIKELY(millihertz > mNiquistFreq / 2)) { + millihertz = mNiquistFreq / 2; + } + uint32_t normFreq = static_cast( + (static_cast(millihertz) * mFrequencyFactor) >> 10); + uint32_t log2minFreq = (mType == kLowShelf ? (32-10) : (32-2)); + if (LIKELY(normFreq > (1U << log2minFreq))) { + mFrequency = (Effects_log2(normFreq) - (log2minFreq << 15)) << (FREQ_PRECISION_BITS - 15); + } else { + mFrequency = 0; + } +} + +void AudioShelvingFilter::setGain(int32_t millibel) { + mGain = millibel + 9600; +} + +void AudioShelvingFilter::commit(bool immediate) { + audio_coef_t coefs[5]; + int intCoord[2] = { + mFrequency >> FREQ_PRECISION_BITS, + mGain >> GAIN_PRECISION_BITS + }; + uint32_t fracCoord[2] = { + mFrequency << (32 - FREQ_PRECISION_BITS), + static_cast(mGain) << (32 - GAIN_PRECISION_BITS) + }; + if (mType == kHighShelf) { + mHiCoefInterp.getCoef(intCoord, fracCoord, coefs); + } else { + mLoCoefInterp.getCoef(intCoord, fracCoord, coefs); + } + mBiquad.setCoefs(coefs, immediate); +} + +} diff --git a/media/libeffects/testlibs/AudioShelvingFilter.h b/media/libeffects/testlibs/AudioShelvingFilter.h new file mode 100644 index 0000000..f72d793 --- /dev/null +++ b/media/libeffects/testlibs/AudioShelvingFilter.h @@ -0,0 +1,146 @@ +/* /android/src/frameworks/base/libs/audioflinger/AudioShelvingFilter.h +** +** Copyright 2009, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +#ifndef AUDIO_SHELVING_FILTER_H +#define AUDIO_SHELVING_FILTER_H + +#include "AudioBiquadFilter.h" +#include "AudioCoefInterpolator.h" + +namespace android { + +// A shelving audio filter, with unity skirt gain, and controllable cutoff +// frequency and gain. +// This filter is able to suppress introduce discontinuities and other artifacts +// in the output, even when changing parameters abruptly. +// Parameters can be set to any value - this class will make sure to clip them +// when they are out of supported range. +// +// Implementation notes: +// This class uses an underlying biquad filter whose parameters are determined +// using a linear interpolation from a coefficient table, using a +// AudioCoefInterpolator. +// All is left for this class to do is mapping between high-level parameters to +// fractional indices into the coefficient table. +class AudioShelvingFilter { +public: + // Shelf type + enum ShelfType { + kLowShelf, + kHighShelf + }; + + // Constructor. Resets the filter (see reset()). + // type Type of the filter (high shelf or low shelf). + // nChannels Number of input/output channels (interlaced). + // sampleRate The input/output sample rate, in Hz. + AudioShelvingFilter(ShelfType type, int nChannels, int sampleRate); + + // Reconfiguration of the filter. Changes input/output format, but does not + // alter current parameter values. Clears delay lines. + // nChannels Number of input/output channels (interlaced). + // sampleRate The input/output sample rate, in Hz. + void configure(int nChannels, int sampleRate); + + // Resets the filter parameters to the following values: + // frequency: 0 + // gain: 0 + // It also disables the filter. Does not clear the delay lines. + void reset(); + + // Clears delay lines. Does not alter parameter values. + void clear() { mBiquad.clear(); } + + // Sets gain value. Actual change will only take place upon commit(). + // This value will be remembered even if the filter is in disabled() state. + // millibel Gain value in millibel (1/100 of decibel). + void setGain(int32_t millibel); + + // Gets the gain, in millibel, as set. + int32_t getGain() const { return mGain - 9600; } + + // Sets cutoff frequency value. Actual change will only take place upon + // commit(). + // This value will be remembered even if the filter is in disabled() state. + // millihertz Frequency value in mHz. + void setFrequency(uint32_t millihertz); + + // Gets the frequency, in mHz, as set. + uint32_t getFrequency() const { return mNominalFrequency; } + + // Applies all parameter changes done to this point in time. + // If the filter is disabled, the new parameters will take place when it is + // enabled again. Does not introduce artifacts, unless immediate is set. + // immediate Whether to apply change abruptly (ignored if filter is + // disabled). + void commit(bool immediate = false); + + // Process a buffer of input data. The input and output should contain + // frameCount * nChannels interlaced samples. Processing can be done + // in-place, by passing the same buffer as both arguments. + // in Input buffer. + // out Output buffer. + // frameCount Number of frames to produce. + void process(const audio_sample_t in[], audio_sample_t out[], + int frameCount) { mBiquad.process(in, out, frameCount); } + + // Enables the filter, so it would start processing input. Does not + // introduce artifacts, unless immediate is set. + // immediate Whether to apply change abruptly. + void enable(bool immediate = false) { mBiquad.enable(immediate); } + + // Disabled (bypasses) the filter. Does not introduce artifacts, unless + // immediate is set. + // immediate Whether to apply change abruptly. + void disable(bool immediate = false) { mBiquad.disable(immediate); } + +private: + // Precision for the mFrequency member. + static const int FREQ_PRECISION_BITS = 26; + // Precision for the mGain member. + static const int GAIN_PRECISION_BITS = 10; + + // Shelf type. + ShelfType mType; + // Nyquist, in mHz. + uint32_t mNiquistFreq; + // Fractional index into the gain dimension of the coef table in + // GAIN_PRECISION_BITS precision. + int32_t mGain; + // Fractional index into the frequency dimension of the coef table in + // FREQ_PRECISION_BITS precision. + uint32_t mFrequency; + // Nominal value of frequency, as set. + uint32_t mNominalFrequency; + // 1/Nyquist[mHz], in 42-bit precision (very small). + // Used for scaling the frequency. + uint32_t mFrequencyFactor; + + // A biquad filter, used for the actual processing. + AudioBiquadFilter mBiquad; + // A coefficient interpolator, used for mapping the high level parameters to + // the low-level biquad coefficients. This one is used for the high shelf. + static AudioCoefInterpolator mHiCoefInterp; + // A coefficient interpolator, used for mapping the high level parameters to + // the low-level biquad coefficients. This one is used for the low shelf. + static AudioCoefInterpolator mLoCoefInterp; +}; + +} + + +#endif // AUDIO_SHELVING_FILTER_H diff --git a/media/libeffects/testlibs/EffectEqualizer.cpp b/media/libeffects/testlibs/EffectEqualizer.cpp new file mode 100644 index 0000000..0eb2bdf --- /dev/null +++ b/media/libeffects/testlibs/EffectEqualizer.cpp @@ -0,0 +1,654 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "Equalizer" +#define ARRAY_SIZE(array) (sizeof array / sizeof array[0]) +// +#define LOG_NDEBUG 0 +#include +#include +#include +#include +#include +#include "AudioEqualizer.h" +#include "AudioBiquadFilter.h" +#include "AudioFormatAdapter.h" +#include + +// effect_interface_t interface implementation for equalizer effect +extern "C" const struct effect_interface_s gEqualizerInterface; + +enum equalizer_state_e { + EQUALIZER_STATE_UNINITIALIZED, + EQUALIZER_STATE_INITIALIZED, + EQUALIZER_STATE_ACTIVE, +}; + +namespace android { +namespace { + +// Google Graphic Equalizer UUID: e25aa840-543b-11df-98a5-0002a5d5c51b +const effect_descriptor_t gEqualizerDescriptor = { + {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type + {0xe25aa840, 0x543b, 0x11df, 0x98a5, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid + EFFECT_API_VERSION, + (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST), + 0, // TODO + 1, + "Graphic Equalizer", + "Google Inc.", +}; + +/////////////////// BEGIN EQ PRESETS /////////////////////////////////////////// +const int kNumBands = 5; +const uint32_t gFreqs[kNumBands] = { 50000, 125000, 900000, 3200000, 6300000 }; +const uint32_t gBandwidths[kNumBands] = { 0, 3600, 3600, 2400, 0 }; + +const AudioEqualizer::BandConfig gBandsClassic[kNumBands] = { + { 300, gFreqs[0], gBandwidths[0] }, + { 400, gFreqs[1], gBandwidths[1] }, + { 0, gFreqs[2], gBandwidths[2] }, + { 200, gFreqs[3], gBandwidths[3] }, + { -300, gFreqs[4], gBandwidths[4] } +}; + +const AudioEqualizer::BandConfig gBandsJazz[kNumBands] = { + { -600, gFreqs[0], gBandwidths[0] }, + { 200, gFreqs[1], gBandwidths[1] }, + { 400, gFreqs[2], gBandwidths[2] }, + { -400, gFreqs[3], gBandwidths[3] }, + { -600, gFreqs[4], gBandwidths[4] } +}; + +const AudioEqualizer::BandConfig gBandsPop[kNumBands] = { + { 400, gFreqs[0], gBandwidths[0] }, + { -400, gFreqs[1], gBandwidths[1] }, + { 300, gFreqs[2], gBandwidths[2] }, + { -400, gFreqs[3], gBandwidths[3] }, + { 600, gFreqs[4], gBandwidths[4] } +}; + +const AudioEqualizer::BandConfig gBandsRock[kNumBands] = { + { 700, gFreqs[0], gBandwidths[0] }, + { 400, gFreqs[1], gBandwidths[1] }, + { -400, gFreqs[2], gBandwidths[2] }, + { 400, gFreqs[3], gBandwidths[3] }, + { 200, gFreqs[4], gBandwidths[4] } +}; + +const AudioEqualizer::PresetConfig gEqualizerPresets[] = { + { "Classic", gBandsClassic }, + { "Jazz", gBandsJazz }, + { "Pop", gBandsPop }, + { "Rock", gBandsRock } +}; + +/////////////////// END EQ PRESETS ///////////////////////////////////////////// + +static const size_t kBufferSize = 32; + +typedef AudioFormatAdapter FormatAdapter; + +struct EqualizerContext { + const struct effect_interface_s *itfe; + effect_config_t config; + FormatAdapter adapter; + AudioEqualizer * pEqualizer; + uint32_t state; +}; + +//--- local function prototypes + +int Equalizer_init(EqualizerContext *pContext); +int Equalizer_configure(EqualizerContext *pContext, effect_config_t *pConfig); +int Equalizer_getParameter(AudioEqualizer * pEqualizer, int32_t *pParam, size_t *pValueSize, void *pValue); +int Equalizer_setParameter(AudioEqualizer * pEqualizer, int32_t *pParam, void *pValue); + + +// +//--- Effect Library Interface Implementation +// + +extern "C" int EffectQueryNumberEffects(uint32_t *pNumEffects) { + *pNumEffects = 1; + return 0; +} /* end EffectQueryNumberEffects */ + +extern "C" int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor) { + if (pDescriptor == NULL) { + return -EINVAL; + } + if (index > 0) { + return -EINVAL; + } + memcpy(pDescriptor, &gEqualizerDescriptor, sizeof(effect_descriptor_t)); + return 0; +} /* end EffectQueryNext */ + +extern "C" int EffectCreate(effect_uuid_t *uuid, + int32_t sessionId, + int32_t ioId, + effect_interface_t *pInterface) { + int ret; + int i; + + LOGV("EffectLibCreateEffect start"); + + if (pInterface == NULL || uuid == NULL) { + return -EINVAL; + } + + if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) != 0) { + return -EINVAL; + } + + EqualizerContext *pContext = new EqualizerContext; + + pContext->itfe = &gEqualizerInterface; + pContext->pEqualizer = NULL; + pContext->state = EQUALIZER_STATE_UNINITIALIZED; + + ret = Equalizer_init(pContext); + if (ret < 0) { + LOGW("EffectLibCreateEffect() init failed"); + delete pContext; + return ret; + } + + *pInterface = (effect_interface_t)pContext; + pContext->state = EQUALIZER_STATE_INITIALIZED; + + LOGV("EffectLibCreateEffect %p, size %d", pContext, AudioEqualizer::GetInstanceSize(kNumBands)+sizeof(EqualizerContext)); + + return 0; + +} /* end EffectCreate */ + +extern "C" int EffectRelease(effect_interface_t interface) { + EqualizerContext * pContext = (EqualizerContext *)interface; + + LOGV("EffectLibReleaseEffect %p", interface); + if (pContext == NULL) { + return -EINVAL; + } + + pContext->state = EQUALIZER_STATE_UNINITIALIZED; + pContext->pEqualizer->free(); + delete pContext; + + return 0; +} /* end EffectRelease */ + + +// +//--- local functions +// + +#define CHECK_ARG(cond) { \ + if (!(cond)) { \ + LOGV("Invalid argument: "#cond); \ + return -EINVAL; \ + } \ +} + +//---------------------------------------------------------------------------- +// Equalizer_configure() +//---------------------------------------------------------------------------- +// Purpose: Set input and output audio configuration. +// +// Inputs: +// pContext: effect engine context +// pConfig: pointer to effect_config_t structure holding input and output +// configuration parameters +// +// Outputs: +// +//---------------------------------------------------------------------------- + +int Equalizer_configure(EqualizerContext *pContext, effect_config_t *pConfig) +{ + LOGV("Equalizer_configure start"); + + CHECK_ARG(pContext != NULL); + CHECK_ARG(pConfig != NULL); + + CHECK_ARG(pConfig->inputCfg.samplingRate == pConfig->outputCfg.samplingRate); + CHECK_ARG(pConfig->inputCfg.channels == pConfig->outputCfg.channels); + CHECK_ARG(pConfig->inputCfg.format == pConfig->outputCfg.format); + CHECK_ARG((pConfig->inputCfg.channels == CHANNEL_MONO) || (pConfig->inputCfg.channels == CHANNEL_STEREO)); + CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE + || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE); + CHECK_ARG(pConfig->inputCfg.format == SAMPLE_FORMAT_PCM_S7_24 + || pConfig->inputCfg.format == SAMPLE_FORMAT_PCM_S15); + + int channelCount; + if (pConfig->inputCfg.channels == CHANNEL_MONO) { + channelCount = 1; + } else { + channelCount = 2; + } + CHECK_ARG(channelCount <= AudioBiquadFilter::MAX_CHANNELS); + + memcpy(&pContext->config, pConfig, sizeof(effect_config_t)); + + pContext->pEqualizer->configure(channelCount, + pConfig->inputCfg.samplingRate); + + pContext->adapter.configure(*pContext->pEqualizer, channelCount, + pConfig->inputCfg.format, + pConfig->outputCfg.accessMode); + + return 0; +} // end Equalizer_configure + + +//---------------------------------------------------------------------------- +// Equalizer_init() +//---------------------------------------------------------------------------- +// Purpose: Initialize engine with default configuration and creates +// AudioEqualizer instance. +// +// Inputs: +// pContext: effect engine context +// +// Outputs: +// +//---------------------------------------------------------------------------- + +int Equalizer_init(EqualizerContext *pContext) +{ + int status; + + LOGV("Equalizer_init start"); + + CHECK_ARG(pContext != NULL); + + if (pContext->pEqualizer != NULL) { + pContext->pEqualizer->free(); + } + + pContext->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; + pContext->config.inputCfg.channels = CHANNEL_STEREO; + pContext->config.inputCfg.format = SAMPLE_FORMAT_PCM_S15; + pContext->config.inputCfg.samplingRate = 44100; + pContext->config.inputCfg.bufferProvider.getBuffer = NULL; + pContext->config.inputCfg.bufferProvider.releaseBuffer = NULL; + pContext->config.inputCfg.bufferProvider.cookie = NULL; + pContext->config.inputCfg.mask = EFFECT_CONFIG_ALL; + pContext->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; + pContext->config.outputCfg.channels = CHANNEL_STEREO; + pContext->config.outputCfg.format = SAMPLE_FORMAT_PCM_S15; + pContext->config.outputCfg.samplingRate = 44100; + pContext->config.outputCfg.bufferProvider.getBuffer = NULL; + pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL; + pContext->config.outputCfg.bufferProvider.cookie = NULL; + pContext->config.outputCfg.mask = EFFECT_CONFIG_ALL; + + pContext->pEqualizer = AudioEqualizer::CreateInstance( + NULL, + kNumBands, + AudioBiquadFilter::MAX_CHANNELS, + 44100, + gEqualizerPresets, + ARRAY_SIZE(gEqualizerPresets)); + + for (int i = 0; i < kNumBands; ++i) { + pContext->pEqualizer->setFrequency(i, gFreqs[i]); + pContext->pEqualizer->setBandwidth(i, gBandwidths[i]); + } + + pContext->pEqualizer->enable(true); + + Equalizer_configure(pContext, &pContext->config); + + return 0; +} // end Equalizer_init + + +//---------------------------------------------------------------------------- +// Equalizer_getParameter() +//---------------------------------------------------------------------------- +// Purpose: +// Get a Equalizer parameter +// +// Inputs: +// pEqualizer - handle to instance data +// pParam - pointer to parameter +// pValue - pointer to variable to hold retrieved value +// pValueSize - pointer to value size: maximum size as input +// +// Outputs: +// *pValue updated with parameter value +// *pValueSize updated with actual value size +// +// +// Side Effects: +// +//---------------------------------------------------------------------------- + +int Equalizer_getParameter(AudioEqualizer * pEqualizer, int32_t *pParam, size_t *pValueSize, void *pValue) +{ + int status = 0; + int32_t param = *pParam++; + int32_t param2; + char *name; + + switch (param) { + case EQ_PARAM_NUM_BANDS: + case EQ_PARAM_CUR_PRESET: + case EQ_PARAM_GET_NUM_OF_PRESETS: + if (*pValueSize < sizeof(int16_t)) { + return -EINVAL; + } + *pValueSize = sizeof(int16_t); + break; + + case EQ_PARAM_LEVEL_RANGE: + case EQ_PARAM_BAND_FREQ_RANGE: + if (*pValueSize < 2 * sizeof(int32_t)) { + return -EINVAL; + } + *pValueSize = 2 * sizeof(int32_t); + break; + case EQ_PARAM_BAND_LEVEL: + case EQ_PARAM_GET_BAND: + case EQ_PARAM_CENTER_FREQ: + if (*pValueSize < sizeof(int32_t)) { + return -EINVAL; + } + *pValueSize = sizeof(int32_t); + break; + + case EQ_PARAM_GET_PRESET_NAME: + break; + + default: + return -EINVAL; + } + + switch (param) { + case EQ_PARAM_NUM_BANDS: + *(int16_t *)pValue = kNumBands; + LOGV("Equalizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue); + break; + + case EQ_PARAM_LEVEL_RANGE: + *(int32_t *)pValue = -9600; + *((int32_t *)pValue + 1) = 4800; + LOGV("Equalizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d", *(int32_t *)pValue, *((int32_t *)pValue + 1)); + break; + + case EQ_PARAM_BAND_LEVEL: + param2 = *pParam; + if (param2 >= kNumBands) { + status = -EINVAL; + break; + } + *(int32_t *)pValue = pEqualizer->getGain(param2); + LOGV("Equalizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", param2, *(int32_t *)pValue); + break; + + case EQ_PARAM_CENTER_FREQ: + param2 = *pParam; + if (param2 >= kNumBands) { + status = -EINVAL; + break; + } + *(int32_t *)pValue = pEqualizer->getFrequency(param2); + LOGV("Equalizer_getParameter() EQ_PARAM_CENTER_FREQ band %d, frequency %d", param2, *(int32_t *)pValue); + break; + + case EQ_PARAM_BAND_FREQ_RANGE: + param2 = *pParam; + if (param2 >= kNumBands) { + status = -EINVAL; + break; + } + pEqualizer->getBandRange(param2, *(uint32_t *)pValue, *((uint32_t *)pValue + 1)); + LOGV("Equalizer_getParameter() EQ_PARAM_BAND_FREQ_RANGE band %d, min %d, max %d", param2, *(int32_t *)pValue, *((int32_t *)pValue + 1)); + break; + + case EQ_PARAM_GET_BAND: + param2 = *pParam; + *(int32_t *)pValue = pEqualizer->getMostRelevantBand(param2); + LOGV("Equalizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d", param2, *(int32_t *)pValue); + break; + + case EQ_PARAM_CUR_PRESET: + *(int16_t *)pValue = pEqualizer->getPreset(); + LOGV("Equalizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue); + break; + + case EQ_PARAM_GET_NUM_OF_PRESETS: + *(int16_t *)pValue = pEqualizer->getNumPresets(); + LOGV("Equalizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue); + break; + + case EQ_PARAM_GET_PRESET_NAME: + param2 = *pParam; + if (param2 >= pEqualizer->getNumPresets()) { + status = -EINVAL; + break; + } + name = (char *)pValue; + strncpy(name, pEqualizer->getPresetName(param2), *pValueSize - 1); + name[*pValueSize - 1] = 0; + *pValueSize = strlen(name) + 1; + LOGV("Equalizer_getParameter() EQ_PARAM_GET_PRESET_NAME preset %d, name %s len %d", param2, gEqualizerPresets[param2].name, *pValueSize); + break; + + default: + LOGV("Equalizer_getParameter() invalid param %d", param); + status = -EINVAL; + break; + } + + return status; +} // end Equalizer_getParameter + + +//---------------------------------------------------------------------------- +// Equalizer_setParameter() +//---------------------------------------------------------------------------- +// Purpose: +// Set a Equalizer parameter +// +// Inputs: +// pEqualizer - handle to instance data +// pParam - pointer to parameter +// pValue - pointer to value +// +// Outputs: +// +// +// Side Effects: +// +//---------------------------------------------------------------------------- + +int Equalizer_setParameter (AudioEqualizer * pEqualizer, int32_t *pParam, void *pValue) +{ + int status = 0; + int32_t preset; + int32_t band; + int32_t level; + int32_t param = *pParam++; + + + switch (param) { + case EQ_PARAM_CUR_PRESET: + preset = *(int16_t *)pValue; + + LOGV("setParameter() EQ_PARAM_CUR_PRESET %d", preset); + if (preset >= pEqualizer->getNumPresets()) { + status = -EINVAL; + break; + } + pEqualizer->setPreset(preset); + pEqualizer->commit(true); + break; + case EQ_PARAM_BAND_LEVEL: + band = *pParam; + level = *(int32_t *)pValue; + LOGV("setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level); + if (band >= kNumBands) { + status = -EINVAL; + break; + } + pEqualizer->setGain(band, level); + pEqualizer->commit(true); + break; + default: + LOGV("setParameter() invalid param %d", param); + break; + } + + return status; +} // end Equalizer_setParameter + +} // namespace +} // namespace + + +// +//--- Effect Control Interface Implementation +// + +extern "C" int Equalizer_process(effect_interface_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) +{ + android::EqualizerContext * pContext = (android::EqualizerContext *) self; + + if (pContext == NULL) { + return -EINVAL; + } + if (inBuffer == NULL || inBuffer->raw == NULL || + outBuffer == NULL || outBuffer->raw == NULL || + inBuffer->frameCount != outBuffer->frameCount) { + return -EINVAL; + } + + if (pContext->state == EQUALIZER_STATE_UNINITIALIZED) { + return -EINVAL; + } + if (pContext->state == EQUALIZER_STATE_INITIALIZED) { + return -ENODATA; + } + + pContext->adapter.process(inBuffer->raw, outBuffer->raw, outBuffer->frameCount); + + return 0; +} // end Equalizer_process + +extern "C" int Equalizer_command(effect_interface_t self, int cmdCode, int cmdSize, + void *pCmdData, int *replySize, void *pReplyData) { + + android::EqualizerContext * pContext = (android::EqualizerContext *) self; + int retsize; + + if (pContext == NULL || pContext->state == EQUALIZER_STATE_UNINITIALIZED) { + return -EINVAL; + } + + android::AudioEqualizer * pEqualizer = pContext->pEqualizer; + + LOGV("Equalizer_command command %d cmdSize %d",cmdCode, cmdSize); + + switch (cmdCode) { + case EFFECT_CMD_INIT: + if (pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + *(int *) pReplyData = Equalizer_init(pContext); + break; + case EFFECT_CMD_CONFIGURE: + if (pCmdData == NULL || cmdSize != sizeof(effect_config_t) + || pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + *(int *) pReplyData = Equalizer_configure(pContext, + (effect_config_t *) pCmdData); + break; + case EFFECT_CMD_RESET: + Equalizer_configure(pContext, &pContext->config); + break; + case EFFECT_CMD_GET_PARAM: { + if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || + pReplyData == NULL || *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))) { + return -EINVAL; + } + effect_param_t *p = (effect_param_t *)pCmdData; + memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); + p = (effect_param_t *)pReplyData; + int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); + p->status = android::Equalizer_getParameter(pEqualizer, (int32_t *)p->data, &p->vsize, + p->data + voffset); + *replySize = sizeof(effect_param_t) + voffset + p->vsize; + LOGV("Equalizer_command EFFECT_CMD_GET_PARAM *pCmdData %d, *replySize %d, *pReplyData %08x %08x", + *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), *replySize, + *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset), + *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset + sizeof(int32_t))); + + } break; + case EFFECT_CMD_SET_PARAM: { + LOGV("Equalizer_command EFFECT_CMD_SET_PARAM cmdSize %d pCmdData %p, *replySize %d, pReplyData %p", cmdSize, pCmdData, *replySize, pReplyData); + if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || + pReplyData == NULL || *replySize != sizeof(int32_t)) { + return -EINVAL; + } + effect_param_t *p = (effect_param_t *) pCmdData; + *(int *)pReplyData = android::Equalizer_setParameter(pEqualizer, (int32_t *)p->data, + p->data + p->psize); + } break; + case EFFECT_CMD_ENABLE: + if (pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + if (pContext->state != EQUALIZER_STATE_INITIALIZED) { + return -ENOSYS; + } + pContext->state = EQUALIZER_STATE_ACTIVE; + LOGV("EFFECT_CMD_ENABLE() OK"); + *(int *)pReplyData = 0; + break; + case EFFECT_CMD_DISABLE: + if (pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + if (pContext->state != EQUALIZER_STATE_ACTIVE) { + return -ENOSYS; + } + pContext->state = EQUALIZER_STATE_INITIALIZED; + LOGV("EFFECT_CMD_DISABLE() OK"); + *(int *)pReplyData = 0; + break; + case EFFECT_CMD_SET_DEVICE: + case EFFECT_CMD_SET_VOLUME: + case EFFECT_CMD_SET_AUDIO_MODE: + break; + default: + LOGW("Equalizer_command invalid command %d",cmdCode); + return -EINVAL; + } + + return 0; +} + +// effect_interface_t interface implementation for equalizer effect +const struct effect_interface_s gEqualizerInterface = { + Equalizer_process, + Equalizer_command +}; + + diff --git a/media/libeffects/testlibs/EffectReverb.c b/media/libeffects/testlibs/EffectReverb.c new file mode 100644 index 0000000..2ce7558 --- /dev/null +++ b/media/libeffects/testlibs/EffectReverb.c @@ -0,0 +1,2135 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "EffectReverb" +//#define LOG_NDEBUG 0 +#include +#include +#include +#include +#include "EffectReverb.h" +#include "EffectsMath.h" + +// effect_interface_t interface implementation for reverb effect +const struct effect_interface_s gReverbInterface = { + Reverb_Process, + Reverb_Command +}; + +// Google auxiliary environmental reverb UUID: 1f0ae2e0-4ef7-11df-bc09-0002a5d5c51b +static const effect_descriptor_t gAuxEnvReverbDescriptor = { + {0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, {0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e}}, + {0x1f0ae2e0, 0x4ef7, 0x11df, 0xbc09, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, + EFFECT_API_VERSION, + // flags other than EFFECT_FLAG_TYPE_AUXILIARY set for test purpose + EFFECT_FLAG_TYPE_AUXILIARY | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_AUDIO_MODE_IND, + 0, // TODO + 33, + "Aux Environmental Reverb", + "Google Inc." +}; + +// Google insert environmental reverb UUID: aa476040-6342-11df-91a4-0002a5d5c51b +static const effect_descriptor_t gInsertEnvReverbDescriptor = { + {0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, {0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e}}, + {0xaa476040, 0x6342, 0x11df, 0x91a4, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, + EFFECT_API_VERSION, + EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST, + 0, // TODO + 33, + "Insert Environmental reverb", + "Google Inc." +}; + +// Google auxiliary preset reverb UUID: 63909320-53a6-11df-bdbd-0002a5d5c51b +static const effect_descriptor_t gAuxPresetReverbDescriptor = { + {0x47382d60, 0xddd8, 0x11db, 0xbf3a, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, + {0x63909320, 0x53a6, 0x11df, 0xbdbd, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, + EFFECT_API_VERSION, + EFFECT_FLAG_TYPE_AUXILIARY, + 0, // TODO + 33, + "Aux Preset Reverb", + "Google Inc." +}; + +// Google insert preset reverb UUID: d93dc6a0-6342-11df-b128-0002a5d5c51b +static const effect_descriptor_t gInsertPresetReverbDescriptor = { + {0x47382d60, 0xddd8, 0x11db, 0xbf3a, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, + {0xd93dc6a0, 0x6342, 0x11df, 0xb128, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, + EFFECT_API_VERSION, + EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST, + 0, // TODO + 33, + "Insert Preset Reverb", + "Google Inc." +}; + +// gDescriptors contains pointers to all defined effect descriptor in this library +static const effect_descriptor_t * const gDescriptors[] = { + &gAuxEnvReverbDescriptor, + &gInsertEnvReverbDescriptor, + &gAuxPresetReverbDescriptor, + &gInsertPresetReverbDescriptor +}; + +/*---------------------------------------------------------------------------- + * Effect API implementation + *--------------------------------------------------------------------------*/ + +/*--- Effect Library Interface Implementation ---*/ + +int EffectQueryNumberEffects(uint32_t *pNumEffects) { + *pNumEffects = sizeof(gDescriptors) / sizeof(const effect_descriptor_t *); + return 0; +} + +int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor) { + if (pDescriptor == NULL) { + return -EINVAL; + } + if (index >= sizeof(gDescriptors) / sizeof(const effect_descriptor_t *)) { + return -EINVAL; + } + memcpy(pDescriptor, gDescriptors[index], + sizeof(effect_descriptor_t)); + return 0; +} + +int EffectCreate(effect_uuid_t *uuid, + int32_t sessionId, + int32_t ioId, + effect_interface_t *pInterface) { + int ret; + int i; + reverb_module_t *module; + const effect_descriptor_t *desc; + int aux = 0; + int preset = 0; + + LOGV("EffectLibCreateEffect start"); + + if (pInterface == NULL || uuid == NULL) { + return -EINVAL; + } + + for (i = 0; gDescriptors[i] != NULL; i++) { + desc = gDescriptors[i]; + if (memcmp(uuid, &desc->uuid, sizeof(effect_uuid_t)) + == 0) { + break; + } + } + + if (gDescriptors[i] == NULL) { + return -ENOENT; + } + + module = malloc(sizeof(reverb_module_t)); + + module->itfe = &gReverbInterface; + + module->context.mState = REVERB_STATE_UNINITIALIZED; + + if (memcmp(&desc->type, SL_IID_PRESETREVERB, sizeof(effect_uuid_t)) == 0) { + preset = 1; + } + if ((desc->flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { + aux = 1; + } + ret = Reverb_Init(module, aux, preset); + if (ret < 0) { + LOGW("EffectLibCreateEffect() init failed"); + free(module); + return ret; + } + + *pInterface = (effect_interface_t) module; + + module->context.mState = REVERB_STATE_INITIALIZED; + + LOGV("EffectLibCreateEffect %p ,size %d", module, sizeof(reverb_module_t)); + + return 0; +} + +int EffectRelease(effect_interface_t interface) { + reverb_module_t *pRvbModule = (reverb_module_t *)interface; + + LOGV("EffectLibReleaseEffect %p", interface); + if (interface == NULL) { + return -EINVAL; + } + + pRvbModule->context.mState = REVERB_STATE_UNINITIALIZED; + + free(pRvbModule); + return 0; +} + + +/*--- Effect Control Interface Implementation ---*/ + +static int Reverb_Process(effect_interface_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) { + reverb_object_t *pReverb; + int16_t *pSrc, *pDst; + reverb_module_t *pRvbModule = (reverb_module_t *)self; + + if (pRvbModule == NULL) { + return -EINVAL; + } + + if (inBuffer == NULL || inBuffer->raw == NULL || + outBuffer == NULL || outBuffer->raw == NULL || + inBuffer->frameCount != outBuffer->frameCount) { + return -EINVAL; + } + + pReverb = (reverb_object_t*) &pRvbModule->context; + + if (pReverb->mState == REVERB_STATE_UNINITIALIZED) { + return -EINVAL; + } + if (pReverb->mState == REVERB_STATE_INITIALIZED) { + return -ENODATA; + } + + //if bypassed or the preset forces the signal to be completely dry + if (pReverb->m_bBypass != 0) { + if (inBuffer->raw != outBuffer->raw) { + int16_t smp; + pSrc = inBuffer->s16; + pDst = outBuffer->s16; + size_t count = inBuffer->frameCount; + if (pRvbModule->config.inputCfg.channels == pRvbModule->config.outputCfg.channels) { + count *= 2; + while (count--) { + *pDst++ = *pSrc++; + } + } else { + while (count--) { + smp = *pSrc++; + *pDst++ = smp; + *pDst++ = smp; + } + } + } + return 0; + } + + if (pReverb->m_nNextRoom != pReverb->m_nCurrentRoom) { + ReverbUpdateRoom(pReverb, true); + } + + pSrc = inBuffer->s16; + pDst = outBuffer->s16; + size_t numSamples = outBuffer->frameCount; + while (numSamples) { + uint32_t processedSamples; + if (numSamples > (uint32_t) pReverb->m_nUpdatePeriodInSamples) { + processedSamples = (uint32_t) pReverb->m_nUpdatePeriodInSamples; + } else { + processedSamples = numSamples; + } + + /* increment update counter */ + pReverb->m_nUpdateCounter += (int16_t) processedSamples; + /* check if update counter needs to be reset */ + if (pReverb->m_nUpdateCounter >= pReverb->m_nUpdatePeriodInSamples) { + /* update interval has elapsed, so reset counter */ + pReverb->m_nUpdateCounter -= pReverb->m_nUpdatePeriodInSamples; + ReverbUpdateXfade(pReverb, pReverb->m_nUpdatePeriodInSamples); + + } /* end if m_nUpdateCounter >= update interval */ + + Reverb(pReverb, processedSamples, pDst, pSrc); + + numSamples -= processedSamples; + if (pReverb->m_Aux) { + pSrc += processedSamples; + } else { + pSrc += processedSamples * NUM_OUTPUT_CHANNELS; + } + pDst += processedSamples * NUM_OUTPUT_CHANNELS; + } + + return 0; +} + + +static int Reverb_Command(effect_interface_t self, int cmdCode, int cmdSize, + void *pCmdData, int *replySize, void *pReplyData) { + reverb_module_t *pRvbModule = (reverb_module_t *) self; + reverb_object_t *pReverb; + int retsize; + + if (pRvbModule == NULL || + pRvbModule->context.mState == REVERB_STATE_UNINITIALIZED) { + return -EINVAL; + } + + pReverb = (reverb_object_t*) &pRvbModule->context; + + LOGV("Reverb_Command command %d cmdSize %d",cmdCode, cmdSize); + + switch (cmdCode) { + case EFFECT_CMD_INIT: + if (pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + *(int *) pReplyData = Reverb_Init(pRvbModule, pReverb->m_Aux, pReverb->m_Preset); + if (*(int *) pReplyData == 0) { + pRvbModule->context.mState = REVERB_STATE_INITIALIZED; + } + break; + case EFFECT_CMD_CONFIGURE: + if (pCmdData == NULL || cmdSize != sizeof(effect_config_t) + || pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + *(int *) pReplyData = Reverb_Configure(pRvbModule, + (effect_config_t *)pCmdData, false); + break; + case EFFECT_CMD_RESET: + Reverb_Reset(pReverb, false); + break; + case EFFECT_CMD_GET_PARAM: + LOGV("Reverb_Command EFFECT_CMD_GET_PARAM pCmdData %p, *replySize %d, pReplyData: %p",pCmdData, *replySize, pReplyData); + + if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || + pReplyData == NULL || *replySize < (int) sizeof(effect_param_t)) { + return -EINVAL; + } + effect_param_t *rep = (effect_param_t *) pReplyData; + memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + sizeof(int32_t)); + LOGV("Reverb_Command EFFECT_CMD_GET_PARAM param %d, replySize %d",*(int32_t *)rep->data, rep->vsize); + rep->status = Reverb_getParameter(pReverb, *(int32_t *)rep->data, &rep->vsize, + rep->data + sizeof(int32_t)); + *replySize = sizeof(effect_param_t) + sizeof(int32_t) + rep->vsize; + break; + case EFFECT_CMD_SET_PARAM: + LOGV("Reverb_Command EFFECT_CMD_SET_PARAM cmdSize %d pCmdData %p, *replySize %d, pReplyData %p", + cmdSize, pCmdData, *replySize, pReplyData); + if (pCmdData == NULL || (cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t))) + || pReplyData == NULL || *replySize != (int)sizeof(int32_t)) { + return -EINVAL; + } + effect_param_t *cmd = (effect_param_t *) pCmdData; + *(int *)pReplyData = Reverb_setParameter(pReverb, *(int32_t *)cmd->data, + cmd->vsize, cmd->data + sizeof(int32_t)); + break; + case EFFECT_CMD_ENABLE: + if (pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + if (pReverb->mState != REVERB_STATE_INITIALIZED) { + return -ENOSYS; + } + pReverb->mState = REVERB_STATE_ACTIVE; + LOGV("EFFECT_CMD_ENABLE() OK"); + *(int *)pReplyData = 0; + break; + case EFFECT_CMD_DISABLE: + if (pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + if (pReverb->mState != REVERB_STATE_ACTIVE) { + return -ENOSYS; + } + pReverb->mState = REVERB_STATE_INITIALIZED; + LOGV("EFFECT_CMD_DISABLE() OK"); + *(int *)pReplyData = 0; + break; + case EFFECT_CMD_SET_DEVICE: + if (pCmdData == NULL || cmdSize != (int)sizeof(uint32_t)) { + return -EINVAL; + } + LOGV("Reverb_Command EFFECT_CMD_SET_DEVICE: 0x%08x", *(uint32_t *)pCmdData); + break; + case EFFECT_CMD_SET_VOLUME: { + // audio output is always stereo => 2 channel volumes + if (pCmdData == NULL || cmdSize != (int)sizeof(uint32_t) * 2) { + return -EINVAL; + } + float left = (float)(*(uint32_t *)pCmdData) / (1 << 24); + float right = (float)(*((uint32_t *)pCmdData + 1)) / (1 << 24); + LOGV("Reverb_Command EFFECT_CMD_SET_VOLUME: left %f, right %f ", left, right); + break; + } + case EFFECT_CMD_SET_AUDIO_MODE: + if (pCmdData == NULL || cmdSize != (int)sizeof(uint32_t)) { + return -EINVAL; + } + LOGV("Reverb_Command EFFECT_CMD_SET_AUDIO_MODE: %d", *(uint32_t *)pCmdData); + break; + default: + LOGW("Reverb_Command invalid command %d",cmdCode); + return -EINVAL; + } + + return 0; +} + + +/*---------------------------------------------------------------------------- + * Reverb internal functions + *--------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- + * Reverb_Init() + *---------------------------------------------------------------------------- + * Purpose: + * Initialize reverb context and apply default parameters + * + * Inputs: + * pRvbModule - pointer to reverb effect module + * aux - indicates if the reverb is used as auxiliary (1) or insert (0) + * preset - indicates if the reverb is used in preset (1) or environmental (0) mode + * + * Outputs: + * + * Side Effects: + * + *---------------------------------------------------------------------------- + */ + +int Reverb_Init(reverb_module_t *pRvbModule, int aux, int preset) { + int ret; + + LOGV("Reverb_Init module %p, aux: %d, preset: %d", pRvbModule,aux, preset); + + memset(&pRvbModule->context, 0, sizeof(reverb_object_t)); + + pRvbModule->context.m_Aux = (uint16_t)aux; + pRvbModule->context.m_Preset = (uint16_t)preset; + + pRvbModule->config.inputCfg.samplingRate = 44100; + if (aux) { + pRvbModule->config.inputCfg.channels = CHANNEL_MONO; + } else { + pRvbModule->config.inputCfg.channels = CHANNEL_STEREO; + } + pRvbModule->config.inputCfg.format = SAMPLE_FORMAT_PCM_S15; + pRvbModule->config.inputCfg.bufferProvider.getBuffer = NULL; + pRvbModule->config.inputCfg.bufferProvider.releaseBuffer = NULL; + pRvbModule->config.inputCfg.bufferProvider.cookie = NULL; + pRvbModule->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; + pRvbModule->config.inputCfg.mask = EFFECT_CONFIG_ALL; + pRvbModule->config.outputCfg.samplingRate = 44100; + pRvbModule->config.outputCfg.channels = CHANNEL_STEREO; + pRvbModule->config.outputCfg.format = SAMPLE_FORMAT_PCM_S15; + pRvbModule->config.outputCfg.bufferProvider.getBuffer = NULL; + pRvbModule->config.outputCfg.bufferProvider.releaseBuffer = NULL; + pRvbModule->config.outputCfg.bufferProvider.cookie = NULL; + pRvbModule->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; + pRvbModule->config.outputCfg.mask = EFFECT_CONFIG_ALL; + + ret = Reverb_Configure(pRvbModule, &pRvbModule->config, true); + if (ret < 0) { + LOGV("Reverb_Init error %d on module %p", ret, pRvbModule); + } + + return ret; +} + +/*---------------------------------------------------------------------------- + * Reverb_Init() + *---------------------------------------------------------------------------- + * Purpose: + * Set input and output audio configuration. + * + * Inputs: + * pRvbModule - pointer to reverb effect module + * pConfig - pointer to effect_config_t structure containing input + * and output audio parameters configuration + * init - true if called from init function + * Outputs: + * + * Side Effects: + * + *---------------------------------------------------------------------------- + */ + +int Reverb_Configure(reverb_module_t *pRvbModule, effect_config_t *pConfig, + bool init) { + reverb_object_t *pReverb = &pRvbModule->context; + int bufferSizeInSamples; + int updatePeriodInSamples; + int xfadePeriodInSamples; + + // Check configuration compatibility with build options + if (pConfig->inputCfg.samplingRate + != pConfig->outputCfg.samplingRate + || pConfig->outputCfg.channels != OUTPUT_CHANNELS + || pConfig->inputCfg.format != SAMPLE_FORMAT_PCM_S15 + || pConfig->outputCfg.format != SAMPLE_FORMAT_PCM_S15) { + LOGV("Reverb_Configure invalid config"); + return -EINVAL; + } + if ((pReverb->m_Aux && (pConfig->inputCfg.channels != CHANNEL_MONO)) || + (!pReverb->m_Aux && (pConfig->inputCfg.channels != CHANNEL_STEREO))) { + LOGV("Reverb_Configure invalid config"); + return -EINVAL; + } + + memcpy(&pRvbModule->config, pConfig, sizeof(effect_config_t)); + + pReverb->m_nSamplingRate = pRvbModule->config.outputCfg.samplingRate; + + switch (pReverb->m_nSamplingRate) { + case 8000: + pReverb->m_nUpdatePeriodInBits = 5; + bufferSizeInSamples = 4096; + pReverb->m_nCosWT_5KHz = -23170; + break; + case 16000: + pReverb->m_nUpdatePeriodInBits = 6; + bufferSizeInSamples = 8192; + pReverb->m_nCosWT_5KHz = -12540; + break; + case 22050: + pReverb->m_nUpdatePeriodInBits = 7; + bufferSizeInSamples = 8192; + pReverb->m_nCosWT_5KHz = 4768; + break; + case 32000: + pReverb->m_nUpdatePeriodInBits = 7; + bufferSizeInSamples = 16384; + pReverb->m_nCosWT_5KHz = 18205; + break; + case 44100: + pReverb->m_nUpdatePeriodInBits = 8; + bufferSizeInSamples = 16384; + pReverb->m_nCosWT_5KHz = 24799; + break; + case 48000: + pReverb->m_nUpdatePeriodInBits = 8; + bufferSizeInSamples = 16384; + pReverb->m_nCosWT_5KHz = 25997; + break; + default: + LOGV("Reverb_Configure invalid sampling rate %d", pReverb->m_nSamplingRate); + return -EINVAL; + } + + // Define a mask for circular addressing, so that array index + // can wraparound and stay in array boundary of 0, 1, ..., (buffer size -1) + // The buffer size MUST be a power of two + pReverb->m_nBufferMask = (int32_t) (bufferSizeInSamples - 1); + /* reverb parameters are updated every 2^(pReverb->m_nUpdatePeriodInBits) samples */ + updatePeriodInSamples = (int32_t) (0x1L << pReverb->m_nUpdatePeriodInBits); + /* + calculate the update counter by bitwise ANDING with this value to + generate a 2^n modulo value + */ + pReverb->m_nUpdatePeriodInSamples = (int32_t) updatePeriodInSamples; + + xfadePeriodInSamples = (int32_t) (REVERB_XFADE_PERIOD_IN_SECONDS + * (double) pReverb->m_nSamplingRate); + + // set xfade parameters + pReverb->m_nPhaseIncrement + = (int16_t) (65536 / ((int16_t) xfadePeriodInSamples + / (int16_t) updatePeriodInSamples)); + + if (init) { + ReverbReadInPresets(pReverb); + + // for debugging purposes, allow noise generator + pReverb->m_bUseNoise = true; + + // for debugging purposes, allow bypass + pReverb->m_bBypass = 0; + + pReverb->m_nNextRoom = 1; + + pReverb->m_nNoise = (int16_t) 0xABCD; + } + + Reverb_Reset(pReverb, init); + + return 0; +} + +/*---------------------------------------------------------------------------- + * Reverb_Reset() + *---------------------------------------------------------------------------- + * Purpose: + * Reset internal states and clear delay lines. + * + * Inputs: + * pReverb - pointer to reverb context + * init - true if called from init function + * + * Outputs: + * + * Side Effects: + * + *---------------------------------------------------------------------------- + */ + +void Reverb_Reset(reverb_object_t *pReverb, bool init) { + int bufferSizeInSamples = (int32_t) (pReverb->m_nBufferMask + 1); + int maxApSamples; + int maxDelaySamples; + int maxEarlySamples; + int ap1In; + int delay0In; + int delay1In; + int32_t i; + uint16_t nOffset; + + maxApSamples = ((int32_t) (MAX_AP_TIME * pReverb->m_nSamplingRate) >> 16); + maxDelaySamples = ((int32_t) (MAX_DELAY_TIME * pReverb->m_nSamplingRate) + >> 16); + maxEarlySamples = ((int32_t) (MAX_EARLY_TIME * pReverb->m_nSamplingRate) + >> 16); + + ap1In = (AP0_IN + maxApSamples + GUARD); + delay0In = (ap1In + maxApSamples + GUARD); + delay1In = (delay0In + maxDelaySamples + GUARD); + // Define the max offsets for the end points of each section + // i.e., we don't expect a given section's taps to go beyond + // the following limits + + pReverb->m_nEarly0in = (delay1In + maxDelaySamples + GUARD); + pReverb->m_nEarly1in = (pReverb->m_nEarly0in + maxEarlySamples + GUARD); + + pReverb->m_sAp0.m_zApIn = AP0_IN; + + pReverb->m_zD0In = delay0In; + + pReverb->m_sAp1.m_zApIn = ap1In; + + pReverb->m_zD1In = delay1In; + + pReverb->m_zOutLpfL = 0; + pReverb->m_zOutLpfR = 0; + + pReverb->m_nRevFbkR = 0; + pReverb->m_nRevFbkL = 0; + + // set base index into circular buffer + pReverb->m_nBaseIndex = 0; + + // clear the reverb delay line + for (i = 0; i < bufferSizeInSamples; i++) { + pReverb->m_nDelayLine[i] = 0; + } + + ReverbUpdateRoom(pReverb, init); + + pReverb->m_nUpdateCounter = 0; + + pReverb->m_nPhase = -32768; + + pReverb->m_nSin = 0; + pReverb->m_nCos = 0; + pReverb->m_nSinIncrement = 0; + pReverb->m_nCosIncrement = 0; + + // set delay tap lengths + nOffset = ReverbCalculateNoise(pReverb); + + pReverb->m_zD1Cross = pReverb->m_nDelay1Out - pReverb->m_nMaxExcursion + + nOffset; + + nOffset = ReverbCalculateNoise(pReverb); + + pReverb->m_zD0Cross = pReverb->m_nDelay0Out - pReverb->m_nMaxExcursion + - nOffset; + + nOffset = ReverbCalculateNoise(pReverb); + + pReverb->m_zD0Self = pReverb->m_nDelay0Out - pReverb->m_nMaxExcursion + - nOffset; + + nOffset = ReverbCalculateNoise(pReverb); + + pReverb->m_zD1Self = pReverb->m_nDelay1Out - pReverb->m_nMaxExcursion + + nOffset; +} + +/*---------------------------------------------------------------------------- + * Reverb_getParameter() + *---------------------------------------------------------------------------- + * Purpose: + * Get a Reverb parameter + * + * Inputs: + * pReverb - handle to instance data + * param - parameter + * pValue - pointer to variable to hold retrieved value + * pSize - pointer to value size: maximum size as input + * + * Outputs: + * *pValue updated with parameter value + * *pSize updated with actual value size + * + * + * Side Effects: + * + *---------------------------------------------------------------------------- + */ +int Reverb_getParameter(reverb_object_t *pReverb, int32_t param, size_t *pSize, + void *pValue) { + int32_t *pValue32; + int16_t *pValue16; + t_reverb_properties *pProperties; + int32_t i; + int32_t temp; + int32_t temp2; + size_t size; + + if (pReverb->m_Preset) { + if (param != REVERB_PARAM_PRESET || *pSize < sizeof(int16_t)) { + return -EINVAL; + } + size = sizeof(int16_t); + pValue16 = (int16_t *)pValue; + // REVERB_PRESET_NONE is mapped to bypass + if (pReverb->m_bBypass != 0) { + *pValue16 = (int16_t)REVERB_PRESET_NONE; + } else { + *pValue16 = (int16_t)(pReverb->m_nNextRoom + 1); + } + LOGV("get REVERB_PARAM_PRESET, preset %d", *pValue16); + } else { + switch (param) { + case REVERB_PARAM_ROOM_LEVEL: + case REVERB_PARAM_ROOM_HF_LEVEL: + case REVERB_PARAM_DECAY_HF_RATIO: + case REVERB_PARAM_REFLECTIONS_LEVEL: + case REVERB_PARAM_REVERB_LEVEL: + case REVERB_PARAM_DIFFUSION: + case REVERB_PARAM_DENSITY: + size = sizeof(int16_t); + break; + + case REVERB_PARAM_BYPASS: + case REVERB_PARAM_DECAY_TIME: + case REVERB_PARAM_REFLECTIONS_DELAY: + case REVERB_PARAM_REVERB_DELAY: + size = sizeof(int32_t); + break; + + case REVERB_PARAM_PROPERTIES: + size = sizeof(t_reverb_properties); + break; + + default: + return -EINVAL; + } + + if (*pSize < size) { + return -EINVAL; + } + + pValue32 = (int32_t *) pValue; + pValue16 = (int16_t *) pValue; + pProperties = (t_reverb_properties *) pValue; + + switch (param) { + case REVERB_PARAM_BYPASS: + *pValue32 = (int32_t) pReverb->m_bBypass; + break; + + case REVERB_PARAM_PROPERTIES: + pValue16 = &pProperties->roomLevel; + /* FALL THROUGH */ + + case REVERB_PARAM_ROOM_LEVEL: + // Convert m_nRoomLpfFwd to millibels + temp = (pReverb->m_nRoomLpfFwd << 15) + / (32767 - pReverb->m_nRoomLpfFbk); + *pValue16 = Effects_Linear16ToMillibels(temp); + + LOGV("get REVERB_PARAM_ROOM_LEVEL %d, gain %d, m_nRoomLpfFwd %d, m_nRoomLpfFbk %d", *pValue16, temp, pReverb->m_nRoomLpfFwd, pReverb->m_nRoomLpfFbk); + + if (param == REVERB_PARAM_ROOM_LEVEL) { + break; + } + pValue16 = &pProperties->roomHFLevel; + /* FALL THROUGH */ + + case REVERB_PARAM_ROOM_HF_LEVEL: + // The ratio between linear gain at 0Hz and at 5000Hz for the room low pass is: + // (1 + a1) / sqrt(a1^2 + 2*C*a1 + 1) where: + // - a1 is minus the LP feedback gain: -pReverb->m_nRoomLpfFbk + // - C is cos(2piWT) @ 5000Hz: pReverb->m_nCosWT_5KHz + + temp = MULT_EG1_EG1(pReverb->m_nRoomLpfFbk, pReverb->m_nRoomLpfFbk); + LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, a1^2 %d", temp); + temp2 = MULT_EG1_EG1(pReverb->m_nRoomLpfFbk, pReverb->m_nCosWT_5KHz) + << 1; + LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, 2 Cos a1 %d", temp2); + temp = 32767 + temp - temp2; + LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, a1^2 + 2 Cos a1 + 1 %d", temp); + temp = Effects_Sqrt(temp) * 181; + LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, SQRT(a1^2 + 2 Cos a1 + 1) %d", temp); + temp = ((32767 - pReverb->m_nRoomLpfFbk) << 15) / temp; + + LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, gain %d, m_nRoomLpfFwd %d, m_nRoomLpfFbk %d", temp, pReverb->m_nRoomLpfFwd, pReverb->m_nRoomLpfFbk); + + *pValue16 = Effects_Linear16ToMillibels(temp); + + if (param == REVERB_PARAM_ROOM_HF_LEVEL) { + break; + } + pValue32 = &pProperties->decayTime; + /* FALL THROUGH */ + + case REVERB_PARAM_DECAY_TIME: + // Calculate reverb feedback path gain + temp = (pReverb->m_nRvbLpfFwd << 15) / (32767 - pReverb->m_nRvbLpfFbk); + temp = Effects_Linear16ToMillibels(temp); + + // Calculate decay time: g = -6000 d/DT , g gain in millibels, d reverb delay, DT decay time + temp = (-6000 * pReverb->m_nLateDelay) / temp; + + // Convert samples to ms + *pValue32 = (temp * 1000) / pReverb->m_nSamplingRate; + + LOGV("get REVERB_PARAM_DECAY_TIME, samples %d, ms %d", temp, *pValue32); + + if (param == REVERB_PARAM_DECAY_TIME) { + break; + } + pValue16 = &pProperties->decayHFRatio; + /* FALL THROUGH */ + + case REVERB_PARAM_DECAY_HF_RATIO: + // If r is the decay HF ratio (r = REVERB_PARAM_DECAY_HF_RATIO/1000) we have: + // DT_5000Hz = DT_0Hz * r + // and G_5000Hz = -6000 * d / DT_5000Hz and G_0Hz = -6000 * d / DT_0Hz in millibels so : + // r = G_0Hz/G_5000Hz in millibels + // The linear gain at 5000Hz is b0 / sqrt(a1^2 + 2*C*a1 + 1) where: + // - a1 is minus the LP feedback gain: -pReverb->m_nRvbLpfFbk + // - b0 is the LP forward gain: pReverb->m_nRvbLpfFwd + // - C is cos(2piWT) @ 5000Hz: pReverb->m_nCosWT_5KHz + if (pReverb->m_nRvbLpfFbk == 0) { + *pValue16 = 1000; + LOGV("get REVERB_PARAM_DECAY_HF_RATIO, pReverb->m_nRvbLpfFbk == 0, ratio %d", *pValue16); + } else { + temp = MULT_EG1_EG1(pReverb->m_nRvbLpfFbk, pReverb->m_nRvbLpfFbk); + temp2 = MULT_EG1_EG1(pReverb->m_nRvbLpfFbk, pReverb->m_nCosWT_5KHz) + << 1; + temp = 32767 + temp - temp2; + temp = Effects_Sqrt(temp) * 181; + temp = (pReverb->m_nRvbLpfFwd << 15) / temp; + // The linear gain at 0Hz is b0 / (a1 + 1) + temp2 = (pReverb->m_nRvbLpfFwd << 15) / (32767 + - pReverb->m_nRvbLpfFbk); + + temp = Effects_Linear16ToMillibels(temp); + temp2 = Effects_Linear16ToMillibels(temp2); + LOGV("get REVERB_PARAM_DECAY_HF_RATIO, gain 5KHz %d mB, gain DC %d mB", temp, temp2); + + if (temp == 0) + temp = 1; + temp = (int16_t) ((1000 * temp2) / temp); + if (temp > 1000) + temp = 1000; + + *pValue16 = temp; + LOGV("get REVERB_PARAM_DECAY_HF_RATIO, ratio %d", *pValue16); + } + + if (param == REVERB_PARAM_DECAY_HF_RATIO) { + break; + } + pValue16 = &pProperties->reflectionsLevel; + /* FALL THROUGH */ + + case REVERB_PARAM_REFLECTIONS_LEVEL: + *pValue16 = Effects_Linear16ToMillibels(pReverb->m_nEarlyGain); + + LOGV("get REVERB_PARAM_REFLECTIONS_LEVEL, %d", *pValue16); + if (param == REVERB_PARAM_REFLECTIONS_LEVEL) { + break; + } + pValue32 = &pProperties->reflectionsDelay; + /* FALL THROUGH */ + + case REVERB_PARAM_REFLECTIONS_DELAY: + // convert samples to ms + *pValue32 = (pReverb->m_nEarlyDelay * 1000) / pReverb->m_nSamplingRate; + + LOGV("get REVERB_PARAM_REFLECTIONS_DELAY, samples %d, ms %d", pReverb->m_nEarlyDelay, *pValue32); + + if (param == REVERB_PARAM_REFLECTIONS_DELAY) { + break; + } + pValue16 = &pProperties->reverbLevel; + /* FALL THROUGH */ + + case REVERB_PARAM_REVERB_LEVEL: + // Convert linear gain to millibels + *pValue16 = Effects_Linear16ToMillibels(pReverb->m_nLateGain << 2); + + LOGV("get REVERB_PARAM_REVERB_LEVEL %d", *pValue16); + + if (param == REVERB_PARAM_REVERB_LEVEL) { + break; + } + pValue32 = &pProperties->reverbDelay; + /* FALL THROUGH */ + + case REVERB_PARAM_REVERB_DELAY: + // convert samples to ms + *pValue32 = (pReverb->m_nLateDelay * 1000) / pReverb->m_nSamplingRate; + + LOGV("get REVERB_PARAM_REVERB_DELAY, samples %d, ms %d", pReverb->m_nLateDelay, *pValue32); + + if (param == REVERB_PARAM_REVERB_DELAY) { + break; + } + pValue16 = &pProperties->diffusion; + /* FALL THROUGH */ + + case REVERB_PARAM_DIFFUSION: + temp = (int16_t) ((1000 * (pReverb->m_sAp0.m_nApGain - AP0_GAIN_BASE)) + / AP0_GAIN_RANGE); + + if (temp < 0) + temp = 0; + if (temp > 1000) + temp = 1000; + + *pValue16 = temp; + LOGV("get REVERB_PARAM_DIFFUSION, %d, AP0 gain %d", *pValue16, pReverb->m_sAp0.m_nApGain); + + if (param == REVERB_PARAM_DIFFUSION) { + break; + } + pValue16 = &pProperties->density; + /* FALL THROUGH */ + + case REVERB_PARAM_DENSITY: + // Calculate AP delay in time units + temp = ((pReverb->m_sAp0.m_zApOut - pReverb->m_sAp0.m_zApIn) << 16) + / pReverb->m_nSamplingRate; + + temp = (int16_t) ((1000 * (temp - AP0_TIME_BASE)) / AP0_TIME_RANGE); + + if (temp < 0) + temp = 0; + if (temp > 1000) + temp = 1000; + + *pValue16 = temp; + + LOGV("get REVERB_PARAM_DENSITY, %d, AP0 delay smps %d", *pValue16, pReverb->m_sAp0.m_zApOut - pReverb->m_sAp0.m_zApIn); + break; + + default: + break; + } + } + + *pSize = size; + + LOGV("Reverb_getParameter, context %p, param %d, value %d", + pReverb, param, *(int *)pValue); + + return 0; +} /* end Reverb_getParameter */ + +/*---------------------------------------------------------------------------- + * Reverb_setParameter() + *---------------------------------------------------------------------------- + * Purpose: + * Set a Reverb parameter + * + * Inputs: + * pReverb - handle to instance data + * param - parameter + * pValue - pointer to parameter value + * size - value size + * + * Outputs: + * + * + * Side Effects: + * + *---------------------------------------------------------------------------- + */ +int Reverb_setParameter(reverb_object_t *pReverb, int32_t param, size_t size, + void *pValue) { + int32_t value32; + int16_t value16; + t_reverb_properties *pProperties; + int32_t i; + int32_t temp; + int32_t temp2; + reverb_preset_t *pPreset; + int maxSamples; + int32_t averageDelay; + size_t paramSize; + + LOGV("Reverb_setParameter, context %p, param %d, value16 %d, value32 %d", + pReverb, param, *(int16_t *)pValue, *(int32_t *)pValue); + + if (pReverb->m_Preset) { + if (param != REVERB_PARAM_PRESET || size != sizeof(int16_t)) { + return -EINVAL; + } + value16 = *(int16_t *)pValue; + LOGV("set REVERB_PARAM_PRESET, preset %d", value16); + if (value16 < REVERB_PRESET_NONE || value16 > REVERB_PRESET_PLATE) { + return -EINVAL; + } + // REVERB_PRESET_NONE is mapped to bypass + if (value16 == REVERB_PRESET_NONE) { + pReverb->m_bBypass = 1; + } else { + pReverb->m_bBypass = 0; + pReverb->m_nNextRoom = value16 - 1; + } + } else { + switch (param) { + case REVERB_PARAM_ROOM_LEVEL: + case REVERB_PARAM_ROOM_HF_LEVEL: + case REVERB_PARAM_DECAY_HF_RATIO: + case REVERB_PARAM_REFLECTIONS_LEVEL: + case REVERB_PARAM_REVERB_LEVEL: + case REVERB_PARAM_DIFFUSION: + case REVERB_PARAM_DENSITY: + paramSize = sizeof(int16_t); + break; + + case REVERB_PARAM_BYPASS: + case REVERB_PARAM_DECAY_TIME: + case REVERB_PARAM_REFLECTIONS_DELAY: + case REVERB_PARAM_REVERB_DELAY: + paramSize = sizeof(int32_t); + break; + + case REVERB_PARAM_PROPERTIES: + paramSize = sizeof(t_reverb_properties); + break; + + default: + return -EINVAL; + } + + if (size != paramSize) { + return -EINVAL; + } + + if (paramSize == sizeof(int16_t)) { + value16 = *(int16_t *) pValue; + } else if (paramSize == sizeof(int32_t)) { + value32 = *(int32_t *) pValue; + } else { + pProperties = (t_reverb_properties *) pValue; + } + + pPreset = &pReverb->m_sPreset.m_sPreset[pReverb->m_nNextRoom]; + + switch (param) { + case REVERB_PARAM_BYPASS: + pReverb->m_bBypass = (uint16_t)value32; + break; + + case REVERB_PARAM_PROPERTIES: + value16 = pProperties->roomLevel; + /* FALL THROUGH */ + + case REVERB_PARAM_ROOM_LEVEL: + // Convert millibels to linear 16 bit signed => m_nRoomLpfFwd + if (value16 > 0) + return -EINVAL; + + temp = Effects_MillibelsToLinear16(value16); + + pReverb->m_nRoomLpfFwd + = MULT_EG1_EG1(temp, (32767 - pReverb->m_nRoomLpfFbk)); + + LOGV("REVERB_PARAM_ROOM_LEVEL, gain %d, new m_nRoomLpfFwd %d, m_nRoomLpfFbk %d", temp, pReverb->m_nRoomLpfFwd, pReverb->m_nRoomLpfFbk); + if (param == REVERB_PARAM_ROOM_LEVEL) + break; + value16 = pProperties->roomHFLevel; + /* FALL THROUGH */ + + case REVERB_PARAM_ROOM_HF_LEVEL: + + // Limit to 0 , -40dB range because of low pass implementation + if (value16 > 0 || value16 < -4000) + return -EINVAL; + // Convert attenuation @ 5000H expressed in millibels to => m_nRoomLpfFbk + // m_nRoomLpfFbk is -a1 where a1 is the solution of: + // a1^2 + 2*(C-dG^2)/(1-dG^2)*a1 + 1 = 0 where: + // - C is cos(2*pi*5000/Fs) (pReverb->m_nCosWT_5KHz) + // - dG is G0/Gf (G0 is the linear gain at DC and Gf is the wanted gain at 5000Hz) + + // Save current DC gain m_nRoomLpfFwd / (32767 - m_nRoomLpfFbk) to keep it unchanged + // while changing HF level + temp2 = (pReverb->m_nRoomLpfFwd << 15) / (32767 + - pReverb->m_nRoomLpfFbk); + if (value16 == 0) { + pReverb->m_nRoomLpfFbk = 0; + } else { + int32_t dG2, b, delta; + + // dG^2 + temp = Effects_MillibelsToLinear16(value16); + LOGV("REVERB_PARAM_ROOM_HF_LEVEL, HF gain %d", temp); + temp = (1 << 30) / temp; + LOGV("REVERB_PARAM_ROOM_HF_LEVEL, 1/ HF gain %d", temp); + dG2 = (int32_t) (((int64_t) temp * (int64_t) temp) >> 15); + LOGV("REVERB_PARAM_ROOM_HF_LEVEL, 1/ HF gain ^ 2 %d", dG2); + // b = 2*(C-dG^2)/(1-dG^2) + b = (int32_t) ((((int64_t) 1 << (15 + 1)) + * ((int64_t) pReverb->m_nCosWT_5KHz - (int64_t) dG2)) + / ((int64_t) 32767 - (int64_t) dG2)); + + // delta = b^2 - 4 + delta = (int32_t) ((((int64_t) b * (int64_t) b) >> 15) - (1 << (15 + + 2))); + + LOGV_IF(delta > (1<<30), " delta overflow %d", delta); + + LOGV("REVERB_PARAM_ROOM_HF_LEVEL, dG2 %d, b %d, delta %d, m_nCosWT_5KHz %d", dG2, b, delta, pReverb->m_nCosWT_5KHz); + // m_nRoomLpfFbk = -a1 = - (- b + sqrt(delta)) / 2 + pReverb->m_nRoomLpfFbk = (b - Effects_Sqrt(delta) * 181) >> 1; + } + LOGV("REVERB_PARAM_ROOM_HF_LEVEL, olg DC gain %d new m_nRoomLpfFbk %d, old m_nRoomLpfFwd %d", + temp2, pReverb->m_nRoomLpfFbk, pReverb->m_nRoomLpfFwd); + + pReverb->m_nRoomLpfFwd + = MULT_EG1_EG1(temp2, (32767 - pReverb->m_nRoomLpfFbk)); + LOGV("REVERB_PARAM_ROOM_HF_LEVEL, new m_nRoomLpfFwd %d", pReverb->m_nRoomLpfFwd); + + if (param == REVERB_PARAM_ROOM_HF_LEVEL) + break; + value32 = pProperties->decayTime; + /* FALL THROUGH */ + + case REVERB_PARAM_DECAY_TIME: + + // Convert milliseconds to => m_nRvbLpfFwd (function of m_nRvbLpfFbk) + // convert ms to samples + value32 = (value32 * pReverb->m_nSamplingRate) / 1000; + + // calculate valid decay time range as a function of current reverb delay and + // max feed back gain. Min value <=> -40dB in one pass, Max value <=> feedback gain = -1 dB + // Calculate attenuation for each round in late reverb given a total attenuation of -6000 millibels. + // g = -6000 d/DT , g gain in millibels, d reverb delay, DT decay time + averageDelay = pReverb->m_nLateDelay - pReverb->m_nMaxExcursion; + averageDelay += ((pReverb->m_sAp0.m_zApOut - pReverb->m_sAp0.m_zApIn) + + (pReverb->m_sAp1.m_zApOut - pReverb->m_sAp1.m_zApIn)) >> 1; + + temp = (-6000 * averageDelay) / value32; + LOGV("REVERB_PARAM_DECAY_TIME, delay smps %d, DT smps %d, gain mB %d",averageDelay, value32, temp); + if (temp < -4000 || temp > -100) + return -EINVAL; + + // calculate low pass gain by adding reverb input attenuation (pReverb->m_nLateGain) and substrating output + // xfade and sum gain (max +9dB) + temp -= Effects_Linear16ToMillibels(pReverb->m_nLateGain) + 900; + temp = Effects_MillibelsToLinear16(temp); + + // DC gain (temp) = b0 / (1 + a1) = pReverb->m_nRvbLpfFwd / (32767 - pReverb->m_nRvbLpfFbk) + pReverb->m_nRvbLpfFwd + = MULT_EG1_EG1(temp, (32767 - pReverb->m_nRvbLpfFbk)); + + LOGV("REVERB_PARAM_DECAY_TIME, gain %d, new m_nRvbLpfFwd %d, old m_nRvbLpfFbk %d, reverb gain %d", temp, pReverb->m_nRvbLpfFwd, pReverb->m_nRvbLpfFbk, Effects_Linear16ToMillibels(pReverb->m_nLateGain)); + + if (param == REVERB_PARAM_DECAY_TIME) + break; + value16 = pProperties->decayHFRatio; + /* FALL THROUGH */ + + case REVERB_PARAM_DECAY_HF_RATIO: + + // We limit max value to 1000 because reverb filter is lowpass only + if (value16 < 100 || value16 > 1000) + return -EINVAL; + // Convert per mille to => m_nLpfFwd, m_nLpfFbk + + // Save current DC gain m_nRoomLpfFwd / (32767 - m_nRoomLpfFbk) to keep it unchanged + // while changing HF level + temp2 = (pReverb->m_nRvbLpfFwd << 15) / (32767 - pReverb->m_nRvbLpfFbk); + + if (value16 == 1000) { + pReverb->m_nRvbLpfFbk = 0; + } else { + int32_t dG2, b, delta; + + temp = Effects_Linear16ToMillibels(temp2); + // G_5000Hz = G_DC * (1000/REVERB_PARAM_DECAY_HF_RATIO) in millibels + + value32 = ((int32_t) 1000 << 15) / (int32_t) value16; + LOGV("REVERB_PARAM_DECAY_HF_RATIO, DC gain %d, DC gain mB %d, 1000/R %d", temp2, temp, value32); + + temp = (int32_t) (((int64_t) temp * (int64_t) value32) >> 15); + + if (temp < -4000) { + LOGV("REVERB_PARAM_DECAY_HF_RATIO HF gain overflow %d mB", temp); + temp = -4000; + } + + temp = Effects_MillibelsToLinear16(temp); + LOGV("REVERB_PARAM_DECAY_HF_RATIO, HF gain %d", temp); + // dG^2 + temp = (temp2 << 15) / temp; + dG2 = (int32_t) (((int64_t) temp * (int64_t) temp) >> 15); + + // b = 2*(C-dG^2)/(1-dG^2) + b = (int32_t) ((((int64_t) 1 << (15 + 1)) + * ((int64_t) pReverb->m_nCosWT_5KHz - (int64_t) dG2)) + / ((int64_t) 32767 - (int64_t) dG2)); + + // delta = b^2 - 4 + delta = (int32_t) ((((int64_t) b * (int64_t) b) >> 15) - (1 << (15 + + 2))); + + // m_nRoomLpfFbk = -a1 = - (- b + sqrt(delta)) / 2 + pReverb->m_nRvbLpfFbk = (b - Effects_Sqrt(delta) * 181) >> 1; + + LOGV("REVERB_PARAM_DECAY_HF_RATIO, dG2 %d, b %d, delta %d", dG2, b, delta); + + } + + LOGV("REVERB_PARAM_DECAY_HF_RATIO, gain %d, m_nRvbLpfFbk %d, m_nRvbLpfFwd %d", temp2, pReverb->m_nRvbLpfFbk, pReverb->m_nRvbLpfFwd); + + pReverb->m_nRvbLpfFwd + = MULT_EG1_EG1(temp2, (32767 - pReverb->m_nRvbLpfFbk)); + + if (param == REVERB_PARAM_DECAY_HF_RATIO) + break; + value16 = pProperties->reflectionsLevel; + /* FALL THROUGH */ + + case REVERB_PARAM_REFLECTIONS_LEVEL: + // We limit max value to 0 because gain is limited to 0dB + if (value16 > 0 || value16 < -6000) + return -EINVAL; + + // Convert millibels to linear 16 bit signed and recompute m_sEarlyL.m_nGain[i] and m_sEarlyR.m_nGain[i]. + value16 = Effects_MillibelsToLinear16(value16); + for (i = 0; i < REVERB_MAX_NUM_REFLECTIONS; i++) { + pReverb->m_sEarlyL.m_nGain[i] + = MULT_EG1_EG1(pPreset->m_sEarlyL.m_nGain[i],value16); + pReverb->m_sEarlyR.m_nGain[i] + = MULT_EG1_EG1(pPreset->m_sEarlyR.m_nGain[i],value16); + } + pReverb->m_nEarlyGain = value16; + LOGV("REVERB_PARAM_REFLECTIONS_LEVEL, m_nEarlyGain %d", pReverb->m_nEarlyGain); + + if (param == REVERB_PARAM_REFLECTIONS_LEVEL) + break; + value32 = pProperties->reflectionsDelay; + /* FALL THROUGH */ + + case REVERB_PARAM_REFLECTIONS_DELAY: + // We limit max value MAX_EARLY_TIME + // convert ms to time units + temp = (value32 * 65536) / 1000; + if (temp < 0 || temp > MAX_EARLY_TIME) + return -EINVAL; + + maxSamples = (int32_t) (MAX_EARLY_TIME * pReverb->m_nSamplingRate) + >> 16; + temp = (temp * pReverb->m_nSamplingRate) >> 16; + for (i = 0; i < REVERB_MAX_NUM_REFLECTIONS; i++) { + temp2 = temp + (((int32_t) pPreset->m_sEarlyL.m_zDelay[i] + * pReverb->m_nSamplingRate) >> 16); + if (temp2 > maxSamples) + temp2 = maxSamples; + pReverb->m_sEarlyL.m_zDelay[i] = pReverb->m_nEarly0in + temp2; + temp2 = temp + (((int32_t) pPreset->m_sEarlyR.m_zDelay[i] + * pReverb->m_nSamplingRate) >> 16); + if (temp2 > maxSamples) + temp2 = maxSamples; + pReverb->m_sEarlyR.m_zDelay[i] = pReverb->m_nEarly1in + temp2; + } + pReverb->m_nEarlyDelay = temp; + + LOGV("REVERB_PARAM_REFLECTIONS_DELAY, m_nEarlyDelay smps %d max smp delay %d", pReverb->m_nEarlyDelay, maxSamples); + + // Convert milliseconds to sample count => m_nEarlyDelay + if (param == REVERB_PARAM_REFLECTIONS_DELAY) + break; + value16 = pProperties->reverbLevel; + /* FALL THROUGH */ + + case REVERB_PARAM_REVERB_LEVEL: + // We limit max value to 0 because gain is limited to 0dB + if (value16 > 0 || value16 < -6000) + return -EINVAL; + // Convert millibels to linear 16 bits (gange 0 - 8191) => m_nLateGain. + pReverb->m_nLateGain = Effects_MillibelsToLinear16(value16) >> 2; + + LOGV("REVERB_PARAM_REVERB_LEVEL, m_nLateGain %d", pReverb->m_nLateGain); + + if (param == REVERB_PARAM_REVERB_LEVEL) + break; + value32 = pProperties->reverbDelay; + /* FALL THROUGH */ + + case REVERB_PARAM_REVERB_DELAY: + // We limit max value to MAX_DELAY_TIME + // convert ms to time units + temp = (value32 * 65536) / 1000; + if (temp < 0 || temp > MAX_DELAY_TIME) + return -EINVAL; + + maxSamples = (int32_t) (MAX_DELAY_TIME * pReverb->m_nSamplingRate) + >> 16; + temp = (temp * pReverb->m_nSamplingRate) >> 16; + if ((temp + pReverb->m_nMaxExcursion) > maxSamples) { + temp = maxSamples - pReverb->m_nMaxExcursion; + } + if (temp < pReverb->m_nMaxExcursion) { + temp = pReverb->m_nMaxExcursion; + } + + temp -= pReverb->m_nLateDelay; + pReverb->m_nDelay0Out += temp; + pReverb->m_nDelay1Out += temp; + pReverb->m_nLateDelay += temp; + + LOGV("REVERB_PARAM_REVERB_DELAY, m_nLateDelay smps %d max smp delay %d", pReverb->m_nLateDelay, maxSamples); + + // Convert milliseconds to sample count => m_nDelay1Out + m_nMaxExcursion + if (param == REVERB_PARAM_REVERB_DELAY) + break; + + value16 = pProperties->diffusion; + /* FALL THROUGH */ + + case REVERB_PARAM_DIFFUSION: + if (value16 < 0 || value16 > 1000) + return -EINVAL; + + // Convert per mille to m_sAp0.m_nApGain, m_sAp1.m_nApGain + pReverb->m_sAp0.m_nApGain = AP0_GAIN_BASE + ((int32_t) value16 + * AP0_GAIN_RANGE) / 1000; + pReverb->m_sAp1.m_nApGain = AP1_GAIN_BASE + ((int32_t) value16 + * AP1_GAIN_RANGE) / 1000; + + LOGV("REVERB_PARAM_DIFFUSION, m_sAp0.m_nApGain %d m_sAp1.m_nApGain %d", pReverb->m_sAp0.m_nApGain, pReverb->m_sAp1.m_nApGain); + + if (param == REVERB_PARAM_DIFFUSION) + break; + + value16 = pProperties->density; + /* FALL THROUGH */ + + case REVERB_PARAM_DENSITY: + if (value16 < 0 || value16 > 1000) + return -EINVAL; + + // Convert per mille to m_sAp0.m_zApOut, m_sAp1.m_zApOut + maxSamples = (int32_t) (MAX_AP_TIME * pReverb->m_nSamplingRate) >> 16; + + temp = AP0_TIME_BASE + ((int32_t) value16 * AP0_TIME_RANGE) / 1000; + /*lint -e{702} shift for performance */ + temp = (temp * pReverb->m_nSamplingRate) >> 16; + if (temp > maxSamples) + temp = maxSamples; + pReverb->m_sAp0.m_zApOut = (uint16_t) (pReverb->m_sAp0.m_zApIn + temp); + + LOGV("REVERB_PARAM_DENSITY, Ap0 delay smps %d", temp); + + temp = AP1_TIME_BASE + ((int32_t) value16 * AP1_TIME_RANGE) / 1000; + /*lint -e{702} shift for performance */ + temp = (temp * pReverb->m_nSamplingRate) >> 16; + if (temp > maxSamples) + temp = maxSamples; + pReverb->m_sAp1.m_zApOut = (uint16_t) (pReverb->m_sAp1.m_zApIn + temp); + + LOGV("Ap1 delay smps %d", temp); + + break; + + default: + break; + } + } + + return 0; +} /* end Reverb_setParameter */ + +/*---------------------------------------------------------------------------- + * ReverbUpdateXfade + *---------------------------------------------------------------------------- + * Purpose: + * Update the xfade parameters as required + * + * Inputs: + * nNumSamplesToAdd - number of samples to write to buffer + * + * Outputs: + * + * + * Side Effects: + * - xfade parameters will be changed + * + *---------------------------------------------------------------------------- + */ +static int ReverbUpdateXfade(reverb_object_t *pReverb, int nNumSamplesToAdd) { + uint16_t nOffset; + int16_t tempCos; + int16_t tempSin; + + if (pReverb->m_nXfadeCounter >= pReverb->m_nXfadeInterval) { + /* update interval has elapsed, so reset counter */ + pReverb->m_nXfadeCounter = 0; + + // Pin the sin,cos values to min / max values to ensure that the + // modulated taps' coefs are zero (thus no clicks) + if (pReverb->m_nPhaseIncrement > 0) { + // if phase increment > 0, then sin -> 1, cos -> 0 + pReverb->m_nSin = 32767; + pReverb->m_nCos = 0; + + // reset the phase to match the sin, cos values + pReverb->m_nPhase = 32767; + + // modulate the cross taps because their tap coefs are zero + nOffset = ReverbCalculateNoise(pReverb); + + pReverb->m_zD1Cross = pReverb->m_nDelay1Out + - pReverb->m_nMaxExcursion + nOffset; + + nOffset = ReverbCalculateNoise(pReverb); + + pReverb->m_zD0Cross = pReverb->m_nDelay0Out + - pReverb->m_nMaxExcursion - nOffset; + } else { + // if phase increment < 0, then sin -> 0, cos -> 1 + pReverb->m_nSin = 0; + pReverb->m_nCos = 32767; + + // reset the phase to match the sin, cos values + pReverb->m_nPhase = -32768; + + // modulate the self taps because their tap coefs are zero + nOffset = ReverbCalculateNoise(pReverb); + + pReverb->m_zD0Self = pReverb->m_nDelay0Out + - pReverb->m_nMaxExcursion - nOffset; + + nOffset = ReverbCalculateNoise(pReverb); + + pReverb->m_zD1Self = pReverb->m_nDelay1Out + - pReverb->m_nMaxExcursion + nOffset; + + } // end if-else (pReverb->m_nPhaseIncrement > 0) + + // Reverse the direction of the sin,cos so that the + // tap whose coef was previously increasing now decreases + // and vice versa + pReverb->m_nPhaseIncrement = -pReverb->m_nPhaseIncrement; + + } // end if counter >= update interval + + //compute what phase will be next time + pReverb->m_nPhase += pReverb->m_nPhaseIncrement; + + //calculate what the new sin and cos need to reach by the next update + ReverbCalculateSinCos(pReverb->m_nPhase, &tempSin, &tempCos); + + //calculate the per-sample increment required to get there by the next update + /*lint -e{702} shift for performance */ + pReverb->m_nSinIncrement = (tempSin - pReverb->m_nSin) + >> pReverb->m_nUpdatePeriodInBits; + + /*lint -e{702} shift for performance */ + pReverb->m_nCosIncrement = (tempCos - pReverb->m_nCos) + >> pReverb->m_nUpdatePeriodInBits; + + /* increment update counter */ + pReverb->m_nXfadeCounter += (uint16_t) nNumSamplesToAdd; + + return 0; + +} /* end ReverbUpdateXfade */ + +/*---------------------------------------------------------------------------- + * ReverbCalculateNoise + *---------------------------------------------------------------------------- + * Purpose: + * Calculate a noise sample and limit its value + * + * Inputs: + * nMaxExcursion - noise value is limited to this value + * pnNoise - return new noise sample in this (not limited) + * + * Outputs: + * new limited noise value + * + * Side Effects: + * - *pnNoise noise value is updated + * + *---------------------------------------------------------------------------- + */ +static uint16_t ReverbCalculateNoise(reverb_object_t *pReverb) { + int16_t nNoise = pReverb->m_nNoise; + + // calculate new noise value + if (pReverb->m_bUseNoise) { + nNoise = (int16_t) (nNoise * 5 + 1); + } else { + nNoise = 0; + } + + pReverb->m_nNoise = nNoise; + // return the limited noise value + return (pReverb->m_nMaxExcursion & nNoise); + +} /* end ReverbCalculateNoise */ + +/*---------------------------------------------------------------------------- + * ReverbCalculateSinCos + *---------------------------------------------------------------------------- + * Purpose: + * Calculate a new sin and cosine value based on the given phase + * + * Inputs: + * nPhase - phase angle + * pnSin - input old value, output new value + * pnCos - input old value, output new value + * + * Outputs: + * + * Side Effects: + * - *pnSin, *pnCos are updated + * + *---------------------------------------------------------------------------- + */ +static int ReverbCalculateSinCos(int16_t nPhase, int16_t *pnSin, int16_t *pnCos) { + int32_t nTemp; + int32_t nNetAngle; + + // -1 <= nPhase < 1 + // However, for the calculation, we need a value + // that ranges from -1/2 to +1/2, so divide the phase by 2 + /*lint -e{702} shift for performance */ + nNetAngle = nPhase >> 1; + + /* + Implement the following + sin(x) = (2-4*c)*x^2 + c + x + cos(x) = (2-4*c)*x^2 + c - x + + where c = 1/sqrt(2) + using the a0 + x*(a1 + x*a2) approach + */ + + /* limit the input "angle" to be between -0.5 and +0.5 */ + if (nNetAngle > EG1_HALF) { + nNetAngle = EG1_HALF; + } else if (nNetAngle < EG1_MINUS_HALF) { + nNetAngle = EG1_MINUS_HALF; + } + + /* calculate sin */ + nTemp = EG1_ONE + MULT_EG1_EG1(REVERB_PAN_G2, nNetAngle); + nTemp = REVERB_PAN_G0 + MULT_EG1_EG1(nTemp, nNetAngle); + *pnSin = (int16_t) SATURATE_EG1(nTemp); + + /* calculate cos */ + nTemp = -EG1_ONE + MULT_EG1_EG1(REVERB_PAN_G2, nNetAngle); + nTemp = REVERB_PAN_G0 + MULT_EG1_EG1(nTemp, nNetAngle); + *pnCos = (int16_t) SATURATE_EG1(nTemp); + + return 0; +} /* end ReverbCalculateSinCos */ + +/*---------------------------------------------------------------------------- + * Reverb + *---------------------------------------------------------------------------- + * Purpose: + * apply reverb to the given signal + * + * Inputs: + * nNu + * pnSin - input old value, output new value + * pnCos - input old value, output new value + * + * Outputs: + * number of samples actually reverberated + * + * Side Effects: + * + *---------------------------------------------------------------------------- + */ +static int Reverb(reverb_object_t *pReverb, int nNumSamplesToAdd, + short *pOutputBuffer, short *pInputBuffer) { + int32_t i; + int32_t nDelayOut0; + int32_t nDelayOut1; + uint16_t nBase; + + uint32_t nAddr; + int32_t nTemp1; + int32_t nTemp2; + int32_t nApIn; + int32_t nApOut; + + int32_t j; + int32_t nEarlyOut; + + int32_t tempValue; + + // get the base address + nBase = pReverb->m_nBaseIndex; + + for (i = 0; i < nNumSamplesToAdd; i++) { + // ********** Left Allpass - start + nApIn = *pInputBuffer; + if (!pReverb->m_Aux) { + pInputBuffer++; + } + // store to early delay line + nAddr = CIRCULAR(nBase, pReverb->m_nEarly0in, pReverb->m_nBufferMask); + pReverb->m_nDelayLine[nAddr] = (short) nApIn; + + // left input = (left dry * m_nLateGain) + right feedback from previous period + + nApIn = SATURATE(nApIn + pReverb->m_nRevFbkR); + nApIn = MULT_EG1_EG1(nApIn, pReverb->m_nLateGain); + + // fetch allpass delay line out + //nAddr = CIRCULAR(nBase, psAp0->m_zApOut, pReverb->m_nBufferMask); + nAddr + = CIRCULAR(nBase, pReverb->m_sAp0.m_zApOut, pReverb->m_nBufferMask); + nDelayOut0 = pReverb->m_nDelayLine[nAddr]; + + // calculate allpass feedforward; subtract the feedforward result + nTemp1 = MULT_EG1_EG1(nApIn, pReverb->m_sAp0.m_nApGain); + nApOut = SATURATE(nDelayOut0 - nTemp1); // allpass output + + // calculate allpass feedback; add the feedback result + nTemp1 = MULT_EG1_EG1(nApOut, pReverb->m_sAp0.m_nApGain); + nTemp1 = SATURATE(nApIn + nTemp1); + + // inject into allpass delay + nAddr + = CIRCULAR(nBase, pReverb->m_sAp0.m_zApIn, pReverb->m_nBufferMask); + pReverb->m_nDelayLine[nAddr] = (short) nTemp1; + + // inject allpass output into delay line + nAddr = CIRCULAR(nBase, pReverb->m_zD0In, pReverb->m_nBufferMask); + pReverb->m_nDelayLine[nAddr] = (short) nApOut; + + // ********** Left Allpass - end + + // ********** Right Allpass - start + nApIn = (*pInputBuffer++); + // store to early delay line + nAddr = CIRCULAR(nBase, pReverb->m_nEarly1in, pReverb->m_nBufferMask); + pReverb->m_nDelayLine[nAddr] = (short) nApIn; + + // right input = (right dry * m_nLateGain) + left feedback from previous period + /*lint -e{702} use shift for performance */ + nApIn = SATURATE(nApIn + pReverb->m_nRevFbkL); + nApIn = MULT_EG1_EG1(nApIn, pReverb->m_nLateGain); + + // fetch allpass delay line out + nAddr + = CIRCULAR(nBase, pReverb->m_sAp1.m_zApOut, pReverb->m_nBufferMask); + nDelayOut1 = pReverb->m_nDelayLine[nAddr]; + + // calculate allpass feedforward; subtract the feedforward result + nTemp1 = MULT_EG1_EG1(nApIn, pReverb->m_sAp1.m_nApGain); + nApOut = SATURATE(nDelayOut1 - nTemp1); // allpass output + + // calculate allpass feedback; add the feedback result + nTemp1 = MULT_EG1_EG1(nApOut, pReverb->m_sAp1.m_nApGain); + nTemp1 = SATURATE(nApIn + nTemp1); + + // inject into allpass delay + nAddr + = CIRCULAR(nBase, pReverb->m_sAp1.m_zApIn, pReverb->m_nBufferMask); + pReverb->m_nDelayLine[nAddr] = (short) nTemp1; + + // inject allpass output into delay line + nAddr = CIRCULAR(nBase, pReverb->m_zD1In, pReverb->m_nBufferMask); + pReverb->m_nDelayLine[nAddr] = (short) nApOut; + + // ********** Right Allpass - end + + // ********** D0 output - start + // fetch delay line self out + nAddr = CIRCULAR(nBase, pReverb->m_zD0Self, pReverb->m_nBufferMask); + nDelayOut0 = pReverb->m_nDelayLine[nAddr]; + + // calculate delay line self out + nTemp1 = MULT_EG1_EG1(nDelayOut0, pReverb->m_nSin); + + // fetch delay line cross out + nAddr = CIRCULAR(nBase, pReverb->m_zD1Cross, pReverb->m_nBufferMask); + nDelayOut0 = pReverb->m_nDelayLine[nAddr]; + + // calculate delay line self out + nTemp2 = MULT_EG1_EG1(nDelayOut0, pReverb->m_nCos); + + // calculate unfiltered delay out + nDelayOut0 = SATURATE(nTemp1 + nTemp2); + + // ********** D0 output - end + + // ********** D1 output - start + // fetch delay line self out + nAddr = CIRCULAR(nBase, pReverb->m_zD1Self, pReverb->m_nBufferMask); + nDelayOut1 = pReverb->m_nDelayLine[nAddr]; + + // calculate delay line self out + nTemp1 = MULT_EG1_EG1(nDelayOut1, pReverb->m_nSin); + + // fetch delay line cross out + nAddr = CIRCULAR(nBase, pReverb->m_zD0Cross, pReverb->m_nBufferMask); + nDelayOut1 = pReverb->m_nDelayLine[nAddr]; + + // calculate delay line self out + nTemp2 = MULT_EG1_EG1(nDelayOut1, pReverb->m_nCos); + + // calculate unfiltered delay out + nDelayOut1 = SATURATE(nTemp1 + nTemp2); + + // ********** D1 output - end + + // ********** mixer and feedback - start + // sum is fedback to right input (R + L) + nDelayOut0 = (short) SATURATE(nDelayOut0 + nDelayOut1); + + // difference is feedback to left input (R - L) + /*lint -e{685} lint complains that it can't saturate negative */ + nDelayOut1 = (short) SATURATE(nDelayOut1 - nDelayOut0); + + // ********** mixer and feedback - end + + // calculate lowpass filter (mixer scale factor included in LPF feedforward) + nTemp1 = MULT_EG1_EG1(nDelayOut0, pReverb->m_nRvbLpfFwd); + + nTemp2 = MULT_EG1_EG1(pReverb->m_nRevFbkL, pReverb->m_nRvbLpfFbk); + + // calculate filtered delay out and simultaneously update LPF state variable + // filtered delay output is stored in m_nRevFbkL + pReverb->m_nRevFbkL = (short) SATURATE(nTemp1 + nTemp2); + + // calculate lowpass filter (mixer scale factor included in LPF feedforward) + nTemp1 = MULT_EG1_EG1(nDelayOut1, pReverb->m_nRvbLpfFwd); + + nTemp2 = MULT_EG1_EG1(pReverb->m_nRevFbkR, pReverb->m_nRvbLpfFbk); + + // calculate filtered delay out and simultaneously update LPF state variable + // filtered delay output is stored in m_nRevFbkR + pReverb->m_nRevFbkR = (short) SATURATE(nTemp1 + nTemp2); + + // ********** start early reflection generator, left + //psEarly = &(pReverb->m_sEarlyL); + + + for (j = 0; j < REVERB_MAX_NUM_REFLECTIONS; j++) { + // fetch delay line out + //nAddr = CIRCULAR(nBase, psEarly->m_zDelay[j], pReverb->m_nBufferMask); + nAddr + = CIRCULAR(nBase, pReverb->m_sEarlyL.m_zDelay[j], pReverb->m_nBufferMask); + + nTemp1 = pReverb->m_nDelayLine[nAddr]; + + // calculate reflection + //nTemp1 = MULT_EG1_EG1(nDelayOut0, psEarly->m_nGain[j]); + nTemp1 = MULT_EG1_EG1(nTemp1, pReverb->m_sEarlyL.m_nGain[j]); + + nDelayOut0 = SATURATE(nDelayOut0 + nTemp1); + + } // end for (j=0; j < REVERB_MAX_NUM_REFLECTIONS; j++) + + // apply lowpass to early reflections and reverb output + //nTemp1 = MULT_EG1_EG1(nEarlyOut, psEarly->m_nRvbLpfFwd); + nTemp1 = MULT_EG1_EG1(nDelayOut0, pReverb->m_nRoomLpfFwd); + + //nTemp2 = MULT_EG1_EG1(psEarly->m_zLpf, psEarly->m_nLpfFbk); + nTemp2 = MULT_EG1_EG1(pReverb->m_zOutLpfL, pReverb->m_nRoomLpfFbk); + + // calculate filtered out and simultaneously update LPF state variable + // filtered output is stored in m_zOutLpfL + pReverb->m_zOutLpfL = (short) SATURATE(nTemp1 + nTemp2); + + //sum with output buffer + tempValue = *pOutputBuffer; + *pOutputBuffer++ = (short) SATURATE(tempValue+pReverb->m_zOutLpfL); + + // ********** end early reflection generator, left + + // ********** start early reflection generator, right + //psEarly = &(pReverb->m_sEarlyR); + + for (j = 0; j < REVERB_MAX_NUM_REFLECTIONS; j++) { + // fetch delay line out + nAddr + = CIRCULAR(nBase, pReverb->m_sEarlyR.m_zDelay[j], pReverb->m_nBufferMask); + nTemp1 = pReverb->m_nDelayLine[nAddr]; + + // calculate reflection + nTemp1 = MULT_EG1_EG1(nTemp1, pReverb->m_sEarlyR.m_nGain[j]); + + nDelayOut1 = SATURATE(nDelayOut1 + nTemp1); + + } // end for (j=0; j < REVERB_MAX_NUM_REFLECTIONS; j++) + + // apply lowpass to early reflections + nTemp1 = MULT_EG1_EG1(nDelayOut1, pReverb->m_nRoomLpfFwd); + + nTemp2 = MULT_EG1_EG1(pReverb->m_zOutLpfR, pReverb->m_nRoomLpfFbk); + + // calculate filtered out and simultaneously update LPF state variable + // filtered output is stored in m_zOutLpfR + pReverb->m_zOutLpfR = (short) SATURATE(nTemp1 + nTemp2); + + //sum with output buffer + tempValue = *pOutputBuffer; + *pOutputBuffer++ = (short) SATURATE(tempValue + pReverb->m_zOutLpfR); + + // ********** end early reflection generator, right + + // decrement base addr for next sample period + nBase--; + + pReverb->m_nSin += pReverb->m_nSinIncrement; + pReverb->m_nCos += pReverb->m_nCosIncrement; + + } // end for (i=0; i < nNumSamplesToAdd; i++) + + // store the most up to date version + pReverb->m_nBaseIndex = nBase; + + return 0; +} /* end Reverb */ + +/*---------------------------------------------------------------------------- + * ReverbUpdateRoom + *---------------------------------------------------------------------------- + * Purpose: + * Update the room's preset parameters as required + * + * Inputs: + * + * Outputs: + * + * + * Side Effects: + * - reverb paramters (fbk, fwd, etc) will be changed + * - m_nCurrentRoom := m_nNextRoom + *---------------------------------------------------------------------------- + */ +static int ReverbUpdateRoom(reverb_object_t *pReverb, bool fullUpdate) { + int temp; + int i; + int maxSamples; + int earlyDelay; + int earlyGain; + + reverb_preset_t *pPreset = + &pReverb->m_sPreset.m_sPreset[pReverb->m_nNextRoom]; + + if (fullUpdate) { + pReverb->m_nRvbLpfFwd = pPreset->m_nRvbLpfFwd; + pReverb->m_nRvbLpfFbk = pPreset->m_nRvbLpfFbk; + + pReverb->m_nEarlyGain = pPreset->m_nEarlyGain; + //stored as time based, convert to sample based + pReverb->m_nLateGain = pPreset->m_nLateGain; + pReverb->m_nRoomLpfFbk = pPreset->m_nRoomLpfFbk; + pReverb->m_nRoomLpfFwd = pPreset->m_nRoomLpfFwd; + + // set the early reflections gains + earlyGain = pPreset->m_nEarlyGain; + for (i = 0; i < REVERB_MAX_NUM_REFLECTIONS; i++) { + pReverb->m_sEarlyL.m_nGain[i] + = MULT_EG1_EG1(pPreset->m_sEarlyL.m_nGain[i],earlyGain); + pReverb->m_sEarlyR.m_nGain[i] + = MULT_EG1_EG1(pPreset->m_sEarlyR.m_nGain[i],earlyGain); + } + + pReverb->m_nMaxExcursion = pPreset->m_nMaxExcursion; + + pReverb->m_sAp0.m_nApGain = pPreset->m_nAp0_ApGain; + pReverb->m_sAp1.m_nApGain = pPreset->m_nAp1_ApGain; + + // set the early reflections delay + earlyDelay = ((int) pPreset->m_nEarlyDelay * pReverb->m_nSamplingRate) + >> 16; + pReverb->m_nEarlyDelay = earlyDelay; + maxSamples = (int32_t) (MAX_EARLY_TIME * pReverb->m_nSamplingRate) + >> 16; + for (i = 0; i < REVERB_MAX_NUM_REFLECTIONS; i++) { + //stored as time based, convert to sample based + temp = earlyDelay + (((int) pPreset->m_sEarlyL.m_zDelay[i] + * pReverb->m_nSamplingRate) >> 16); + if (temp > maxSamples) + temp = maxSamples; + pReverb->m_sEarlyL.m_zDelay[i] = pReverb->m_nEarly0in + temp; + //stored as time based, convert to sample based + temp = earlyDelay + (((int) pPreset->m_sEarlyR.m_zDelay[i] + * pReverb->m_nSamplingRate) >> 16); + if (temp > maxSamples) + temp = maxSamples; + pReverb->m_sEarlyR.m_zDelay[i] = pReverb->m_nEarly1in + temp; + } + + maxSamples = (int32_t) (MAX_DELAY_TIME * pReverb->m_nSamplingRate) + >> 16; + //stored as time based, convert to sample based + /*lint -e{702} shift for performance */ + temp = (pPreset->m_nLateDelay * pReverb->m_nSamplingRate) >> 16; + if ((temp + pReverb->m_nMaxExcursion) > maxSamples) { + temp = maxSamples - pReverb->m_nMaxExcursion; + } + temp -= pReverb->m_nLateDelay; + pReverb->m_nDelay0Out += temp; + pReverb->m_nDelay1Out += temp; + pReverb->m_nLateDelay += temp; + + maxSamples = (int32_t) (MAX_AP_TIME * pReverb->m_nSamplingRate) >> 16; + //stored as time based, convert to absolute sample value + temp = pPreset->m_nAp0_ApOut; + /*lint -e{702} shift for performance */ + temp = (temp * pReverb->m_nSamplingRate) >> 16; + if (temp > maxSamples) + temp = maxSamples; + pReverb->m_sAp0.m_zApOut = (uint16_t) (pReverb->m_sAp0.m_zApIn + temp); + + //stored as time based, convert to absolute sample value + temp = pPreset->m_nAp1_ApOut; + /*lint -e{702} shift for performance */ + temp = (temp * pReverb->m_nSamplingRate) >> 16; + if (temp > maxSamples) + temp = maxSamples; + pReverb->m_sAp1.m_zApOut = (uint16_t) (pReverb->m_sAp1.m_zApIn + temp); + //gpsReverbObject->m_sAp1.m_zApOut = pPreset->m_nAp1_ApOut; + } + + //stored as time based, convert to sample based + temp = pPreset->m_nXfadeInterval; + /*lint -e{702} shift for performance */ + temp = (temp * pReverb->m_nSamplingRate) >> 16; + pReverb->m_nXfadeInterval = (uint16_t) temp; + //gsReverbObject.m_nXfadeInterval = pPreset->m_nXfadeInterval; + pReverb->m_nXfadeCounter = pReverb->m_nXfadeInterval + 1; // force update on first iteration + + pReverb->m_nCurrentRoom = pReverb->m_nNextRoom; + + return 0; + +} /* end ReverbUpdateRoom */ + +/*---------------------------------------------------------------------------- + * ReverbReadInPresets() + *---------------------------------------------------------------------------- + * Purpose: sets global reverb preset bank to defaults + * + * Inputs: + * + * Outputs: + * + *---------------------------------------------------------------------------- + */ +static int ReverbReadInPresets(reverb_object_t *pReverb) { + + int preset; + + // this is for test only. OpenSL ES presets are mapped to 4 presets. + // REVERB_PRESET_NONE is mapped to bypass + for (preset = 0; preset < REVERB_NUM_PRESETS; preset++) { + reverb_preset_t *pPreset = &pReverb->m_sPreset.m_sPreset[preset]; + switch (preset + 1) { + case REVERB_PRESET_PLATE: + case REVERB_PRESET_SMALLROOM: + pPreset->m_nRvbLpfFbk = 5077; + pPreset->m_nRvbLpfFwd = 11076; + pPreset->m_nEarlyGain = 27690; + pPreset->m_nEarlyDelay = 1311; + pPreset->m_nLateGain = 8191; + pPreset->m_nLateDelay = 3932; + pPreset->m_nRoomLpfFbk = 3692; + pPreset->m_nRoomLpfFwd = 20474; + pPreset->m_sEarlyL.m_zDelay[0] = 1376; + pPreset->m_sEarlyL.m_nGain[0] = 22152; + pPreset->m_sEarlyL.m_zDelay[1] = 1462; + pPreset->m_sEarlyL.m_nGain[1] = 17537; + pPreset->m_sEarlyL.m_zDelay[2] = 0; + pPreset->m_sEarlyL.m_nGain[2] = 14768; + pPreset->m_sEarlyL.m_zDelay[3] = 1835; + pPreset->m_sEarlyL.m_nGain[3] = 14307; + pPreset->m_sEarlyL.m_zDelay[4] = 0; + pPreset->m_sEarlyL.m_nGain[4] = 13384; + pPreset->m_sEarlyR.m_zDelay[0] = 721; + pPreset->m_sEarlyR.m_nGain[0] = 20306; + pPreset->m_sEarlyR.m_zDelay[1] = 2621; + pPreset->m_sEarlyR.m_nGain[1] = 17537; + pPreset->m_sEarlyR.m_zDelay[2] = 0; + pPreset->m_sEarlyR.m_nGain[2] = 14768; + pPreset->m_sEarlyR.m_zDelay[3] = 0; + pPreset->m_sEarlyR.m_nGain[3] = 16153; + pPreset->m_sEarlyR.m_zDelay[4] = 0; + pPreset->m_sEarlyR.m_nGain[4] = 13384; + pPreset->m_nMaxExcursion = 127; + pPreset->m_nXfadeInterval = 6470; //6483; + pPreset->m_nAp0_ApGain = 14768; + pPreset->m_nAp0_ApOut = 792; + pPreset->m_nAp1_ApGain = 14777; + pPreset->m_nAp1_ApOut = 1191; + pPreset->m_rfu4 = 0; + pPreset->m_rfu5 = 0; + pPreset->m_rfu6 = 0; + pPreset->m_rfu7 = 0; + pPreset->m_rfu8 = 0; + pPreset->m_rfu9 = 0; + pPreset->m_rfu10 = 0; + break; + case REVERB_PRESET_MEDIUMROOM: + case REVERB_PRESET_LARGEROOM: + pPreset->m_nRvbLpfFbk = 5077; + pPreset->m_nRvbLpfFwd = 12922; + pPreset->m_nEarlyGain = 27690; + pPreset->m_nEarlyDelay = 1311; + pPreset->m_nLateGain = 8191; + pPreset->m_nLateDelay = 3932; + pPreset->m_nRoomLpfFbk = 3692; + pPreset->m_nRoomLpfFwd = 21703; + pPreset->m_sEarlyL.m_zDelay[0] = 1376; + pPreset->m_sEarlyL.m_nGain[0] = 22152; + pPreset->m_sEarlyL.m_zDelay[1] = 1462; + pPreset->m_sEarlyL.m_nGain[1] = 17537; + pPreset->m_sEarlyL.m_zDelay[2] = 0; + pPreset->m_sEarlyL.m_nGain[2] = 14768; + pPreset->m_sEarlyL.m_zDelay[3] = 1835; + pPreset->m_sEarlyL.m_nGain[3] = 14307; + pPreset->m_sEarlyL.m_zDelay[4] = 0; + pPreset->m_sEarlyL.m_nGain[4] = 13384; + pPreset->m_sEarlyR.m_zDelay[0] = 721; + pPreset->m_sEarlyR.m_nGain[0] = 20306; + pPreset->m_sEarlyR.m_zDelay[1] = 2621; + pPreset->m_sEarlyR.m_nGain[1] = 17537; + pPreset->m_sEarlyR.m_zDelay[2] = 0; + pPreset->m_sEarlyR.m_nGain[2] = 14768; + pPreset->m_sEarlyR.m_zDelay[3] = 0; + pPreset->m_sEarlyR.m_nGain[3] = 16153; + pPreset->m_sEarlyR.m_zDelay[4] = 0; + pPreset->m_sEarlyR.m_nGain[4] = 13384; + pPreset->m_nMaxExcursion = 127; + pPreset->m_nXfadeInterval = 6449; + pPreset->m_nAp0_ApGain = 15691; + pPreset->m_nAp0_ApOut = 774; + pPreset->m_nAp1_ApGain = 16317; + pPreset->m_nAp1_ApOut = 1155; + pPreset->m_rfu4 = 0; + pPreset->m_rfu5 = 0; + pPreset->m_rfu6 = 0; + pPreset->m_rfu7 = 0; + pPreset->m_rfu8 = 0; + pPreset->m_rfu9 = 0; + pPreset->m_rfu10 = 0; + break; + case REVERB_PRESET_MEDIUMHALL: + pPreset->m_nRvbLpfFbk = 6461; + pPreset->m_nRvbLpfFwd = 14307; + pPreset->m_nEarlyGain = 27690; + pPreset->m_nEarlyDelay = 1311; + pPreset->m_nLateGain = 8191; + pPreset->m_nLateDelay = 3932; + pPreset->m_nRoomLpfFbk = 3692; + pPreset->m_nRoomLpfFwd = 24569; + pPreset->m_sEarlyL.m_zDelay[0] = 1376; + pPreset->m_sEarlyL.m_nGain[0] = 22152; + pPreset->m_sEarlyL.m_zDelay[1] = 1462; + pPreset->m_sEarlyL.m_nGain[1] = 17537; + pPreset->m_sEarlyL.m_zDelay[2] = 0; + pPreset->m_sEarlyL.m_nGain[2] = 14768; + pPreset->m_sEarlyL.m_zDelay[3] = 1835; + pPreset->m_sEarlyL.m_nGain[3] = 14307; + pPreset->m_sEarlyL.m_zDelay[4] = 0; + pPreset->m_sEarlyL.m_nGain[4] = 13384; + pPreset->m_sEarlyR.m_zDelay[0] = 721; + pPreset->m_sEarlyR.m_nGain[0] = 20306; + pPreset->m_sEarlyR.m_zDelay[1] = 2621; + pPreset->m_sEarlyR.m_nGain[1] = 17537; + pPreset->m_sEarlyR.m_zDelay[2] = 0; + pPreset->m_sEarlyR.m_nGain[2] = 14768; + pPreset->m_sEarlyR.m_zDelay[3] = 0; + pPreset->m_sEarlyR.m_nGain[3] = 16153; + pPreset->m_sEarlyR.m_zDelay[4] = 0; + pPreset->m_sEarlyR.m_nGain[4] = 13384; + pPreset->m_nMaxExcursion = 127; + pPreset->m_nXfadeInterval = 6391; + pPreset->m_nAp0_ApGain = 15230; + pPreset->m_nAp0_ApOut = 708; + pPreset->m_nAp1_ApGain = 15547; + pPreset->m_nAp1_ApOut = 1023; + pPreset->m_rfu4 = 0; + pPreset->m_rfu5 = 0; + pPreset->m_rfu6 = 0; + pPreset->m_rfu7 = 0; + pPreset->m_rfu8 = 0; + pPreset->m_rfu9 = 0; + pPreset->m_rfu10 = 0; + break; + case REVERB_PRESET_LARGEHALL: + pPreset->m_nRvbLpfFbk = 8307; + pPreset->m_nRvbLpfFwd = 14768; + pPreset->m_nEarlyGain = 27690; + pPreset->m_nEarlyDelay = 1311; + pPreset->m_nLateGain = 8191; + pPreset->m_nLateDelay = 3932; + pPreset->m_nRoomLpfFbk = 3692; + pPreset->m_nRoomLpfFwd = 24569; + pPreset->m_sEarlyL.m_zDelay[0] = 1376; + pPreset->m_sEarlyL.m_nGain[0] = 22152; + pPreset->m_sEarlyL.m_zDelay[1] = 2163; + pPreset->m_sEarlyL.m_nGain[1] = 17537; + pPreset->m_sEarlyL.m_zDelay[2] = 0; + pPreset->m_sEarlyL.m_nGain[2] = 14768; + pPreset->m_sEarlyL.m_zDelay[3] = 1835; + pPreset->m_sEarlyL.m_nGain[3] = 14307; + pPreset->m_sEarlyL.m_zDelay[4] = 0; + pPreset->m_sEarlyL.m_nGain[4] = 13384; + pPreset->m_sEarlyR.m_zDelay[0] = 721; + pPreset->m_sEarlyR.m_nGain[0] = 20306; + pPreset->m_sEarlyR.m_zDelay[1] = 2621; + pPreset->m_sEarlyR.m_nGain[1] = 17537; + pPreset->m_sEarlyR.m_zDelay[2] = 0; + pPreset->m_sEarlyR.m_nGain[2] = 14768; + pPreset->m_sEarlyR.m_zDelay[3] = 0; + pPreset->m_sEarlyR.m_nGain[3] = 16153; + pPreset->m_sEarlyR.m_zDelay[4] = 0; + pPreset->m_sEarlyR.m_nGain[4] = 13384; + pPreset->m_nMaxExcursion = 127; + pPreset->m_nXfadeInterval = 6388; + pPreset->m_nAp0_ApGain = 15691; + pPreset->m_nAp0_ApOut = 711; + pPreset->m_nAp1_ApGain = 16317; + pPreset->m_nAp1_ApOut = 1029; + pPreset->m_rfu4 = 0; + pPreset->m_rfu5 = 0; + pPreset->m_rfu6 = 0; + pPreset->m_rfu7 = 0; + pPreset->m_rfu8 = 0; + pPreset->m_rfu9 = 0; + pPreset->m_rfu10 = 0; + break; + } + } + + return 0; +} diff --git a/media/libeffects/testlibs/EffectReverb.h b/media/libeffects/testlibs/EffectReverb.h new file mode 100644 index 0000000..ee8e390 --- /dev/null +++ b/media/libeffects/testlibs/EffectReverb.h @@ -0,0 +1,437 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EFFECTREVERB_H_ +#define ANDROID_EFFECTREVERB_H_ + +#include +#include + + +/*------------------------------------ + * defines + *------------------------------------ +*/ + +/* +CIRCULAR() calculates the array index using modulo arithmetic. +The "trick" is that modulo arithmetic is simplified by masking +the effective address where the mask is (2^n)-1. This only works +if the buffer size is a power of two. +*/ +#define CIRCULAR(base,offset,size) (uint32_t)( \ + ( \ + ((int32_t)(base)) + ((int32_t)(offset)) \ + ) \ + & size \ + ) + +#define NUM_OUTPUT_CHANNELS 2 +#define OUTPUT_CHANNELS CHANNEL_STEREO + +#define REVERB_BUFFER_SIZE_IN_SAMPLES_MAX 16384 + +#define REVERB_NUM_PRESETS REVERB_PRESET_PLATE // REVERB_PRESET_NONE is not included +#define REVERB_MAX_NUM_REFLECTIONS 5 // max num reflections per channel + + +// xfade parameters +#define REVERB_XFADE_PERIOD_IN_SECONDS (double) (100.0 / 1000.0) // xfade once every this many seconds + + +/**********/ +/* the entire synth uses various flags in a bit field */ + +/* if flag is set, synth reset has been requested */ +#define REVERB_FLAG_RESET_IS_REQUESTED 0x01 /* bit 0 */ +#define MASK_REVERB_RESET_IS_REQUESTED 0x01 +#define MASK_REVERB_RESET_IS_NOT_REQUESTED (uint32_t)(~MASK_REVERB_RESET_IS_REQUESTED) + +/* +by default, we always want to update ALL channel parameters +when we reset the synth (e.g., during GM ON) +*/ +#define DEFAULT_REVERB_FLAGS 0x0 + +/* coefficients for generating sin, cos */ +#define REVERB_PAN_G2 4294940151 /* -0.82842712474619 = 2 - 4/sqrt(2) */ +/* +int32_t nPanG1 = +1.0 for sin +int32_t nPanG1 = -1.0 for cos +*/ +#define REVERB_PAN_G0 23170 /* 0.707106781186547 = 1/sqrt(2) */ + +/*************************************************************/ +// define the input injection points +#define GUARD 5 // safety guard of this many samples + +#define MAX_AP_TIME (int) ((20*65536)/1000) // delay time in time units (65536th of sec) +#define MAX_DELAY_TIME (int) ((65*65536)/1000) // delay time in time units +#define MAX_EARLY_TIME (int) ((65*65536)/1000) // delay time in time units + +#define AP0_IN 0 + + +#define REVERB_DEFAULT_ROOM_NUMBER 1 // default preset number +#define DEFAULT_AP0_GAIN 19400 +#define DEFAULT_AP1_GAIN -19400 + +#define REVERB_DEFAULT_WET 32767 +#define REVERB_DEFAULT_DRY 0 + +#define REVERB_WET_MAX 32767 +#define REVERB_WET_MIN 0 +#define REVERB_DRY_MAX 32767 +#define REVERB_DRY_MIN 0 + +// constants for reverb density +// The density expressed in permilles changes the Allpass delay in a linear manner in the range defined by +// AP0_TIME_BASE to AP0_TIME_BASE + AP0_TIME_RANGE +#define AP0_TIME_BASE (int)((9*65536)/1000) +#define AP0_TIME_RANGE (int)((4*65536)/1000) +#define AP1_TIME_BASE (int)((12*65536)/1000) +#define AP1_TIME_RANGE (int)((8*65536)/1000) + +// constants for reverb diffusion +// The diffusion expressed in permilles changes the Allpass gain in a linear manner in the range defined by +// AP0_GAIN_BASE to AP0_GAIN_BASE + AP0_GAIN_RANGE +#define AP0_GAIN_BASE (int)(9830) +#define AP0_GAIN_RANGE (int)(19660-9830) +#define AP1_GAIN_BASE (int)(6553) +#define AP1_GAIN_RANGE (int)(22936-6553) + + +enum reverb_state_e { + REVERB_STATE_UNINITIALIZED, + REVERB_STATE_INITIALIZED, + REVERB_STATE_ACTIVE, +}; + +/* parameters for each allpass */ +typedef struct +{ + uint16_t m_zApOut; // delay offset for ap out + + int16_t m_nApGain; // gain for ap + + uint16_t m_zApIn; // delay offset for ap in + +} allpass_object_t; + + +/* parameters for early reflections */ +typedef struct +{ + uint16_t m_zDelay[REVERB_MAX_NUM_REFLECTIONS]; // delay offset for ap out + + int16_t m_nGain[REVERB_MAX_NUM_REFLECTIONS]; // gain for ap + +} early_reflection_object_t; + +//demo +typedef struct +{ + int16_t m_nRvbLpfFbk; + int16_t m_nRvbLpfFwd; + int16_t m_nRoomLpfFbk; + int16_t m_nRoomLpfFwd; + + int16_t m_nEarlyGain; + int16_t m_nEarlyDelay; + int16_t m_nLateGain; + int16_t m_nLateDelay; + + early_reflection_object_t m_sEarlyL; + early_reflection_object_t m_sEarlyR; + + uint16_t m_nMaxExcursion; //28 + int16_t m_nXfadeInterval; + + int16_t m_nAp0_ApGain; //30 + int16_t m_nAp0_ApOut; + int16_t m_nAp1_ApGain; + int16_t m_nAp1_ApOut; + int16_t m_nDiffusion; + + int16_t m_rfu4; + int16_t m_rfu5; + int16_t m_rfu6; + int16_t m_rfu7; + int16_t m_rfu8; + int16_t m_rfu9; + int16_t m_rfu10; //43 + +} reverb_preset_t; + +typedef struct +{ + reverb_preset_t m_sPreset[REVERB_NUM_PRESETS]; // array of presets(does not include REVERB_PRESET_NONE) + +} reverb_preset_bank_t; + + +/* parameters for each reverb */ +typedef struct +{ + /* update counter keeps track of when synth params need updating */ + /* only needs to be as large as REVERB_UPDATE_PERIOD_IN_SAMPLES */ + int16_t m_nUpdateCounter; + + uint16_t m_nBaseIndex; // base index for circular buffer + + // reverb delay line offsets, allpass parameters, etc: + + short m_nRevFbkR; // combine feedback reverb right out with dry left in + short m_zOutLpfL; // left reverb output + + allpass_object_t m_sAp0; // allpass 0 (left channel) + + uint16_t m_zD0In; // delay offset for delay line D0 in + + short m_nRevFbkL; // combine feedback reverb left out with dry right in + short m_zOutLpfR; // right reverb output + + allpass_object_t m_sAp1; // allpass 1 (right channel) + + uint16_t m_zD1In; // delay offset for delay line D1 in + + // delay output taps, notice criss cross order + uint16_t m_zD0Self; // self feeds forward d0 --> d0 + + uint16_t m_zD1Cross; // cross feeds across d1 --> d0 + + uint16_t m_zD1Self; // self feeds forward d1 --> d1 + + uint16_t m_zD0Cross; // cross feeds across d0 --> d1 + + int16_t m_nSin; // gain for self taps + + int16_t m_nCos; // gain for cross taps + + int16_t m_nSinIncrement; // increment for gain + + int16_t m_nCosIncrement; // increment for gain + + int16_t m_nRvbLpfFwd; // reverb feedback lpf forward gain (includes scaling for mixer) + + int16_t m_nRvbLpfFbk; // reverb feedback lpf feedback gain + + int16_t m_nRoomLpfFwd; // room lpf forward gain (includes scaling for mixer) + + int16_t m_nRoomLpfFbk; // room lpf feedback gain + + uint16_t m_nXfadeInterval; // update/xfade after this many samples + + uint16_t m_nXfadeCounter; // keep track of when to xfade + + int16_t m_nPhase; // -1 <= m_nPhase < 1 + // but during sin,cos calculations + // use m_nPhase/2 + + int16_t m_nPhaseIncrement; // add this to m_nPhase each frame + + int16_t m_nNoise; // random noise sample + + uint16_t m_nMaxExcursion; // the taps can excurse +/- this amount + + uint16_t m_bUseNoise; // if TRUE, use noise as input signal + + uint16_t m_bBypass; // if TRUE, then bypass reverb and copy input to output + + int16_t m_nCurrentRoom; // preset number for current room + + int16_t m_nNextRoom; // preset number for next room + + int16_t m_nEarlyGain; // gain for early (widen) signal + int16_t m_nEarlyDelay; // initial dealy for early (widen) signal + int16_t m_nEarly0in; + int16_t m_nEarly1in; + int16_t m_nLateGain; // gain for late reverb + int16_t m_nLateDelay; + + int16_t m_nDiffusion; + + early_reflection_object_t m_sEarlyL; // left channel early reflections + early_reflection_object_t m_sEarlyR; // right channel early reflections + + short m_nDelayLine[REVERB_BUFFER_SIZE_IN_SAMPLES_MAX]; // one large delay line for all reverb elements + + reverb_preset_t pPreset; + + reverb_preset_bank_t m_sPreset; + + //int8_t preset; + uint32_t m_nSamplingRate; + int32_t m_nUpdatePeriodInBits; + int32_t m_nBufferMask; + int32_t m_nUpdatePeriodInSamples; + int32_t m_nDelay0Out; + int32_t m_nDelay1Out; + int16_t m_nCosWT_5KHz; + + uint16_t m_Aux; // if TRUE, is connected as auxiliary effect + uint16_t m_Preset; // if TRUE, expose preset revert interface + + uint32_t mState; +} reverb_object_t; + + + +typedef struct reverb_module_s { + const struct effect_interface_s *itfe; + effect_config_t config; + reverb_object_t context; +} reverb_module_t; + +/*------------------------------------ + * Effect API + *------------------------------------ +*/ +int EffectQueryNumberEffects(uint32_t *pNumEffects); +int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor); +int EffectCreate(effect_uuid_t *effectUID, int32_t sessionId, int32_t ioId, effect_interface_t *pInterface); +int EffectRelease(effect_interface_t interface); + +static int Reverb_Process(effect_interface_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer); +static int Reverb_Command(effect_interface_t self, int cmdCode, int cmdSize, void *pCmdData, int *replySize, void *pReplyData); + + +/*------------------------------------ + * internal functions + *------------------------------------ +*/ + +int Reverb_Init(reverb_module_t *pRvbModule, int aux, int preset); +int Reverb_Configure(reverb_module_t *pRvbModule, effect_config_t *pConfig, bool init); +void Reverb_Reset(reverb_object_t *pReverb, bool init); + +int Reverb_setParameter (reverb_object_t *pReverb, int32_t param, size_t size, void *pValue); +int Reverb_getParameter(reverb_object_t *pReverb, int32_t param, size_t *pSize, void *pValue); + +/*---------------------------------------------------------------------------- + * ReverbUpdateXfade + *---------------------------------------------------------------------------- + * Purpose: + * Update the xfade parameters as required + * + * Inputs: + * nNumSamplesToAdd - number of samples to write to buffer + * + * Outputs: + * + * + * Side Effects: + * - xfade parameters will be changed + * + *---------------------------------------------------------------------------- +*/ +static int ReverbUpdateXfade(reverb_object_t* pReverbData, int nNumSamplesToAdd); + +/*---------------------------------------------------------------------------- + * ReverbCalculateNoise + *---------------------------------------------------------------------------- + * Purpose: + * Calculate a noise sample and limit its value + * + * Inputs: + * Pointer to reverb context + * + * Outputs: + * new limited noise value + * + * Side Effects: + * - pReverbData->m_nNoise value is updated + * + *---------------------------------------------------------------------------- +*/ +static uint16_t ReverbCalculateNoise(reverb_object_t *pReverbData); + +/*---------------------------------------------------------------------------- + * ReverbCalculateSinCos + *---------------------------------------------------------------------------- + * Purpose: + * Calculate a new sin and cosine value based on the given phase + * + * Inputs: + * nPhase - phase angle + * pnSin - input old value, output new value + * pnCos - input old value, output new value + * + * Outputs: + * + * Side Effects: + * - *pnSin, *pnCos are updated + * + *---------------------------------------------------------------------------- +*/ +static int ReverbCalculateSinCos(int16_t nPhase, int16_t *pnSin, int16_t *pnCos); + +/*---------------------------------------------------------------------------- + * Reverb + *---------------------------------------------------------------------------- + * Purpose: + * apply reverb to the given signal + * + * Inputs: + * nNu + * pnSin - input old value, output new value + * pnCos - input old value, output new value + * + * Outputs: + * number of samples actually reverberated + * + * Side Effects: + * + *---------------------------------------------------------------------------- +*/ +static int Reverb(reverb_object_t* pReverbData, int nNumSamplesToAdd, short *pOutputBuffer, short *pInputBuffer); + +/*---------------------------------------------------------------------------- + * ReverbReadInPresets() + *---------------------------------------------------------------------------- + * Purpose: sets global reverb preset bank to defaults + * + * Inputs: + * + * Outputs: + * + *---------------------------------------------------------------------------- +*/ +static int ReverbReadInPresets(reverb_object_t* pReverbData); + + +/*---------------------------------------------------------------------------- + * ReverbUpdateRoom + *---------------------------------------------------------------------------- + * Purpose: + * Update the room's preset parameters as required + * + * Inputs: + * + * Outputs: + * + * + * Side Effects: + * - reverb paramters (fbk, fwd, etc) will be changed + * - m_nCurrentRoom := m_nNextRoom + *---------------------------------------------------------------------------- +*/ +static int ReverbUpdateRoom(reverb_object_t* pReverbData, bool fullUpdate); + + +static int ReverbComputeConstants(reverb_object_t *pReverbData, uint32_t samplingRate); + +#endif /*ANDROID_EFFECTREVERB_H_*/ diff --git a/media/libeffects/testlibs/EffectsMath.c b/media/libeffects/testlibs/EffectsMath.c new file mode 100644 index 0000000..41ec662 --- /dev/null +++ b/media/libeffects/testlibs/EffectsMath.c @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define LOG_TAG "EFFECTSMATH" +//#define LOG_NDEBUG 0 +#include +#include + +#include "EffectsMath.h" + +// gLogTab contains pre-calculated values of log2(1 + ai5*2^-1 + ai4*2^-2 + ai3*2^-3 + ai2*2^-4 + ai1*2^-5 + ai0*2^-6) +// for integers in the range 0 to 63 (i = ai5*2^5 + ai4*2^4 + ai3*2^3 + ai2*2^2 + ai1*2^1 + ai0*2^0) +// It is used for a better than piece wise approximation of lin to log2 conversion + +static const uint16_t gLogTab[] = +{ + 0, 733, 1455, 2166, + 2866, 3556, 4236, 4907, + 5568, 6220, 6863, 7498, + 8124, 8742, 9352, 9954, + 10549, 11136, 11716, 12289, + 12855, 13415, 13968, 14514, + 15055, 15589, 16117, 16639, + 17156, 17667, 18173, 18673, + 19168, 19658, 20143, 20623, + 21098, 21568, 22034, 22495, + 22952, 23404, 23852, 24296, + 24736, 25172, 25604, 26031, + 26455, 26876, 27292, 27705, + 28114, 28520, 28922, 29321, + 29717, 30109, 30498, 30884, + 31267, 31647, 32024, 32397, + 32768 +}; + +int32_t Effects_log2(uint32_t x) { + int32_t exp = 31 - __builtin_clz(x); + uint32_t segStart = x >> (exp - 6); + uint32_t i = segStart & 0x3F; + int32_t log = (int32_t)gLogTab[i]; + int32_t logEnd = (int32_t)gLogTab[i+1]; + segStart <<= exp - 6; + + return (exp << 15) + log + (((x - segStart) * (logEnd - log)) >> (exp - 6)); +} + +// gExpTab[i] = (2^(i>>6)) << 22 +static const uint32_t gExpTab[] = { + 4194304, 4239977, 4286147, 4332820, + 4380002, 4427697, 4475911, 4524651, + 4573921, 4623728, 4674077, 4724974, + 4776426, 4828438, 4881016, 4934167, + 4987896, 5042211, 5097117, 5152621, + 5208729, 5265449, 5322786, 5380747, + 5439339, 5498570, 5558445, 5618973, + 5680159, 5742012, 5804539, 5867746, + 5931642, 5996233, 6061528, 6127533, + 6194258, 6261709, 6329894, 6398822, + 6468501, 6538938, 6610143, 6682122, + 6754886, 6828442, 6902799, 6977965, + 7053950, 7130763, 7208412, 7286906, + 7366255, 7446469, 7527555, 7609525, + 7692387, 7776152, 7860829, 7946428, + 8032959, 8120432, 8208857, 8298246, + 8388608 +}; + + +uint32_t Effects_exp2(int32_t x) { + int32_t i = x >> 15; + assert(i < 32); + x &= (1 << 15) - 1; + int32_t j = x >> 9; + x &= (1 << 9) - 1; + uint32_t exp = gExpTab[j]; + uint32_t expEnd = gExpTab[j+1]; + + return ((exp << 9) + (expEnd - exp) * x) >> (31 - i); +} + + +int16_t Effects_MillibelsToLinear16 (int32_t nGain) +{ + nGain = ((nGain + MB_TO_LIN_K1) << 15 ) / MB_TO_LIN_K2; + uint32_t exp2 = Effects_exp2(nGain); + + if (exp2 > 32767) exp2 = 32767; + + return (int16_t)exp2; +} + + +int16_t Effects_Linear16ToMillibels (int32_t nGain) +{ + return (int16_t)(((MB_TO_LIN_K2*Effects_log2(nGain))>>15)-MB_TO_LIN_K1); +} + + +int32_t Effects_Sqrt(int32_t in) +{ + int32_t tmp; + int32_t out = 0; + int32_t i; + int32_t j; + + + if (in == 0) return 0; + + if (in >= 0x10000000) + { + out = 0x4000; + in -= 0x10000000; + } + + j = 32 - __builtin_clz(in); + + if (j & 1) j++; + j >>= 1; + + for (i = j; i > 0; i--) { + tmp = (out << i) + (1 << ((i - 1)*2)); + if (in >= tmp) + { + out += 1 << (i-1); + in -= tmp; + } + } + + return out; +} + diff --git a/media/libeffects/testlibs/EffectsMath.h b/media/libeffects/testlibs/EffectsMath.h new file mode 100644 index 0000000..2a44399 --- /dev/null +++ b/media/libeffects/testlibs/EffectsMath.h @@ -0,0 +1,424 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EFFECTSMATH_H_ +#define ANDROID_EFFECTSMATH_H_ + +#include + +#if __cplusplus +extern "C" { +#endif + +/** coefs for pan, generates sin, cos */ +#define COEFF_PAN_G2 -27146 /* -0.82842712474619 = 2 - 4/sqrt(2) */ +#define COEFF_PAN_G0 23170 /* 0.707106781186547 = 1/sqrt(2) */ + +/* +coefficients for approximating +2^x = gn2toX0 + gn2toX1*x + gn2toX2*x^2 + gn2toX3*x^3 +where x is a int.frac number representing number of octaves. +Actually, we approximate only the 2^(frac) using the power series +and implement the 2^(int) as a shift, so that +2^x == 2^(int.frac) == 2^(int) * 2^(fract) + == (gn2toX0 + gn2toX1*x + gn2toX2*x^2 + gn2toX3*x^3) << (int) + +The gn2toX.. were generated using a best fit for a 3rd +order polynomial, instead of taking the coefficients from +a truncated Taylor (or Maclaurin?) series. +*/ + +#define GN2_TO_X0 32768 /* 1 */ +#define GN2_TO_X1 22833 /* 0.696807861328125 */ +#define GN2_TO_X2 7344 /* 0.22412109375 */ +#define GN2_TO_X3 2588 /* 0.0789794921875 */ + +/*---------------------------------------------------------------------------- + * Fixed Point Math + *---------------------------------------------------------------------------- + * These macros are used for fixed point multiplies. If the processor + * supports fixed point multiplies, replace these macros with inline + * assembly code to improve performance. + *---------------------------------------------------------------------------- +*/ + +/* Fixed point multiply 0.15 x 0.15 = 0.15 returned as 32-bits */ +#define FMUL_15x15(a,b) \ + /*lint -e(704) */ \ + (((int32_t)(a) * (int32_t)(b)) >> 15) + +/* Fixed point multiply 0.7 x 0.7 = 0.15 returned as 32-bits */ +#define FMUL_7x7(a,b) \ + /*lint -e(704) */ \ + (((int32_t)(a) * (int32_t)(b) ) << 1) + +/* Fixed point multiply 0.8 x 0.8 = 0.15 returned as 32-bits */ +#define FMUL_8x8(a,b) \ + /*lint -e(704) */ \ + (((int32_t)(a) * (int32_t)(b) ) >> 1) + +/* Fixed point multiply 0.8 x 1.15 = 0.15 returned as 32-bits */ +#define FMUL_8x15(a,b) \ + /*lint -e(704) */ \ + (((int32_t)((a) << 7) * (int32_t)(b)) >> 15) + +/* macros for fractional phase accumulator */ +/* +Note: changed the _U32 to _I32 on 03/14/02. This should not +affect the phase calculations, and should allow us to reuse these +macros for other audio sample related math. +*/ +#define HARDWARE_BIT_WIDTH 32 + +#define NUM_PHASE_INT_BITS 1 +#define NUM_PHASE_FRAC_BITS 15 + +#define PHASE_FRAC_MASK (uint32_t) ((0x1L << NUM_PHASE_FRAC_BITS) -1) + +#define GET_PHASE_INT_PART(x) (uint32_t)((uint32_t)(x) >> NUM_PHASE_FRAC_BITS) +#define GET_PHASE_FRAC_PART(x) (uint32_t)((uint32_t)(x) & PHASE_FRAC_MASK) + +#define DEFAULT_PHASE_FRAC 0 +#define DEFAULT_PHASE_INT 0 + +/* +Linear interpolation calculates: +output = (1-frac) * sample[n] + (frac) * sample[n+1] + +where conceptually 0 <= frac < 1 + +For a fixed point implementation, frac is actually an integer value +with an implied binary point one position to the left. The value of +one (unity) is given by PHASE_ONE +one half and one quarter are useful for 4-point linear interp. +*/ +#define PHASE_ONE (int32_t) (0x1L << NUM_PHASE_FRAC_BITS) + +/* + Multiply the signed audio sample by the unsigned fraction. +- a is the signed audio sample +- b is the unsigned fraction (cast to signed int as long as coef + uses (n-1) or less bits, where n == hardware bit width) +*/ +#define MULT_AUDIO_COEF(audio,coef) /*lint -e704 */ \ + (int32_t)( \ + ( \ + ((int32_t)(audio)) * ((int32_t)(coef)) \ + ) \ + >> NUM_PHASE_FRAC_BITS \ + ) \ + /* lint +704 */ + +/* wet / dry calculation macros */ +#define NUM_WET_DRY_FRAC_BITS 7 // 15 +#define NUM_WET_DRY_INT_BITS 9 // 1 + +/* define a 1.0 */ +#define WET_DRY_ONE (int32_t) ((0x1L << NUM_WET_DRY_FRAC_BITS)) +#define WET_DRY_MINUS_ONE (int32_t) (~WET_DRY_ONE) +#define WET_DRY_FULL_SCALE (int32_t) (WET_DRY_ONE - 1) + +#define MULT_AUDIO_WET_DRY_COEF(audio,coef) /*lint -e(702) */ \ + (int32_t)( \ + ( \ + ((int32_t)(audio)) * ((int32_t)(coef)) \ + ) \ + >> NUM_WET_DRY_FRAC_BITS \ + ) + +/* Envelope 1 (EG1) calculation macros */ +#define NUM_EG1_INT_BITS 1 +#define NUM_EG1_FRAC_BITS 15 + +/* the max positive gain used in the synth for EG1 */ +/* SYNTH_FULL_SCALE_EG1_GAIN must match the value in the dls2eas +converter, otherwise, the values we read from the .eas file are bogus. */ +#define SYNTH_FULL_SCALE_EG1_GAIN (int32_t) ((0x1L << NUM_EG1_FRAC_BITS) -1) + +/* define a 1.0 */ +#define EG1_ONE (int32_t) ((0x1L << NUM_EG1_FRAC_BITS)) +#define EG1_MINUS_ONE (int32_t) (~SYNTH_FULL_SCALE_EG1_GAIN) + +#define EG1_HALF (int32_t) (EG1_ONE/2) +#define EG1_MINUS_HALF (int32_t) (EG1_MINUS_ONE/2) + +/* +We implement the EG1 using a linear gain value, which means that the +attack segment is handled by incrementing (adding) the linear gain. +However, EG1 treats the Decay, Sustain, and Release differently than +the Attack portion. For Decay, Sustain, and Release, the gain is +linear on dB scale, which is equivalent to exponential damping on +a linear scale. Because we use a linear gain for EG1, we implement +the Decay and Release as multiplication (instead of incrementing +as we did for the attack segment). +Therefore, we need the following macro to implement the multiplication +(i.e., exponential damping) during the Decay and Release segments of +the EG1 +*/ +#define MULT_EG1_EG1(gain,damping) /*lint -e(704) */ \ + (int32_t)( \ + ( \ + ((int32_t)(gain)) * ((int32_t)(damping)) \ + ) \ + >> NUM_EG1_FRAC_BITS \ + ) + +// Use the following macro specifically for the filter, when multiplying +// the b1 coefficient. The 0 <= |b1| < 2, which therefore might overflow +// in certain conditions because we store b1 as a 1.15 value. +// Instead, we could store b1 as b1p (b1' == b1 "prime") where +// b1p == b1/2, thus ensuring no potential overflow for b1p because +// 0 <= |b1p| < 1 +// However, during the filter calculation, we must account for the fact +// that we are using b1p instead of b1, and thereby multiply by +// an extra factor of 2. Rather than multiply by an extra factor of 2, +// we can instead shift the result right by one less, hence the +// modified shift right value of (NUM_EG1_FRAC_BITS -1) +#define MULT_EG1_EG1_X2(gain,damping) /*lint -e(702) */ \ + (int32_t)( \ + ( \ + ((int32_t)(gain)) * ((int32_t)(damping)) \ + ) \ + >> (NUM_EG1_FRAC_BITS -1) \ + ) + +#define SATURATE_EG1(x) /*lint -e{734} saturation operation */ \ + ((int32_t)(x) > SYNTH_FULL_SCALE_EG1_GAIN) ? (SYNTH_FULL_SCALE_EG1_GAIN) : \ + ((int32_t)(x) < EG1_MINUS_ONE) ? (EG1_MINUS_ONE) : (x); + + +/* use "digital cents" == "dents" instead of cents */ +/* we coudl re-use the phase frac macros, but if we do, +we must change the phase macros to cast to _I32 instead of _U32, +because using a _U32 cast causes problems when shifting the exponent +for the 2^x calculation, because right shift a negative values MUST +be sign extended, or else the 2^x calculation is wrong */ + +/* use "digital cents" == "dents" instead of cents */ +#define NUM_DENTS_FRAC_BITS 12 +#define NUM_DENTS_INT_BITS (HARDWARE_BIT_WIDTH - NUM_DENTS_FRAC_BITS) + +#define DENTS_FRAC_MASK (int32_t) ((0x1L << NUM_DENTS_FRAC_BITS) -1) + +#define GET_DENTS_INT_PART(x) /*lint -e(704) */ \ + (int32_t)((int32_t)(x) >> NUM_DENTS_FRAC_BITS) + +#define GET_DENTS_FRAC_PART(x) (int32_t)((int32_t)(x) & DENTS_FRAC_MASK) + +#define DENTS_ONE (int32_t) (0x1L << NUM_DENTS_FRAC_BITS) + +/* use CENTS_TO_DENTS to convert a value in cents to dents */ +#define CENTS_TO_DENTS (int32_t) (DENTS_ONE * (0x1L << NUM_EG1_FRAC_BITS) / 1200L) \ + + +/* +For gain, the LFO generates a value that modulates in terms +of dB. However, we use a linear gain value, so we must convert +the LFO value in dB to a linear gain. Normally, we would use +linear gain = 10^x, where x = LFO value in dB / 20. +Instead, we implement 10^x using our 2^x approximation. +because + + 10^x = 2^(log2(10^x)) = 2^(x * log2(10)) + +so we need to multiply by log2(10) which is just a constant. +Ah, but just wait -- our 2^x actually doesn't exactly implement +2^x, but it actually assumes that the input is in cents, and within +the 2^x approximation converts its input from cents to octaves +by dividing its input by 1200. + +So, in order to convert the LFO gain value in dB to something +that our existing 2^x approximation can use, multiply the LFO gain +by log2(10) * 1200 / 20 + +The divide by 20 helps convert dB to linear gain, and we might +as well incorporate that operation into this conversion. +Of course, we need to keep some fractional bits, so multiply +the constant by NUM_EG1_FRAC_BITS +*/ + +/* use LFO_GAIN_TO_CENTS to convert the LFO gain value to cents */ +#if 0 +#define DOUBLE_LOG2_10 (double) (3.32192809488736) /* log2(10) */ + +#define DOUBLE_LFO_GAIN_TO_CENTS (double) \ + ( \ + (DOUBLE_LOG2_10) * \ + 1200.0 / \ + 20.0 \ + ) + +#define LFO_GAIN_TO_CENTS (int32_t) \ + ( \ + DOUBLE_LFO_GAIN_TO_CENTS * \ + (0x1L << NUM_EG1_FRAC_BITS) \ + ) +#endif + +#define LFO_GAIN_TO_CENTS (int32_t) (1671981156L >> (23 - NUM_EG1_FRAC_BITS)) + + +#define MULT_DENTS_COEF(dents,coef) /*lint -e704 */ \ + (int32_t)( \ + ( \ + ((int32_t)(dents)) * ((int32_t)(coef)) \ + ) \ + >> NUM_DENTS_FRAC_BITS \ + ) \ + /* lint +e704 */ + + +/* we use 16-bits in the PC per audio sample */ +#define BITS_PER_AUDIO_SAMPLE 16 + +/* we define 1 as 1.0 - 1 LSbit */ +#define DISTORTION_ONE (int32_t)((0x1L << (BITS_PER_AUDIO_SAMPLE-1)) -1) +#define DISTORTION_MINUS_ONE (int32_t)(~DISTORTION_ONE) + +/* drive coef is given as int.frac */ +#define NUM_DRIVE_COEF_INT_BITS 1 +#define NUM_DRIVE_COEF_FRAC_BITS 4 + +#define MULT_AUDIO_DRIVE(audio,drive) /*lint -e(702) */ \ + (int32_t) ( \ + ( \ + ((int32_t)(audio)) * ((int32_t)(drive)) \ + ) \ + >> NUM_DRIVE_COEF_FRAC_BITS \ + ) + +#define MULT_AUDIO_AUDIO(audio1,audio2) /*lint -e(702) */ \ + (int32_t) ( \ + ( \ + ((int32_t)(audio1)) * ((int32_t)(audio2)) \ + ) \ + >> (BITS_PER_AUDIO_SAMPLE-1) \ + ) + +#define SATURATE(x) \ + ((((int32_t)(x)) > DISTORTION_ONE) ? (DISTORTION_ONE) : \ + (((int32_t)(x)) < DISTORTION_MINUS_ONE) ? (DISTORTION_MINUS_ONE) : ((int32_t)(x))); + + +/*---------------------------------------------------------------------------- + * Effects_log2() + *---------------------------------------------------------------------------- + * Purpose: + * Fixed-point log2 function. + * + * Inputs: + * Input is interpreted as an integer (should not be 0). + * + * Outputs: + * Output is in 15-bit precision. + * + * Side Effects: + * + *---------------------------------------------------------------------------- +*/ +int32_t Effects_log2(uint32_t x); + +/*---------------------------------------------------------------------------- + * Effects_exp2() + *---------------------------------------------------------------------------- + * Purpose: + * Fixed-point radix-2 exponent. + * + * Inputs: + * Input is in 15-bit precision. Must be non-negative and less than 32. + * + * Outputs: + * Output is an integer. + * + * Side Effects: + * + *---------------------------------------------------------------------------- +*/ +uint32_t Effects_exp2(int32_t x); + +/*---------------------------------------------------------------------------- + * Effects_MillibelsToLinear16() + *---------------------------------------------------------------------------- + * Purpose: + * Transform gain in millibels to linear gain multiplier: + * + * mB = 2000*log(lin/32767) + * => lin = 2^((mB+2000*log(32767))/2000*log(2)) + * => lin = Effects_exp2(((mB + K1) << 15) / K2) + * with: + * K1 = 2000*log(32767) and K2 = 2000*log(2) + * + * Inputs: + * nGain - log scale value in millibels. + * + * Outputs: + * Returns a 16-bit linear value approximately equal to 2^(nGain/1024) + * + * Side Effects: + * + *---------------------------------------------------------------------------- +*/ +#define MB_TO_LIN_K1 9031 +#define MB_TO_LIN_K2 602 +int16_t Effects_MillibelsToLinear16 (int32_t nGain); + +/*---------------------------------------------------------------------------- + * Effects_Linear16ToMillibels() + *---------------------------------------------------------------------------- + * Purpose: + * Transform linear gain multiplier to millibels + * mB = 2000*log(lin/32767) + * = 2000*log(2)*log2(lin)-2000*log(32767) + * => mB = K1*Effects_log2(lin) + K2 + * with: + * K1 = 2000*log(2) and K2 = -2000*log(32767) + * + * Inputs: + * nGain - linear multiplier ranging form 0 to 32767 (corresponding to [0 1] gain range). + * + * Outputs: + * Returns a 16-bit log value expressed in milllibels. + * + * Side Effects: + * + *---------------------------------------------------------------------------- +*/ +int16_t Effects_Linear16ToMillibels (int32_t nGain); + +/*---------------------------------------------------------------------------- + * Effects_Sqrt() + *---------------------------------------------------------------------------- + * Purpose: + * Returns the square root of the argument given. + * + * Inputs: + * in - positive number in the range 0 - 2^28 + * + * Outputs: + * Returned value: square root of in. + * + * Side Effects: + * + *---------------------------------------------------------------------------- +*/ +int32_t Effects_Sqrt(int32_t in); + +#if __cplusplus +} // extern "C" +#endif + +#endif /*ANDROID_EFFECTSMATH_H_*/ + diff --git a/media/libeffects/visualizer/Android.mk b/media/libeffects/visualizer/Android.mk new file mode 100644 index 0000000..82cd925 --- /dev/null +++ b/media/libeffects/visualizer/Android.mk @@ -0,0 +1,30 @@ +LOCAL_PATH:= $(call my-dir) + +# Visualizer library +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + EffectVisualizer.cpp + +LOCAL_CFLAGS+= -O2 + +LOCAL_SHARED_LIBRARIES := \ + libcutils + +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/soundfx +LOCAL_MODULE:= libvisualizer + +ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true) +LOCAL_LDLIBS += -ldlS +endif + +ifneq ($(TARGET_SIMULATOR),true) +LOCAL_SHARED_LIBRARIES += libdl +endif + +LOCAL_C_INCLUDES := \ + $(call include-path-for, graphics corecg) + +LOCAL_PRELINK_MODULE := false + +include $(BUILD_SHARED_LIBRARY) \ No newline at end of file diff --git a/media/libeffects/visualizer/EffectVisualizer.cpp b/media/libeffects/visualizer/EffectVisualizer.cpp new file mode 100644 index 0000000..bcda06e --- /dev/null +++ b/media/libeffects/visualizer/EffectVisualizer.cpp @@ -0,0 +1,401 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "Visualizer" +//#define LOG_NDEBUG 0 +#include +#include +#include +#include +#include +#include + +namespace android { + +// effect_interface_t interface implementation for visualizer effect +extern "C" const struct effect_interface_s gVisualizerInterface; + +// Google Visualizer UUID: d069d9e0-8329-11df-9168-0002a5d5c51b +const effect_descriptor_t gVisualizerDescriptor = { + {0xe46b26a0, 0xdddd, 0x11db, 0x8afd, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type + {0xd069d9e0, 0x8329, 0x11df, 0x9168, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid + EFFECT_API_VERSION, + (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST), + 0, // TODO + 1, + "Visualizer", + "Google Inc.", +}; + +enum visualizer_state_e { + VISUALIZER_STATE_UNINITIALIZED, + VISUALIZER_STATE_INITIALIZED, + VISUALIZER_STATE_ACTIVE, +}; + +struct VisualizerContext { + const struct effect_interface_s *mItfe; + effect_config_t mConfig; + uint32_t mState; + uint32_t mCaptureIdx; + uint32_t mCaptureSize; + uint32_t mCurrentBuf; + uint8_t mCaptureBuf[2][VISUALIZER_CAPTURE_SIZE_MAX]; +}; + + +// +//--- Local functions +// + +void Visualizer_reset(VisualizerContext *pContext) +{ + pContext->mCaptureIdx = 0; + pContext->mCurrentBuf = 0; + memset(pContext->mCaptureBuf[0], 0, VISUALIZER_CAPTURE_SIZE_MAX); + memset(pContext->mCaptureBuf[1], 0, VISUALIZER_CAPTURE_SIZE_MAX); +} + +//---------------------------------------------------------------------------- +// Visualizer_configure() +//---------------------------------------------------------------------------- +// Purpose: Set input and output audio configuration. +// +// Inputs: +// pContext: effect engine context +// pConfig: pointer to effect_config_t structure holding input and output +// configuration parameters +// +// Outputs: +// +//---------------------------------------------------------------------------- + +int Visualizer_configure(VisualizerContext *pContext, effect_config_t *pConfig) +{ + LOGV("Visualizer_configure start"); + + if (pConfig->inputCfg.samplingRate != pConfig->outputCfg.samplingRate) return -EINVAL; + if (pConfig->inputCfg.channels != pConfig->outputCfg.channels) return -EINVAL; + if (pConfig->inputCfg.format != pConfig->outputCfg.format) return -EINVAL; + if (pConfig->inputCfg.channels != CHANNEL_STEREO) return -EINVAL; + if (pConfig->outputCfg.accessMode != EFFECT_BUFFER_ACCESS_WRITE && + pConfig->outputCfg.accessMode != EFFECT_BUFFER_ACCESS_ACCUMULATE) return -EINVAL; + if (pConfig->inputCfg.format != SAMPLE_FORMAT_PCM_S15) return -EINVAL; + + memcpy(&pContext->mConfig, pConfig, sizeof(effect_config_t)); + + Visualizer_reset(pContext); + + return 0; +} + + +//---------------------------------------------------------------------------- +// Visualizer_init() +//---------------------------------------------------------------------------- +// Purpose: Initialize engine with default configuration. +// +// Inputs: +// pContext: effect engine context +// +// Outputs: +// +//---------------------------------------------------------------------------- + +int Visualizer_init(VisualizerContext *pContext) +{ + pContext->mConfig.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; + pContext->mConfig.inputCfg.channels = CHANNEL_STEREO; + pContext->mConfig.inputCfg.format = SAMPLE_FORMAT_PCM_S15; + pContext->mConfig.inputCfg.samplingRate = 44100; + pContext->mConfig.inputCfg.bufferProvider.getBuffer = NULL; + pContext->mConfig.inputCfg.bufferProvider.releaseBuffer = NULL; + pContext->mConfig.inputCfg.bufferProvider.cookie = NULL; + pContext->mConfig.inputCfg.mask = EFFECT_CONFIG_ALL; + pContext->mConfig.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; + pContext->mConfig.outputCfg.channels = CHANNEL_STEREO; + pContext->mConfig.outputCfg.format = SAMPLE_FORMAT_PCM_S15; + pContext->mConfig.outputCfg.samplingRate = 44100; + pContext->mConfig.outputCfg.bufferProvider.getBuffer = NULL; + pContext->mConfig.outputCfg.bufferProvider.releaseBuffer = NULL; + pContext->mConfig.outputCfg.bufferProvider.cookie = NULL; + pContext->mConfig.outputCfg.mask = EFFECT_CONFIG_ALL; + + pContext->mCaptureSize = VISUALIZER_CAPTURE_SIZE_MAX; + + Visualizer_configure(pContext, &pContext->mConfig); + + return 0; +} + +// +//--- Effect Library Interface Implementation +// + +extern "C" int EffectQueryNumberEffects(uint32_t *pNumEffects) { + *pNumEffects = 1; + return 0; +} + +extern "C" int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor) { + if (pDescriptor == NULL) { + return -EINVAL; + } + if (index > 0) { + return -EINVAL; + } + memcpy(pDescriptor, &gVisualizerDescriptor, sizeof(effect_descriptor_t)); + return 0; +} + +extern "C" int EffectCreate(effect_uuid_t *uuid, + int32_t sessionId, + int32_t ioId, + effect_interface_t *pInterface) { + int ret; + int i; + + if (pInterface == NULL || uuid == NULL) { + return -EINVAL; + } + + if (memcmp(uuid, &gVisualizerDescriptor.uuid, sizeof(effect_uuid_t)) != 0) { + return -EINVAL; + } + + VisualizerContext *pContext = new VisualizerContext; + + pContext->mItfe = &gVisualizerInterface; + pContext->mState = VISUALIZER_STATE_UNINITIALIZED; + + ret = Visualizer_init(pContext); + if (ret < 0) { + LOGW("EffectCreate() init failed"); + delete pContext; + return ret; + } + + *pInterface = (effect_interface_t)pContext; + + pContext->mState = VISUALIZER_STATE_INITIALIZED; + + LOGV("EffectCreate %p", pContext); + + return 0; + +} + +extern "C" int EffectRelease(effect_interface_t interface) { + VisualizerContext * pContext = (VisualizerContext *)interface; + + LOGV("EffectRelease %p", interface); + if (pContext == NULL) { + return -EINVAL; + } + pContext->mState = VISUALIZER_STATE_UNINITIALIZED; + delete pContext; + + return 0; +} + +// +//--- Effect Control Interface Implementation +// + +static inline int16_t clamp16(int32_t sample) +{ + if ((sample>>15) ^ (sample>>31)) + sample = 0x7FFF ^ (sample>>31); + return sample; +} + +extern "C" int Visualizer_process( + effect_interface_t self,audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) +{ + android::VisualizerContext * pContext = (android::VisualizerContext *)self; + + if (pContext == NULL) { + return -EINVAL; + } + if (pContext->mState != VISUALIZER_STATE_ACTIVE) { + return -ENODATA; + } + + if (inBuffer == NULL || inBuffer->raw == NULL || + outBuffer == NULL || outBuffer->raw == NULL || + inBuffer->frameCount != outBuffer->frameCount || + inBuffer->frameCount == 0) { + return -EINVAL; + } + + // all code below assumes stereo 16 bit PCM output and input + uint32_t captIdx; + uint32_t inIdx; + uint8_t *buf = pContext->mCaptureBuf[pContext->mCurrentBuf]; + for (inIdx = 0, captIdx = pContext->mCaptureIdx; + inIdx < inBuffer->frameCount && captIdx < pContext->mCaptureSize; + inIdx++, captIdx++) { + int32_t smp = inBuffer->s16[2 * inIdx] + inBuffer->s16[2 * inIdx + 1]; + smp = (smp + (1 << 8)) >> 9; + buf[captIdx] = ((uint8_t)smp)^0x80; + } + pContext->mCaptureIdx = captIdx; + + // go to next buffer when buffer full + if (pContext->mCaptureIdx == pContext->mCaptureSize) { + pContext->mCurrentBuf ^= 1; + pContext->mCaptureIdx = 0; + } + + if (inBuffer->raw != outBuffer->raw) { + if (pContext->mConfig.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) { + for (size_t i = 0; i < outBuffer->frameCount*2; i++) { + outBuffer->s16[i] = clamp16(outBuffer->s16[i] + inBuffer->s16[i]); + } + } else { + memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount * 2 * sizeof(int16_t)); + } + } + return 0; +} // end Visualizer_process + +extern "C" int Visualizer_command(effect_interface_t self, int cmdCode, int cmdSize, + void *pCmdData, int *replySize, void *pReplyData) { + + android::VisualizerContext * pContext = (android::VisualizerContext *)self; + int retsize; + + if (pContext == NULL || pContext->mState == VISUALIZER_STATE_UNINITIALIZED) { + return -EINVAL; + } + +// LOGV("Visualizer_command command %d cmdSize %d",cmdCode, cmdSize); + + switch (cmdCode) { + case EFFECT_CMD_INIT: + if (pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + *(int *) pReplyData = Visualizer_init(pContext); + break; + case EFFECT_CMD_CONFIGURE: + if (pCmdData == NULL || cmdSize != sizeof(effect_config_t) + || pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + *(int *) pReplyData = Visualizer_configure(pContext, + (effect_config_t *) pCmdData); + break; + case EFFECT_CMD_RESET: + Visualizer_reset(pContext); + break; + case EFFECT_CMD_ENABLE: + if (pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + if (pContext->mState != VISUALIZER_STATE_INITIALIZED) { + return -ENOSYS; + } + pContext->mState = VISUALIZER_STATE_ACTIVE; + LOGV("EFFECT_CMD_ENABLE() OK"); + *(int *)pReplyData = 0; + break; + case EFFECT_CMD_DISABLE: + if (pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + if (pContext->mState != VISUALIZER_STATE_ACTIVE) { + return -ENOSYS; + } + pContext->mState = VISUALIZER_STATE_INITIALIZED; + LOGV("EFFECT_CMD_DISABLE() OK"); + *(int *)pReplyData = 0; + break; + case EFFECT_CMD_GET_PARAM: { + if (pCmdData == NULL || + cmdSize != (int)(sizeof(effect_param_t) + sizeof(uint32_t)) || + pReplyData == NULL || + *replySize < (int)(sizeof(effect_param_t) + sizeof(uint32_t) + sizeof(uint32_t))) { + return -EINVAL; + } + memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + sizeof(uint32_t)); + effect_param_t *p = (effect_param_t *)pReplyData; + p->status = 0; + *replySize = sizeof(effect_param_t) + sizeof(uint32_t); + if (p->psize != sizeof(uint32_t) || + *(uint32_t *)p->data != VISU_PARAM_CAPTURE_SIZE) { + p->status = -EINVAL; + break; + } + LOGV("get mCaptureSize = %d", pContext->mCaptureSize); + *((uint32_t *)p->data + 1) = pContext->mCaptureSize; + p->vsize = sizeof(uint32_t); + *replySize += sizeof(uint32_t); + } break; + case EFFECT_CMD_SET_PARAM: { + if (pCmdData == NULL || + cmdSize != (int)(sizeof(effect_param_t) + sizeof(uint32_t) + sizeof(uint32_t)) || + pReplyData == NULL || *replySize != sizeof(int32_t)) { + return -EINVAL; + } + *(int32_t *)pReplyData = 0; + effect_param_t *p = (effect_param_t *)pCmdData; + if (p->psize != sizeof(uint32_t) || + p->vsize != sizeof(uint32_t) || + *(uint32_t *)p->data != VISU_PARAM_CAPTURE_SIZE) { + *(int32_t *)pReplyData = -EINVAL; + break;; + } + pContext->mCaptureSize = *((uint32_t *)p->data + 1); + LOGV("set mCaptureSize = %d", pContext->mCaptureSize); + } break; + case EFFECT_CMD_SET_DEVICE: + case EFFECT_CMD_SET_VOLUME: + case EFFECT_CMD_SET_AUDIO_MODE: + break; + + + case VISU_CMD_CAPTURE: + if (pReplyData == NULL || *replySize != (int)pContext->mCaptureSize) { + LOGV("VISU_CMD_CAPTURE() error *replySize %d pContext->mCaptureSize %d", + *replySize, pContext->mCaptureSize); + return -EINVAL; + } + if (pContext->mState == VISUALIZER_STATE_ACTIVE) { + memcpy(pReplyData, + pContext->mCaptureBuf[pContext->mCurrentBuf ^ 1], + pContext->mCaptureSize); + } else { + memset(pReplyData, 0x80, pContext->mCaptureSize); + } + break; + + default: + LOGW("Visualizer_command invalid command %d",cmdCode); + return -EINVAL; + } + + return 0; +} + +// effect_interface_t interface implementation for visualizer effect +const struct effect_interface_s gVisualizerInterface = { + Visualizer_process, + Visualizer_command +}; + +} // namespace + -- cgit v1.1