1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #include "sound/simple_sound3d.hh"
|
---|
10 | #include "error/error.hh"
|
---|
11 |
|
---|
12 | #define speed_of_sound 512.0
|
---|
13 | #define position_to_volume 0.1
|
---|
14 |
|
---|
15 | i4_simple_3d_sound_manager_class i4_simple_3d_sound;
|
---|
16 |
|
---|
17 |
|
---|
18 | void i4_simple_3d_voice_class::play()
|
---|
19 | //{{{
|
---|
20 | {
|
---|
21 | update();
|
---|
22 | voc->play();
|
---|
23 | }
|
---|
24 | //}}}
|
---|
25 |
|
---|
26 |
|
---|
27 | void i4_simple_3d_voice_class::update()
|
---|
28 | //{{{
|
---|
29 | {
|
---|
30 | i4_frequency freq;
|
---|
31 | i4_volume vol, pan;
|
---|
32 |
|
---|
33 | i4_3d_vector a(position);
|
---|
34 | i4_float len = a.length();
|
---|
35 |
|
---|
36 | pan = (i4_volume)(a.x*position_to_volume);
|
---|
37 | pan =
|
---|
38 | (pan>=I4_SOUND_VOLUME_LEVELS)? I4_SOUND_VOLUME_LEVELS-1 :
|
---|
39 | ((pan<=-I4_SOUND_VOLUME_LEVELS)? -I4_SOUND_VOLUME_LEVELS+1 : pan);
|
---|
40 |
|
---|
41 | if (len<0.0001)
|
---|
42 | a.set(0,0,0);
|
---|
43 | else
|
---|
44 | a /= len;
|
---|
45 | i4_float vel = a.dot(velocity);
|
---|
46 |
|
---|
47 | freq = (i4_frequency)((i4_float)frequency)*((-vel + speed_of_sound)/speed_of_sound);
|
---|
48 |
|
---|
49 | vol = volume - (i4_volume)(len*position_to_volume);
|
---|
50 | vol = (vol<0)? 0 : vol;
|
---|
51 |
|
---|
52 | voc->set_frequency(freq);
|
---|
53 | voc->set_volume(vol);
|
---|
54 | voc->set_pan(pan);
|
---|
55 | }
|
---|
56 | //}}}
|
---|
57 |
|
---|
58 |
|
---|
59 | void i4_simple_3d_sound_manager_class::init()
|
---|
60 | //{{{
|
---|
61 | {
|
---|
62 | i4_3d_sound_manager_class::init();
|
---|
63 |
|
---|
64 | // note: should theoretically turn itself off if the only sound manager
|
---|
65 | // available is the null_sound_manager;
|
---|
66 | }
|
---|
67 | //}}}
|
---|
68 |
|
---|
69 |
|
---|
70 | void i4_simple_3d_sound_manager_class::load_sounds(w32 max_sounds)
|
---|
71 | //{{{
|
---|
72 | {
|
---|
73 | i4_sound_man->load_sounds(max_sounds);
|
---|
74 | }
|
---|
75 | //}}}
|
---|
76 |
|
---|
77 |
|
---|
78 | i4_3d_voice_class *i4_simple_3d_sound_manager_class::alloc(i4_sound_id sound_id,
|
---|
79 | const i4_3d_sound_parameters& param)
|
---|
80 | //{{{
|
---|
81 | {
|
---|
82 | i4_sound_manager_class::sound_parameters dummy;
|
---|
83 |
|
---|
84 | dummy.looping = param.looping;
|
---|
85 | dummy.reverb = param.reverb;
|
---|
86 |
|
---|
87 | i4_voice_class *voc = i4_sound_man->alloc(sound_id, dummy);
|
---|
88 |
|
---|
89 | if (voc)
|
---|
90 | return new i4_simple_3d_voice_class(voc, param);
|
---|
91 | else
|
---|
92 | return 0;
|
---|
93 | }
|
---|
94 | //}}}
|
---|
95 |
|
---|
96 |
|
---|
97 | //{{{ Emacs Locals
|
---|
98 | // Local Variables:
|
---|
99 | // folded-file: t
|
---|
100 | // End:
|
---|
101 | //}}}
|
---|