zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Sound_Buffer.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 
36 #ifndef ZENI_SOUND_BUFFER_H
37 #define ZENI_SOUND_BUFFER_H
38 
39 #include <Zeni/Coordinate.h>
40 #include <Zeni/Database.h>
41 #include <Zeni/Vector3f.h>
42 
43 #if defined(ENABLE_SLES)
44 #include <SLES/OpenSLES.h>
45 #if defined(ANDROID)
46 #include <SLES/OpenSLES_Android.h>
47 #endif
48 #endif
49 
50 #if !defined(DISABLE_AL)
51 #if defined(_MACOSX)
52 #include <OpenAL/al.h>
53 #else
54 #include <AL/al.h>
55 #endif
56 
57 #else
58 
59 #if defined(ENABLE_SLES)
60 #define ALint sl_int32_t
61 #define ALuint sl_uint32_t
62 #define ALfloat sl_float_t
63 #define ALenum sl_int32_t
64 #define AL_NONE 0
65 #define AL_TRUE SL_BOOLEAN_TRUE
66 #define AL_FALSE SL_BOOLEAN_FALSE
67 #else
68 #define ALint int
69 #define ALuint unsigned int
70 #define ALfloat float
71 #define ALenum int
72 #define AL_NONE 0
73 #define AL_TRUE true
74 #define AL_FALSE false
75 #endif
76 
77 #endif
78 
79 namespace Zeni {
80 
81  class ZENI_AUDIO_DLL Sound_Source;
82 
83  class ZENI_AUDIO_DLL Sound_Buffer {
84  friend class Sound;
85  friend class Database<Sound_Buffer>;
86  friend class Sounds;
87 
88  Sound_Buffer(const Sound_Buffer &rhs);
89  Sound_Buffer & operator=(const Sound_Buffer &rhs);
90 
91  Sound_Buffer();
92  Sound_Buffer(const String &filename);
93  ~Sound_Buffer();
94 
95  public:
96 #ifndef DISABLE_AL
97  const ALuint & get_id() const {return m_buffer;}
98 #endif
99 #ifdef ENABLE_SLES
100  const SLDataSource & get_audioSrc() const {return audioSrc;}
101 #endif
102  const float & get_duration() const {return m_duration;}
103 
105  static std::pair<ALuint, float> load_ogg_vorbis(const String &filename);
106 
107  private:
108 #ifndef DISABLE_AL
109  mutable ALuint m_buffer;
110 #endif
111 #ifdef ENABLE_SLES
112  void init_SLES(const String &filename);
113 
114  SLDataLocator_AndroidFD loc_fd;
115  SLDataFormat_MIME format_mime;
116  SLDataSource audioSrc;
117 #endif
118 
119  mutable float m_duration;
120 
121  // class ZENI_AUDIO_DLL Loader : public Task {
122  // Loader(const Loader &);
123  // Loader & operator=(const Loader &);
124  //
125  // public:
126  // Loader(const String &filename);
127  //
128  // virtual int function();
129  //
130  // ALuint m_buffer;
131  // float m_duration;
132  // const String m_filename;
133  // };
134  //
135  // void finish_loading() const;
136  //
137  // mutable Loader *m_loader;
138  // mutable Thread *m_thread;
139  };
140 
141  struct ZENI_AUDIO_DLL Sound_Buffer_Init_Failure : public Error {
142  Sound_Buffer_Init_Failure() : Error("Zeni Sound Buffer Failed to Initialize Correctly") {}
143  };
144 
145 }
146 
147 #endif
const float & get_duration() const
Get the duration of the Sound_Buffer in seconds.
Definition: Sound_Buffer.h:102
A Sound_Buffer Database Singleton.
Definition: Sounds.h:48
A Texture Database Singleton.
Definition: Database.h:46
const ALuint & get_id() const
Get the OpenAL id of the Sound_Buffer.
Definition: Sound_Buffer.h:97
unsigned int ALuint
Definition: al.h:59
Stores Sound Data.
Definition: Sound_Buffer.h:83
The Sound Singleton.
Definition: Sound.h:53
The Error Class.
Definition: Error.h:52