Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
Expand All @@ -43,7 +43,7 @@ SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 0
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
Expand Down
54 changes: 27 additions & 27 deletions include/xlite/oal/Buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@
#include <cstddef>
#include <cstdint>

namespace Lite {
namespace lite {

namespace Sound {
namespace sound {

enum BufferFormat : int {
/** Signed 16-bit mono buffer format. */
MONO_SIGNED_16_BIT = 0x1101,
/** Unsigned 8-bit mono buffer format. */
MONO_UNSIGNED_8_BIT = 0x1100,
/** Signed 16-bit stereo buffer format. */
STEREO_SIGNED_16_BIT = 0x1103,
/** Unsigned 8-bit stereo buffer format. */
STEREO_UNSIGNED_8_BIT = 0x1102,
};
enum BufferFormat : int {
/** Signed 16-bit mono buffer format. */
MONO_SIGNED_16_BIT = 0x1101,
/** Unsigned 8-bit mono buffer format. */
MONO_UNSIGNED_8_BIT = 0x1100,
/** Signed 16-bit stereo buffer format. */
STEREO_SIGNED_16_BIT = 0x1103,
/** Unsigned 8-bit stereo buffer format. */
STEREO_UNSIGNED_8_BIT = 0x1102,
};

class LITE_API Buffer {
public:
Buffer(BufferFormat format, int sampleRate);
~Buffer();
class LITE_API Buffer {
public:
Buffer(BufferFormat format, int sampleRate);
~Buffer();

void Data(const void *data, size_t size) const;
void Data(const void *data, std::size_t size) const;

inline uint32_t GetBuffer() const {
return buffer;
}
inline uint32_t GetBuffer() const {
return buffer;
}

private:
uint32_t buffer = 0;
private:
uint32_t buffer = 0;

BufferFormat format;
int sampleRate;
};
BufferFormat format;
int sampleRate;
};

}// namespace Sound
} // namespace sound

}// namespace Lite
} // namespace lite
30 changes: 15 additions & 15 deletions include/xlite/oal/Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

#include <xlite/Config.hpp>

#define LITE_MAX_MONO_SOURCES 64
#define LITE_MAX_STEREO_SOURCES 64
constexpr std::size_t LITE_MAX_MONO_SOURCES = 64;
constexpr std::size_t LITE_MAX_STEREO_SOURCES = 64;

namespace Lite {
namespace lite {

namespace Sound {
namespace sound {

class LITE_API Device {
public:
explicit Device(const char *deviceName);
class LITE_API Device {
public:
explicit Device(const char *deviceName);

Device() : Device("OpenAL Soft") {}
Device() : Device("OpenAL Soft") {}

~Device();
~Device();

private:
void *device;
void *context;
};
private:
void *device;
void *context;
};

}// namespace Sound
} // namespace sound

}// namespace Lite
} // namespace lite
42 changes: 21 additions & 21 deletions include/xlite/oal/Source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@

#include <cstdint>

namespace Lite {
namespace lite {

namespace Sound {
namespace sound {

class LITE_API Source {
public:
Source();
~Source();
class LITE_API Source {
public:
Source();
~Source();

void Play() const;
void Stop() const;
void Loop(bool loop) const;
void Gain(float gain) const;
bool IsPlaying() const;
void Attach(const Buffer &buffer) const;
void Detach() const;
bool Available() const;
void Play() const;
void Stop() const;
void Loop(bool loop) const;
void Gain(float gain) const;
bool IsPlaying() const;
void Attach(const Buffer &buffer) const;
void Detach() const;
bool Available() const;

private:
uint32_t source = 0;
private:
uint32_t source = 0;

Source(Source &) = delete;
Source(Source const &) = delete;
};
Source(Source &) = delete;
Source(Source const &) = delete;
};

}// namespace Sound
} // namespace sound

}// namespace Lite
} // namespace lite
24 changes: 12 additions & 12 deletions include/xlite/sound/Audio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
#include <xlite/Config.hpp>
#include <xlite/oal/Source.hpp>

namespace Lite {
namespace lite {

namespace Sound {
namespace sound {

class LITE_API Audio {
public:
Audio(BufferFormat channelFormat, int sampleRate, const void *data, size_t size);
~Audio() = default;
class LITE_API Audio {
public:
Audio(BufferFormat channelFormat, int sampleRate, const void *data, std::size_t size);
~Audio() = default;

void Play(const Source &source) const;
void Play(const Source &source) const;

private:
Buffer buffer;
};
private:
Buffer buffer;
};

}// namespace Sound
} // namespace sound

}// namespace Lite
} // namespace lite
26 changes: 13 additions & 13 deletions include/xlite/sound/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
#include <memory>
#include <string>

