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 unsigned int m_MaxInputChannels;
61 unsigned int m_MaxOutputChannels;
64 m_DeviceId(-1), m_DeviceName("Unknown"), m_MaxInputChannels(0), m_MaxOutputChannels(0)
67 DeviceInfo(unsigned int deviceID, const std::string & deviceName):
68 m_DeviceId(deviceID), m_DeviceName(deviceName), m_MaxInputChannels(0), m_MaxOutputChannels(0)
72 typedef std::vector<DeviceInfo*> DeviceInfoVec;
73 typedef DeviceInfoVec::iterator DeviceInfoVecIter;
74 typedef DeviceInfoVec::const_iterator DeviceInfoVecConstIter;
76 /// for notification... A client must derive it's class from us.
77 class WCMRAudioDeviceManagerClient
80 enum NotificationReason
86 SamplingRateChanged, //param has new SR, or -1 if not known
87 SamplingRateChangedSilent, //To indicate sampling rate changed but no need to notify user
90 DeviceStoppedStreaming,
91 DeviceStartsStreaming,
96 DeviceStatisticsUpdated,
97 DeviceDebugInfo, //param has c string
98 DeviceProgressInfo, //param has c string
102 DeviceSampleRateMisMatch,
103 SystemSamplingRateChangedInfoOnly,
105 IODeviceDisconnected,
106 ChannelCountModified,
111 AGDeviceSamplingRateChangedInfoOnly,
113 SetDisplayNameFromIOModule,
114 IOMStateChanged, ///< This is used when IOM state is changed.
115 AudioCallback // VKamyshniy: param is AudioCallbackDataData*
118 WCMRAudioDeviceManagerClient () {}
119 virtual ~WCMRAudioDeviceManagerClient () {}
121 // VKamyshniy: This is a structure to call the client's AudioDeviceManagerNotification
122 // every AudioCallback time
123 struct AudioCallbackData
125 const float *acdInputBuffer;
126 float *acdOutputBuffer;
128 int64_t acdSampleTime;
129 int64_t acdCycleStartTimeNanos;
132 virtual void AudioDeviceManagerNotification (NotificationReason WCUNUSEDPARAM(reason), void *WCUNUSEDPARAM(pParam)) {}
136 class WCMRAudioDevice : public WCRefManager
140 enum ConnectionStates
147 WCMRAudioDevice (WCMRAudioDeviceManager *pManager);///<Constructor
148 virtual ~WCMRAudioDevice ();///<Destructor
150 virtual const std::string& DeviceName() const;///<Name?
151 virtual const std::vector<std::string>& InputChannels();///<Current Input Channel List? - note that this may change with change in sampling rate.
152 virtual const std::vector<std::string>& OutputChannels();///<Current Output Channel List? - note that this may change with change in sampling rate.
154 virtual const std::vector<int>& SamplingRates();///<Supported Sampling Rate List?
155 virtual int CurrentSamplingRate(); ///<Current Sampling rate.?
156 virtual WTErr SetCurrentSamplingRate(int newRate);///<Change Current Sampling Rate : This is a requset, might not be successful at run time!
158 virtual const std::vector<int>& BufferSizes();///<Supported Buffer Size List? - note that this may change with change in sampling rate.
159 virtual int CurrentBufferSize();///<Current Buffer Size.? - note that this may change with change in sampling rate.
160 virtual WTErr SetCurrentBufferSize (int newSize);///<Change Current Buffer Size : This is a requset, might not be successful at run time!
162 virtual int CurrentBlockSize();
164 virtual ConnectionStates ConnectionStatus();///< Connection Status - device available, gone, disconnected
166 virtual bool Active();///<Active status - mainly significant for ASIO, as certain ops can only be performed on active devices!
167 virtual WTErr SetActive (bool newState);///<Prepare/Activate device.
169 virtual bool Streaming();///<Streaming Status?
170 virtual WTErr SetStreaming (bool newState);///<Start/Stop Streaming - should reconnect connections when streaming starts!
172 virtual WTErr ResetDevice ();
174 virtual bool IsProcessActive();
176 virtual WTErr DoIdle();///<Do Idle Processing
178 virtual const std::vector<float>& InputLevels();///<Retrieve Input Levels (for VU display)?
180 virtual const std::vector<float>& OutputLevels();///<Retrieve Output Levels (for VU display)?
182 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
183 virtual WTErr SetMonitorChannels (int leftChannel, int rightChannel);///<Set monitor channels. - optional, will not be available with AG
184 virtual WTErr SetMonitorGain (float newGain);///<Set monitor gain. - optional, will not be available with AG
186 virtual WTErr ShowConfigPanel (void *pParam);///< Show Control Panel - in case of ASIO this will work only with Active device!
187 virtual WTErr SendCustomCommand (int customCommand, void *pCommandParam); ///< Send a custom command to the audiodevice...
189 virtual uint32_t GetLatency (bool isInput); ///Get latency.
191 virtual WTErr UpdateDeviceInfo () = 0;
194 WCMRAudioDeviceManager *m_pMyManager; ///< The manager who's managing this device, can be used for sending notifications!
196 std::string m_DeviceName; ///< Name of the device.
197 std::vector<std::string> m_InputChannels; ///< List of input channel names.
198 std::vector<std::string> m_OutputChannels; ///< List of output channel names.
199 std::vector<int> m_SamplingRates; ///< List of available sampling rates.
200 std::vector<int> m_BufferSizes; ///< List of available buffer sizes.
202 int m_CurrentSamplingRate; ///< Currently selected sampling rate.
203 int m_CurrentBufferSize; ///< Currently selected buffer size.
205 ConnectionStates m_ConnectionStatus; ///< Status of device connection
206 bool m_IsActive; ///< Flag for teh active status.
207 bool m_IsStreaming; ///< Flag for streaming status.
208 std::vector<float> m_InputLevels; ///< List of input levels.
209 std::vector<float> m_OutputLevels; ///< List of output levels.
211 int m_LeftMonitorChannel; ///< The device channel to use for monitoring left channel data.
212 int m_RightMonitorChannel; ///< The device channel to use for monitoring right channel data.
213 float m_MonitorGain; ///< Amount of gain to apply for monitoring signal.
217 // This enum is for choosing filter for audio devices scan
218 typedef enum eAudioDeviceFilter
220 eAllDevices = 0, // Choose all audio devices
221 eInputOnlyDevices, // Choose only input audio devices
222 eOutputOnlyDevices, // Choose only output audio devices
223 eFullDuplexDevices, // Choose audio devices that have both input and output channels on the same device
224 eMatchedDuplexDevices, // Match(aggregate) audio devices that have both input and output channels but are considered different audio devices (For mac)
225 eAudioDeviceFilterNum // Number of enums
226 } eAudioDeviceFilter;
229 class WCMRAudioDeviceManager : public WCRefManager
231 public://< Public functions for the class.
233 WCMRAudioDeviceManager(WCMRAudioDeviceManagerClient *pTheClient, eAudioDeviceFilter eCurAudioDeviceFilter); ///< constructor
234 virtual ~WCMRAudioDeviceManager(void); ///< Destructor
237 WCMRAudioDevice* InitNewCurrentDevice(const std::string & deviceName);
238 void DestroyCurrentDevice();
239 const DeviceInfoVec DeviceInfoList () const;
240 WTErr GetDeviceInfoByName(const std::string & nameToMatch, DeviceInfo & devInfo) const;
241 WTErr GetDeviceSampleRates(const std::string & nameToMatch, std::vector<int>& sampleRates) const;
242 WTErr GetDeviceBufferSizes(const std::string & nameToMatch, std::vector<int>& bufferSizes) const;
244 //virtual void EnableVerboseLogging(bool /*bEnable*/, const std::string& /*logFilePath*/) { };
247 void NotifyClient (WCMRAudioDeviceManagerClient::NotificationReason forReason, void *pParam = NULL);
251 mutable wvNS::wvThread::ThreadMutex m_AudioDeviceInfoVecMutex; // mutex to lock device info list
252 DeviceInfoVec m_DeviceInfoVec;
254 eAudioDeviceFilter m_eAudioDeviceFilter;
255 WCMRAudioDevice* m_CurrentDevice;
258 // override in derived classes
259 // made private to avoid pure virtual function call
260 virtual WCMRAudioDevice* initNewCurrentDeviceImpl(const std::string & deviceName) = 0;
261 virtual void destroyCurrentDeviceImpl() = 0;
262 virtual WTErr getDeviceSampleRatesImpl(const std::string & deviceName, std::vector<int>& sampleRates) const = 0;
263 virtual WTErr getDeviceBufferSizesImpl(const std::string & deviceName, std::vector<int>& bufferSizes) const = 0;
264 virtual WTErr generateDeviceListImpl() = 0;
265 virtual WTErr updateDeviceListImpl() = 0;
267 WCMRAudioDeviceManagerClient *m_pTheClient; ///< The device manager's client, used to send notifications.
270 #endif //#ifndef __WCMRAudioDeviceManager_h_