zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Sound_Renderer_AL.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef ZENI_SOUND_RENDERER_AL_H
19 #define ZENI_SOUND_RENDERER_AL_H
20 
21 #include <Zeni/Sound_Renderer.h>
22 
23 #ifndef DISABLE_AL
24 
25 #ifdef _MACOSX
26 #include <OpenAL/alc.h>
27 #else
28 #include <AL/alc.h>
29 #endif
30 
31 #define OV_EXCLUDE_STATIC_CALLBACKS
32 #include <vorbis/vorbisfile.h>
33 #undef OV_EXCLUDE_STATIC_CALLBACKS
34 
35 #ifdef _WINDOWS
36 #include <Windows.h>
37 #endif
38 
39 namespace Zeni {
40 
41  class ZENI_AUDIO_DLL Sound_Renderer_AL : public Sound_Renderer {
42  friend class Sound;
43 
46 
47  // Undefined
49  Sound_Renderer_AL & operator=(const Sound_Renderer_AL &);
50 
51  public:
52  typedef void (AL_APIENTRY *alBufferData_fcn)( ALuint bid, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq );
53  typedef ALCboolean (ALC_APIENTRY *alcCloseDevice_fcn)( ALCdevice *device );
54  typedef ALCcontext * (ALC_APIENTRY *alcCreateContext_fcn)( ALCdevice *device, const ALCint* attrlist );
55  typedef void (ALC_APIENTRY *alcDestroyContext_fcn)( ALCcontext *context );
56  typedef ALboolean (AL_APIENTRY *alIsExtensionPresent_fcn)( const ALchar* extname );
57  typedef ALCboolean (ALC_APIENTRY *alcMakeContextCurrent_fcn)( ALCcontext *context );
58  typedef ALCdevice * (ALC_APIENTRY *alcOpenDevice_fcn)( const ALCchar *devicename );
59  typedef void (AL_APIENTRY *alDeleteBuffers_fcn)( ALsizei n, const ALuint* buffers );
60  typedef void (AL_APIENTRY *alDeleteSources_fcn)( ALsizei n, const ALuint* sources );
61  typedef void (AL_APIENTRY *alGenBuffers_fcn)( ALsizei n, ALuint* buffers );
62  typedef ALenum (AL_APIENTRY *alGetError_fcn)( void );
63  typedef void (AL_APIENTRY *alGetListenerf_fcn)( ALenum param, ALfloat* value );
64  typedef void (AL_APIENTRY *alGetListenerfv_fcn)( ALenum param, ALfloat* values );
65  typedef void (AL_APIENTRY *alGetSourcef_fcn)( ALuint sid, ALenum param, ALfloat* value );
66  typedef void (AL_APIENTRY *alGetSourcefv_fcn)( ALuint sid, ALenum param, ALfloat* values );
67  typedef void (AL_APIENTRY *alGetSourcei_fcn)( ALuint sid, ALenum param, ALint* value );
68  typedef void (AL_APIENTRY *alGenSources_fcn)( ALsizei n, ALuint* sources );
69  typedef void (AL_APIENTRY *alListenerf_fcn)( ALenum param, ALfloat value );
70  typedef void (AL_APIENTRY *alListenerfv_fcn)( ALenum param, const ALfloat* values );
71  typedef void (AL_APIENTRY *alSourcef_fcn)( ALuint sid, ALenum param, ALfloat value );
72  typedef void (AL_APIENTRY *alSourcefv_fcn)( ALuint sid, ALenum param, const ALfloat* values );
73  typedef void (AL_APIENTRY *alSourcei_fcn)( ALuint sid, ALenum param, ALint value );
74  typedef void (AL_APIENTRY *alSourcePause_fcn)( ALuint sid );
75  typedef void (AL_APIENTRY *alSourcePlay_fcn)( ALuint sid );
76  typedef void (AL_APIENTRY *alSourceStop_fcn)( ALuint sid );
77  typedef void (AL_APIENTRY *alSourceQueueBuffers_fcn)( ALuint sid, ALsizei numEntries, const ALuint *bids );
78  typedef void (AL_APIENTRY *alSourceUnqueueBuffers_fcn)( ALuint sid, ALsizei numEntries, ALuint *bids );
79 
80  // DLL Functions
81  static alBufferData_fcn alBufferData() {return g_alBufferData;}
82  static alcCloseDevice_fcn alcCloseDevice() {return g_alcCloseDevice;}
83  static alcCreateContext_fcn alcCreateContext() {return g_alcCreateContext;}
84  static alcDestroyContext_fcn alcDestroyContext() {return g_alcDestroyContext;}
85  static alIsExtensionPresent_fcn alIsExtensionPresent() {return g_alIsExtensionPresent;}
86  static alcMakeContextCurrent_fcn alcMakeContextCurrent() {return g_alcMakeContextCurrent;}
87  static alcOpenDevice_fcn alcOpenDevice() {return g_alcOpenDevice;}
88  static alDeleteBuffers_fcn alDeleteBuffers() {return g_alDeleteBuffers;}
89  static alDeleteSources_fcn alDeleteSources() {return g_alDeleteSources;}
90  static alGenBuffers_fcn alGenBuffers() {return g_alGenBuffers;}
91  static alGetError_fcn alGetError() {return g_alGetError;}
92  static alGetListenerf_fcn alGetListenerf() {return g_alGetListenerf;}
93  static alGetListenerfv_fcn alGetListenerfv() {return g_alGetListenerfv;}
94  static alGetSourcef_fcn alGetSourcef() {return g_alGetSourcef;}
95  static alGetSourcefv_fcn alGetSourcefv() {return g_alGetSourcefv;}
96  static alGetSourcei_fcn alGetSourcei() {return g_alGetSourcei;}
97  static alGenSources_fcn alGenSources() {return g_alGenSources;}
98  static alListenerf_fcn alListenerf() {return g_alListenerf;}
99  static alListenerfv_fcn alListenerfv() {return g_alListenerfv;}
100  static alSourcef_fcn alSourcef() {return g_alSourcef;}
101  static alSourcefv_fcn alSourcefv() {return g_alSourcefv;}
102  static alSourcei_fcn alSourcei() {return g_alSourcei;}
103  static alSourcePause_fcn alSourcePause() {return g_alSourcePause;}
104  static alSourcePlay_fcn alSourcePlay() {return g_alSourcePlay;}
105  static alSourceStop_fcn alSourceStop() {return g_alSourceStop;}
106  static alSourceQueueBuffers_fcn alSourceQueueBuffers() {return g_alSourceQueueBuffers;}
107  static alSourceUnqueueBuffers_fcn alSourceUnqueueBuffers() {return g_alSourceUnqueueBuffers;}
108 
109  static String errorString(const ALenum &err);
110  static String errorString();
111 
112  // Listener Functions
113  void set_listener_position(const Point3f &position);
114  void set_listener_velocity(const Vector3f &velocity);
115  void set_listener_forward_and_up(const Vector3f &forward, const Vector3f &up);
116  void set_listener_gain(const float &gain);
117 
118  std::pair<Vector3f, Vector3f> get_listener_forward_and_up() const;
119 
120  private:
121  void zero_handles();
122 
123 #ifndef _WINDOWS
124  typedef void * HMODULE;
125 #endif
126 
127  HMODULE m_openal32;
128  static alBufferData_fcn g_alBufferData;
129  static alcCloseDevice_fcn g_alcCloseDevice;
130  static alcCreateContext_fcn g_alcCreateContext;
131  static alcDestroyContext_fcn g_alcDestroyContext;
132  static alIsExtensionPresent_fcn g_alIsExtensionPresent;
133  static alcMakeContextCurrent_fcn g_alcMakeContextCurrent;
134  static alcOpenDevice_fcn g_alcOpenDevice;
135  static alDeleteBuffers_fcn g_alDeleteBuffers;
136  static alDeleteSources_fcn g_alDeleteSources;
137  static alGenBuffers_fcn g_alGenBuffers;
138  static alGetError_fcn g_alGetError;
139  static alGetListenerf_fcn g_alGetListenerf;
140  static alGetListenerfv_fcn g_alGetListenerfv;
141  static alGetSourcef_fcn g_alGetSourcef;
142  static alGetSourcefv_fcn g_alGetSourcefv;
143  static alGetSourcei_fcn g_alGetSourcei;
144  static alGenSources_fcn g_alGenSources;
145  static alListenerf_fcn g_alListenerf;
146  static alListenerfv_fcn g_alListenerfv;
147  static alSourcef_fcn g_alSourcef;
148  static alSourcefv_fcn g_alSourcefv;
149  static alSourcei_fcn g_alSourcei;
150  static alSourcePause_fcn g_alSourcePause;
151  static alSourcePlay_fcn g_alSourcePlay;
152  static alSourceStop_fcn g_alSourceStop;
153  static alSourceQueueBuffers_fcn g_alSourceQueueBuffers;
154  static alSourceUnqueueBuffers_fcn g_alSourceUnqueueBuffers;
155 
156  ALCdevice *m_device;
157  ALCcontext *m_context;
158 
159  String m_bgmusic;
160  Sound_Buffer *m_bgm;
161  Sound_Source *m_bgm_source;
162  };
163 
164 }
165 
166 #endif
167 
168 #endif
static alGetSourcefv_fcn alGetSourcefv()
#define AL_APIENTRY
Definition: al.h:21
void ALvoid
Definition: al.h:74
GLenum GLint param
Definition: gl2ext.h:1491
static alListenerf_fcn alListenerf()
static alcMakeContextCurrent_fcn alcMakeContextCurrent()
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1824
static alcDestroyContext_fcn alcDestroyContext()
char ALchar
Definition: al.h:41
static alGetListenerf_fcn alGetListenerf()
static alSourceStop_fcn alSourceStop()
static alDeleteSources_fcn alDeleteSources()
static alGetSourcei_fcn alGetSourcei()
GLsizei GLenum * sources
Definition: glew.h:3769
GLclampd n
Definition: glew.h:7287
int ALsizei
Definition: al.h:62
FT_UInt sid
Definition: cffcmap.c:128
ALCdevice *(ALC_APIENTRY * alcOpenDevice_fcn)(const ALCchar *devicename)
int ALint
Definition: al.h:56
static alSourcei_fcn alSourcei()
static alGetListenerfv_fcn alGetListenerfv()
#define ALC_APIENTRY
Definition: alc.h:21
static alGetSourcef_fcn alGetSourcef()
static alcCreateContext_fcn alcCreateContext()
float ALfloat
Definition: al.h:68
char ALCchar
Definition: alc.h:42
static alSourcef_fcn alSourcef()
A 3D Point represented with floats.
Definition: Coordinate.h:133
const GLuint * buffers
Definition: glew.h:1669
Plays Sound Data.
Definition: Sound_Source.h:147
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
static alSourceQueueBuffers_fcn alSourceQueueBuffers()
static alcOpenDevice_fcn alcOpenDevice()
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
static alBufferData_fcn alBufferData()
int ALenum
Definition: al.h:65
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl2ext.h:845
unsigned int ALuint
Definition: al.h:59
ALCcontext *(ALC_APIENTRY * alcCreateContext_fcn)(ALCdevice *device, const ALCint *attrlist)
Stores Sound Data.
Definition: Sound_Buffer.h:83
static alIsExtensionPresent_fcn alIsExtensionPresent()
static alDeleteBuffers_fcn alDeleteBuffers()
static alSourcefv_fcn alSourcefv()
static alGetError_fcn alGetError()
static alSourcePlay_fcn alSourcePlay()
EGLSurface EGLint void ** value
Definition: eglext.h:301
char ALCboolean
Definition: alc.h:39
The Sound Singleton.
Definition: Sound.h:53
int ALCint
Definition: alc.h:57
char ALboolean
Definition: al.h:38
static alSourceUnqueueBuffers_fcn alSourceUnqueueBuffers()
static alSourcePause_fcn alSourcePause()
static alListenerfv_fcn alListenerfv()
static alcCloseDevice_fcn alcCloseDevice()
TParseContext * context
static alGenSources_fcn alGenSources()
GLint GLsizei const GLuint64 * values
Definition: glew.h:3473
static alGenBuffers_fcn alGenBuffers()
GLsizei size
Definition: gl2ext.h:1467