namespace Lite {
namespace lite {

namespace Sound {
namespace sound {

class LITE_API Engine {
public:
Engine() = default;
~Engine() = default;
class LITE_API Engine {
public:
Engine() = default;
~Engine() = default;

bool Play(const Audio &audio);
bool Play(const Audio &audio);

private:
Device device;
Pool pool;
};
private:
Device device;
Pool pool;
};

}// namespace Sound
} // namespace sound

}// namespace Lite
} // namespace lite
36 changes: 18 additions & 18 deletions include/xlite/sound/Pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@

#pragma warning(push)
#pragma warning(disable : 4251)// Template warnings on vector/queue private members
namespace Lite {
namespace lite {

namespace Sound {
namespace sound {

class LITE_API Pool {
public:
Pool();
~Pool() = default;
class LITE_API Pool {
public:
Pool();
~Pool() = default;

std::shared_ptr<Source> Fetch();
std::shared_ptr<Source> Fetch();

inline size_t Size() const {
return sources.size();
}
std::size_t Size() const {
return sources.size();
}

private:
std::vector<std::shared_ptr<Source>> sources;
std::vector<std::shared_ptr<Source>> acquired;
std::queue<std::shared_ptr<Source>> available;
private:
std::vector<std::shared_ptr<Source>> sources;
std::vector<std::shared_ptr<Source>> acquired;
std::queue<std::shared_ptr<Source>> available;

void Update();
};
void Update();
};

}// namespace Sound
} // namespace sound

}// namespace Lite
} // namespace lite
#pragma warning(pop)
10 changes: 8 additions & 2 deletions src/oal/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include <AL/al.h>

using namespace Lite::Sound;
namespace lite {

namespace sound {

Buffer::Buffer(BufferFormat format, int sampleRate)
: format(format), sampleRate(sampleRate) {
Expand All @@ -13,6 +15,10 @@ Buffer::~Buffer() {
alDeleteBuffers(1, &buffer);
}

void Buffer::Data(const void *data, size_t size) const {
void Buffer::Data(const void *data, std::size_t size) const {
alBufferData(buffer, format, data, static_cast<ALint>(size), sampleRate);
}

} // namespace sound

} // namespace lite
8 changes: 7 additions & 1 deletion src/oal/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include <AL/alc.h>

using namespace Lite::Sound;
namespace lite {

namespace sound {

Device::Device(const char *deviceName) {
device = alcOpenDevice(deviceName);
Expand All @@ -20,3 +22,7 @@ Device::~Device() {
alcDestroyContext(static_cast<ALCcontext *>(context));
alcCloseDevice(static_cast<ALCdevice *>(device));
}

} // namespace sound

} // namespace lite
8 changes: 7 additions & 1 deletion src/oal/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include <AL/al.h>

using namespace Lite::Sound;
namespace lite {

namespace sound {

Source::Source() {
alGenSources(1, &source);
Expand Down Expand Up @@ -56,3 +58,7 @@ bool Source::Available() const {

return AL_STOPPED == state;
}

} // namespace sound

} // namespace lite
10 changes: 8 additions & 2 deletions src/sound/Audio.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <xlite/sound/Audio.hpp>

using namespace Lite::Sound;
namespace lite {

Audio::Audio(BufferFormat channelFormat, int sampleRate, const void *data, size_t size)
namespace sound {

Audio::Audio(BufferFormat channelFormat, int sampleRate, const void *data, std::size_t size)
: buffer(channelFormat, sampleRate) {
buffer.Data(data, size);
}
Expand All @@ -11,3 +13,7 @@ void Audio::Play(const Source &source) const {
source.Attach(buffer);
source.Play();
}

} // namespace sound

} // namespace lite
8 changes: 7 additions & 1 deletion src/sound/Engine.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#include <xlite/sound/Engine.hpp>

using namespace Lite::Sound;
namespace lite {

namespace sound {

bool Engine::Play(const Audio &audio) {
auto source = pool.Fetch();
audio.Play(*source);

return true;
}

} // namespace sound

} // namespace lite
Loading