Skip to content

Commit 97b26a5

Browse files
committed
new audio sys integration (almost)
1 parent 9e80408 commit 97b26a5

File tree

9 files changed

+509
-490
lines changed

9 files changed

+509
-490
lines changed

Qor/Audio.cpp

Lines changed: 397 additions & 376 deletions
Large diffs are not rendered by default.

Qor/Audio.h

Lines changed: 84 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
#define _AUDIO_H
33
#ifndef QOR_NO_AUDIO
44

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>
1617
#include <memory>
1718
#include "kit/log/log.h"
1819
#include "Filesystem.h"
@@ -40,24 +41,25 @@ class Audio
4041
public Resource
4142
{
4243
unsigned id = 0;
43-
44+
std::shared_ptr<coal::Buffer> buf;
4445
Buffer();
4546
Buffer(const std::string& fn, ICache* c);
4647
Buffer(const std::tuple<std::string, ICache*>& args);
4748
virtual ~Buffer();
48-
bool good() const { return id!=0; }
49+
//bool good() const { return id!=0; }
4950
float length() const;
5051
};
5152

5253
struct Source
5354
{
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;
5658
float gain = 1.0f;
57-
float rolloff = 0.0f;
59+
//float rolloff = 0.0f;
5860
glm::vec3 pos;
59-
glm::vec3 vel;
60-
unsigned int buffer_id = 0;
61+
//glm::vec3 vel;
62+
//unsigned int buffer_id = 0;
6163
enum eFlags {
6264
F_LOOP = kit::bit(0),
6365
F_AUTOPLAY = kit::bit(1),
@@ -68,19 +70,19 @@ class Audio
6870
virtual ~Source();
6971
virtual bool update();
7072
void bind(Buffer* buf);
71-
virtual void refresh();
73+
//virtual void refresh();
7274
virtual void play();
7375
bool playing() const;
7476
bool stopped() const;
7577
void pause();
7678
void stop();
77-
virtual bool good() const { return id!=0; }
79+
//virtual bool good() const { return id!=0; }
7880
};
7981

8082
struct Stream:
8183
public Source,
8284
public Resource
83-
{
85+
{
8486
public:
8587

8688
Stream();
@@ -91,82 +93,83 @@ class Audio
9193

9294
virtual ~Stream();
9395
virtual bool update() override;
94-
void clear();
95-
virtual void refresh() override;
96+
//void clear();
97+
//virtual void refresh() override;
9698
virtual void play() override;
97-
virtual bool good() const override { return m_bOpen; }
99+
//virtual bool good() const override { return m_bOpen; }
98100

99101
protected:
100-
void init(std::string fn = "");
101-
virtual void deinit();
102+
//void init(std::string fn = "";
103+
//virtual void deinit();
102104

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;
107110

108-
virtual bool stream(unsigned int buffer);
111+
//virtual bool stream(unsigned int buffer);
109112
};
110113

111-
struct OggStream:
112-
public Stream
113-
{
114-
public:
114+
//struct OggStream:
115+
// public Stream
116+
//{
117+
// public:
115118

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+
// {}
120123

121-
virtual ~OggStream();
124+
// virtual ~OggStream();
122125

123-
private:
126+
// private:
124127

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;
127130

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+
//};
133136

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+
// {}
146149

147-
virtual ~RawStream() {}
150+
// virtual ~RawStream() {}
148151

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+
// }
152155

153-
private:
156+
// private:
154157

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;
157160

158-
long m_Rate = 44100L;
161+
// long m_Rate = 44100L;
159162

160-
std::function<int(char*,int)> m_onRead;
161-
};
162-
163+
// std::function<int(char*,int)> m_onRead;
164+
//};
163165

164166
struct Listener
165167
{
166168
glm::vec3 pos, vel;
167169
glm::vec3 at;
168170
glm::vec3 up;
169171
float gain;
172+
std::shared_ptr<coal::Listener> listener;
170173

171174
Listener();
172175
virtual ~Listener();
@@ -175,13 +178,14 @@ class Audio
175178

176179
Audio();
177180
virtual ~Audio();
181+
void update();
178182
void set_context();
179183
void listen(Listener* listener) const;
180184
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);
185189

186190
static float rolloff() { return s_Rolloff; }
187191
static float max_distance() { return s_MaxDist; }
@@ -204,12 +208,15 @@ class Audio
204208
//K_S_GET_SET(float, reference_distance, m_ReferenceDist);
205209

206210
private:
207-
ALCdevice* m_pDevice = nullptr;
208-
ALCcontext* m_pContext = nullptr;
211+
//ALCdevice* m_pDevice = nullptr;
212+
//ALCcontext* m_pContext = nullptr;
209213

210214
static float s_Rolloff;
211215
static float s_MaxDist;
212216
static float s_ReferenceDist;
217+
218+
static std::unique_ptr<Coal> s_pCoal;
219+
static std::unique_ptr<coal::Space> s_pSpace;
213220
};
214221

215222
#endif

Qor/Camera.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,7 @@ void Camera :: logic_self(Freq::Time t)
8181

8282
if(m_bListens)
8383
{
84-
//auto pos = position();
85-
//auto wpos = position(Space::WORLD);
86-
//LOGf("camera mtx: %s", Matrix::to_string(*matrix_c(Space::WORLD)));
87-
//LOGf("camera local: (%s, %s, %s)", pos.x % pos.y % pos.z);
88-
//LOGf("camera world: (%s, %s, %s)", wpos.x % wpos.y % wpos.z);
89-
//auto fo = focal_offset();
90-
//LOGf("focal offset: (%s, %s, %s)", fo.x % fo.y % fo.z);
91-
//auto opos = wpos - fo * Matrix::scale(*matrix_c(Space::WORLD));
9284
m_Listener.pos = position(Space::WORLD);
93-
//LOGf("camera pos w/ offset: (%s, %s, %s)", opos.x % opos.y % opos.z);
9485
m_Listener.at = Matrix::heading(*matrix_c(Space::WORLD));
9586
m_Listener.up = Matrix::up(*matrix_c(Space::WORLD));
9687
m_Listener.listen();

Qor/LoadingState.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ void LoadingState :: logic(Freq::Time t)
171171

172172
#ifndef QOR_NO_AUDIO
173173
if(m_pMusic && m_pMusic->source()) {
174-
m_pMusic->source()->gain = m_Fade.get().r();
175-
m_pMusic->source()->refresh();
174+
//m_pMusic->source()->gain = m_Fade.get().r();
175+
//m_pMusic->source()->refresh();
176176
}
177177
#endif
178178

Qor/Qor.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ namespace fs = boost::filesystem;
3434
Qor* Qor :: s_pQor = nullptr;
3535

3636
Qor :: Qor(const Args& args, std::string appname="qor"):
37-
m_Args(args),
38-
m_App(appname)
37+
m_Args(args)
3938
{
4039
m_Filename = args.filename();
4140
s_pQor = this;
4241

42+
4343
if(m_Args.has('d', "dedicated")||
4444
m_Args.has('s', "server"))
4545
{
@@ -69,7 +69,6 @@ Qor :: Qor(const Args& args, std::string appname="qor"):
6969
#ifndef QOR_NO_AUDIO
7070
m_Resources.register_class<Audio::Buffer>("audiobuffer");
7171
m_Resources.register_class<Audio::Stream>("audiostream");
72-
m_Resources.register_class<Audio::OggStream>("oggstream");
7372
#endif
7473
m_Resources.register_class<Mesh::Data>("meshdata");
7574
//m_Resources.register_class<Particle::Data>("particledata");
@@ -381,7 +380,7 @@ unsigned Qor :: resolve_resource(
381380
return class_id;
382381
}
383382
if(ends_with(fn_cut, ".ogg")) {
384-
static unsigned class_id = m_Resources.class_id("oggstream");
383+
static unsigned class_id = m_Resources.class_id("audiostream");
385384
return class_id;
386385
}
387386
#endif

Qor/Sound.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
#include "Headless.h"
55
using namespace std;
66

7-
shared_ptr<Sound> Sound :: raw(std::function<int(char*,int)> func, Cache<Resource, std::string>* cache)
8-
{
9-
auto snd = make_shared<Sound>(cache);
10-
if(not Headless::enabled()){
11-
snd->m_pSource = make_shared<Audio::RawStream>();
12-
((Audio::RawStream*)(snd->m_pSource.get()))->on_read(func);
13-
snd->m_pSource->flags |= Audio::Source::F_AMBIENT;
14-
snd->m_pSource->refresh();
15-
snd->update_signals();
16-
}
17-
return snd;
18-
}
7+
//shared_ptr<Sound> Sound :: raw(std::function<int(char*,int)> func, Cache<Resource, std::string>* cache)
8+
//{
9+
// auto snd = make_shared<Sound>(cache);
10+
// if(not Headless::enabled()){
11+
// snd->m_pSource = make_shared<Audio::RawStream>();
12+
// ((Audio::RawStream*)(snd->m_pSource.get()))->on_read(func);
13+
// snd->m_pSource->flags |= Audio::Source::F_AMBIENT;
14+
// snd->m_pSource->refresh();
15+
// snd->update_signals();
16+
// }
17+
// return snd;
18+
//}
1919

2020
Sound :: Sound(Cache<Resource, std::string>* cache):
2121
m_pResources(cache)
@@ -56,7 +56,7 @@ Sound :: Sound(const std::string& fn, Cache<Resource, std::string>* cache):
5656

5757
if(m_bStream){
5858
//m_pSource = cache->cache_cast<Audio::Stream>(fn);
59-
m_pSource = make_shared<Audio::OggStream>(cache->transform(fn));
59+
m_pSource = make_shared<Audio::Stream>(cache->transform(fn));
6060
//m_pSource->refresh();
6161
}else{
6262
m_pBuffer = cache->cache_cast<Audio::Buffer>(fn);
@@ -70,8 +70,8 @@ Sound :: Sound(const std::string& fn, Cache<Resource, std::string>* cache):
7070
m_pSource->flags |= Audio::Source::F_LOOP;
7171
//if(m_bAutoplay)
7272
// source()->play();
73-
if(m_pSource)
74-
m_pSource->refresh();
73+
//if(m_pSource)
74+
// m_pSource->refresh();
7575

7676
update_signals();
7777
}
@@ -108,7 +108,7 @@ void Sound :: logic_self(Freq::Time t)
108108
{
109109
if(not m_bAmbient)
110110
m_pSource->pos = position(Space::WORLD);
111-
m_pSource->refresh();
111+
//m_pSource->refresh();
112112
m_pSource->update();
113113
}
114114

@@ -189,7 +189,7 @@ void Sound :: gain(float g)
189189
m_Gain = g;
190190
if(m_pSource){
191191
m_pSource->gain = g;
192-
m_pSource->refresh();
192+
//m_pSource->refresh();
193193
}
194194
}
195195

0 commit comments

Comments
 (0)