summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/invoker/audio/OpenALInvoker.h
blob: 9b71d954c1570df8dce964e21617a9c91e358702 (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
87
88
89
90
91
92
#ifndef OPENALINVOKER_H_W09J90F0
#define OPENALINVOKER_H_W09J90F0

#include "uscxml/config.h"
#include <uscxml/Interpreter.h>
#include "OpenALPlayer.h"

#include "PCMConverter.h"
#ifdef LIBSNDFILE_FOUND
#	include "LibSoundFile.h"
#else
#	ifdef AUDIOTOOLBOX_FOUND
#	include "AudioToolbox.h"
#	endif
#endif

#ifdef BUILD_AS_PLUGINS
#include "uscxml/plugins/Plugins.h"
#endif

namespace uscxml {

class OpenALSource {
public:
	OpenALSource();
	~OpenALSource();

	OpenALPlayer* player;
	char buffer[ALPLAY_AUDIO_BUFFER_SIZE];
	bool loop;
	bool finished;
	int read;
	int written;
	ALfloat pos[3];
	URL file;
	PCMConverter* transform;
};

class OpenALInvoker : public InvokerImpl {
public:
	OpenALInvoker();
	virtual ~OpenALInvoker();
	virtual boost::shared_ptr<InvokerImpl> create(InterpreterImpl* interpreter);

	virtual std::set<std::string> getNames() {
		std::set<std::string> names;
		names.insert("openal");
		names.insert("spatial-audio");
		names.insert("http://uscxml.tk.informatik.tu-darmstadt.de/#openal");
		return names;
	}

	virtual Data getDataModelVariables();
	virtual void send(const SendRequest& req);
	virtual void cancel(const std::string sendId);
	virtual void invoke(const InvokeRequest& req);

protected:
	std::map<std::string, OpenALSource*> _sources;
	ALCcontext* _alContext;
	ALCdevice* _alDevice;

	tthread::recursive_mutex _mutex;
	tthread::thread* _thread;
	tthread::condition_variable _sourcesAvailable;

	bool _isStarted;
	bool _isRunning;
	ALfloat _listenerPos[3];
	ALfloat _listenerVel[3];
	ALfloat _listenerOrient[6];
	float _maxPos[3];

	static void fillBuffers(void* userdata);
	void start();

	void notifyOfEnd(OpenALSource*);
	void notifyOfLoop(OpenALSource*);

	float posToRadian(const std::string& pos);
	void getPosFromParams(const std::multimap<std::string, std::string>& params, float* position);

};

#ifdef BUILD_AS_PLUGINS
PLUMA_INHERIT_PROVIDER(OpenALInvoker, InvokerImpl);
#endif

}


#endif /* end of include guard: OPENALINVOKER_H_W09J90F0 */