2 Copyright (C) 2013 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.
19 //----------------------------------------------------------------------------------
22 //! \file WCMRAudioDeviceManager.h
24 //! WCMRAudioDeviceManager and related class declarations
26 //---------------------------------------------------------------------------------*/
27 #ifndef __WCMRAudioDeviceManager_h_
28 #define __WCMRAudioDeviceManager_h_
31 #include "WCMRAudioDeviceManager.h"
34 #define AUTO_FUNC_DEBUG
36 #define ASSERT_ERROR(a, b)
42 #include "WCRefManager.h"
43 #include "BasicTypes/WUTypes.h"
46 #define WCUNUSEDPARAM(a)
49 class WCMRAudioConnection;
50 class WCMRAudioDevice;
51 class WCMRAudioDeviceManager;
53 typedef std::vector<WCMRAudioDevice *> WCMRAudioDeviceList; ///< Vector for audio devices
54 typedef std::vector<WCMRAudioDevice *>::iterator WCMRAudioDeviceListIter; ///< Vector iterator for audio devices
55 typedef std::vector<WCMRAudioDevice *>::const_iterator WCMRAudioDeviceListConstIter; ///< Vector iterator for audio devices
56 typedef std::vector<WCMRAudioConnection *> WCMRAudioConnectionsList; ///< Vector for audio devices
59 /// for notification... A client must derive it's class from us.
60 class WCMRAudioDeviceManagerClient
63 enum NotificationReason
69 SamplingRateChanged, //param has new SR, or -1 if not known
70 SamplingRateChangedSilent, //To indicate sampling rate changed but no need to notify user
73 DeviceStoppedStreaming,
78 DeviceStatisticsUpdated,
79 DeviceDebugInfo, //param has c string
80 DeviceProgressInfo, //param has c string
84 DeviceSampleRateMisMatch,
85 SystemSamplingRateChangedInfoOnly,
93 AGDeviceSamplingRateChangedInfoOnly,
95 SetDisplayNameFromIOModule,
96 IOMStateChanged, ///< This is used when IOM state is changed.
97 AudioCallback // VKamyshniy: param is AudioCallbackDataData*
100 WCMRAudioDeviceManagerClient () {}
101 virtual ~WCMRAudioDeviceManagerClient () {}
103 // VKamyshniy: This is a structure to call the client's AudioDeviceManagerNotification
104 // every AudioCallback time
105 struct AudioCallbackData
107 const float *acdInputBuffer;
108 float *acdOutputBuffer;
110 uint32_t acdSampleTime;
111 uint64_t acdCycleStartTimeNanos;
114 virtual void AudioDeviceManagerNotification (NotificationReason WCUNUSEDPARAM(reason), void *WCUNUSEDPARAM(pParam)) {}
118 class WCMRAudioDevice : public WCRefManager
122 enum ConnectionStates
129 WCMRAudioDevice (WCMRAudioDeviceManager *pManager);///<Constructor
130 virtual ~WCMRAudioDevice ();///<Destructor
132 virtual const std::string& DeviceName() const;///<Name?
133 virtual const std::vector<std::string>& InputChannels();///<Current Input Channel List? - note that this may change with change in sampling rate.
134 virtual const std::vector<std::string>& OutputChannels();///<Current Output Channel List? - note that this may change with change in sampling rate.
136 virtual const std::vector<int>& SamplingRates();///<Supported Sampling Rate List?
137 virtual int CurrentSamplingRate(); ///<Current Sampling rate.?
138 virtual WTErr SetCurrentSamplingRate(int newRate);///<Change Current Sampling Rate : This is a requset, might not be successful at run time!
140 virtual const std::vector<int>& BufferSizes();///<Supported Buffer Size List? - note that this may change with change in sampling rate.
141 virtual int CurrentBufferSize();///<Current Buffer Size.? - note that this may change with change in sampling rate.
142 virtual WTErr SetCurrentBufferSize (int newSize);///<Change Current Buffer Size : This is a requset, might not be successful at run time!
144 virtual int CurrentBlockSize();
146 virtual ConnectionStates ConnectionStatus();///< Connection Status - device available, gone, disconnected
148 virtual bool Active();///<Active status - mainly significant for ASIO, as certain ops can only be performed on active devices!
149 virtual WTErr SetActive (bool newState);///<Prepare/Activate device.
151 virtual bool Streaming();///<Streaming Status?
152 virtual WTErr SetStreaming (bool newState);///<Start/Stop Streaming - should reconnect connections when streaming starts!
154 virtual bool IsProcessActive();
156 virtual WTErr DoIdle();///<Do Idle Processing
158 virtual const std::vector<float>& InputLevels();///<Retrieve Input Levels (for VU display)?
160 virtual const std::vector<float>& OutputLevels();///<Retrieve Output Levels (for VU display)?
162 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
163 virtual WTErr SetMonitorChannels (int leftChannel, int rightChannel);///<Set monitor channels. - optional, will not be available with AG
164 virtual WTErr SetMonitorGain (float newGain);///<Set monitor gain. - optional, will not be available with AG
166 virtual WTErr ShowConfigPanel (void *pParam);///< Show Control Panel - in case of ASIO this will work only with Active device!
167 virtual WTErr SendCustomCommand (int customCommand, void *pCommandParam); ///< Send a custom command to the audiodevice...
169 virtual uint32_t GetLatency (bool isInput); ///Get latency.
172 WCMRAudioDeviceManager *m_pMyManager; ///< The manager who's managing this device, can be used for sending notifications!
174 std::string m_DeviceName; ///< Name of the device.
175 std::vector<std::string> m_InputChannels; ///< List of input channel names.
176 std::vector<std::string> m_OutputChannels; ///< List of output channel names.
177 std::vector<int> m_SamplingRates; ///< List of available sampling rates.
178 std::vector<int> m_BufferSizes; ///< List of available buffer sizes.
180 int m_CurrentSamplingRate; ///< Currently selected sampling rate.
181 int m_CurrentBufferSize; ///< Currently selected buffer size.
183 ConnectionStates m_ConnectionStatus; ///< Status of device connection
184 bool m_IsActive; ///< Flag for teh active status.
185 bool m_IsStreaming; ///< Flag for streaming status.
186 std::vector<float> m_InputLevels; ///< List of input levels.
187 std::vector<float> m_OutputLevels; ///< List of output levels.
189 int m_LeftMonitorChannel; ///< The device channel to use for monitoring left channel data.
190 int m_RightMonitorChannel; ///< The device channel to use for monitoring right channel data.
191 float m_MonitorGain; ///< Amount of gain to apply for monitoring signal.
194 // This enum is for choosing filter for audio devices scan
195 typedef enum eAudioDeviceFilter
197 eAllDevices = 0, // Choose all audio devices
198 eInputOnlyDevices, // Choose only input audio devices
199 eOutputOnlyDevices, // Choose only output audio devices
200 eFullDuplexDevices, // Choose audio devices that have both input and output channels on the same device
201 eMatchedDuplexDevices, // Match(aggregate) audio devices that have both input and output channels but are considered different audio devices (For mac)
202 eAudioDeviceFilterNum // Number of enums
203 } eAudioDeviceFilter;
205 //! WCMRAudioDeviceManager
206 /*! The Audio Device Manager class */
207 class WCMRAudioDeviceManager : public WCRefManager
209 private://< Private version of class functions which will be called by class's public function after mutex lock acquistion.
210 WCMRAudioDevice* GetDefaultDevice_Private();
211 WTErr DoIdle_Private();
212 const WCMRAudioDeviceList& Devices_Private() const;
213 WCMRAudioDevice* GetDeviceByName_Private(const std::string & nameToMatch) const;
215 public://< Public functions for the class.
216 WCMRAudioDevice* GetDefaultDevice()
218 //wvNS::wvThread::ThreadMutex::lock theLock(m_AudioDeviceManagerMutex);
219 return GetDefaultDevice_Private();
222 virtual WTErr DoIdle()
224 //wvNS::wvThread::ThreadMutex::lock theLock(m_AudioDeviceManagerMutex);
225 return DoIdle_Private();
228 const WCMRAudioDeviceList& Devices() const
230 //wvNS::wvThread::ThreadMutex::lock theLock(m_AudioDeviceManagerMutex);
231 return Devices_Private();
234 WCMRAudioDevice* GetDeviceByName(const std::string & nameToMatch) const
236 //wvNS::wvThread::ThreadMutex::lock theLock(m_AudioDeviceManagerMutex);
237 return GetDeviceByName_Private(nameToMatch);
242 WCMRAudioDeviceManager(WCMRAudioDeviceManagerClient *pTheClient, eAudioDeviceFilter eCurAudioDeviceFilter
244 virtual ~WCMRAudioDeviceManager(void); ///< Destructor
246 virtual WTErr UpdateDeviceList () = 0; //has to be overridden!
249 //This is primarily for use by WCMRAudioDevice and it's descendants... We could have made it
250 //protected and made WCMRAudioDevice a friend, and then in some way found a way to extend
251 //the friendship to WCMRAudioDevice's descendants, but that would require a lot of extra
253 void NotifyClient (WCMRAudioDeviceManagerClient::NotificationReason forReason, void *pParam = NULL);
254 virtual void EnableVerboseLogging(bool /*bEnable*/, const std::string& /*logFilePath*/) { };
258 //< NOTE : Mutex protection is commented, but wrapper classes are still there, in case they are required in future.
259 //wvNS::wvThread::ThreadMutex m_AudioDeviceManagerMutex; ///< Mutex for Audio device manager class function access.
260 WCMRAudioDeviceManagerClient *m_pTheClient; ///< The device manager's client, used to send notifications.
262 WCMRAudioDeviceList m_Devices; ///< List of all relevant devices devices
263 eAudioDeviceFilter m_eAudioDeviceFilter; // filter of 'm_Devices'
266 #endif //#ifndef __WCMRAudioDeviceManager_h_