Go to the documentation of this file.00001 #pragma once
00002 #include <ogg/ogg.h>
00003 #include <vorbis/codec.h>
00004 #include <vorbis/vorbisenc.h>
00005 #include <vorbis/vorbisfile.h>
00006
00007
00008
00009
00010 #define WAVE_FORMAT_EXTENSIBLE 0xFFFE
00011
00012
00013 #define SPEAKER_FRONT_LEFT 0x1
00014 #define SPEAKER_FRONT_RIGHT 0x2
00015 #define SPEAKER_FRONT_CENTER 0x4
00016 #define SPEAKER_LOW_FREQUENCY 0x8
00017 #define SPEAKER_BACK_LEFT 0x10
00018 #define SPEAKER_BACK_RIGHT 0x20
00019 #define SPEAKER_FRONT_LEFT_OF_CENTER 0x40
00020 #define SPEAKER_FRONT_RIGHT_OF_CENTER 0x80
00021 #define SPEAKER_BACK_CENTER 0x100
00022 #define SPEAKER_SIDE_LEFT 0x200
00023 #define SPEAKER_SIDE_RIGHT 0x400
00024 #define SPEAKER_TOP_CENTER 0x800
00025 #define SPEAKER_TOP_FRONT_LEFT 0x1000
00026 #define SPEAKER_TOP_FRONT_CENTER 0x2000
00027 #define SPEAKER_TOP_FRONT_RIGHT 0x4000
00028 #define SPEAKER_TOP_BACK_LEFT 0x8000
00029 #define SPEAKER_TOP_BACK_CENTER 0x10000
00030 #define SPEAKER_TOP_BACK_RIGHT 0x20000
00031
00032
00033 enum WAVEFILETYPE {
00034 WF_EX = 1,
00035 WF_EXT = 2
00036 };
00037
00038 #ifndef GUID_DEFINED
00039 #define GUID_DEFINED
00040 #if defined(__midl)
00041 typedef struct {
00042 unsigned long Data1;
00043 unsigned short Data2;
00044 unsigned short Data3;
00045 byte Data4[ 8 ];
00046 } GUID;
00047 #else
00048 typedef struct _GUID {
00049 unsigned long Data1;
00050 unsigned short Data2;
00051 unsigned short Data3;
00052 unsigned char Data4[ 8 ];
00053 } GUID;
00054 #endif
00055 #endif
00056
00057 #ifndef _WAVEFORMATEX_
00058 #define _WAVEFORMATEX_
00059
00060 typedef struct tWAVEFORMATEX{
00061 unsigned short wFormatTag;
00062 unsigned short nChannels;
00063 unsigned long nSamplesPerSec;
00064 unsigned long nAvgBytesPerSec;
00065 unsigned short nBlockAlign;
00066 unsigned short wBitsPerSample;
00067 unsigned short cbSize;
00068 } WAVEFORMATEX, *PWAVEFORMATEX, NEAR *NPWAVEFORMATEX, FAR *LPWAVEFORMATEX;
00069
00070 #endif
00071
00072 typedef struct {
00073 WAVEFORMATEX Format;
00074 union {
00075 unsigned short wValidBitsPerSample;
00076 unsigned short wSamplesPerBlock;
00077 unsigned short wReserved;
00078 } Samples;
00079 unsigned long dwChannelMask;
00080 GUID SubFormat;
00081 } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
00082
00083
00084 typedef struct {
00085 WAVEFILETYPE wfType;
00086 WAVEFORMATEXTENSIBLE wfEXT;
00087 char *pData;
00088 unsigned long ulDataSize;
00089 FILE *pFile;
00090 unsigned long ulDataOffset;
00091 } WAVEFILEINFO, *LPWAVEFILEINFO;
00092
00093 #ifndef WAVE_FORMAT_PCM
00094
00095
00096 typedef struct waveformat_tag {
00097 WORD wFormatTag;
00098 WORD nChannels;
00099 DWORD nSamplesPerSec;
00100 DWORD nAvgBytesPerSec;
00101 WORD nBlockAlign;
00102 } WAVEFORMAT, *PWAVEFORMAT, NEAR *NPWAVEFORMAT, FAR *LPWAVEFORMAT;
00103
00104
00105 #define WAVE_FORMAT_PCM 1
00106
00107
00108 typedef struct pcmwaveformat_tag {
00109 WAVEFORMAT wf;
00110 WORD wBitsPerSample;
00111 } PCMWAVEFORMAT, *PPCMWAVEFORMAT, NEAR *NPPCMWAVEFORMAT, FAR *LPPCMWAVEFORMAT;
00112
00113 #endif
00114
00115 #pragma pack(push, 4)
00116
00117 typedef struct {
00118 char szRIFF[4];
00119 unsigned long ulRIFFSize;
00120 char szWAVE[4];
00121 } WAVEFILEHEADER;
00122
00123 typedef struct {
00124 char szChunkName[4];
00125 unsigned long ulChunkSize;
00126 } RIFFCHUNK;
00127
00128 typedef struct {
00129 unsigned short usFormatTag;
00130 unsigned short usChannels;
00131 unsigned long ulSamplesPerSec;
00132 unsigned long ulAvgBytesPerSec;
00133 unsigned short usBlockAlign;
00134 unsigned short usBitsPerSample;
00135 unsigned short usSize;
00136 unsigned short usReserved;
00137 unsigned long ulChannelMask;
00138 GUID guidSubFormat;
00139 } WAVEFMT;
00140
00141 #pragma pack(pop)
00142
00143
00144 STARTNAMESPACE
00145
00146 struct Orientation {
00147 Orientation() {}
00148 Orientation(float3 dir, float3 up) : dir(dir), up(up) {}
00149 float3 dir;
00150 float3 up;
00151 };
00152
00153 struct SListener {
00154 float3 *position, *velocity;
00155 Orientation* orientation;
00156 };
00157
00158 class SoundBuffer {
00159 public:
00160 SoundBuffer();
00161 virtual ~SoundBuffer();
00162 virtual bool load(const wchar* file) = 0;
00163 ALuint buffer;
00164 };
00165
00166 class SoundBufferWAVE :
00167 public SoundBuffer {
00168 public:
00169 SoundBufferWAVE() : SoundBuffer(){};
00170 ~SoundBufferWAVE(){};
00171 bool load(const wchar* file);
00172 private:
00173 bool LoadWaveFile(const wchar* file, int* iDataSize, char** pData, int* iFrequency, ALenum* eBufferFormat);
00174 bool ParseFile(const wchar *file, WAVEFILEINFO* pWaveInfo);
00175 ALenum GetBufferFormat(WAVEFILEINFO& waveinfo);
00176 };
00177
00178 class Music :
00179 public ::Music {
00180 public:
00181 virtual void update() = 0;
00182 virtual bool load(const wchar* file, bool loop, float volume) = 0;
00183
00184 bool m_play, m_playing, m_loop;
00185 };
00186
00187 class SMusicOGG :
00188 public Music {
00189 public:
00190 SMusicOGG(ArrayList<Music*>&);
00191 ~SMusicOGG();
00192
00193 void play();
00194 void stop();
00195 void pause();
00196 void resume();
00197 void update();
00198 bool load(const wchar* file, bool loop, float volume);
00199
00200 protected:
00201 bool recreate(void);
00202 void free();
00203 bool isPlaying();
00204 bool isLooping(){return m_loop;};
00205 bool stream(ALuint buffer);
00206 void empty();
00207
00208 private:
00209 FILE* oggFile;
00210 OggVorbis_File oggStream;
00211 vorbis_info* vorbisInfo;
00212 ALuint source, buffers[2];
00213 ALenum format;
00214 bool m_release;
00215 ArrayList<Music*>& list;
00216 };
00217
00218 class Sound :
00219 public ::Sound {
00220 public:
00221 Sound(ArrayList<Sound*>&);
00222 ~Sound();
00223
00224 void play();
00225 void stop();
00226 void pause();
00227 void resume();
00228 bool load(::pBuffer buffer, bool dynamic,
00229 float3* position, float3* velocity, float3* direction,
00230 float distance, float coneAngle, bool loop, float volume);
00231 void update(float3* listener);
00232
00233 bool m_play, m_playing, m_dynamic;
00234 ALuint source;
00235 float distance;
00236 float3 *position, *velocity, *direction;
00237 ArrayList<Sound*>& list;
00238 };
00239
00240 ENDNAMESPACE