HulaLoop
Simple cross-platform audio loopback and recording.
WindowsAudio.h
1 #ifndef HL_WIN_AUDIO_H
2 #define HL_WIN_AUDIO_H
3 
4 // Windows Audio
5 #include <Audioclient.h>
6 #include <comdef.h>
7 #include <endpointvolume.h>
8 #include <initguid.h>
9 #include <mmdeviceapi.h>
10 #include <windows.h>
11 
12 // Do not move this before mmdeviceapi.h
13 #include <functiondiscoverykeys_devpkey.h>
14 
15 // PortAudio
16 #include <portaudio.h>
17 
18 // System
19 #include <cstdlib>
20 #include <string>
21 #include <thread>
22 #include <vector>
23 
24 #include "hlaudio/internal/Device.h"
25 #include "hlaudio/internal/OSAudio.h"
26 
27 #define REFTIMES_PER_SEC 10000000
28 #define REFTIMES_PER_MILLISEC 10000
29 
30 // Error handling
31 #define HANDLE_ERROR(hres) \
32  if (FAILED(hres)) { goto Exit; }
33 #define HANDLE_PA_ERROR(hres) \
34  if (hres != paNoError) { goto Exit; }
35 #define SAFE_RELEASE(punk) \
36  if ((punk) != nullptr) \
37  { (punk)->Release(); (punk) = nullptr; }
38 
39 namespace hula
40 {
44  class WindowsAudio : public OSAudio {
45 
46  private:
47  const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
48  const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
49  const IID IID_IAudioClient = __uuidof(IAudioClient);
50  const IID IID_IAudioCaptureClient = __uuidof(IAudioCaptureClient);
51 
52  // System necessary variables
53  HRESULT status;
54  PaError pa_status;
55 
56  REFERENCE_TIME requestDuration = REFTIMES_PER_SEC;
57  REFERENCE_TIME bufferDuration;
58 
59  IMMDeviceEnumerator *pEnumerator = nullptr;
60  IMMDeviceCollection *deviceCollection = nullptr;
61 
62  // Audio data
63  uint8_t *pData;
64 
65  public:
66  WindowsAudio();
67  ~WindowsAudio();
68 
69  bool checkDeviceParams(Device *device);
70  std::vector<Device *> getDevices(DeviceType type);
71 
72  void capture();
73  };
74 }
75 
76 #endif // END HL_WIN_AUDIO_H
Abstract class that defines the required components for OS specfic audio classes. ...
Definition: OSAudio.h:19
~WindowsAudio()
Clear all global pointers.
Definition: WindowsAudio.cpp:443
A audio class that captures system wide audio on Windows.
Definition: WindowsAudio.h:44
void capture()
Execution loop for loopback capture.
Definition: WindowsAudio.cpp:198
bool checkDeviceParams(Device *device)
Checks the sampling rate and bit depth of the device.
Definition: WindowsAudio.cpp:394
std::vector< Device * > getDevices(DeviceType type)
Receive the list of available record, playback and/or loopback audio devices connected to the OS and ...
Definition: WindowsAudio.cpp:29
Wrapper for OS specific device information.
Definition: Device.h:55
Wrapper around translation functions for Qt.
Definition: Controller.h:10
DeviceType
Denotes type of Device.
Definition: Device.h:18