Skip to content

Commit

Permalink
static analyzer pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Sploder12 committed Oct 20, 2024
1 parent 2a41606 commit b2a17ff
Show file tree
Hide file tree
Showing 39 changed files with 135 additions and 170 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,7 @@ lib/

GPUCache/

Intel*
Intel*

# Jetbrains IDEs
.idea/
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CMakeList.txt : CMake project for SNDXlib, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.12)
cmake_minimum_required (VERSION 3.14)

# Enable Hot Reload for MSVC compilers if supported.
if (POLICY CMP0141)
Expand Down
10 changes: 3 additions & 7 deletions src/include/sndx/audio/al/abo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "./audio_data.hpp"

#include "../mixin/handle.hpp"
#include "../../mixin/handle.hpp"

namespace sndx::audio {
class ABO {
Expand All @@ -24,9 +24,7 @@ namespace sndx::audio {
}

public:
explicit ABO() :
m_id(0) {

explicit ABO() {
gen();
}

Expand Down Expand Up @@ -58,9 +56,7 @@ namespace sndx::audio {
}

ABO& setData(const ALaudioData& data) {
auto size = ALsizei(data.getByteSize());

if (size > 0) {
if (auto size = ALsizei(data.getByteSize()); size > 0) {
gen();
alBufferData(m_id, ALenum(data.getFormat()), data.data(), size, ALsizei(data.getFrequency()));
}
Expand Down
38 changes: 4 additions & 34 deletions src/include/sndx/audio/al/al.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,23 @@
#include <stdexcept>

namespace sndx::audio {

struct AL_error : public std::runtime_error {
using std::runtime_error::runtime_error;
};

struct AL_invalid_name_error : public AL_error {
using AL_error::AL_error;
};

struct AL_invalid_enum_error : public AL_error {
using AL_error::AL_error;
};

struct AL_invalid_value_error : public AL_error {
using AL_error::AL_error;
};

struct AL_invalid_operation_error : public AL_error {
using AL_error::AL_error;
};

struct AL_OOM_error : public AL_error {
using AL_error::AL_error;
};

inline void alThrowError(ALenum err) {
inline void alThrowIfError(ALenum err) {
switch (err) {
case AL_INVALID_NAME:
throw AL_invalid_name_error("A bad ID was passed to OpenAL!");
case AL_INVALID_ENUM:
throw AL_invalid_enum_error("A invalid enum was passed to OpenAL!");
case AL_INVALID_VALUE:
throw AL_invalid_value_error("Invalid OpenAL argument!");
case AL_INVALID_OPERATION:
throw AL_invalid_operation_error("Invalid OpenAL operation!");
case AL_OUT_OF_MEMORY:
throw AL_OOM_error("OpenAL ran out of memory!");
throw err;
default:
break;
}
}

inline void alGetAndThrowError() {
alThrowError(alGetError());
alThrowIfError(alGetError());
}


enum class ALformat : ALenum {
mono8 = AL_FORMAT_MONO8,
mono16 = AL_FORMAT_MONO16,
Expand Down Expand Up @@ -136,7 +106,7 @@ namespace sndx::audio {

[[nodiscard]]
constexpr unsigned char getBytesPerSample(ALformat format) noexcept {
return (unsigned char)(getByteDepth(format) * getChannels(format));
return static_cast<unsigned char>(getByteDepth(format) * getChannels(format));
}

[[nodiscard]]
Expand Down
11 changes: 5 additions & 6 deletions src/include/sndx/audio/al/audio_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ namespace sndx::audio {

public:

explicit ALaudioData() noexcept :
m_meta(), m_buffer{} {}
explicit ALaudioData() noexcept = default;

explicit ALaudioData(const ALaudioMeta& meta) noexcept :
m_meta(meta), m_buffer{} {}
m_meta(meta) {}

explicit ALaudioData(const ALaudioMeta& meta, std::vector<std::byte>&& buf) noexcept :
m_meta(meta), m_buffer{ std::move(buf) } {}

template <std::floating_point F>
explicit ALaudioData(const ALaudioMeta& meta, const std::vector<F>& buf) :
m_meta(meta), m_buffer{} {
m_meta(meta) {

m_buffer.resize(buf.size() * getChannels() * getByteDepth(meta.m_format));

Expand Down Expand Up @@ -116,11 +115,11 @@ namespace sndx::audio {
auto bytePos = getBytePos(sample, channel);

if (is8Bit(m_meta.m_format)) {
uint8_t* ptr = (uint8_t*)(m_buffer.data() + bytePos);
auto ptr = reinterpret_cast<const uint8_t*>(m_buffer.data() + bytePos);
return (long double)(*ptr);
}
else {
int16_t* ptr = (int16_t*)(m_buffer.data() + bytePos);
auto ptr = reinterpret_cast<const int16_t*>(m_buffer.data() + bytePos);
return (long double)(*ptr);
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/include/sndx/audio/al/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@ namespace sndx::audio {

template <typename IdT = std::string>
class ALcontext {
protected:
private:
ALdevice m_device;
ALCcontext* m_context;
ALCcontext* m_context{nullptr};

// buffers and sources are context specific
// also despite being based on OpenGL there is no "bindBuffer" etc.
std::unordered_map<IdT, ABO> m_buffers;
std::unordered_map<IdT, ALsource> m_sources;
std::unordered_map<IdT, ABO> m_buffers{};
std::unordered_map<IdT, ALsource> m_sources{};

public:
explicit ALcontext(const ALCchar* deviceName = nullptr, const ALCint* attrList = nullptr) :
m_device(deviceName), m_context(nullptr), m_buffers{}, m_sources{} {
m_device(deviceName) {

if (!m_device.valid()) return;

m_context = alcCreateContext(m_device, attrList);
}

explicit ALcontext(ALdevice&& device, const ALCint* attrList = nullptr) :
m_device(std::move(device)), m_context(nullptr), m_buffers{}, m_sources{} {
m_device(std::move(device)) {

if (!m_device.valid()) return;

m_context = alcCreateContext(m_device, attrList);
}

ALcontext(ALcontext&& other) noexcept :
m_device(std::exchange(other.m_device, {})), m_context(std::exchange(other.m_context, nullptr)),
m_device(std::exchange(other.m_device, ALdevice{})), m_context(std::exchange(other.m_context, nullptr)),
m_buffers(std::exchange(other.m_buffers, {})), m_sources(std::exchange(other.m_sources, {})) {}

ALcontext(const ALcontext&) = delete;
Expand Down Expand Up @@ -86,7 +86,7 @@ namespace sndx::audio {
}

[[nodiscard]]
ALdeviceHandle getDevice() const {
ALdeviceHandle getDevice() {
return m_device;
}

Expand Down
13 changes: 8 additions & 5 deletions src/include/sndx/audio/al/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
#include <string>
#include <vector>
#include <algorithm>
#include <utility>

#include "../../mixin/handle.hpp"

namespace sndx::audio {

[[nodiscard]]
inline bool isALEnumExtPresent() {
static bool present =
alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE &&
alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") == AL_TRUE;
alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT") == AL_TRUE &&
alcIsExtensionPresent(nullptr, "ALC_ENUMERATE_ALL_EXT") == AL_TRUE;

return present;
}
Expand All @@ -23,7 +26,7 @@ namespace sndx::audio {
return {};
}

auto devices = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
auto devices = alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
if (devices == nullptr || *devices == '\0') return {};

std::vector<std::string> out{};
Expand All @@ -38,7 +41,7 @@ namespace sndx::audio {

[[nodiscard]]
inline std::string getDefaultAlDevice() {
return alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
return alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER);
}

class ALdevice {
Expand All @@ -55,7 +58,7 @@ namespace sndx::audio {
return device;
}

operator const ALCdevice* () const {
operator ALCdevice const* () const {
return device;
}

Expand Down
6 changes: 2 additions & 4 deletions src/include/sndx/audio/al/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "./al.hpp"

#include "../mixin/handle.hpp"
#include "../../mixin/handle.hpp"

#include "./abo.hpp"

Expand Down Expand Up @@ -35,9 +35,7 @@ namespace sndx::audio {
}

public:
explicit ALsource() :
m_id(0) {

explicit ALsource() {
gen();
}

Expand Down
4 changes: 2 additions & 2 deletions src/include/sndx/audio/audio_decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace sndx::audio {

class AudioDecoder {
public:
typedef std::unique_ptr<AudioDecoder>(*Factory)(std::istream&);
using Factory = std::unique_ptr<AudioDecoder> (*)(std::istream&);

virtual ~AudioDecoder() = default;

Expand Down Expand Up @@ -106,7 +106,7 @@ namespace sndx::audio {
}

template <std::derived_from<AudioDecoder> T>
inline bool registerDecoder(const std::string& extension) {
bool registerDecoder(const std::string& extension) {
return getDecoderRegistry().add(extension, [](std::istream& in) {
return std::unique_ptr<AudioDecoder>{std::make_unique<T>(in)};
});
Expand Down
5 changes: 2 additions & 3 deletions src/include/sndx/audio/mp3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ namespace sndx::audio {

public:
explicit MP3decoder(std::istream& stream) :
m_stream(stream.rdbuf()), m_buffer{},
m_dec{}, m_pos(0), m_dirty(false) {
m_stream(stream.rdbuf()) {

stream.seekg(0, std::ios::end);
size_t size = stream.tellg();
Expand All @@ -67,7 +66,7 @@ namespace sndx::audio {
}
}

~MP3decoder() {
~MP3decoder() override {
mp3dec_ex_close(&m_dec);
}

Expand Down
12 changes: 5 additions & 7 deletions src/include/sndx/audio/vorbis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ namespace sndx::audio {
}

[[nodiscard]]
std::vector<std::span<float>> lapout(Info& info) noexcept {
std::vector<std::span<float>> lapout(const Info& info) noexcept {
float** pcm;
auto samples = vorbis_synthesis_lapout(&m_state, &pcm);

Expand All @@ -211,7 +211,7 @@ namespace sndx::audio {
}

[[nodiscard]]
std::vector<std::span<float>> out(Info& info) noexcept {
std::vector<std::span<float>> out(const Info& info) noexcept {
float** pcm;
auto samples = vorbis_synthesis_pcmout(&m_state, &pcm);

Expand Down Expand Up @@ -318,15 +318,13 @@ namespace sndx::audio {
if (!opckt)
return out;

if (m_block.decode(*opckt)) {
if (!m_state.blockIn(m_block))
return out;
}
if (m_block.decode(*opckt) && !m_state.blockIn(m_block))
return out;

while (true) {
auto data = m_state.out(m_info);

if (data.size() > 0 && data[0].size() > 0) {
if (!data.empty() && data[0].size() > 0) {
for (size_t i = 0; i < data[0].size(); ++i) {
for (size_t c = 0; c < data.size(); ++c) {
int val = int(std::floor(data[c][i] * 32767.0f + 0.5f));
Expand Down
Loading

0 comments on commit b2a17ff

Please sign in to comment.