2 Copyright (C) 2014 Waves Audio Ltd.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //----------------------------------------------------------------------------------
23 //! \file WCMRAudioDeviceManager.h
25 //! WCMRAudioDeviceManager and related class declarations
27 //---------------------------------------------------------------------------------*/
28 #ifndef __WCMRAudioDeviceManager_h_
29 #define __WCMRAudioDeviceManager_h_
32 #include "WCMRAudioDeviceManager.h"
35 #define AUTO_FUNC_DEBUG
37 #define ASSERT_ERROR(a, b)
43 #include "WCRefManager.h"
44 #include "BasicTypes/WUTypes.h"
46 #include "WCThreadSafe.h"
48 #define WCUNUSEDPARAM(a)
50 class WCMRAudioDevice;
51 class WCMRAudioDeviceManager;
53 typedef unsigned int DeviceID;
58 std::string m_DeviceName;
59 std::vector<int> m_AvailableSampleRates;
60 std::vector<int> m_AvailableBufferSizes;
61 unsigned int m_MaxInputChannels;
62 unsigned int m_MaxOutputChannels;
65 m_DeviceId(-1), m_DeviceName("Unknown"), m_MaxInputChannels(0), m_MaxOutputChannels(0)
68 DeviceInfo(unsigned int deviceID, const std::string & deviceName):
69 m_DeviceId(deviceID), m_DeviceName(deviceName), m_MaxInputChannels(0), m_MaxOutputChannels(0)
73 typedef std::vector<DeviceInfo*> DeviceInfoVec;
74 typedef DeviceInfoVec::iterator DeviceInfoVecIter;
75 typedef DeviceInfoVec::const_iterator DeviceInfoVecConstIter;
77 /// for notification... A client must derive it's class from us.
78 class WCMRAudioDeviceManagerClient
81 enum NotificationReason
87 SamplingRateChanged, //param has new SR, or -1 if not known
88 SamplingRateChangedSilent, //To indicate sampling rate changed but no need to notify user
91 DeviceStoppedStreaming,
92 DeviceStartsStreaming,
97 DeviceStatisticsUpdated,
98 DeviceDebugInfo, //param has c string
99 DeviceProgressInfo, //param has c string
103 DeviceSampleRateMisMatch,
104 SystemSamplingRateChangedInfoOnly,
106 IODeviceDisconnected,
107 ChannelCountModified,
112 AGDeviceSamplingRateChangedInfoOnly,
114 SetDisplayNameFromIOModule,
115 IOMStateChanged, ///< This is used when IOM state is changed.
116 AudioCallback // VKamyshniy: param is AudioCallbackDataData*
119 WCMRAudioDeviceManagerClient () {}
120 virtual ~WCMRAudioDeviceManagerClient () {}
122 // VKamyshniy: This is a structure to call the client's AudioDeviceManagerNotification
123 // every AudioCallback time
124 struct AudioCallbackData
126 const float *acdInputBuffer;
127 float *acdOutputBuffer;
129 int64_t acdSampleTime;
130 uint64_t acdCycleStartTimeNanos;
133 virtual void AudioDeviceManagerNotification (NotificationReason WCUNUSEDPARAM(reason), void *WCUNUSEDPARAM(pParam)) {}
137 class WCMRAudioDevice : public WCRefManager
141 enum ConnectionStates
148 WCMRAudioDevice (WCMRAudioDeviceManager *pManager);///<Constructor
149 virtual ~WCMRAudioDevice ();///<Destructor
151 virtual const std::string& DeviceName() const;///<Name?
152 virtual const std::vector<std::string>& InputChannels();///<Current Input Channel List? - note that this may change with change in sampling rate.
153 virtual const std::vector<std::string>& OutputChannels();///<Current Output Channel List? - note that this may change with change in sampling rate.
155 virtual const std::vector<int>& SamplingRates();///<Supported Sampling Rate List?
156 virtual int CurrentSamplingRate(); ///<Current Sampling rate.?
157 virtual WTErr SetCurrentSamplingRate(int newRate);///<Change Current Sampling Rate : This is a requset, might not be successful at run time!
159 virtual const std::vector<int>& BufferSizes();///<Supported Buffer Size List? - note that this may change with change in sampling rate.
160 virtual int CurrentBufferSize();///<Current Buffer Size.? - note that this may change with change in sampling rate.
161 virtual WTErr SetCurrentBufferSize (int newSize);///<Change Current Buffer Size : This is a requset, might not be successful at run time!
163 virtual int CurrentBlockSize();
165 virtual ConnectionStates ConnectionStatus();///< Connection Status - device available, gone, disconnected
167 virtual bool Active();///<Active status - mainly significant for ASIO, as certain ops can only be performed on active devices!
168 virtual WTErr SetActive (bool newState);///<Prepare/Activate device.
170 virtual bool Streaming();///<Streaming Status?
171 virtual WTErr SetStreaming (bool newState);///<Start/Stop Streaming - should reconnect connections when streaming starts!
173 virtual WTErr ResetDevice ();
175 virtual bool IsProcessActive();
177 virtual WTErr DoIdle();///<Do Idle Processing
179 virtual const std::vector<float>& InputLevels();///<Retrieve Input Levels (for VU display)?
181 virtual const std::vector<float>& OutputLevels();///<Retrieve Output Levels (for VU display)?
183 void GetMonitorInfo (int *pLeftChannel = NULL, int *pRightChannel = NULL, float *pGain = NULL);///<Retrieve current monitor channel pair and gain - optional, will not be available with AG
184 virtual WTErr SetMonitorChannels (int leftChannel, int rightChannel);///<Set monitor channels. - optional, will not be available with AG
185 virtual WTErr SetMonitorGain (float newGain);///<Set monitor gain. - optional, will not be available with AG
187 virtual WTErr ShowConfigPanel (void *pParam);///< Show Control Panel - in case of ASIO this will work only with Active device!
188 virtual WTErr SendCustomCommand (int customCommand, void *pCommandParam); ///< Send a custom command to the audiodevice...
190 virtual uint32_t GetLatency (bool isInput); ///Get latency.
192 virtual WTErr UpdateDeviceInfo () = 0;
195 WCMRAudioDeviceManager *m_pMyManager; ///< The manager who's managing this device, can be used for sending notifications!
197 std::string m_DeviceName; ///< Name of the device.
198 std::vector<std::string> m_InputChannels; ///< List of input channel names.
199 std::vector<std::string> m_OutputChannels; ///< List of output channel names.
200 std::vector<int> m_SamplingRates; ///< List of available sampling rates.
201 std::vector<int> m_BufferSizes; ///< List of available buffer sizes.
203 int m_CurrentSamplingRate; ///< Currently selected sampling rate.
204 int m_CurrentBufferSize; ///< Currently selected buffer size.
206 ConnectionStates m_ConnectionStatus; ///< Status of device connection
207 bool m_IsActive; ///< Flag for teh active status.
208 bool m_IsStreaming; ///< Flag for streaming status.
209 std::vector<float> m_InputLevels; ///< List of input levels.
210 std::vector<float> m_OutputLevels; ///< List of output levels.
212 int m_LeftMonitorChannel; ///< The device channel to use for monitoring left channel data.
213 int m_RightMonitorChannel; ///< The device channel to use for monitoring right channel data.
214 float m_MonitorGain; ///< Amount of gain to apply for monitoring signal.
218 // This enum is for choosing filter for audio devices scan
219 typedef enum eAudioDeviceFilter
221 eAllDevices = 0, // Choose all audio devices
222 eInputOnlyDevices, // Choose only input audio devices
223 eOutputOnlyDevices, // Choose only output audio devices
224 eFullDuplexDevices, // Choose audio devices that have both input and output channels on the same device
225 eMatchedDuplexDevices, // Match(aggregate) audio devices that have both input and output channels but are considered different audio devices (For mac)
226 eAudioDeviceFilterNum // Number of enums
227 } eAudioDeviceFilter;
230 class WCMRAudioDeviceManager : public WCRefManager
232 public://< Public functions for the class.
234 WCMRAudioDeviceManager(WCMRAudioDeviceManagerClient *pTheClient, eAudioDeviceFilter eCurAudioDeviceFilter); ///< constructor
235 virtual ~WCMRAudioDeviceManager(void); ///< Destructor
238 WCMRAudioDevice* InitNewCurrentDevice(const std::string & deviceName);
239 void DestroyCurrentDevice();
240 const DeviceInfoVec DeviceInfoList () const;
241 WTErr GetDeviceInfoByName(const std::string & nameToMatch, DeviceInfo & devInfo) const;
242 WTErr GetDeviceSampleRates(const std::string & nameToMatch, std::vector<int>& sampleRates) const;
243 WTErr GetDeviceBufferSizes(const std::string & nameToMatch, std::vector<int>& bufferSizes) const;
245 //virtual void EnableVerboseLogging(bool /*bEnable*/, const std::string& /*logFilePath*/) { };
248 void NotifyClient (WCMRAudioDeviceManagerClient::NotificationReason forReason, void *pParam = NULL);
252 mutable wvNS::wvThread::ThreadMutex m_AudioDeviceInfoVecMutex; // mutex to lock device info list
253 DeviceInfoVec m_DeviceInfoVec;
255 eAudioDeviceFilter m_eAudioDeviceFilter;
256 WCMRAudioDevice* m_CurrentDevice;
259 // override in derived classes
260 // made private to avoid pure virtual function call
261 virtual WCMRAudioDevice* initNewCurrentDeviceImpl(const std::string & deviceName) = 0;
262 virtual void destroyCurrentDeviceImpl() = 0;
263 virtual WTErr getDeviceSampleRatesImpl(const std::string & deviceName, std::vector<int>& sampleRates) const = 0;
264 virtual WTErr getDeviceBufferSizesImpl(const std::string & deviceName, std::vector<int>& bufferSizes) const = 0;
265 virtual WTErr generateDeviceListImpl() = 0;
266 virtual WTErr updateDeviceListImpl() = 0;
268 WCMRAudioDeviceManagerClient *m_pTheClient; ///< The device manager's client, used to send notifications.
271 #endif //#ifndef __WCMRAudioDeviceManager_h_