File: XAudio2fx.cpp

package info (click to toggle)
faudio 21.02-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,576 kB
  • sloc: ansic: 25,642; cpp: 10,815; cs: 1,899; sh: 82; makefile: 21
file content (123 lines) | stat: -rw-r--r-- 2,714 bytes parent folder | download
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
#include "XAudio2fx.h"
#include "XAPOBase.h"

#include <FAudioFX.h>


class XAudio2VolumeMeter : public CXAPOParametersBase 
{
public:
	XAudio2VolumeMeter(void *object) : fapo_object(object),
									   CXAPOParametersBase(reinterpret_cast<FAPOBase *>(object)) 
	{
	}

	COM_METHOD(void) Process(
		UINT32 InputProcessParameterCount,
		const XAPO_PROCESS_BUFFER_PARAMETERS* pInputProcessParameters,
		UINT32 OutputProcessParameterCount,
		XAPO_PROCESS_BUFFER_PARAMETERS* pOutputProcessParameters,
		BOOL IsEnabled
	) {
		reinterpret_cast<FAPO *>(fapo_object)->Process(
			fapo_object,
			InputProcessParameterCount,
			pInputProcessParameters,
			OutputProcessParameterCount,
			pOutputProcessParameters,
			IsEnabled);
	}

private:
	void *fapo_object;
};

class XAudio2Reverb : public CXAPOParametersBase 
{
public:
	XAudio2Reverb(void *object) : fapo_object(object),
								  CXAPOParametersBase(reinterpret_cast<FAPOBase *>(object)) 
	{
	}

	COM_METHOD(void) Process(
		UINT32 InputProcessParameterCount,
		const XAPO_PROCESS_BUFFER_PARAMETERS* pInputProcessParameters,
		UINT32 OutputProcessParameterCount,
		XAPO_PROCESS_BUFFER_PARAMETERS* pOutputProcessParameters,
		BOOL IsEnabled
	) {
		reinterpret_cast<FAPO *>(fapo_object)->Process(
			fapo_object,
			InputProcessParameterCount,
			pInputProcessParameters,
			OutputProcessParameterCount,
			pOutputProcessParameters,
			IsEnabled);
	}

private:
	void *fapo_object;
};



///////////////////////////////////////////////////////////////////////////////
//
// Create functions
//

void* CDECL XAudio2FX_INTERNAL_Malloc(size_t size)
{
	return CoTaskMemAlloc(size);
}
void CDECL XAudio2FX_INTERNAL_Free(void* ptr)
{
	CoTaskMemFree(ptr);
}
void* CDECL XAudio2FX_INTERNAL_Realloc(void* ptr, size_t size)
{
	return CoTaskMemRealloc(ptr, size);
}

void *CreateAudioVolumeMeterInternal() 
{
	FAPO *fapo_object = NULL;
	FAudioCreateVolumeMeterWithCustomAllocatorEXT(
		&fapo_object,
		0,
		XAudio2FX_INTERNAL_Malloc,
		XAudio2FX_INTERNAL_Free,
		XAudio2FX_INTERNAL_Realloc
	);
	return new XAudio2VolumeMeter(fapo_object);
}

void *CreateAudioReverbInternal() 
{
	FAPO *fapo_object = NULL;
	FAudioCreateReverbWithCustomAllocatorEXT(
		&fapo_object,
		0,
		XAudio2FX_INTERNAL_Malloc,
		XAudio2FX_INTERNAL_Free,
		XAudio2FX_INTERNAL_Realloc
	);
	return new XAudio2Reverb(fapo_object);
}

#if XAUDIO2_VERSION >=8

extern "C" FAUDIOCPP_API CreateAudioVolumeMeter(class IUnknown** ppApo)
{
	*ppApo = reinterpret_cast<IUnknown *> (CreateAudioVolumeMeterInternal());
	return S_OK;
}

extern "C" FAUDIOCPP_API CreateAudioReverb(class IUnknown** ppApo)
{
	*ppApo = reinterpret_cast<IUnknown *> (CreateAudioReverbInternal());
	return S_OK;
}

#endif // XAUDIO2_VERSION >=8