xref: /haiku/src/add-ons/kernel/drivers/audio/usb/AudioControlInterface.h (revision 140c408d7b16f7be86d302e8d390933f4e5aafbf)
1 /*
2  *	Driver for USB Audio Device Class devices.
3  *	Copyright (c) 2009-13 S.Zharski <imker@gmx.li>
4  *	Distributed under the terms of the MIT license.
5  *
6  */
7 #ifndef _AUDIO_CONTROL_INTERFACE_H_
8 #define _AUDIO_CONTROL_INTERFACE_H_
9 
10 
11 #include <USB3.h>
12 #include <hmulti_audio.h>
13 #include <usb/USB_audio.h>
14 #include <util/VectorMap.h>
15 
16 
17 class Device;
18 class AudioControlInterface;
19 
20 class _AudioControl;
21 typedef	VectorMap<uint32, _AudioControl*> AudioControlsMap;
22 typedef	VectorMap<uint32, _AudioControl*>::Iterator AudioControlsIterator;
23 
24 
25 class AudioChannelCluster {
26 public:
27 							AudioChannelCluster();
28 	virtual					~AudioChannelCluster();
29 
ChannelsCount()30 			uint8			ChannelsCount()		{ return fOutChannelsNumber; }
ChannelsConfig()31 			uint32			ChannelsConfig()	{ return fChannelsConfig;	 }
32 
33 			bool			HasChannel(uint32 location);
34 
35 protected:
36 			uint8			fOutChannelsNumber;
37 			uint32			fChannelsConfig;
38 			uint8			fChannelNames;
39 };
40 
41 
42 template<class __base_class_name>
43 class _AudioChannelCluster : public __base_class_name,
44 	public AudioChannelCluster {
45 public:
_AudioChannelCluster(AudioControlInterface * interface,usb_audiocontrol_header_descriptor * Header)46 							_AudioChannelCluster(AudioControlInterface* interface,
47 								usb_audiocontrol_header_descriptor* Header)
48 							:
49 							__base_class_name(interface, Header) {}
~_AudioChannelCluster()50 	virtual					~_AudioChannelCluster() {}
51 
52 	virtual	AudioChannelCluster*
OutCluster()53 							OutCluster() { return this; }
54 };
55 
56 
57 class _AudioControl {
58 public:
59 							_AudioControl(AudioControlInterface* interface,
60 								usb_audiocontrol_header_descriptor* Header);
61 	virtual					~_AudioControl();
62 
ID()63 			uint8			ID() { return fID; }
SourceID()64 			uint8			SourceID() { return fSourceID; }
SubType()65 			uint8			SubType() { return fSubType; }
InitCheck()66 			status_t		InitCheck() { return fStatus; };
67 
Name()68 	virtual	const char*		Name() { return ""; }
69 
70 	virtual AudioChannelCluster*
71 							OutCluster();
72 
73 protected:
74 			status_t		fStatus;
75 			AudioControlInterface*	fInterface;
76 			uint8			fSubType;
77 			uint8			fID;
78 			uint8			fSourceID;
79 			uint8			fStringIndex;
80 };
81 
82 
83 class _Terminal : public _AudioControl {
84 public:
85 							_Terminal(AudioControlInterface* interface,
86 								usb_audiocontrol_header_descriptor* Header);
87 	virtual					~_Terminal();
88 
TerminalType()89 			uint16			TerminalType() { return fTerminalType; }
90 			bool			IsUSBIO();
91 	virtual	const char*		Name();
92 	static	const char*		_GetTerminalDescription(uint16 TerminalType);
93 
94 protected:
95 			uint16			fTerminalType;
96 			uint8			fAssociatedTerminal;
97 			uint8			fClockSourceId;
98 			uint16			fControlsBitmap;
99 };
100 
101 
102 class InputTerminal : public _AudioChannelCluster<_Terminal> {
103 public:
104 							InputTerminal(AudioControlInterface* interface,
105 								usb_audiocontrol_header_descriptor* Header);
106 	virtual					~InputTerminal();
107 
108 	virtual	const char*		Name();
109 
110 protected:
111 };
112 
113 
114 class OutputTerminal : public _Terminal {
115 public:
116 							OutputTerminal(AudioControlInterface* interface,
117 								usb_audiocontrol_header_descriptor* Header);
118 	virtual					~OutputTerminal();
119 
120 	virtual	const char*		Name();
121 
122 protected:
123 };
124 
125 
126 class MixerUnit : public _AudioChannelCluster<_AudioControl> {
127 public:
128 							MixerUnit(AudioControlInterface* interface,
129 								usb_audiocontrol_header_descriptor* Header);
130 	virtual					~MixerUnit();
131 
Name()132 	virtual	const char*		Name() { return "Mixer"; }
133 			bool			HasProgrammableControls();
134 			bool			IsControlProgrammable(int inChannel, int outChannel);
135 
136 //protected:
137 			Vector<uint8>	fInputPins;
138 			Vector<uint8>	fControlsBitmap;
139 			uint8			fBmControlsR2;
140 };
141 
142 
143 class SelectorUnit : public _AudioControl {
144 public:
145 							SelectorUnit(AudioControlInterface* interface,
146 								usb_audiocontrol_header_descriptor* Header);
147 	virtual					~SelectorUnit();
148 
149 	virtual	AudioChannelCluster*
150 							OutCluster();
Name()151 	virtual	const char*		Name() { return "Selector"; }
152 
153 // protected:
154 			Vector<uint8>	fInputPins;
155 			uint8			fControlsBitmap;
156 };
157 
158 
159 class FeatureUnit : public _AudioControl {
160 public:
161 							FeatureUnit(AudioControlInterface* interface,
162 								usb_audiocontrol_header_descriptor* Header);
163 	virtual					~FeatureUnit();
164 
165 	virtual	const char*		Name();
166 			bool			HasControl(int32 Channel, uint32 Control);
167 
168 // protected:
169 			void			NormalizeAndTraceChannel(int32 Channel);
170 
171 			Vector<uint32>	fControlBitmaps;
172 };
173 
174 
175 class EffectUnit : public _AudioControl {
176 public:
177 							EffectUnit(AudioControlInterface* interface,
178 								usb_audiocontrol_header_descriptor* Header);
179 	virtual					~EffectUnit();
180 
Name()181 	virtual	const char*		Name() { return "Effect"; }
182 protected:
183 /*			uint16			fProcessType;
184 			Vector<uint8>	fInputPins;
185 			uint8			fControlsBitmap;
186 			Vector<uint16>	fModes;
187 */};
188 
189 
190 class ProcessingUnit : public _AudioChannelCluster<_AudioControl> {
191 public:
192 							ProcessingUnit(AudioControlInterface* interface,
193 								usb_audiocontrol_header_descriptor* Header);
194 	virtual					~ProcessingUnit();
195 
Name()196 	virtual	const char*		Name() { return "Processing"; }
197 
198 protected:
199 			uint16			fProcessType;
200 			Vector<uint8>	fInputPins;
201 			uint8			fControlsBitmap;
202 			Vector<uint16>	fModes;
203 };
204 
205 
206 class ExtensionUnit : public _AudioChannelCluster<_AudioControl> {
207 public:
208 							ExtensionUnit(AudioControlInterface* interface,
209 								usb_audiocontrol_header_descriptor* Header);
210 	virtual					~ExtensionUnit();
211 
Name()212 	virtual	const char*		Name() { return "Extension"; }
213 
214 protected:
215 			uint16			fExtensionCode;
216 			Vector<uint8>	fInputPins;
217 			uint8			fControlsBitmap;
218 };
219 
220 
221 class ClockSource : public _AudioControl {
222 public:
223 							ClockSource(AudioControlInterface* interface,
224 								usb_audiocontrol_header_descriptor* Header);
225 	virtual					~ClockSource();
226 
227 protected:
228 };
229 
230 
231 class ClockSelector : public _AudioControl {
232 public:
233 							ClockSelector(AudioControlInterface* interface,
234 								usb_audiocontrol_header_descriptor* Header);
235 	virtual					~ClockSelector();
236 
237 protected:
238 };
239 
240 
241 class ClockMultiplier : public _AudioControl {
242 public:
243 							ClockMultiplier(AudioControlInterface* interface,
244 								usb_audiocontrol_header_descriptor* Header);
245 	virtual					~ClockMultiplier();
246 
247 protected:
248 };
249 
250 
251 class SampleRateConverter : public _AudioControl {
252 public:
253 							SampleRateConverter(
254 								AudioControlInterface* interface,
255 								usb_audiocontrol_header_descriptor* Header);
256 	virtual					~SampleRateConverter();
257 
258 protected:
259 };
260 
261 
262 class AudioControlInterface {
263 public:
264 			enum {
265 				kLeftChannel = 0,
266 				kRightChannel = 1,
267 				kChannels = 18
268 			};
269 
270 							AudioControlInterface(Device* device);
271 							~AudioControlInterface();
272 
InitCheck()273 			status_t		InitCheck() { return fStatus; }
274 			status_t		Init(size_t interface, usb_interface_info* Interface);
275 
276 			_AudioControl*	Find(uint8 id);
277 			_AudioControl*	FindOutputTerminal(uint8 id);
SpecReleaseNumber()278 			uint16			SpecReleaseNumber() { return fADCSpecification; }
279 
280 			AudioControlsMap&
Controls()281 							Controls() { return fAudioControls; }
282 
283 			uint32			GetChannelsDescription(
284 								Vector<multi_channel_info>& Channels,
285 								multi_description* Description,
286 								Vector<_AudioControl*>& USBTerminals,
287 								bool isForInput);
288 			uint32			GetBusChannelsDescription(
289 								Vector<multi_channel_info>& Channels,
290 								multi_description* Description);
291 
292 			status_t		GetMix(multi_mix_value_info* Info);
293 			status_t		SetMix(multi_mix_value_info* Info);
294 			status_t		ListMixControls(multi_mix_control_info* Info);
295 
296 protected:
297 			status_t		InitACHeader(size_t interface,
298 								usb_audiocontrol_header_descriptor* Header);
299 
300 			uint32			GetTerminalChannels(
301 								Vector<multi_channel_info>& Channels,
302 								AudioChannelCluster* cluster,
303 								channel_kind kind, uint32 connectors = 0);
304 
305 			void			_HarvestRecordFeatureUnits(_AudioControl* rootControl,
306 								AudioControlsMap& Map);
307 			void			_HarvestOutputFeatureUnits(_AudioControl* rootControl,
308 								AudioControlsMap& Map);
309 			void			_ListMixControlsPage(int32& index,
310 								multi_mix_control_info* Info,
311 								AudioControlsMap& Map, const char* Name);
312 			int32			_ListFeatureUnitControl(int32& index, int32 parentId,
313 								multi_mix_control_info* Info,
314 								_AudioControl* control);
315 			uint32			_ListFeatureUnitOption(uint32 controlType,
316 								int32& index, int32 parentIndex,
317 								multi_mix_control_info* Info, FeatureUnit* unit,
318 								uint32 channel, uint32 channels);
319 			void			_ListSelectorUnitControl(int32& index,
320 								int32 parentGroup, multi_mix_control_info* Info,
321 								_AudioControl* control);
322 			void			_ListMixControlsForMixerUnit(int32& index,
323 								multi_mix_control_info* Info,
324 								_AudioControl* control);
325 			void			_ListMixerUnitControls(int32& index,
326 								multi_mix_control_info* Info,
327 								Vector<multi_mix_control>& controls);
328 			size_t			_CollectMixerUnitControls(
329 								const uint32 controlIds[kChannels][kChannels],
330 								size_t inLeft, size_t outLeft,
331 								size_t inRight, size_t outRight,
332 								const char* inputName, const char* name,
333 								Vector<multi_mix_control>& Controls);
334 			bool			_InitGainLimits(multi_mix_control& Control);
335 
336 			size_t			fInterface;
337 			status_t		fStatus;
338 			// part of AudioControl Header description
339 			uint16			fADCSpecification;
340 			Vector<uint8>	fStreams;
341 			uint8			fFunctionCategory;
342 			uint8			fControlsBitmap;
343 			Device*			fDevice;
344 
345 			// map to store all controls and lookup by control ID
346 			AudioControlsMap	fAudioControls;
347 			// map to store output terminal and lookup them by source ID
348 			AudioControlsMap	fOutputTerminals;
349 			// map to store output terminal and lookup them by control ID
350 			AudioControlsMap	fInputTerminals;
351 };
352 
353 
354 #endif // _AUDIO_CONTROL_INTERFACE_H_
355 
356