summaryrefslogtreecommitdiffhomepage
path: root/nGenEx/Sound.h
blob: d4e037429159e7e481240ad03279211ce7904f23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*  Starshatter OpenSource Distribution
    Copyright (c) 1997-2004, Destroyer Studios LLC.
    All Rights Reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name "Destroyer Studios" nor the names of its contributors
      may be used to endorse or promote products derived from this software
      without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.

    SUBSYSTEM:    nGenEx.lib
    FILE:         Sound.h
    AUTHOR:       John DiCamillo


    OVERVIEW
    ========
    Abstract Sound Object
*/

#ifndef Sound_h
#define Sound_h

#include "Types.h"
#include "Geometry.h"

// +--------------------------------------------------------------------+

class SoundCard;
class SoundCheck;
class Camera;

// +--------------------------------------------------------------------+

class Sound
{
public:
    static const char* TYPENAME() { return "Sound"; }

    static Sound*     CreateStream(const char* filename);
    static Sound*     CreateOggStream(const char* filename);
    static Sound*     Create(DWORD flags, LPWAVEFORMATEX format);
    static Sound*     Create(DWORD flags, LPWAVEFORMATEX format, DWORD len, LPBYTE data);
    static void       SetListener(const Camera& cam, const Vec3& vel);
    static void       UseSoundCard(SoundCard* s) { creator = s; }

public:
    Sound();
    virtual ~Sound();

    int operator==(const Sound& rhs) const { return this == &rhs; }

    enum FlagEnum {   AMBIENT   = 0x0000,
        LOCALIZED = 0x0001,
        LOC_3D    = 0x0002,
        MEMORY    = 0x0000,
        STREAMED  = 0x0004,
        ONCE      = 0x0000,
        LOOP      = 0x0008,
        FREE      = 0x0000,
        LOCKED    = 0x0010,
        DOPPLER   = 0x0020,
        INTERFACE = 0x0040,
        OGGVORBIS = 0x4000,
        RESOURCE  = 0x8000   // not playable, only used to store data
    };

    enum StatusEnum { UNINITIALIZED,
        INITIALIZING,
        READY,
        PLAYING,
        DONE };

    // once per frame:
    virtual void      Update()                      { }

    // mark for collection:
    virtual void      Release();

    // data loading:
    // this method is for streamed sounds:
    virtual HRESULT   StreamFile(const char* name, DWORD offset) { return E_NOINTERFACE; }

    // this method is for memory sounds:
    virtual HRESULT   Load(DWORD bytes, BYTE* data) { return E_NOINTERFACE; }  // => Ready

    // this method is for sound resources:
    virtual Sound*    Duplicate()                   { return 0;             }  // => Ready

    // transport operations:
    virtual HRESULT   Play()                        { return E_NOINTERFACE; }  // => Playing
    virtual HRESULT   Rewind()                      { return E_NOINTERFACE; }  // => Ready
    virtual HRESULT   Pause()                       { return E_NOINTERFACE; }  // => Ready
    virtual HRESULT   Stop()                        { return E_NOINTERFACE; }  // => Done

    // accessors / mutators
    int               IsReady()               const { return status == READY;   }
    int               IsPlaying()             const { return status == PLAYING; }
    int               IsDone()                const { return status == DONE;    }
    int               LoopCount()             const { return looped;   }

    virtual DWORD     GetFlags()              const { return flags;    }
    virtual void      SetFlags(DWORD f)             { flags = f;       }
    virtual DWORD     GetStatus()             const { return status;   }

    virtual long      GetVolume()             const { return volume;   }
    virtual void      SetVolume(long v)             { volume = v;      }
    virtual long      GetPan()                const { return 0;        }
    virtual void      SetPan(long p)                {                  }

    // (only for streamed sounds)
    virtual double    GetTotalTime()          const { return 0; }
    virtual double    GetTimeRemaining()      const { return 0; }
    virtual double    GetTimeElapsed()        const { return 0; }

    // These should be relative to the listener:
    // (only used for localized sounds)
    virtual const Vec3& GetLocation()         const { return location; }
    virtual void        SetLocation(const Vec3& l)  { location = l;    }
    virtual const Vec3& GetVelocity()         const { return velocity; }
    virtual void        SetVelocity(const Vec3& v)  { velocity = v;    }

    virtual float     GetMinDistance()        const { return 0; }
    virtual void      SetMinDistance(float f)       {           }
    virtual float     GetMaxDistance()        const { return 0; }
    virtual void      SetMaxDistance(float f)       {           }

    virtual void      SetSoundCheck(SoundCheck* s)  { sound_check = s; }
    virtual void      AddToSoundCard();

    const char*       GetFilename()           const { return filename; }
    void              SetFilename(const char* s);

protected:
    DWORD             flags;
    DWORD             status;
    long              volume;  // centibels, (0 .. -10000)
    int               looped;
    Vec3              location;
    Vec3              velocity;
    SoundCheck*       sound_check;
    char              filename[64];

    static SoundCard* creator;
};

// +--------------------------------------------------------------------+

class SoundCheck
{
public:
    virtual void Update(Sound* s) { }
};

#endif Sound_h