summaryrefslogtreecommitdiff
path: root/3rdparty/portaudio/bindings/cpp/source/portaudiocpp/CFunCallbackStream.cxx
blob: 9cceda9ab9ef69463a26e9684b9cc0bbb30cd381 (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
#include "portaudiocpp/CFunCallbackStream.hxx"

#include "portaudiocpp/StreamParameters.hxx"
#include "portaudiocpp/Exception.hxx"

namespace portaudio
{
	CFunCallbackStream::CFunCallbackStream()
	{
	}

	CFunCallbackStream::CFunCallbackStream(const StreamParameters &parameters, PaStreamCallback *funPtr, void *userData)
	{
		open(parameters, funPtr, userData);
	}

	CFunCallbackStream::~CFunCallbackStream()
	{
		try
		{
			close();
		}
		catch (...)
		{
			// ignore all errors
		}
	}

	// ---------------------------------------------------------------------------------==

	void CFunCallbackStream::open(const StreamParameters &parameters, PaStreamCallback *funPtr, void *userData)
	{
		PaError err = Pa_OpenStream(&stream_, parameters.inputParameters().paStreamParameters(), parameters.outputParameters().paStreamParameters(), 
			parameters.sampleRate(), parameters.framesPerBuffer(), parameters.flags(), funPtr, userData);

		if (err != paNoError)
		{
			throw PaException(err);
		}
	}
}