2
2
#define _AUDIO_H
3
3
#ifndef QOR_NO_AUDIO
4
4
5
- #ifdef _WIN32
6
- #include < al.h>
7
- #include < alut.h>
8
- #else
9
- #include < AL/al.h>
10
- #include < AL/alut.h>
11
- #endif
12
- #include < ogg/ogg.h>
13
- #include < vorbis/codec.h>
14
- #include < vorbis/vorbisenc.h>
15
- #include < vorbis/vorbisfile.h>
5
+ // #ifdef _WIN32
6
+ // #include <al.h>
7
+ // #include <alut.h>
8
+ // #else
9
+ // #include <AL/al.h>
10
+ // #include <AL/alut.h>
11
+ // #endif
12
+ // #include <ogg/ogg.h>
13
+ // #include <vorbis/codec.h>
14
+ // #include <vorbis/vorbisenc.h>
15
+ // #include <vorbis/vorbisfile.h>
16
+ #include < coal/coal.h>
16
17
#include < memory>
17
18
#include " kit/log/log.h"
18
19
#include " Filesystem.h"
@@ -40,24 +41,25 @@ class Audio
40
41
public Resource
41
42
{
42
43
unsigned id = 0 ;
43
-
44
+ std::shared_ptr<coal::Buffer> buf;
44
45
Buffer ();
45
46
Buffer (const std::string& fn, ICache* c);
46
47
Buffer (const std::tuple<std::string, ICache*>& args);
47
48
virtual ~Buffer ();
48
- bool good () const { return id!=0 ; }
49
+ // bool good() const { return id!=0; }
49
50
float length () const ;
50
51
};
51
52
52
53
struct Source
53
54
{
54
- mutable unsigned id;
55
- float pitch = 1 .0f ;
55
+ // mutable unsigned id;
56
+ std::shared_ptr<coal::Source> source;
57
+ // float pitch = 1.0f;
56
58
float gain = 1 .0f ;
57
- float rolloff = 0 .0f ;
59
+ // float rolloff = 0.0f;
58
60
glm::vec3 pos;
59
- glm::vec3 vel;
60
- unsigned int buffer_id = 0 ;
61
+ // glm::vec3 vel;
62
+ // unsigned int buffer_id = 0;
61
63
enum eFlags {
62
64
F_LOOP = kit::bit (0 ),
63
65
F_AUTOPLAY = kit::bit (1 ),
@@ -68,19 +70,19 @@ class Audio
68
70
virtual ~Source ();
69
71
virtual bool update ();
70
72
void bind (Buffer* buf);
71
- virtual void refresh ();
73
+ // virtual void refresh();
72
74
virtual void play ();
73
75
bool playing () const ;
74
76
bool stopped () const ;
75
77
void pause ();
76
78
void stop ();
77
- virtual bool good () const { return id!=0 ; }
79
+ // virtual bool good() const { return id!=0; }
78
80
};
79
81
80
82
struct Stream :
81
83
public Source,
82
84
public Resource
83
- {
85
+ {
84
86
public:
85
87
86
88
Stream ();
@@ -91,82 +93,83 @@ class Audio
91
93
92
94
virtual ~Stream ();
93
95
virtual bool update () override ;
94
- void clear ();
95
- virtual void refresh () override ;
96
+ // void clear();
97
+ // virtual void refresh() override;
96
98
virtual void play () override ;
97
- virtual bool good () const override { return m_bOpen; }
99
+ // virtual bool good() const override { return m_bOpen; }
98
100
99
101
protected:
100
- void init (std::string fn = " " ) ;
101
- virtual void deinit ();
102
+ // void init(std::string fn = "";
103
+ // virtual void deinit();
102
104
103
- ALenum m_Format;
104
- ALuint m_Buffers[NUM_BUFFERS];
105
- bool m_bOpen = false ;
106
- std::string m_Filename;
105
+ std::shared_ptr<coal::Stream> m_pStream;
106
+ // ALenum m_Format;
107
+ // ALuint m_Buffers[NUM_BUFFERS];
108
+ // bool m_bOpen = false;
109
+ // std::string m_Filename;
107
110
108
- virtual bool stream (unsigned int buffer);
111
+ // virtual bool stream(unsigned int buffer);
109
112
};
110
113
111
- struct OggStream :
112
- public Stream
113
- {
114
- public:
114
+ // struct OggStream:
115
+ // public Stream
116
+ // {
117
+ // public:
115
118
116
- OggStream (std::string fn);
117
- OggStream (const std::tuple<std::string, ICache*>& args):
118
- OggStream (std::get<0 >(args))
119
- {}
119
+ // OggStream(std::string fn);
120
+ // OggStream(const std::tuple<std::string, ICache*>& args):
121
+ // OggStream(std::get<0>(args))
122
+ // {}
120
123
121
- virtual ~OggStream ();
124
+ // virtual ~OggStream();
122
125
123
- private:
126
+ // private:
124
127
125
- virtual void deinit () override ;
126
- virtual bool stream (unsigned int buffer) override ;
128
+ // virtual void deinit() override;
129
+ // virtual bool stream(unsigned int buffer) override;
127
130
128
- // FILE* m_File;
129
- OggVorbis_File m_Ogg;
130
- vorbis_info* m_VorbisInfo;
131
- vorbis_comment* m_VorbisComment;
132
- };
131
+ // //FILE* m_File;
132
+ // OggVorbis_File m_Ogg;
133
+ // vorbis_info* m_VorbisInfo;
134
+ // vorbis_comment* m_VorbisComment;
135
+ // };
133
136
134
- struct RawStream :
135
- public Stream
136
- {
137
- public:
138
-
139
- RawStream () {}
140
- RawStream (std::string fn):
141
- Stream (fn)
142
- {}
143
- RawStream (const std::tuple<std::string, ICache*>& args):
144
- RawStream (std::get<0 >(args))
145
- {}
137
+ // struct RawStream:
138
+ // public Stream
139
+ // {
140
+ // public:
141
+
142
+ // RawStream() {}
143
+ // RawStream(std::string fn):
144
+ // Stream(fn)
145
+ // {}
146
+ // RawStream(const std::tuple<std::string, ICache*>& args):
147
+ // RawStream(std::get<0>(args))
148
+ // {}
146
149
147
- virtual ~RawStream () {}
150
+ // virtual ~RawStream() {}
148
151
149
- void on_read (std::function<int (char *,int )> func) {
150
- m_onRead = func;
151
- }
152
+ // void on_read(std::function<int(char*,int)> func) {
153
+ // m_onRead = func;
154
+ // }
152
155
153
- private:
156
+ // private:
154
157
155
- virtual void deinit () override {}
156
- virtual bool stream (unsigned int buffer) override ;
158
+ // virtual void deinit() override {}
159
+ // virtual bool stream(unsigned int buffer) override;
157
160
158
- long m_Rate = 44100L ;
161
+ // long m_Rate = 44100L;
159
162
160
- std::function<int (char *,int )> m_onRead;
161
- };
162
-
163
+ // std::function<int(char*,int)> m_onRead;
164
+ // };
163
165
164
166
struct Listener
165
167
{
166
168
glm::vec3 pos, vel;
167
169
glm::vec3 at;
168
170
glm::vec3 up;
169
171
float gain;
172
+ std::shared_ptr<coal::Listener> listener;
170
173
171
174
Listener ();
172
175
virtual ~Listener ();
@@ -175,13 +178,14 @@ class Audio
175
178
176
179
Audio ();
177
180
virtual ~Audio ();
181
+ void update ();
178
182
void set_context ();
179
183
void listen (Listener* listener) const ;
180
184
bool error () const ;
181
- static void clear_errors ();
182
- static bool check_errors ();
183
- static std::tuple<std::string, std::string> error_string_al (int code);
184
- static std::tuple<std::string,std::string> error_string_ov (int code);
185
+ // static void clear_errors();
186
+ // static bool check_errors();
187
+ // static std::tuple<std::string, std::string> error_string_al(int code);
188
+ // static std::tuple<std::string,std::string> error_string_ov(int code);
185
189
186
190
static float rolloff () { return s_Rolloff; }
187
191
static float max_distance () { return s_MaxDist; }
@@ -204,12 +208,15 @@ class Audio
204
208
// K_S_GET_SET(float, reference_distance, m_ReferenceDist);
205
209
206
210
private:
207
- ALCdevice* m_pDevice = nullptr ;
208
- ALCcontext* m_pContext = nullptr ;
211
+ // ALCdevice* m_pDevice = nullptr;
212
+ // ALCcontext* m_pContext = nullptr;
209
213
210
214
static float s_Rolloff;
211
215
static float s_MaxDist;
212
216
static float s_ReferenceDist;
217
+
218
+ static std::unique_ptr<Coal> s_pCoal;
219
+ static std::unique_ptr<coal::Space> s_pSpace;
213
220
};
214
221
215
222
#endif
0 commit comments