zenilib  0.5.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups
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 
78  // DLL Functions
79  static alBufferData_fcn alBufferData() {return g_alBufferData;}
80  static alcCloseDevice_fcn alcCloseDevice() {return g_alcCloseDevice;}
81  static alcCreateContext_fcn alcCreateContext() {return g_alcCreateContext;}
82  static alcDestroyContext_fcn alcDestroyContext() {return g_alcDestroyContext;}
83  static alIsExtensionPresent_fcn alIsExtensionPresent() {return g_alIsExtensionPresent;}
84  static alcMakeContextCurrent_fcn alcMakeContextCurrent() {return g_alcMakeContextCurrent;}
85  static alcOpenDevice_fcn alcOpenDevice() {return g_alcOpenDevice;}
86  static alDeleteBuffers_fcn alDeleteBuffers() {return g_alDeleteBuffers;}
87  static alDeleteSources_fcn alDeleteSources() {return g_alDeleteSources;}
88  static alGenBuffers_fcn alGenBuffers() {return g_alGenBuffers;}
89  static alGetError_fcn alGetError() {return g_alGetError;}
90  static alGetListenerf_fcn alGetListenerf() {return g_alGetListenerf;}
91  static alGetListenerfv_fcn alGetListenerfv() {return g_alGetListenerfv;}
92  static alGetSourcef_fcn alGetSourcef() {return g_alGetSourcef;}
93  static alGetSourcefv_fcn alGetSourcefv() {return g_alGetSourcefv;}
94  static alGetSourcei_fcn alGetSourcei() {return g_alGetSourcei;}
95  static alGenSources_fcn alGenSources() {return g_alGenSources;}
96  static alListenerf_fcn alListenerf() {return g_alListenerf;}
97  static alListenerfv_fcn alListenerfv() {return g_alListenerfv;}
98  static alSourcef_fcn alSourcef() {return g_alSourcef;}
99  static alSourcefv_fcn alSourcefv() {return g_alSourcefv;}
100  static alSourcei_fcn alSourcei() {return g_alSourcei;}
101  static alSourcePause_fcn alSourcePause() {return g_alSourcePause;}
102  static alSourcePlay_fcn alSourcePlay() {return g_alSourcePlay;}
103  static alSourceStop_fcn alSourceStop() {return g_alSourceStop;}
104 
105  static String errorString(const ALenum &err);
106  static String errorString();
107 
108  // Listener Functions
109  void set_listener_position(const Point3f &position);
110  void set_listener_velocity(const Vector3f &velocity);
111  void set_listener_forward_and_up(const Vector3f &forward, const Vector3f &up);
112  void set_listener_gain(const float &gain);
113 
114  std::pair<Vector3f, Vector3f> get_listener_forward_and_up() const;
115 
116  private:
117  void zero_handles();
118 
119 #ifndef _WINDOWS
120  typedef void * HMODULE;
121 #endif
122 
123  HMODULE m_openal32;
124  static alBufferData_fcn g_alBufferData;
125  static alcCloseDevice_fcn g_alcCloseDevice;
126  static alcCreateContext_fcn g_alcCreateContext;
127  static alcDestroyContext_fcn g_alcDestroyContext;
128  static alIsExtensionPresent_fcn g_alIsExtensionPresent;
129  static alcMakeContextCurrent_fcn g_alcMakeContextCurrent;
130  static alcOpenDevice_fcn g_alcOpenDevice;
131  static alDeleteBuffers_fcn g_alDeleteBuffers;
132  static alDeleteSources_fcn g_alDeleteSources;
133  static alGenBuffers_fcn g_alGenBuffers;
134  static alGetError_fcn g_alGetError;
135  static alGetListenerf_fcn g_alGetListenerf;
136  static alGetListenerfv_fcn g_alGetListenerfv;
137  static alGetSourcef_fcn g_alGetSourcef;
138  static alGetSourcefv_fcn g_alGetSourcefv;
139  static alGetSourcei_fcn g_alGetSourcei;
140  static alGenSources_fcn g_alGenSources;
141  static alListenerf_fcn g_alListenerf;
142  static alListenerfv_fcn g_alListenerfv;
143  static alSourcef_fcn g_alSourcef;
144  static alSourcefv_fcn g_alSourcefv;
145  static alSourcei_fcn g_alSourcei;
146  static alSourcePause_fcn g_alSourcePause;
147  static alSourcePlay_fcn g_alSourcePlay;
148  static alSourceStop_fcn g_alSourceStop;
149 
150  ALCdevice *m_device;
151  ALCcontext *m_context;
152 
153  String m_bgmusic;
154  Sound_Buffer *m_bgm;
155  Sound_Source *m_bgm_source;
156  };
157 
158 }
159 
160 #endif
161 
162 #endif