Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Sound.h
Go to the documentation of this file.
1 /* Project nGenEx
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: nGenEx.lib
6  FILE: Sound.h
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Abstract Sound Object
13 */
14 
15 #ifndef Sound_h
16 #define Sound_h
17 
18 #include "Types.h"
19 #include "Geometry.h"
20 
21 // +--------------------------------------------------------------------+
22 
23 class SoundCard;
24 class SoundCheck;
25 class Camera;
26 
27 // +--------------------------------------------------------------------+
28 
29 class Sound
30 {
31 public:
32  static const char* TYPENAME() { return "Sound"; }
33 
34  static Sound* CreateStream(const char* filename);
35  static Sound* CreateOggStream(const char* filename);
36  static Sound* Create(DWORD flags, LPWAVEFORMATEX format);
37  static Sound* Create(DWORD flags, LPWAVEFORMATEX format, DWORD len, LPBYTE data);
38  static void SetListener(const Camera& cam, const Vec3& vel);
39  static void UseSoundCard(SoundCard* s) { creator = s; }
40 
41 public:
42  Sound();
43  virtual ~Sound();
44 
45  int operator==(const Sound& rhs) const { return this == &rhs; }
46 
47  enum FlagEnum { AMBIENT = 0x0000,
48  LOCALIZED = 0x0001,
49  LOC_3D = 0x0002,
50  MEMORY = 0x0000,
51  STREAMED = 0x0004,
52  ONCE = 0x0000,
53  LOOP = 0x0008,
54  FREE = 0x0000,
55  LOCKED = 0x0010,
56  DOPPLER = 0x0020,
57  INTERFACE = 0x0040,
58  OGGVORBIS = 0x4000,
59  RESOURCE = 0x8000 // not playable, only used to store data
60  };
61 
66  DONE };
67 
68  // once per frame:
69  virtual void Update() { }
70 
71  // mark for collection:
72  virtual void Release();
73 
74  // data loading:
75  // this method is for streamed sounds:
76  virtual HRESULT StreamFile(const char* name, DWORD offset) { return E_NOINTERFACE; }
77 
78  // this method is for memory sounds:
79  virtual HRESULT Load(DWORD bytes, BYTE* data) { return E_NOINTERFACE; } // => Ready
80 
81  // this method is for sound resources:
82  virtual Sound* Duplicate() { return 0; } // => Ready
83 
84  // transport operations:
85  virtual HRESULT Play() { return E_NOINTERFACE; } // => Playing
86  virtual HRESULT Rewind() { return E_NOINTERFACE; } // => Ready
87  virtual HRESULT Pause() { return E_NOINTERFACE; } // => Ready
88  virtual HRESULT Stop() { return E_NOINTERFACE; } // => Done
89 
90  // accessors / mutators
91  int IsReady() const { return status == READY; }
92  int IsPlaying() const { return status == PLAYING; }
93  int IsDone() const { return status == DONE; }
94  int LoopCount() const { return looped; }
95 
96  virtual DWORD GetFlags() const { return flags; }
97  virtual void SetFlags(DWORD f) { flags = f; }
98  virtual DWORD GetStatus() const { return status; }
99 
100  virtual long GetVolume() const { return volume; }
101  virtual void SetVolume(long v) { volume = v; }
102  virtual long GetPan() const { return 0; }
103  virtual void SetPan(long p) { }
104 
105  // (only for streamed sounds)
106  virtual double GetTotalTime() const { return 0; }
107  virtual double GetTimeRemaining() const { return 0; }
108  virtual double GetTimeElapsed() const { return 0; }
109 
110  // These should be relative to the listener:
111  // (only used for localized sounds)
112  virtual const Vec3& GetLocation() const { return location; }
113  virtual void SetLocation(const Vec3& l) { location = l; }
114  virtual const Vec3& GetVelocity() const { return velocity; }
115  virtual void SetVelocity(const Vec3& v) { velocity = v; }
116 
117  virtual float GetMinDistance() const { return 0; }
118  virtual void SetMinDistance(float f) { }
119  virtual float GetMaxDistance() const { return 0; }
120  virtual void SetMaxDistance(float f) { }
121 
122  virtual void SetSoundCheck(SoundCheck* s) { sound_check = s; }
123  virtual void AddToSoundCard();
124 
125  const char* GetFilename() const { return filename; }
126  void SetFilename(const char* s);
127 
128 protected:
129  DWORD flags;
130  DWORD status;
131  long volume; // centibels, (0 .. -10000)
132  int looped;
136  char filename[64];
137 
139 };
140 
141 // +--------------------------------------------------------------------+
142 
144 {
145 public:
146  virtual void Update(Sound* s) { }
147 };
148 
149 #endif Sound_h
150