xref: /haiku/src/add-ons/kernel/drivers/audio/usb/AudioControlInterface.h (revision aa4b5749d64af0c0573513c27296af16f4680367)
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 
30 			uint8			ChannelsCount()		{ return fOutChannelsNumber; }
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:
46 							_AudioChannelCluster(AudioControlInterface* interface,
47 								usb_audiocontrol_header_descriptor* Header)
48 							:
49 							__base_class_name(interface, Header) {}
50 	virtual					~_AudioChannelCluster() {}
51 
52 	virtual	AudioChannelCluster*
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 
63 			uint8			ID() { return fID; }
64 			uint8			SourceID() { return fSourceID; }
65 			uint8			SubType() { return fSubType; }
66 			status_t		InitCheck() { return fStatus; };
67 
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 
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 
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();
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 
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 
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 
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 
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);
278 			uint16			SpecReleaseNumber() { return fADCSpecification; }
279 
280 			AudioControlsMap&
281 							Controls() { return fAudioControls; }
282 
283 			uint32			GetChannelsDescription(
284 								Vector<multi_channel_info>& Channels,
285 								multi_description* Description,
286 								Vector<_AudioControl*>& USBTerminals);
287 			uint32			GetBusChannelsDescription(
288 								Vector<multi_channel_info>& Channels,
289 								multi_description* Description);
290 
291 			status_t		GetMix(multi_mix_value_info* Info);
292 			status_t		SetMix(multi_mix_value_info* Info);
293 			status_t		ListMixControls(multi_mix_control_info* Info);
294 
295 protected:
296 			status_t		InitACHeader(size_t interface,
297 								usb_audiocontrol_header_descriptor* Header);
298 
299 			uint32			GetTerminalChannels(
300 								Vector<multi_channel_info>& Channels,
301 								AudioChannelCluster* cluster,
302 								channel_kind kind, uint32 connectors = 0);
303 
304 			void			_HarvestRecordFeatureUnits(_AudioControl* rootControl,
305 								AudioControlsMap& Map);
306 			void			_HarvestOutputFeatureUnits(_AudioControl* rootControl,
307 								AudioControlsMap& Map);
308 			void			_ListMixControlsPage(int32& index,
309 								multi_mix_control_info* Info,
310 								AudioControlsMap& Map, const char* Name);
311 			int32			_ListFeatureUnitControl(int32& index, int32 parentId,
312 								multi_mix_control_info* Info,
313 								_AudioControl* control);
314 			uint32			_ListFeatureUnitOption(uint32 controlType,
315 								int32& index, int32 parentIndex,
316 								multi_mix_control_info* Info, FeatureUnit* unit,
317 								uint32 channel, uint32 channels);
318 			void			_ListSelectorUnitControl(int32& index,
319 								int32 parentGroup, multi_mix_control_info* Info,
320 								_AudioControl* control);
321 			void			_ListMixControlsForMixerUnit(int32& index,
322 								multi_mix_control_info* Info,
323 								_AudioControl* control);
324 			void			_ListMixerUnitControls(int32& index,
325 								multi_mix_control_info* Info,
326 								Vector<multi_mix_control>& controls);
327 			size_t			_CollectMixerUnitControls(
328 								const uint32 controlIds[kChannels][kChannels],
329 								size_t inLeft, size_t outLeft,
330 								size_t inRight, size_t outRight,
331 								const char* inputName, const char* name,
332 								Vector<multi_mix_control>& Controls);
333 			bool			_InitGainLimits(multi_mix_control& Control);
334 
335 			size_t			fInterface;
336 			status_t		fStatus;
337 			// part of AudioControl Header description
338 			uint16			fADCSpecification;
339 			Vector<uint8>	fStreams;
340 			uint8			fFunctionCategory;
341 			uint8			fControlsBitmap;
342 			Device*			fDevice;
343 
344 			// map to store all controls and lookup by control ID
345 			AudioControlsMap	fAudioControls;
346 			// map to store output terminal and lookup them by source ID
347 			AudioControlsMap	fOutputTerminals;
348 			// map to store output terminal and lookup them by control ID
349 			AudioControlsMap	fInputTerminals;
350 };
351 
352 
353 #endif // _AUDIO_CONTROL_INTERFACE_H_
354 
355