blob: b4ab12957033a2c6a23b4aea69b8d5657a8d159d [file] [log] [blame]
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -08001/*
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
17namespace android {
18
19class VolumeCurvePoint
20{
21public:
22 int mIndex;
23 float mDBAttenuation;
24};
25
26class StreamDescriptor;
27
28class ApmGains
29{
30public :
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
79class AudioGain: public RefBase
80{
81public:
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
96class StreamDescriptor
97{
98public:
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