7
#include "vrpn_Tracker.h"
11
#define MAX_MATERIAL_NAME_LENGTH 128
12
#define MAX_NUMBER_SOUNDS 1024
13
#define MAX_NUMBER_MATERIALS 64
14
#define MAX_NUMBER_POLYGONS 2048
15
#define MAX_FILENAME_LENGTH 2048
17
// everything is on order found in these structs!
19
typedef vrpn_int32 vrpn_SoundID;
21
typedef struct _vrpn_PoseDef
23
vrpn_float64 position[3];
24
vrpn_float64 orientation[4];
27
typedef struct _vrpn_SoundDef
30
vrpn_float64 velocity[4];
31
vrpn_float64 max_front_dist;
32
vrpn_float64 min_front_dist;
33
vrpn_float64 max_back_dist;
34
vrpn_float64 min_back_dist;
35
vrpn_float64 cone_inner_angle;
36
vrpn_float64 cone_outer_angle;
37
vrpn_float64 cone_gain;
38
vrpn_float64 dopler_scale;
39
vrpn_float64 equalization_val;
41
vrpn_float32 volume; // Jason Clark calls this volume, but really its gain!
44
typedef struct _vrpn_ListenerDef
47
vrpn_float64 velocity[4];
50
typedef struct _vrpn_MaterialDef
52
char material_name[MAX_MATERIAL_NAME_LENGTH];
53
vrpn_float64 transmittance_gain;
54
vrpn_float64 transmittance_highfreq;
55
vrpn_float64 reflectance_gain;
56
vrpn_float64 reflectance_highfreq;
59
typedef struct _vrpn_QuadDef
61
vrpn_int32 subQuad; // really a bool
62
vrpn_float64 openingFactor;
64
vrpn_float64 vertices[4][3];
65
char material_name[MAX_MATERIAL_NAME_LENGTH];
68
typedef struct _vrpn_TriDef
71
vrpn_float64 openingFactor;
73
vrpn_float64 vertices[3][3];
74
char material_name[MAX_MATERIAL_NAME_LENGTH];
77
class VRPN_API vrpn_Sound : public vrpn_BaseClass {
80
vrpn_Sound(const char * name, vrpn_Connection * c);
85
vrpn_int32 load_sound_local; // ID of message to load a sound from server side
86
vrpn_int32 load_sound_remote; // ID of message to load a sound from client side
87
vrpn_int32 unload_sound; // ID of message to unload a sound
88
vrpn_int32 play_sound; // ID of message to play a sound
89
vrpn_int32 stop_sound; // ID of message to stop a sound
90
vrpn_int32 change_sound_status; // ID of message to change the sound's status
91
vrpn_int32 set_listener_pose; // ID of message to set the listener's pos/orient
92
vrpn_int32 set_listener_velocity; // ID of message to set the listener's velocity
93
vrpn_int32 set_sound_pose; //
94
vrpn_int32 set_sound_velocity; //
95
vrpn_int32 set_sound_distanceinfo; //
96
vrpn_int32 set_sound_coneinfo; //
97
vrpn_int32 set_sound_doplerfactor; //
98
vrpn_int32 set_sound_eqvalue; //
99
vrpn_int32 set_sound_pitch;
100
vrpn_int32 set_sound_volume; //
102
vrpn_int32 load_model_local; // load model file from server side
103
vrpn_int32 load_model_remote; // load model file from client side
104
vrpn_int32 load_polyquad; // ID of message to load a quad polygon
105
vrpn_int32 load_polytri; // ID of message to load a tri polygon
106
vrpn_int32 load_material; // ID of message to load a material definition
107
vrpn_int32 set_polyquad_vertices;
108
vrpn_int32 set_polytri_vertices;
109
vrpn_int32 set_poly_openingfactor;
110
vrpn_int32 set_poly_material;
112
vrpn_int32 receive_text_message;
114
struct timeval timestamp; // Current timestamp
116
int register_types(void);
118
/*All encodes and decodes functions are for the purpose of setting up
119
messages to be sent over the network properly (ie to put them in one
120
char buffer and to put them in proper network order and for getting
121
the messages back into a usable format once they have been received*/
123
/*Note encodeSound allocates space dynamically for buf, it is your
124
responsibility to free it up*/
125
vrpn_int32 encodeSound_local(const char *filename, const vrpn_SoundID id, const vrpn_SoundDef soundDef, char **buf);
126
/*Note decodeSound allocates space dynamically for filename, it is your
127
responsibility to free it up*/
128
vrpn_int32 decodeSound_local(const char *buf, char **filename, vrpn_SoundID *id, vrpn_SoundDef * soundDef, const int payload);
130
// These two are not supported yet!
131
vrpn_int32 encodeSound_remote(const char *filename, const vrpn_SoundID id, char **buf);
132
vrpn_int32 decodeSound_remote(const char *buf, char **filename, vrpn_SoundID *id, const int payload);
134
vrpn_int32 encodeSoundID(const vrpn_SoundID id, char* buf);
135
vrpn_int32 decodeSoundID(const char* buf, vrpn_SoundID *id);
136
vrpn_int32 encodeSoundDef(const vrpn_SoundDef sound, const vrpn_SoundID id, const vrpn_int32 repeat, char* buf);
137
vrpn_int32 decodeSoundDef(const char* buf, vrpn_SoundDef *sound, vrpn_SoundID *id, vrpn_int32 *repeat);
138
vrpn_int32 encodeSoundPlay(const vrpn_SoundID id, const vrpn_int32 repeat, char* buf);
139
vrpn_int32 decodeSoundPlay(const char* buf, vrpn_SoundID *id, vrpn_int32 *repeat);
140
vrpn_int32 encodeListenerVelocity(const vrpn_float64 *velocity, char* buf);
141
vrpn_int32 decodeListenerVelocity(const char* buf, vrpn_float64 *velocity);
142
vrpn_int32 encodeListenerPose(const vrpn_PoseDef pose, char* buf);
143
vrpn_int32 decodeListenerPose(const char* buf, vrpn_PoseDef * pose);
146
vrpn_int32 encodeSoundPose(const vrpn_PoseDef pose, const vrpn_SoundID id, char* buf);
147
vrpn_int32 decodeSoundPose(const char* buf, vrpn_PoseDef *pose, vrpn_SoundID *id);
148
vrpn_int32 encodeSoundVelocity(const vrpn_float64 *velocity, const vrpn_SoundID id, char* buf);
149
vrpn_int32 decodeSoundVelocity(const char* buf, vrpn_float64 *velocity, vrpn_SoundID *id);
150
vrpn_int32 encodeSoundDistInfo(const vrpn_float64 min_back,
151
const vrpn_float64 max_back,
152
const vrpn_float64 min_front,
153
const vrpn_float64 max_front, const vrpn_SoundID id, char* buf);
154
vrpn_int32 decodeSoundDistInfo(const char* buf, vrpn_float64 *min_back,
155
vrpn_float64 * max_back,
156
vrpn_float64 * min_front,
157
vrpn_float64 * max_front, vrpn_SoundID *id);
158
vrpn_int32 encodeSoundConeInfo(const vrpn_float64 cone_inner_angle,
159
const vrpn_float64 cone_outer_angle,
160
const vrpn_float64 cone_gain, const vrpn_SoundID id, char* buf);
161
vrpn_int32 decodeSoundConeInfo(const char* buf, vrpn_float64 *cone_inner_angle,
162
vrpn_float64 *cone_outer_angle,
163
vrpn_float64 *cone_gain, vrpn_SoundID *id);
164
vrpn_int32 encodeSoundDoplerScale(const vrpn_float64 doplerfactor, const vrpn_SoundID id, char* buf);
165
vrpn_int32 decodeSoundDoplerScale(const char* buf, vrpn_float64 *doplerfactor, vrpn_SoundID *id);
166
vrpn_int32 encodeSoundEqFactor(const vrpn_float64 eqfactor, const vrpn_SoundID id, char* buf);
167
vrpn_int32 decodeSoundEqFactor(const char* buf, vrpn_float64 *eqfactor, vrpn_SoundID *id);
168
vrpn_int32 encodeSoundPitch(const vrpn_float64 pitch, const vrpn_SoundID id, char* buf);
169
vrpn_int32 decodeSoundPitch(const char* buf, vrpn_float64 *pitch, vrpn_SoundID *id);
170
vrpn_int32 encodeSoundVolume(const vrpn_float64 volume, const vrpn_SoundID id, char* buf);
171
vrpn_int32 decodeSoundVolume(const char* buf, vrpn_float64 *volume, vrpn_SoundID *id);
173
vrpn_int32 encodeLoadModel_local(const char *filename, char **buf);
174
vrpn_int32 decodeLoadModel_local(const char *buf, char **filename, const int payload);
176
// Remote stuff not supported yet!
177
vrpn_int32 encodeLoadModel_remote(const char *filename, char **buf);
178
vrpn_int32 decodeLoadModel_remote(const char *buf, char **filename, const int payload);
180
vrpn_int32 encodeLoadPolyQuad(const vrpn_QuadDef quad, char* buf);
181
vrpn_int32 decodeLoadPolyQuad(const char* buf, vrpn_QuadDef * quad);
182
vrpn_int32 encodeLoadPolyTri(const vrpn_TriDef tri, char* buf);
183
vrpn_int32 decodeLoadPolyTri(const char* buf, vrpn_TriDef * tri);
184
vrpn_int32 encodeLoadMaterial(const vrpn_int32 id, const vrpn_MaterialDef material, char* buf);
185
vrpn_int32 decodeLoadMaterial(const char* buf, vrpn_MaterialDef * material, vrpn_int32 * id);
186
vrpn_int32 encodeSetQuadVert(const vrpn_float64 vertices[4][3], const vrpn_int32 tag, char* buf);
187
vrpn_int32 decodeSetQuadVert(const char* buf, vrpn_float64 (* vertices)[4][3], vrpn_int32 *tag);
188
vrpn_int32 encodeSetTriVert(const vrpn_float64 vertices[3][3], const vrpn_int32 tag, char* buf);
189
vrpn_int32 decodeSetTriVert(const char* buf, vrpn_float64 (*vertices)[3][3], vrpn_int32 *tag);
190
vrpn_int32 encodeSetPolyOF(const vrpn_float64 openingfactor, const vrpn_int32 tag, char* buf);
191
vrpn_int32 decodeSetPolyOF(const char* buf, vrpn_float64 * openingfactor, vrpn_int32 *tag);
192
vrpn_int32 encodeSetPolyMaterial(const char * material, const vrpn_int32 tag, char* buf);
193
vrpn_int32 decodeSetPolyMaterial(const char* buf, char ** material, vrpn_int32 *tag, const int payload);
196
class VRPN_API vrpn_Sound_Client : public vrpn_Sound, public vrpn_Text_Receiver {
198
vrpn_Sound_Client(const char * name, vrpn_Connection * c);
199
~vrpn_Sound_Client();
201
//This command starts a sound playing, the repeat value indicates how
202
//many times to play it. Continuously if repeat is set to 0
203
vrpn_int32 playSound(const vrpn_SoundID id, vrpn_int32 repeat);
204
vrpn_int32 stopSound(const vrpn_SoundID id);
205
//Loads a sound into memory on the server side, returns the ID value to be
206
//used to refer to the sound from now on. Pass in the path and filename
207
vrpn_SoundID loadSound(const char* sound, const vrpn_SoundID id, const vrpn_SoundDef soundDef);
208
vrpn_int32 unloadSound(const vrpn_SoundID id);
210
//All the functions with change and sound in them, can change either an
211
//already playing sound or one yet to be played
212
vrpn_int32 setSoundVolume(const vrpn_SoundID id, const vrpn_float64 volume);
213
vrpn_int32 setSoundPose(const vrpn_SoundID id, vrpn_float64 position[3], vrpn_float64 orientation[4]);
214
vrpn_int32 setSoundVelocity(const vrpn_SoundID id, const vrpn_float64 velocity[4]);
215
vrpn_int32 setSoundDistances(const vrpn_SoundID id,
216
const vrpn_float64 max_front_dist,
217
const vrpn_float64 min_front_dist,
218
const vrpn_float64 max_back_dist,
219
const vrpn_float64 min_back_dist);
220
vrpn_int32 setSoundConeInfo(const vrpn_SoundID id,
221
const vrpn_float64 inner_angle,
222
const vrpn_float64 outer_angle,
223
const vrpn_float64 gain);
225
vrpn_int32 setSoundDopScale(const vrpn_SoundID id, vrpn_float64 dopfactor);
226
vrpn_int32 setSoundEqValue(const vrpn_SoundID id, vrpn_float64 eq_value);
227
vrpn_int32 setSoundPitch(const vrpn_SoundID id, vrpn_float64 pitch);
229
vrpn_int32 setListenerPose(const vrpn_float64 position[3], const vrpn_float64 orientation[4]);
230
vrpn_int32 setListenerVelocity(const vrpn_float64 velocity[4]);
232
vrpn_int32 LoadModel_local(const char *filename);
234
// Remote stuff not supported yet!
235
vrpn_int32 LoadModel_remote(const char *data);
237
vrpn_int32 LoadPolyQuad(const vrpn_QuadDef quad);
238
vrpn_int32 LoadPolyTri(const vrpn_TriDef tri);
239
vrpn_int32 LoadMaterial(const vrpn_int32 id, const vrpn_MaterialDef material);
241
vrpn_int32 setMaterialName(const int id, const char * materialname);
242
vrpn_int32 setMaterialTransGain(const int id, const vrpn_float64 transmittance_gain);
243
vrpn_int32 setMaterialTransHF(const int id, const vrpn_float64 transmittance_hf);
244
vrpn_int32 setMaterialReflGain(const int id, const vrpn_float64 reflectance_gain);
245
vrpn_int32 setMaterialReflHF(const int id, const vrpn_float64 reflectance_hf);
247
vrpn_int32 setPolyOF(const int id, const vrpn_float64 OF);
248
vrpn_int32 setQuadVertices(const int id, const vrpn_float64 vertices[4][3]);
249
vrpn_int32 setPolyMaterialName(const int id, const char * materialname);
251
vrpn_int32 setTriVertices(const int id, const vrpn_float64 vertices[3][3]);
253
virtual void mainloop();
255
virtual void receiveTextMessage(const char * message, vrpn_uint32 type,vrpn_uint32 level, struct timeval msg_time);
260
static void VRPN_CALLBACK handle_receiveTextMessage(void *userdata, const vrpn_TEXTCB t);
265
/*Note on the server design
266
The server is designed in such a way that it expects a sub-class that is implemented
267
that actually implements sound functionality to have certain functions that it can
268
call to tell the child to play, load, whatever. This parent server class, handles
269
all of the callback functionality and decoding, allowing child classes to only have
270
to worry about sound functionality*/
271
#ifndef VRPN_CLIENT_ONLY
272
class VRPN_API vrpn_Sound_Server : public vrpn_Sound, public vrpn_Text_Sender
275
vrpn_Sound_Server(const char * name, vrpn_Connection * c);
276
~vrpn_Sound_Server();
278
virtual void playSound(vrpn_SoundID id, vrpn_int32 repeat, vrpn_SoundDef soundDef) = 0;
279
virtual void loadSoundLocal(char* filename, vrpn_SoundID id, vrpn_SoundDef soundDef) = 0;
280
virtual void loadSoundRemote(char* file, vrpn_SoundID id, vrpn_SoundDef soundDef) = 0;
281
virtual void stopSound(vrpn_SoundID id) = 0;
282
virtual void unloadSound(vrpn_SoundID id) = 0;
283
virtual void changeSoundStatus(vrpn_SoundID id, vrpn_SoundDef soundDef) = 0;
284
virtual void setListenerPose(vrpn_PoseDef pose) = 0;
285
virtual void setListenerVelocity(vrpn_float64 *velocity) = 0;
287
virtual void setSoundPose(vrpn_SoundID id, vrpn_PoseDef pose) = 0;
288
virtual void setSoundVelocity(vrpn_SoundID id, vrpn_float64 *velocity) = 0;
289
virtual void setSoundDistInfo(vrpn_SoundID id, vrpn_float64 *distinfo) = 0;
290
virtual void setSoundConeInfo(vrpn_SoundID id, vrpn_float64 *coneinfo) = 0;
292
virtual void setSoundDoplerFactor(vrpn_SoundID id, vrpn_float64 doplerfactor) = 0;
293
virtual void setSoundEqValue(vrpn_SoundID id, vrpn_float64 eqvalue) = 0;
294
virtual void setSoundPitch(vrpn_SoundID id, vrpn_float64 pitch) = 0;
295
virtual void setSoundVolume(vrpn_SoundID id, vrpn_float64 volume) = 0;
296
virtual void loadModelLocal(const char * filename) = 0;
297
virtual void loadModelRemote() = 0; // not supported
298
virtual void loadPolyQuad(vrpn_QuadDef * quad) = 0;
299
virtual void loadPolyTri(vrpn_TriDef * tri) = 0;
300
virtual void loadMaterial(vrpn_MaterialDef * material, vrpn_int32 id) = 0;
301
virtual void setPolyQuadVertices(vrpn_float64 vertices[4][3], const vrpn_int32 id) = 0;
302
virtual void setPolyTriVertices(vrpn_float64 vertices[3][3], const vrpn_int32 id) = 0;
303
virtual void setPolyOF(vrpn_float64 OF, vrpn_int32 tag) = 0;
304
virtual void setPolyMaterial(const char * material, vrpn_int32 tag) = 0;
310
static int VRPN_CALLBACK handle_loadSoundLocal(void *userdata, vrpn_HANDLERPARAM p);
311
static int VRPN_CALLBACK handle_loadSoundRemote(void *userdata, vrpn_HANDLERPARAM p);
312
static int VRPN_CALLBACK handle_unloadSound(void *userdata, vrpn_HANDLERPARAM p);
313
static int VRPN_CALLBACK handle_playSound(void *userdata, vrpn_HANDLERPARAM p);
314
static int VRPN_CALLBACK handle_stopSound(void *userdata, vrpn_HANDLERPARAM p);
315
static int VRPN_CALLBACK handle_changeSoundStatus(void *userdata, vrpn_HANDLERPARAM p);
316
static int VRPN_CALLBACK handle_setListenerPose(void *userdata, vrpn_HANDLERPARAM p);
317
static int VRPN_CALLBACK handle_setListenerVelocity(void *userdata, vrpn_HANDLERPARAM p);
319
static int VRPN_CALLBACK handle_setSoundPose(void *userdata, vrpn_HANDLERPARAM p);
320
static int VRPN_CALLBACK handle_setSoundVelocity(void *userdata, vrpn_HANDLERPARAM p);
321
static int VRPN_CALLBACK handle_setSoundDistanceinfo(void *userdata, vrpn_HANDLERPARAM p);
322
static int VRPN_CALLBACK handle_setSoundConeinfo(void *userdata, vrpn_HANDLERPARAM p);
324
static int VRPN_CALLBACK handle_setSoundDoplerfactor(void *userdata, vrpn_HANDLERPARAM p);
325
static int VRPN_CALLBACK handle_setSoundEqvalue(void *userdata, vrpn_HANDLERPARAM p);
326
static int VRPN_CALLBACK handle_setSoundPitch(void *userdata, vrpn_HANDLERPARAM p);
327
static int VRPN_CALLBACK handle_setSoundVolume(void *userdata, vrpn_HANDLERPARAM p);
329
static int VRPN_CALLBACK handle_loadModelLocal(void *userdata, vrpn_HANDLERPARAM p);
330
static int VRPN_CALLBACK handle_loadModelRemote(void *userdata, vrpn_HANDLERPARAM p);
331
static int VRPN_CALLBACK handle_loadPolyquad(void *userdata, vrpn_HANDLERPARAM p);
332
static int VRPN_CALLBACK handle_loadPolytri(void *userdata, vrpn_HANDLERPARAM p);
333
static int VRPN_CALLBACK handle_loadMaterial(void *userdata, vrpn_HANDLERPARAM p);
334
static int VRPN_CALLBACK handle_setPolyquadVertices(void *userdata, vrpn_HANDLERPARAM p);
335
static int VRPN_CALLBACK handle_setPolytriVertices(void *userdata, vrpn_HANDLERPARAM p);
336
static int VRPN_CALLBACK handle_setPolyOpeningfactor(void *userdata, vrpn_HANDLERPARAM p);
337
static int VRPN_CALLBACK handle_setPolyMaterial(void *userdata, vrpn_HANDLERPARAM p);
340
#endif //#ifndef VRPN_CLIENT_ONLY