EffectBundle.h revision c59c6fd7f859b4010d788db89b8d4d76bbb70e57
12c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* 22c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Copyright (C) 2010 The Android Open Source Project 32c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * 42c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Licensed under the Apache License, Version 2.0 (the "License"); 52c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * you may not use this file except in compliance with the License. 62c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * You may obtain a copy of the License at 72c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * 82c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * http://www.apache.org/licenses/LICENSE-2.0 92c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * 102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Unless required by applicable law or agreed to in writing, software 112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * distributed under the License is distributed on an "AS IS" BASIS, 122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * See the License for the specific language governing permissions and 142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * limitations under the License. 152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent */ 162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#ifndef ANDROID_EFFECTBUNDLE_H_ 182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define ANDROID_EFFECTBUNDLE_H_ 192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 2023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent#include <media/EffectEqualizerApi.h> 2123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent#include <media/EffectBassBoostApi.h> 2223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent#include <media/EffectVirtualizerApi.h> 232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <LVM.h> 242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#if __cplusplus 262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" { 272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#endif 282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define FIVEBAND_NUMBANDS 5 302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define MAX_NUM_BANDS 5 312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define MAX_CALL_SIZE 256 32163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//#define LVM_PCM 332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 3423e1de74359f4bb1763aef0adfebe073122b032cEric Laurent#ifndef OPENSL_ES_H_ 35163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentstatic const effect_uuid_t SL_IID_VOLUME_ = { 0x09e8ede0, 0xddde, 0x11db, 0xb4f6, 36163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }; 372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_uuid_t * const SL_IID_VOLUME = &SL_IID_VOLUME_; 3823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent#endif //OPENSL_ES_H_ 392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurenttypedef enum 412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent{ 422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent LVM_BASS_BOOST, 432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent LVM_VIRTUALIZER, 44163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent LVM_EQUALIZER, 452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent LVM_VOLUME 462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} lvm_effect_en; 472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Preset configuration. 492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentstruct PresetConfig { 502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent // Human-readable name. 512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent const char * name; 522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent // An array of size nBands where each element is a configuration for the 532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent // corresponding band. 542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent //const BandConfig * bandConfigs; 552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}; 562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* BundledEffectContext : One per session */ 582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentstruct BundledEffectContext{ 59163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent LVM_Handle_t hInstance; /* Instance handle */ 60163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent int SessionNo; /* Current session number */ 61c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent int SessionId; /* Current session id */ 62163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent bool bVolumeEnabled; /* Flag for Volume */ 63163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent bool bEqualizerEnabled; /* Flag for EQ */ 64163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent bool bBassEnabled; /* Flag for Bass */ 65163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent bool bBassTempDisabled; /* Flag for Bass to be re-enabled */ 66163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent bool bVirtualizerEnabled; /* Flag for Virtualizer */ 67163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent bool bVirtualizerTempDisabled; /* Flag for effect to be re-enabled */ 68163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent int NumberEffectsEnabled; /* Effects in this session */ 69163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent int NumberEffectsCalled; /* Effects called so far */ 702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent // Saved parameters for each effect */ 712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent // Bass Boost 72163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent int BassStrengthSaved; /* Conversion between Get/Set */ 732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent // Equalizer 74163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent int CurPreset; /* Current preset being used */ 752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent // Virtualzer 76163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent int VirtStrengthSaved; /* Conversion between Get/Set */ 772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent // Volume 782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent int levelSaved; /* for when mute is set, level must be saved */ 79163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent int positionSaved; 80163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent bool bMuteEnabled; /* Must store as mute = -96dB level */ 81163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent bool bStereoPositionEnabled; 82163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent int frameCount; 83163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent LVM_Fs_en SampleRate; 84c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent int SamplesPerSecond; 85c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent int SamplesToExitCountEq; 86c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent int SamplesToExitCountBb; 87c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent int SamplesToExitCountVirt; 88163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent #ifdef LVM_PCM 89163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent FILE *PcmInPtr; 90163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent FILE *PcmOutPtr; 91163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent #endif 922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}; 932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* SessionContext : One session */ 952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentstruct SessionContext{ 962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent bool bBundledEffectsEnabled; 97163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent bool bVolumeInstantiated; 982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent bool bEqualizerInstantiated; 992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent bool bBassInstantiated; 100163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent bool bVirtualizerInstantiated; 101163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent BundledEffectContext *pBundledContext; 1022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}; 1032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 1042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentstruct EffectContext{ 1052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent const struct effect_interface_s *itfe; 1062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent effect_config_t config; 1072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent lvm_effect_en EffectType; 108163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent BundledEffectContext *pBundledContext; 1092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}; 1102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 1112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 1122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* enumerated parameter settings for Volume effect */ 1132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurenttypedef enum 1142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent{ 1152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent VOLUME_PARAM_LEVEL, // type SLmillibel = typedef SLuint16 (set & get) 1162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent VOLUME_PARAM_MAXLEVEL, // type SLmillibel = typedef SLuint16 (get) 1172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent VOLUME_PARAM_MUTE, // type SLboolean = typedef SLuint32 (set & get) 1182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent VOLUME_PARAM_ENABLESTEREOPOSITION, // type SLboolean = typedef SLuint32 (set & get) 1192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent VOLUME_PARAM_STEREOPOSITION, // type SLpermille = typedef SLuint16 (set & get) 1202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} t_volume_params; 1212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 1222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentstatic const int PRESET_CUSTOM = -1; 1232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 1242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentstatic const uint32_t bandFreqRange[FIVEBAND_NUMBANDS][2] = { 125163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {30000, 120000}, 126163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {120001, 460000}, 127163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {460001, 1800000}, 128163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {1800001, 7000000}, 129163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {7000001, 1}}; 1302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 1312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentstatic const LVM_UINT16 EQNB_5BandPresetsFrequencies[] = { 132163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 60, /* Frequencies in Hz */ 133163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 230, 134163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 910, 135163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 3600, 136163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 14000}; 1372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 1382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentstatic const LVM_UINT16 EQNB_5BandPresetsQFactors[] = { 139163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 96, /* Q factor multiplied by 100 */ 140163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 96, 141163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 96, 142163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 96, 143163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 96}; 1442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 1452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentstatic const LVM_INT16 EQNB_5BandNormalPresets[] = { 146163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 3, 0, 0, 0, 3, /* Normal Preset */ 1472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 8, 5, -3, 5, 6, /* Classical Preset */ 1482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 15, -6, 7, 13, 10, /* Dance Preset */ 1492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 0, 0, 0, 0, 0, /* Flat Preset */ 1502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 6, -2, -2, 6, -3, /* Folk Preset */ 1512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 8, -8, 13, -1, -4, /* Heavy Metal Preset */ 1522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 10, 6, -4, 5, 8, /* Hip Hop Preset */ 1532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 8, 5, -4, 5, 9, /* Jazz Preset */ 1542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent -6, 4, 9, 4, -5, /* Pop Preset */ 1552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 10, 6, -1, 8, 10}; /* Rock Preset */ 1562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 157163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentstatic const LVM_INT16 EQNB_5BandSoftPresets[] = { 158163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 3, 0, 0, 0, 3, /* Normal Preset */ 159163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 5, 3, -2, 4, 4, /* Classical Preset */ 160163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 6, 0, 2, 4, 1, /* Dance Preset */ 161163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 0, 0, 0, 0, 0, /* Flat Preset */ 162163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 3, 0, 0, 2, -1, /* Folk Preset */ 163163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 4, 1, 9, 3, 0, /* Heavy Metal Preset */ 164163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 5, 3, 0, 1, 3, /* Hip Hop Preset */ 165163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 4, 2, -2, 2, 5, /* Jazz Preset */ 166163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent -1, 2, 5, 1, -2, /* Pop Preset */ 167163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 5, 3, -1, 3, 5}; /* Rock Preset */ 168163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent 1692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentstatic const PresetConfig gEqualizerPresets[] = { 170163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {"Normal"}, 171163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {"Classical"}, 172163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {"Dance"}, 173163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {"Flat"}, 174163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {"Folk"}, 175163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {"Heavy Metal"}, 176163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {"Hip Hop"}, 177163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {"Jazz"}, 178163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {"Pop"}, 179163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent {"Rock"}}; 1802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 1812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#if __cplusplus 1822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} // extern "C" 1832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#endif 1842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 1852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 1862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#endif /*ANDROID_EFFECTBUNDLE_H_*/ 187