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 <mmdeviceapi.h>
9 #include <windows.h>
10 
11 // Do not move this before mmdeviceapi.h
12 #include <functiondiscoverykeys_devpkey.h>
13 
14 // PortAudio
15 #include <portaudio.h>
16 
17 // System
18 #include <cstdio>
19 #include <cstdlib>
20 #include <iostream>
21 #include <string>
22 #include <thread>
23 #include <vector>
24 
25 #include "hlaudio/internal/Device.h"
26 #include "hlaudio/internal/OSAudio.h"
27 
28 #define REFTIMES_PER_SEC 10000000
29 #define REFTIMES_PER_MILLISEC 10000
30 
31 // Error handling
32 #define HANDLE_ERROR(hres) \
33  if (FAILED(hres)) { goto Exit; }
34 #define HANDLE_PA_ERROR(hres) \
35  if (hres != paNoError) { goto Exit; }
36 #define SAFE_RELEASE(punk) \
37  if ((punk) != NULL) \
38  { (punk)->Release(); (punk) = NULL; }
39 
40 namespace hula
41 {
45  class WindowsAudio : public OSAudio {
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 = NULL;
60  IMMDeviceCollection *deviceCollection = NULL;
61 
62  // Audio data
63  uint8_t *pData;
64 
65  public:
66  WindowsAudio();
67  ~WindowsAudio();
68 
69  bool checkRates(Device *device);
70  std::vector<Device *> getDevices(DeviceType type);
71 
72  void capture();
73 
74  void setActiveOutputDevice(Device *device);
75  };
76 }
77 
78 #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:293
A audio class that captures system wide audio on Windows.
Definition: WindowsAudio.h:45
void capture()
Execution loop for loopback capture.
Definition: WindowsAudio.cpp:175
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:19
Wrapper for OS specific device information.
Definition: Device.h:34
Definition: Controller.h:11
bool checkRates(Device *device)
TODO: Fill in with something.
Definition: WindowsAudio.cpp:285
void setActiveOutputDevice(Device *device)
Set the selected output device and restart capture threads with new device.
Definition: WindowsAudio.cpp:168