summaryrefslogtreecommitdiff
path: root/servers/spatial_sound_2d_server.h
blob: 9917b36be1e08839f5e46e630017d75706b7fa68 (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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*************************************************************************/
/*  spatial_sound_2d_server.h                                            */
/*************************************************************************/
/*                       This file is part of:                           */
/*                           GODOT ENGINE                                */
/*                    http://www.godotengine.org                         */
/*************************************************************************/
/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur.                 */
/*                                                                       */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the       */
/* "Software"), to deal in the Software without restriction, including   */
/* without limitation the rights to use, copy, modify, merge, publish,   */
/* distribute, sublicense, and/or sell copies of the Software, and to    */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions:                                             */
/*                                                                       */
/* The above copyright notice and this permission notice shall be        */
/* included in all copies or substantial portions of the Software.       */
/*                                                                       */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
/*************************************************************************/
#ifndef SPATIAL_SOUND_2D_SERVER_H
#define SPATIAL_SOUND_2D_SERVER_H

#include "object.h"
#include "bsp_tree.h"
#include "servers/audio_server.h"

class SpatialSound2DServer : public Object {

	OBJ_TYPE(SpatialSound2DServer,Object);
	static SpatialSound2DServer *singleton;
public:


	enum {
		SOURCE_INVALID_VOICE=-1,
		SOURCE_NEXT_VOICE=-2,
	};

	typedef int SourceVoiceID;

	/* SPACE */
	virtual RID space_create()=0;

	/* ROOM */

	virtual RID room_create()=0;
	virtual void room_set_space(RID p_room,RID p_space)=0;
	virtual RID room_get_space(RID p_room) const=0;


	virtual void room_set_bounds(RID p_room, const DVector<Point2>& p_bounds)=0;
	virtual DVector<Point2> room_get_bounds(RID p_room) const=0;
	virtual void room_set_transform(RID p_room, const Matrix32& p_transform)=0;
	virtual Matrix32 room_get_transform(RID p_room) const=0;

	enum RoomParam {
		ROOM_PARAM_PITCH_SCALE,
		ROOM_PARAM_VOLUME_SCALE_DB,
		ROOM_PARAM_REVERB_SEND,
		ROOM_PARAM_CHORUS_SEND,
		ROOM_PARAM_ATTENUATION_SCALE,
		ROOM_PARAM_ATTENUATION_HF_CUTOFF,
		ROOM_PARAM_ATTENUATION_HF_FLOOR_DB,
		ROOM_PARAM_ATTENUATION_HF_RATIO_EXP,
		ROOM_PARAM_ATTENUATION_REVERB_SCALE,
		ROOM_PARAM_MAX
	};

	virtual void room_set_param(RID p_room, RoomParam p_param, float p_value)=0;
	virtual float room_get_param(RID p_room, RoomParam p_param) const=0;

	enum RoomReverb {
		ROOM_REVERB_SMALL,
		ROOM_REVERB_MEDIUM,
		ROOM_REVERB_LARGE,
		ROOM_REVERB_HALL
	};

	virtual void room_set_reverb(RID p_room, RoomReverb p_reverb)=0;
	virtual RoomReverb room_get_reverb(RID p_room) const=0;

	virtual void room_set_level(RID p_room, int p_level)=0;
	virtual int room_get_level(RID p_room) const=0;

	//useful for underwater or rooms with very strange conditions
	virtual void room_set_force_params_to_all_sources(RID p_room, bool p_force)=0;
	virtual bool room_is_forcing_params_to_all_sources(RID p_room) const=0;

	/* SOURCE */

	virtual RID source_create(RID p_space)=0;

	virtual void source_set_transform(RID p_source, const Matrix32& p_transform)=0;
	virtual Matrix32 source_get_transform(RID p_source) const=0;

	virtual void source_set_polyphony(RID p_source,int p_voice_count)=0;
	virtual int source_get_polyphony(RID p_source) const=0;

	enum SourceParam {

		SOURCE_PARAM_VOLUME_DB,
		SOURCE_PARAM_PITCH_SCALE,
		SOURCE_PARAM_ATTENUATION_MIN_DISTANCE,
		SOURCE_PARAM_ATTENUATION_MAX_DISTANCE,
		SOURCE_PARAM_ATTENUATION_DISTANCE_EXP,
		SOURCE_PARAM_MAX
	};

	virtual void source_set_param(RID p_source, SourceParam p_param, float p_value)=0;
	virtual float source_get_param(RID p_source, SourceParam p_param) const=0;

	virtual void source_set_audio_stream(RID p_source, AudioServer::AudioStream *p_stream)=0; //null to unset
	virtual SourceVoiceID source_play_sample(RID p_source, RID p_sample, int p_mix_rate, int p_voice=SOURCE_NEXT_VOICE)=0;
	//voices
	virtual void source_voice_set_pitch_scale(RID p_source,SourceVoiceID p_voice, float p_pitch_scale)=0;
	virtual void source_voice_set_volume_scale_db(RID p_source,SourceVoiceID p_voice, float p_volume_db)=0;

	virtual bool source_is_voice_active(RID p_source,SourceVoiceID p_voice) const=0;
	virtual void source_stop_voice(RID p_source,SourceVoiceID p_voice)=0;

	/* LISTENER */

	enum ListenerParam {

		LISTENER_PARAM_VOLUME_SCALE_DB,
		LISTENER_PARAM_PITCH_SCALE,
		LISTENER_PARAM_ATTENUATION_SCALE,
		LISTENER_PARAM_PAN_RANGE,
		LISTENER_PARAM_MAX
	};

	virtual RID listener_create()=0;
	virtual void listener_set_space(RID p_listener, RID p_space)=0;

	virtual void listener_set_transform(RID p_listener, const Matrix32& p_transform)=0;
	virtual Matrix32 listener_get_transform(RID p_listener) const=0;

	virtual void listener_set_param(RID p_listener, ListenerParam p_param, float p_value)=0;
	virtual float listener_get_param(RID p_listener, ListenerParam p_param) const=0;

	/* MISC */

	virtual void free(RID p_id)=0;

	virtual void init()=0;
	virtual void update(float p_delta)=0;
	virtual void finish()=0;

	static SpatialSound2DServer *get_singleton();

	SpatialSound2DServer();

};

#endif // SPATIAL_SOUND_2D_SERVER_H