1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
| #pragma once
#include <list>
#include <string>
#include <stdint.h>
#include <mmdeviceapi.h>
#include <Audioclient.h>
#include <propsys.h>
#include <Functiondiscoverykeys_devpkey.h>
#include "../libsamplerate/samplerate.h"
#pragma comment(lib, "libsamplerate.lib")
using namespace std;
#ifdef C64
typedef long long PARAM;
typedef unsigned long long UPARAM;
#else
typedef long PARAM;
typedef unsigned long UPARAM;
#endif
typedef char *LPSTR;
typedef const char *LPCSTR;
typedef wchar_t *WSTR;
typedef const wchar_t *CWSTR;
typedef TCHAR *TSTR;
typedef const TCHAR *CTSTR;
#define DEFAULT_SAMPLE_RATE 44100
#define KSAUDIO_SPEAKER_4POINT1 (KSAUDIO_SPEAKER_QUAD|SPEAKER_LOW_FREQUENCY)
#define KSAUDIO_SPEAKER_3POINT1 (KSAUDIO_SPEAKER_STEREO|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY)
#define KSAUDIO_SPEAKER_2POINT1 (KSAUDIO_SPEAKER_STEREO|SPEAKER_LOW_FREQUENCY)
#define SafeRelease(var) if(var) {var->Release(); var = NULL;}
enum edges {
edgeLeft = 0x01,
edgeRight = 0x02,
edgeTop = 0x04,
edgeBottom = 0x08,
};
struct AudioDeviceInfo
{
string strID;
string strName;
~AudioDeviceInfo() {strID.empty(); strName.empty();}
};
union TripleToLong
{
LONG val;
struct
{
WORD wVal;
BYTE tripleVal;
BYTE lastByte;
};
};
struct NotAResampler
{
SRC_STATE *resampler;
uint64_t jumpRange;
};
enum AudioDeviceType {
ADT_PLAYBACK,
ADT_RECORDING
};
class CDesktopAudioDevice
{
public:
CDesktopAudioDevice(void);
~CDesktopAudioDevice(void);
bool Init(bool isPlayBack, const string devGUID = "Default");
void StartCapture();
void StopCapture();
int QueryAudioBuffer(string &outData);
int GetAudioDevices(list<AudioDeviceInfo *> &deviceList, AudioDeviceType deviceType, bool bConnectedOnly);
bool GetDefaultDevice(string &strVal, AudioDeviceType deviceType);
bool GetDefaultMicID(string &strVal);
bool GetDefaultSpeakerID(string &strVal);
protected:
wchar_t* MByteToWChar(uint32_t CodePage,LPCSTR lpcszSrcStr);
char* WCharToMByte(uint32_t CodePage,LPCWSTR lpcwszSrcStr);
bool GetNextBuffer(string &buffer, uint32_t &numFrames);
void FreeData();
protected:
list<AudioDeviceInfo *> m_DeviceList;
string m_CurDeviceID;
string m_CurDeviceName;
IMMDeviceEnumerator *mmEnumerator_;
IMMDevice *mmDevice_;
IAudioClient *mmClient_;
IAudioCaptureClient *mmCapture_;
uint32_t m_SampleWindowSize;
DWORD m_InputChannelMask;
WORD m_InputChannels;
uint32_t m_InputSamplesPerSec;
uint32_t m_InputBufferSize;
uint32_t m_InputBitsPerSample;
bool m_bFloat;
NotAResampler *m_pResampler;
double m_ResampleRatio;
uint8_t *m_pBlankBuffer, *m_pTempResampleBuffer;
uint8_t *m_pDataOutputBuffer;
uint8_t *m_pTmpBuffer;
};
|