summaryrefslogtreecommitdiff
path: root/3rdparty/portaudio/bindings/cpp/include/portaudiocpp/CppFunCallbackStream.hxx
blob: 3f219eef87f6cb41bbc0c1b2d0b63cf83a0782dc (plain)
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
#ifndef INCLUDED_PORTAUDIO_CPPFUNCALLBACKSTREAM_HXX
#define INCLUDED_PORTAUDIO_CPPFUNCALLBACKSTREAM_HXX

// ---------------------------------------------------------------------------------------

#include "portaudio.h"

#include "portaudiocpp/CallbackStream.hxx"

// ---------------------------------------------------------------------------------------

// Forward declaration(s):
namespace portaudio
{
	class StreamParameters;
}

// ---------------------------------------------------------------------------------------

// Declaration(s):
namespace portaudio
{


	namespace impl
	{
		extern "C"
		{
			int cppCallbackToPaCallbackAdapter(const void *inputBuffer, void *outputBuffer, unsigned long numFrames, 
				const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, 
				void *userData);
		} // extern "C"
	}

	// -----------------------------------------------------------------------------------

	//////
	/// @brief Callback stream using a C++ function (either a free function or a static function) 
	/// callback.
	//////
	class FunCallbackStream : public CallbackStream
	{
	public:
		typedef int (*CallbackFunPtr)(const void *inputBuffer, void *outputBuffer, unsigned long numFrames, 
			const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, 
			void *userData);

		// -------------------------------------------------------------------------------

		//////
		/// @brief Simple structure containing a function pointer to the C++ callback function and a 
		/// (void) pointer to the user supplied data.
		//////
		struct CppToCCallbackData
		{
			CppToCCallbackData();
			CppToCCallbackData(CallbackFunPtr funPtr, void *userData);
			void init(CallbackFunPtr funPtr, void *userData);

			CallbackFunPtr funPtr;
			void *userData;
		};

		// -------------------------------------------------------------------------------

		FunCallbackStream();
		FunCallbackStream(const StreamParameters &parameters, CallbackFunPtr funPtr, void *userData);
		~FunCallbackStream();

		void open(const StreamParameters &parameters, CallbackFunPtr funPtr, void *userData);

	private:
		FunCallbackStream(const FunCallbackStream &); // non-copyable
		FunCallbackStream &operator=(const FunCallbackStream &); // non-copyable

		CppToCCallbackData adapterData_;

		void open(const StreamParameters &parameters);
	};


} // portaudio

// ---------------------------------------------------------------------------------------

#endif // INCLUDED_PORTAUDIO_CPPFUNCALLBACKSTREAM_HXX