Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | namespace android { |
| 18 | |
| 19 | class VolumeCurvePoint |
| 20 | { |
| 21 | public: |
| 22 | int mIndex; |
| 23 | float mDBAttenuation; |
| 24 | }; |
| 25 | |
| 26 | class StreamDescriptor; |
| 27 | |
| 28 | class ApmGains |
| 29 | { |
| 30 | public : |
| 31 | // 4 points to define the volume attenuation curve, each characterized by the volume |
| 32 | // index (from 0 to 100) at which they apply, and the attenuation in dB at that index. |
| 33 | // we use 100 steps to avoid rounding errors when computing the volume in volIndexToAmpl() |
| 34 | enum { VOLMIN = 0, VOLKNEE1 = 1, VOLKNEE2 = 2, VOLMAX = 3, VOLCNT = 4}; |
| 35 | |
| 36 | // device categories used for volume curve management. |
| 37 | enum device_category { |
| 38 | DEVICE_CATEGORY_HEADSET, |
| 39 | DEVICE_CATEGORY_SPEAKER, |
| 40 | DEVICE_CATEGORY_EARPIECE, |
| 41 | DEVICE_CATEGORY_EXT_MEDIA, |
| 42 | DEVICE_CATEGORY_CNT |
| 43 | }; |
| 44 | |
| 45 | // returns the category the device belongs to with regard to volume curve management |
| 46 | static ApmGains::device_category getDeviceCategory(audio_devices_t device); |
| 47 | |
| 48 | // extract one device relevant for volume control from multiple device selection |
| 49 | static audio_devices_t getDeviceForVolume(audio_devices_t device); |
| 50 | |
| 51 | static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc, |
| 52 | int indexInUi); |
| 53 | |
| 54 | // default volume curve |
| 55 | static const VolumeCurvePoint sDefaultVolumeCurve[ApmGains::VOLCNT]; |
| 56 | // default volume curve for media strategy |
| 57 | static const VolumeCurvePoint sDefaultMediaVolumeCurve[ApmGains::VOLCNT]; |
| 58 | // volume curve for non-media audio on ext media outputs (HDMI, Line, etc) |
| 59 | static const VolumeCurvePoint sExtMediaSystemVolumeCurve[ApmGains::VOLCNT]; |
| 60 | // volume curve for media strategy on speakers |
| 61 | static const VolumeCurvePoint sSpeakerMediaVolumeCurve[ApmGains::VOLCNT]; |
| 62 | static const VolumeCurvePoint sSpeakerMediaVolumeCurveDrc[ApmGains::VOLCNT]; |
| 63 | // volume curve for sonification strategy on speakers |
| 64 | static const VolumeCurvePoint sSpeakerSonificationVolumeCurve[ApmGains::VOLCNT]; |
| 65 | static const VolumeCurvePoint sSpeakerSonificationVolumeCurveDrc[ApmGains::VOLCNT]; |
| 66 | static const VolumeCurvePoint sDefaultSystemVolumeCurve[ApmGains::VOLCNT]; |
| 67 | static const VolumeCurvePoint sDefaultSystemVolumeCurveDrc[ApmGains::VOLCNT]; |
| 68 | static const VolumeCurvePoint sHeadsetSystemVolumeCurve[ApmGains::VOLCNT]; |
| 69 | static const VolumeCurvePoint sDefaultVoiceVolumeCurve[ApmGains::VOLCNT]; |
| 70 | static const VolumeCurvePoint sSpeakerVoiceVolumeCurve[ApmGains::VOLCNT]; |
| 71 | static const VolumeCurvePoint sLinearVolumeCurve[ApmGains::VOLCNT]; |
| 72 | static const VolumeCurvePoint sSilentVolumeCurve[ApmGains::VOLCNT]; |
| 73 | static const VolumeCurvePoint sFullScaleVolumeCurve[ApmGains::VOLCNT]; |
| 74 | // default volume curves per stream and device category. See initializeVolumeCurves() |
| 75 | static const VolumeCurvePoint *sVolumeProfiles[AUDIO_STREAM_CNT][ApmGains::DEVICE_CATEGORY_CNT]; |
| 76 | }; |
| 77 | |
| 78 | |
| 79 | class AudioGain: public RefBase |
| 80 | { |
| 81 | public: |
| 82 | AudioGain(int index, bool useInChannelMask); |
| 83 | virtual ~AudioGain() {} |
| 84 | |
| 85 | void dump(int fd, int spaces, int index) const; |
| 86 | |
| 87 | void getDefaultConfig(struct audio_gain_config *config); |
| 88 | status_t checkConfig(const struct audio_gain_config *config); |
| 89 | int mIndex; |
| 90 | struct audio_gain mGain; |
| 91 | bool mUseInChannelMask; |
| 92 | }; |
| 93 | |
| 94 | |
| 95 | // stream descriptor used for volume control |
| 96 | class StreamDescriptor |
| 97 | { |
| 98 | public: |
| 99 | StreamDescriptor(); |
| 100 | |
| 101 | int getVolumeIndex(audio_devices_t device); |
| 102 | void dump(int fd); |
| 103 | |
| 104 | int mIndexMin; // min volume index |
| 105 | int mIndexMax; // max volume index |
| 106 | KeyedVector<audio_devices_t, int> mIndexCur; // current volume index per device |
| 107 | bool mCanBeMuted; // true is the stream can be muted |
| 108 | |
| 109 | const VolumeCurvePoint *mVolumeCurve[ApmGains::DEVICE_CATEGORY_CNT]; |
| 110 | }; |
| 111 | |
| 112 | }; // namespace android |