RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_Sound.h
1// vrpn_Sound.h
2//
3// April 12 2000 - ZK
4
5#ifndef VRPN_SOUND_H
6#define VRPN_SOUND_H
7
8#include "vrpn_BaseClass.h" // for vrpn_BaseClass
9#include "vrpn_Configure.h" // for VRPN_CALLBACK, VRPN_API
10#include "vrpn_Shared.h" // for timeval
11#include "vrpn_Text.h" // for vrpn_TEXTCB, etc
12#include "vrpn_Types.h" // for vrpn_int32, vrpn_float64, etc
13
14class VRPN_API vrpn_Connection;
16
17#define MAX_MATERIAL_NAME_LENGTH 128
18#define MAX_NUMBER_SOUNDS 1024
19#define MAX_NUMBER_MATERIALS 64
20#define MAX_NUMBER_POLYGONS 2048
21#define MAX_FILENAME_LENGTH 2048
22
23// everything is on order found in these structs!
24
25typedef vrpn_int32 vrpn_SoundID;
26
27typedef struct _vrpn_PoseDef {
28 vrpn_float64 position[3];
29 vrpn_float64 orientation[4];
31 {
32 position[0] = position[1] = position[2] = 0.0;
33 orientation[0] = orientation[1] = orientation[2] = 0.0;
34 orientation[3] = 1.0;
35 };
37
38typedef struct _vrpn_SoundDef {
39 vrpn_PoseDef pose;
40 vrpn_float64 velocity[4];
41 vrpn_float64 max_front_dist;
42 vrpn_float64 min_front_dist;
43 vrpn_float64 max_back_dist;
44 vrpn_float64 min_back_dist;
45 vrpn_float64 cone_inner_angle;
46 vrpn_float64 cone_outer_angle;
47 vrpn_float64 cone_gain;
48 vrpn_float64 dopler_scale;
49 vrpn_float64 equalization_val;
50 vrpn_float64 pitch;
51 vrpn_float32 volume; // Jason Clark calls this volume, but really it is gain!
53 : max_front_dist(0)
54 , min_front_dist(0)
55 , max_back_dist(0)
56 , min_back_dist(0)
57 , cone_inner_angle(0)
58 , cone_outer_angle(0)
59 , cone_gain(0)
60 , dopler_scale(0)
61 , equalization_val(0)
62 , pitch(0)
63 , volume(0)
64 { velocity[0] = velocity[1] = velocity[2] = velocity[3] = 0.0; };
65
67
68typedef struct _vrpn_ListenerDef {
69 vrpn_PoseDef pose;
70 vrpn_float64 velocity[4];
72
73typedef struct _vrpn_MaterialDef {
74 char material_name[MAX_MATERIAL_NAME_LENGTH];
75 vrpn_float64 transmittance_gain;
76 vrpn_float64 transmittance_highfreq;
77 vrpn_float64 reflectance_gain;
78 vrpn_float64 reflectance_highfreq;
80
81typedef struct _vrpn_QuadDef {
82 vrpn_int32 subQuad; // really a bool
83 vrpn_float64 openingFactor;
84 vrpn_int32 tag;
85 vrpn_float64 vertices[4][3];
86 char material_name[MAX_MATERIAL_NAME_LENGTH];
88
89typedef struct _vrpn_TriDef {
90 vrpn_int32 subTri;
91 vrpn_float64 openingFactor;
92 vrpn_int32 tag;
93 vrpn_float64 vertices[3][3];
94 char material_name[MAX_MATERIAL_NAME_LENGTH];
96
97class VRPN_API vrpn_Sound : public vrpn_BaseClass {
98
99public:
100 vrpn_Sound(const char *name, vrpn_Connection *c);
101 ~vrpn_Sound();
102
103protected:
104 vrpn_int32
105 load_sound_local; // ID of message to load a sound from server side
106 vrpn_int32
107 load_sound_remote; // ID of message to load a sound from client side
108 vrpn_int32 unload_sound; // ID of message to unload a sound
109 vrpn_int32 play_sound; // ID of message to play a sound
110 vrpn_int32 stop_sound; // ID of message to stop a sound
111 vrpn_int32
112 change_sound_status; // ID of message to change the sound's status
113 vrpn_int32
114 set_listener_pose; // ID of message to set the listener's pos/orient
115 vrpn_int32
116 set_listener_velocity; // ID of message to set the listener's velocity
117 vrpn_int32 set_sound_pose; //
118 vrpn_int32 set_sound_velocity; //
119 vrpn_int32 set_sound_distanceinfo; //
120 vrpn_int32 set_sound_coneinfo; //
121 vrpn_int32 set_sound_doplerfactor; //
122 vrpn_int32 set_sound_eqvalue; //
123 vrpn_int32 set_sound_pitch;
124 vrpn_int32 set_sound_volume; //
125
126 vrpn_int32 load_model_local; // load model file from server side
127 vrpn_int32 load_model_remote; // load model file from client side
128 vrpn_int32 load_polyquad; // ID of message to load a quad polygon
129 vrpn_int32 load_polytri; // ID of message to load a tri polygon
130 vrpn_int32 load_material; // ID of message to load a material definition
131 vrpn_int32 set_polyquad_vertices;
132 vrpn_int32 set_polytri_vertices;
133 vrpn_int32 set_poly_openingfactor;
134 vrpn_int32 set_poly_material;
135
136 vrpn_int32 receive_text_message;
137
138 struct timeval timestamp; // Current timestamp
139
140 int register_types(void);
141
142 /*All encodes and decodes functions are for the purpose of setting up
143 messages to be sent over the network properly (ie to put them in one
144 char buffer and to put them in proper network order and for getting
145 the messages back into a usable format once they have been received*/
146
147 /*Note encodeSound allocates space dynamically for buf, it is your
148 responsibility to free it up*/
149 vrpn_int32 encodeSound_local(const char *filename, const vrpn_SoundID id,
150 const vrpn_SoundDef soundDef, char **buf);
151 /*Note decodeSound allocates space dynamically for filename, it is your
152 responsibility to free it up*/
153 vrpn_int32 decodeSound_local(const char *buf, char **filename,
154 vrpn_SoundID *id, vrpn_SoundDef *soundDef,
155 const int payload);
156
157 // These two are not supported yet!
158 vrpn_int32 encodeSound_remote(const char *filename, const vrpn_SoundID id,
159 char **buf);
160 vrpn_int32 decodeSound_remote(const char *buf, char **filename,
161 vrpn_SoundID *id, const int payload);
162
163 vrpn_int32 encodeSoundID(const vrpn_SoundID id, char *buf);
164 vrpn_int32 decodeSoundID(const char *buf, vrpn_SoundID *id);
165 vrpn_int32 encodeSoundDef(const vrpn_SoundDef sound, const vrpn_SoundID id,
166 const vrpn_int32 repeat, char *buf);
167 vrpn_int32 decodeSoundDef(const char *buf, vrpn_SoundDef *sound,
168 vrpn_SoundID *id, vrpn_int32 *repeat);
169 vrpn_int32 encodeSoundPlay(const vrpn_SoundID id, const vrpn_int32 repeat,
170 char *buf);
171 vrpn_int32 decodeSoundPlay(const char *buf, vrpn_SoundID *id,
172 vrpn_int32 *repeat);
173 vrpn_int32 encodeListenerVelocity(const vrpn_float64 *velocity, char *buf);
174 vrpn_int32 decodeListenerVelocity(const char *buf, vrpn_float64 *velocity);
175 vrpn_int32 encodeListenerPose(const vrpn_PoseDef pose, char *buf);
176 vrpn_int32 decodeListenerPose(const char *buf, vrpn_PoseDef *pose);
177
178 vrpn_int32 encodeSoundPose(const vrpn_PoseDef pose, const vrpn_SoundID id,
179 char *buf);
180 vrpn_int32 decodeSoundPose(const char *buf, vrpn_PoseDef *pose,
181 vrpn_SoundID *id);
182 vrpn_int32 encodeSoundVelocity(const vrpn_float64 *velocity,
183 const vrpn_SoundID id, char *buf);
184 vrpn_int32 decodeSoundVelocity(const char *buf, vrpn_float64 *velocity,
185 vrpn_SoundID *id);
186 vrpn_int32 encodeSoundDistInfo(const vrpn_float64 min_back,
187 const vrpn_float64 max_back,
188 const vrpn_float64 min_front,
189 const vrpn_float64 max_front,
190 const vrpn_SoundID id, char *buf);
191 vrpn_int32 decodeSoundDistInfo(const char *buf, vrpn_float64 *min_back,
192 vrpn_float64 *max_back,
193 vrpn_float64 *min_front,
194 vrpn_float64 *max_front, vrpn_SoundID *id);
195 vrpn_int32 encodeSoundConeInfo(const vrpn_float64 cone_inner_angle,
196 const vrpn_float64 cone_outer_angle,
197 const vrpn_float64 cone_gain,
198 const vrpn_SoundID id, char *buf);
199 vrpn_int32 decodeSoundConeInfo(const char *buf,
200 vrpn_float64 *cone_inner_angle,
201 vrpn_float64 *cone_outer_angle,
202 vrpn_float64 *cone_gain, vrpn_SoundID *id);
203 vrpn_int32 encodeSoundDoplerScale(const vrpn_float64 doplerfactor,
204 const vrpn_SoundID id, char *buf);
205 vrpn_int32 decodeSoundDoplerScale(const char *buf,
206 vrpn_float64 *doplerfactor,
207 vrpn_SoundID *id);
208 vrpn_int32 encodeSoundEqFactor(const vrpn_float64 eqfactor,
209 const vrpn_SoundID id, char *buf);
210 vrpn_int32 decodeSoundEqFactor(const char *buf, vrpn_float64 *eqfactor,
211 vrpn_SoundID *id);
212 vrpn_int32 encodeSoundPitch(const vrpn_float64 pitch, const vrpn_SoundID id,
213 char *buf);
214 vrpn_int32 decodeSoundPitch(const char *buf, vrpn_float64 *pitch,
215 vrpn_SoundID *id);
216 vrpn_int32 encodeSoundVolume(const vrpn_float64 volume,
217 const vrpn_SoundID id, char *buf);
218 vrpn_int32 decodeSoundVolume(const char *buf, vrpn_float64 *volume,
219 vrpn_SoundID *id);
220
221 vrpn_int32 encodeLoadModel_local(const char *filename, char **buf);
222 vrpn_int32 decodeLoadModel_local(const char *buf, char **filename,
223 const int payload);
224
225 // Remote stuff not supported yet!
226 vrpn_int32 encodeLoadModel_remote(const char *filename, char **buf);
227 vrpn_int32 decodeLoadModel_remote(const char *buf, char **filename,
228 const int payload);
229
230 vrpn_int32 encodeLoadPolyQuad(const vrpn_QuadDef quad, char *buf);
231 vrpn_int32 decodeLoadPolyQuad(const char *buf, vrpn_QuadDef *quad);
232 vrpn_int32 encodeLoadPolyTri(const vrpn_TriDef tri, char *buf);
233 vrpn_int32 decodeLoadPolyTri(const char *buf, vrpn_TriDef *tri);
234 vrpn_int32 encodeLoadMaterial(const vrpn_int32 id,
235 const vrpn_MaterialDef material, char *buf);
236 vrpn_int32 decodeLoadMaterial(const char *buf, vrpn_MaterialDef *material,
237 vrpn_int32 *id);
238 vrpn_int32 encodeSetQuadVert(const vrpn_float64 vertices[4][3],
239 const vrpn_int32 tag, char *buf);
240 vrpn_int32 decodeSetQuadVert(const char *buf,
241 vrpn_float64 (*vertices)[4][3],
242 vrpn_int32 *tag);
243 vrpn_int32 encodeSetTriVert(const vrpn_float64 vertices[3][3],
244 const vrpn_int32 tag, char *buf);
245 vrpn_int32 decodeSetTriVert(const char *buf, vrpn_float64 (*vertices)[3][3],
246 vrpn_int32 *tag);
247 vrpn_int32 encodeSetPolyOF(const vrpn_float64 openingfactor,
248 const vrpn_int32 tag, char *buf);
249 vrpn_int32 decodeSetPolyOF(const char *buf, vrpn_float64 *openingfactor,
250 vrpn_int32 *tag);
251 vrpn_int32 encodeSetPolyMaterial(const char *material, const vrpn_int32 tag,
252 char *buf);
253 vrpn_int32 decodeSetPolyMaterial(const char *buf, char **material,
254 vrpn_int32 *tag, const int payload);
255};
256
257class VRPN_API vrpn_Sound_Client : public vrpn_Sound,
258 public vrpn_Text_Receiver {
259public:
260 vrpn_Sound_Client(const char *name, vrpn_Connection *c);
262
263 // This command starts a sound playing, the repeat value indicates how
264 // many times to play it. Continuously if repeat is set to 0
265 vrpn_int32 playSound(const vrpn_SoundID id, vrpn_int32 repeat);
266 vrpn_int32 stopSound(const vrpn_SoundID id);
267 // Loads a sound into memory on the server side, returns the ID value to be
268 // used to refer to the sound from now on. Pass in the path and filename
269 vrpn_SoundID loadSound(const char *sound, const vrpn_SoundID id,
270 const vrpn_SoundDef soundDef);
271 vrpn_int32 unloadSound(const vrpn_SoundID id);
272
273 // All the functions with change and sound in them, can change either an
274 // already playing sound or one yet to be played
275 vrpn_int32 setSoundVolume(const vrpn_SoundID id, const vrpn_float64 volume);
276 vrpn_int32 setSoundPose(const vrpn_SoundID id, vrpn_float64 position[3],
277 vrpn_float64 orientation[4]);
278 vrpn_int32 setSoundVelocity(const vrpn_SoundID id,
279 const vrpn_float64 velocity[4]);
280 vrpn_int32 setSoundDistances(const vrpn_SoundID id,
281 const vrpn_float64 max_front_dist,
282 const vrpn_float64 min_front_dist,
283 const vrpn_float64 max_back_dist,
284 const vrpn_float64 min_back_dist);
285 vrpn_int32 setSoundConeInfo(const vrpn_SoundID id,
286 const vrpn_float64 inner_angle,
287 const vrpn_float64 outer_angle,
288 const vrpn_float64 gain);
289
290 vrpn_int32 setSoundDopScale(const vrpn_SoundID id, vrpn_float64 dopfactor);
291 vrpn_int32 setSoundEqValue(const vrpn_SoundID id, vrpn_float64 eq_value);
292 vrpn_int32 setSoundPitch(const vrpn_SoundID id, vrpn_float64 pitch);
293
294 vrpn_int32 setListenerPose(const vrpn_float64 position[3],
295 const vrpn_float64 orientation[4]);
296 vrpn_int32 setListenerVelocity(const vrpn_float64 velocity[4]);
297
298 vrpn_int32 LoadModel_local(const char *filename);
299
300 // Remote stuff not supported yet!
301 vrpn_int32 LoadModel_remote(const char *data);
302
303 vrpn_int32 LoadPolyQuad(const vrpn_QuadDef quad);
304 vrpn_int32 LoadPolyTri(const vrpn_TriDef tri);
305 vrpn_int32 LoadMaterial(const vrpn_int32 id,
306 const vrpn_MaterialDef material);
307
308 vrpn_int32 setMaterialName(const int id, const char *materialname);
309 vrpn_int32 setMaterialTransGain(const int id,
310 const vrpn_float64 transmittance_gain);
311 vrpn_int32 setMaterialTransHF(const int id,
312 const vrpn_float64 transmittance_hf);
313 vrpn_int32 setMaterialReflGain(const int id,
314 const vrpn_float64 reflectance_gain);
315 vrpn_int32 setMaterialReflHF(const int id,
316 const vrpn_float64 reflectance_hf);
317
318 vrpn_int32 setPolyOF(const int id, const vrpn_float64 OF);
319 vrpn_int32 setQuadVertices(const int id, const vrpn_float64 vertices[4][3]);
320 vrpn_int32 setPolyMaterialName(const int id, const char *materialname);
321
322 vrpn_int32 setTriVertices(const int id, const vrpn_float64 vertices[3][3]);
323
324 virtual void mainloop();
325
326 virtual void receiveTextMessage(const char *message, vrpn_uint32 type,
327 vrpn_uint32 level, struct timeval msg_time);
328
329protected:
330private:
331 static void VRPN_CALLBACK
332 handle_receiveTextMessage(void *userdata, const vrpn_TEXTCB t);
333};
334
335/*Note on the server design
336 The server is designed in such a way that it expects a sub-class that is
337 implemented
338 that actually implements sound functionality to have certain functions that it
339 can
340 call to tell the child to play, load, whatever. This parent server class,
341 handles
342 all of the callback functionality and decoding, allowing child classes to only
343 have
344 to worry about sound functionality*/
345#ifndef VRPN_CLIENT_ONLY
346class VRPN_API vrpn_Sound_Server : public vrpn_Sound, public vrpn_Text_Sender {
347public:
348 vrpn_Sound_Server(const char *name, vrpn_Connection *c);
350
351 virtual void playSound(vrpn_SoundID id, vrpn_int32 repeat,
352 vrpn_SoundDef soundDef) = 0;
353 virtual void loadSoundLocal(char *filename, vrpn_SoundID id,
354 vrpn_SoundDef soundDef) = 0;
355 virtual void loadSoundRemote(char *file, vrpn_SoundID id,
356 vrpn_SoundDef soundDef) = 0;
357 virtual void stopSound(vrpn_SoundID id) = 0;
358 virtual void unloadSound(vrpn_SoundID id) = 0;
359 virtual void changeSoundStatus(vrpn_SoundID id, vrpn_SoundDef soundDef) = 0;
360 virtual void setListenerPose(vrpn_PoseDef pose) = 0;
361 virtual void setListenerVelocity(vrpn_float64 *velocity) = 0;
362
363 virtual void setSoundPose(vrpn_SoundID id, vrpn_PoseDef pose) = 0;
364 virtual void setSoundVelocity(vrpn_SoundID id, vrpn_float64 *velocity) = 0;
365 virtual void setSoundDistInfo(vrpn_SoundID id, vrpn_float64 *distinfo) = 0;
366 virtual void setSoundConeInfo(vrpn_SoundID id, vrpn_float64 *coneinfo) = 0;
367
368 virtual void setSoundDoplerFactor(vrpn_SoundID id,
369 vrpn_float64 doplerfactor) = 0;
370 virtual void setSoundEqValue(vrpn_SoundID id, vrpn_float64 eqvalue) = 0;
371 virtual void setSoundPitch(vrpn_SoundID id, vrpn_float64 pitch) = 0;
372 virtual void setSoundVolume(vrpn_SoundID id, vrpn_float64 volume) = 0;
373 virtual void loadModelLocal(const char *filename) = 0;
374 virtual void loadModelRemote() = 0; // not supported
375 virtual void loadPolyQuad(vrpn_QuadDef *quad) = 0;
376 virtual void loadPolyTri(vrpn_TriDef *tri) = 0;
377 virtual void loadMaterial(vrpn_MaterialDef *material, vrpn_int32 id) = 0;
378 virtual void setPolyQuadVertices(vrpn_float64 vertices[4][3],
379 const vrpn_int32 id) = 0;
380 virtual void setPolyTriVertices(vrpn_float64 vertices[3][3],
381 const vrpn_int32 id) = 0;
382 virtual void setPolyOF(vrpn_float64 OF, vrpn_int32 tag) = 0;
383 virtual void setPolyMaterial(const char *material, vrpn_int32 tag) = 0;
384
385protected:
386private:
387 static int VRPN_CALLBACK
388 handle_loadSoundLocal(void *userdata, vrpn_HANDLERPARAM p);
389 static int VRPN_CALLBACK
390 handle_loadSoundRemote(void *userdata, vrpn_HANDLERPARAM p);
391 static int VRPN_CALLBACK
392 handle_unloadSound(void *userdata, vrpn_HANDLERPARAM p);
393 static int VRPN_CALLBACK
394 handle_playSound(void *userdata, vrpn_HANDLERPARAM p);
395 static int VRPN_CALLBACK
396 handle_stopSound(void *userdata, vrpn_HANDLERPARAM p);
397 static int VRPN_CALLBACK
398 handle_changeSoundStatus(void *userdata, vrpn_HANDLERPARAM p);
399 static int VRPN_CALLBACK
400 handle_setListenerPose(void *userdata, vrpn_HANDLERPARAM p);
401 static int VRPN_CALLBACK
402 handle_setListenerVelocity(void *userdata, vrpn_HANDLERPARAM p);
403
404 static int VRPN_CALLBACK
405 handle_setSoundPose(void *userdata, vrpn_HANDLERPARAM p);
406 static int VRPN_CALLBACK
407 handle_setSoundVelocity(void *userdata, vrpn_HANDLERPARAM p);
408 static int VRPN_CALLBACK
409 handle_setSoundDistanceinfo(void *userdata, vrpn_HANDLERPARAM p);
410 static int VRPN_CALLBACK
411 handle_setSoundConeinfo(void *userdata, vrpn_HANDLERPARAM p);
412
413 static int VRPN_CALLBACK
414 handle_setSoundDoplerfactor(void *userdata, vrpn_HANDLERPARAM p);
415 static int VRPN_CALLBACK
416 handle_setSoundEqvalue(void *userdata, vrpn_HANDLERPARAM p);
417 static int VRPN_CALLBACK
418 handle_setSoundPitch(void *userdata, vrpn_HANDLERPARAM p);
419 static int VRPN_CALLBACK
420 handle_setSoundVolume(void *userdata, vrpn_HANDLERPARAM p);
421
422 static int VRPN_CALLBACK
423 handle_loadModelLocal(void *userdata, vrpn_HANDLERPARAM p);
424 static int VRPN_CALLBACK
425 handle_loadModelRemote(void *userdata, vrpn_HANDLERPARAM p);
426 static int VRPN_CALLBACK
427 handle_loadPolyquad(void *userdata, vrpn_HANDLERPARAM p);
428 static int VRPN_CALLBACK
429 handle_loadPolytri(void *userdata, vrpn_HANDLERPARAM p);
430 static int VRPN_CALLBACK
431 handle_loadMaterial(void *userdata, vrpn_HANDLERPARAM p);
432 static int VRPN_CALLBACK
433 handle_setPolyquadVertices(void *userdata, vrpn_HANDLERPARAM p);
434 static int VRPN_CALLBACK
435 handle_setPolytriVertices(void *userdata, vrpn_HANDLERPARAM p);
436 static int VRPN_CALLBACK
437 handle_setPolyOpeningfactor(void *userdata, vrpn_HANDLERPARAM p);
438 static int VRPN_CALLBACK
439 handle_setPolyMaterial(void *userdata, vrpn_HANDLERPARAM p);
440};
441#endif //#ifndef VRPN_CLIENT_ONLY
442
443#endif
定义 vrpn_BaseClass.h:310
Generic connection class not specific to the transport mechanism.
定义 vrpn_Connection.h:562
定义 vrpn_Sound.h:258
virtual void mainloop()
定义 vrpn_Sound.h:346
定义 vrpn_Sound.h:97
int register_types(void)
Allows a user to handle text messages directly, in addition to having the
定义 vrpn_Text.h:69
Allows a user to send text messages from a device (usually,
定义 vrpn_Text.h:40
定义 vrpn_Sound.h:68
定义 vrpn_Sound.h:73
定义 vrpn_Sound.h:27
定义 vrpn_Sound.h:81
定义 vrpn_Sound.h:38
Structure passed back to user-level code from a vrpn_Text_Receiver.
定义 vrpn_Text.h:22
定义 vrpn_Sound.h:89
This structure is what is passed to a vrpn_Connection message callback.
定义 vrpn_Connection.h:41