EffectBundle.h revision d918324d44aa48b3b064ea9b87d0c520c38f15a9
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_EFFECTBUNDLE_H_
18#define ANDROID_EFFECTBUNDLE_H_
19
20#include <media/EffectEqualizerApi.h>
21#include <media/EffectBassBoostApi.h>
22#include <media/EffectVirtualizerApi.h>
23#include <LVM.h>
24
25#if __cplusplus
26extern "C" {
27#endif
28
29#define FIVEBAND_NUMBANDS          5
30#define MAX_NUM_BANDS              5
31#define MAX_CALL_SIZE              256
32#define LVM_MAX_SESSIONS           32
33#define BASS_BOOST_CUP_LOAD_ARM9E  150    // Expressed in 0.1 MIPS
34#define VIRTUALIZER_CUP_LOAD_ARM9E 120    // Expressed in 0.1 MIPS
35#define EQUALIZER_CUP_LOAD_ARM9E   220    // Expressed in 0.1 MIPS
36#define VOLUME_CUP_LOAD_ARM9E      0      // Expressed in 0.1 MIPS
37#define BUNDLE_MEM_USAGE           25     // Expressed in kB
38//#define LVM_PCM
39
40#ifndef OPENSL_ES_H_
41static const effect_uuid_t SL_IID_VOLUME_ = { 0x09e8ede0, 0xddde, 0x11db, 0xb4f6,
42                                            { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
43const effect_uuid_t * const SL_IID_VOLUME = &SL_IID_VOLUME_;
44#endif //OPENSL_ES_H_
45
46typedef enum
47{
48    LVM_BASS_BOOST,
49    LVM_VIRTUALIZER,
50    LVM_EQUALIZER,
51    LVM_VOLUME
52} lvm_effect_en;
53
54// Preset configuration.
55struct PresetConfig {
56    // Human-readable name.
57    const char * name;
58    // An array of size nBands where each element is a configuration for the
59    // corresponding band.
60    //const BandConfig * bandConfigs;
61};
62
63/* BundledEffectContext : One per session */
64struct BundledEffectContext{
65    LVM_Handle_t                    hInstance;                /* Instance handle */
66    int                             SessionNo;                /* Current session number */
67    int                             SessionId;                /* Current session id */
68    bool                            bVolumeEnabled;           /* Flag for Volume */
69    bool                            bEqualizerEnabled;        /* Flag for EQ */
70    bool                            bBassEnabled;             /* Flag for Bass */
71    bool                            bBassTempDisabled;        /* Flag for Bass to be re-enabled */
72    bool                            bVirtualizerEnabled;      /* Flag for Virtualizer */
73    bool                            bVirtualizerTempDisabled; /* Flag for effect to be re-enabled */
74    int                             NumberEffectsEnabled;     /* Effects in this session */
75    int                             NumberEffectsCalled;      /* Effects called so far */
76    bool                            firstVolume;              /* No smoothing on first Vol change */
77    // Saved parameters for each effect */
78    // Bass Boost
79    int                             BassStrengthSaved;        /* Conversion between Get/Set */
80    // Equalizer
81    int                             CurPreset;                /* Current preset being used */
82    // Virtualzer
83    int                             VirtStrengthSaved;        /* Conversion between Get/Set */
84    // Volume
85    int                             levelSaved;     /* for when mute is set, level must be saved */
86    int                             positionSaved;
87    bool                            bMuteEnabled;   /* Must store as mute = -96dB level */
88    bool                            bStereoPositionEnabled;
89    int                             frameCount;
90    LVM_Fs_en                       SampleRate;
91    int                             SamplesPerSecond;
92    int                             SamplesToExitCountEq;
93    int                             SamplesToExitCountBb;
94    int                             SamplesToExitCountVirt;
95    #ifdef LVM_PCM
96    FILE                            *PcmInPtr;
97    FILE                            *PcmOutPtr;
98    #endif
99};
100
101/* SessionContext : One session */
102struct SessionContext{
103    bool                            bBundledEffectsEnabled;
104    bool                            bVolumeInstantiated;
105    bool                            bEqualizerInstantiated;
106    bool                            bBassInstantiated;
107    bool                            bVirtualizerInstantiated;
108    BundledEffectContext            *pBundledContext;
109};
110
111struct EffectContext{
112    const struct effect_interface_s *itfe;
113    effect_config_t                 config;
114    lvm_effect_en                   EffectType;
115    BundledEffectContext            *pBundledContext;
116};
117
118
119/* enumerated parameter settings for Volume effect */
120typedef enum
121{
122    VOLUME_PARAM_LEVEL,                       // type SLmillibel = typedef SLuint16 (set & get)
123    VOLUME_PARAM_MAXLEVEL,                    // type SLmillibel = typedef SLuint16 (get)
124    VOLUME_PARAM_MUTE,                        // type SLboolean  = typedef SLuint32 (set & get)
125    VOLUME_PARAM_ENABLESTEREOPOSITION,        // type SLboolean  = typedef SLuint32 (set & get)
126    VOLUME_PARAM_STEREOPOSITION,              // type SLpermille = typedef SLuint16 (set & get)
127} t_volume_params;
128
129static const int PRESET_CUSTOM = -1;
130
131static const uint32_t bandFreqRange[FIVEBAND_NUMBANDS][2] = {
132                                       {30000, 120000},
133                                       {120001, 460000},
134                                       {460001, 1800000},
135                                       {1800001, 7000000},
136                                       {7000001, 1}};
137
138static const LVM_UINT16  EQNB_5BandPresetsFrequencies[] = {
139                                       60,           /* Frequencies in Hz */
140                                       230,
141                                       910,
142                                       3600,
143                                       14000};
144
145static const LVM_UINT16 EQNB_5BandPresetsQFactors[] = {
146                                       96,               /* Q factor multiplied by 100 */
147                                       96,
148                                       96,
149                                       96,
150                                       96};
151
152static const LVM_INT16 EQNB_5BandNormalPresets[] = {
153                                       3, 0, 0, 0, 3,       /* Normal Preset */
154                                       8, 5, -3, 5, 6,      /* Classical Preset */
155                                       15, -6, 7, 13, 10,   /* Dance Preset */
156                                       0, 0, 0, 0, 0,       /* Flat Preset */
157                                       6, -2, -2, 6, -3,    /* Folk Preset */
158                                       8, -8, 13, -1, -4,   /* Heavy Metal Preset */
159                                       10, 6, -4, 5, 8,     /* Hip Hop Preset */
160                                       8, 5, -4, 5, 9,      /* Jazz Preset */
161                                      -6, 4, 9, 4, -5,      /* Pop Preset */
162                                       10, 6, -1, 8, 10};   /* Rock Preset */
163
164static const LVM_INT16 EQNB_5BandSoftPresets[] = {
165                                        3, 0, 0, 0, 3,      /* Normal Preset */
166                                        5, 3, -2, 4, 4,     /* Classical Preset */
167                                        6, 0, 2, 4, 1,      /* Dance Preset */
168                                        0, 0, 0, 0, 0,      /* Flat Preset */
169                                        3, 0, 0, 2, -1,     /* Folk Preset */
170                                        4, 1, 9, 3, 0,      /* Heavy Metal Preset */
171                                        5, 3, 0, 1, 3,      /* Hip Hop Preset */
172                                        4, 2, -2, 2, 5,     /* Jazz Preset */
173                                       -1, 2, 5, 1, -2,     /* Pop Preset */
174                                        5, 3, -1, 3, 5};    /* Rock Preset */
175
176static const PresetConfig gEqualizerPresets[] = {
177                                        {"Normal"},
178                                        {"Classical"},
179                                        {"Dance"},
180                                        {"Flat"},
181                                        {"Folk"},
182                                        {"Heavy Metal"},
183                                        {"Hip Hop"},
184                                        {"Jazz"},
185                                        {"Pop"},
186                                        {"Rock"}};
187
188#if __cplusplus
189}  // extern "C"
190#endif
191
192
193#endif /*ANDROID_EFFECTBUNDLE_H_*/
194