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