source: golgotha/src/i4/sound/sound.hh @ 608

Last change on this file since 608 was 80, checked in by Sam Hocevar, 15 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 4.1 KB
Line 
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#ifndef SOUND_HH
10#define SOUND_HH
11
12#include "math/num_type.hh"
13#include "init/init.hh"
14#include "sound/sound_types.hh"
15
16class i4_stream_wav_player;
17
18class i4_voice_class
19{
20public:
21   
22  i4_frequency default_frequency;
23  w32          sound_length;
24
25
26  virtual void stop() = 0;
27  virtual void play() = 0;
28  virtual i4_bool is_playing() = 0;
29  virtual void set_frequency(i4_frequency freq) = 0;
30  virtual void set_volume(i4_volume vol) = 0; 
31  virtual void set_pan(i4_pan pan) = 0;
32  virtual void set_looping(i4_bool yes_no) = 0;   // must be called before play
33
34  virtual i4_frequency get_frequency() = 0;
35  virtual i4_volume get_volume() = 0;
36  virtual i4_pan get_pan() = 0;
37
38  virtual void lock(w32 start_position, w32 size,
39                    void *&block1, w32 &block1_size,
40                    void *&block2, w32 &block2_size) = 0;
41
42  virtual void unlock(void *block1, w32 block1_size,
43                      void *block2, w32 block2_size) = 0;
44
45  virtual w32 get_sound_position() = 0; // current play position in bytes
46  virtual void set_sound_position(w32 pos) = 0;
47
48  virtual void set_hearable_distance(float x) = 0;
49  virtual float get_hearable_distance() = 0;
50 
51  virtual ~i4_voice_class() { ; }
52
53  // these function are only available if you created a 3d sound
54  virtual void set_3d_position(i4_float x, i4_float y, i4_float z, i4_bool immediately) = 0;
55  virtual void set_3d_velocity(i4_float x,i4_float y,i4_float z,i4_bool immediately) = 0;
56};
57
58class i4_sound_manager_class;
59extern i4_sound_manager_class *i4_sound_man;
60extern i4_sound_manager_class i4_null_sound;
61
62class i4_sound_manager_class : public i4_init_class
63{
64public:
65  class sound_parameters
66  {
67  public:
68    w32          channels;     //1 for mono,  2 for stereo
69    w32          sample_size;  //1 for 8-bit, 2 for 16-bit
70    i4_frequency frequency;
71    i4_volume    volume;
72    i4_pan       pan;
73    i4_bool      looping,
74                 reverb,
75                 streaming,
76                 capable_3d; //if you want this to be capable of being used as a 3d sound
77
78    sound_parameters(i4_frequency  _frequency   = 11025,
79                     w32           _channels    = 1,
80                     w32           _sample_size = 1,
81                     i4_volume     _volume      = I4_SOUND_VOLUME_LEVELS-1,
82                     i4_pan        _pan         = 0,
83                     i4_bool       _looping     = i4_F,
84                     i4_bool       _reverb      = i4_F,
85                     i4_bool       _streaming   = i4_F,
86                     i4_bool       _capable_3d  = i4_F);
87  };
88
89  virtual void init();
90
91  // if you want to play a sound twice (mix with self) you have to duplicate it
92  // and play the duplicate and the oruginal,  the duplicate will not duplicate the
93  // actual data in the sound buffer, but rather the position, frequency, etc.
94  virtual i4_voice_class *duplicate_2d(i4_voice_class *voice) { return 0; }
95  virtual i4_voice_class *duplicate_3d(i4_voice_class *voice) { return 0; }
96
97  // returns 0 not enough memory to alloc buffer
98  virtual i4_voice_class *alloc(w32 buffer_size, sound_parameters &description) { return 0; }
99
100  virtual void set_listener_velocity(i4_float x,i4_float y,i4_float z){}
101  virtual void set_listener_position(i4_float x,i4_float y,i4_float z){}
102  virtual void set_listener_orientation(i4_float f_x,i4_float f_y,i4_float f_z,
103                                        i4_float u_x,i4_float u_y,i4_float u_z){}
104
105  virtual void commit_3d_changes() {}
106
107  virtual void free_voice(i4_voice_class *voice) {delete voice;}
108
109#ifndef I4_RETAIL
110  virtual char *name() { return "null sound"; }
111#endif
112};
113
114
115
116#endif
Note: See TracBrowser for help on using the repository browser.