diff options
Diffstat (limited to 'src/server/Buffer.cpp')
-rw-r--r-- | src/server/Buffer.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/server/Buffer.cpp b/src/server/Buffer.cpp index 394d3323..0c4c0951 100644 --- a/src/server/Buffer.cpp +++ b/src/server/Buffer.cpp @@ -18,15 +18,16 @@ #include "BufferFactory.hpp" #include "Engine.hpp" +#include "PortType.hpp" #include "RunContext.hpp" #include "ingen_config.h" -#include "ingen/Atom.hpp" -#include "ingen/Log.hpp" -#include "ingen/URIs.hpp" -#include "lv2/atom/atom.h" -#include "lv2/atom/util.h" -#include "lv2/urid/urid.h" +#include <ingen/Atom.hpp> +#include <ingen/Log.hpp> +#include <ingen/URIs.hpp> +#include <lv2/atom/atom.h> +#include <lv2/atom/util.h> +#include <lv2/urid/urid.h> #include <algorithm> #include <cstdint> @@ -171,7 +172,12 @@ void Buffer::resize(uint32_t capacity) { if (!_external) { - _buf = realloc(_buf, capacity); + void* const new_buf = realloc(_buf, capacity); + if (!new_buf) { + throw std::bad_alloc{}; + } + + _buf = new_buf; _capacity = capacity; clear(); } else { @@ -182,18 +188,18 @@ Buffer::resize(uint32_t capacity) void* Buffer::port_data(PortType port_type, SampleCount offset) { - switch (port_type.id()) { - case PortType::ID::CONTROL: + switch (port_type) { + case PortType::CONTROL: return &_value_buffer->get<LV2_Atom_Float>()->body; - case PortType::ID::CV: - case PortType::ID::AUDIO: + case PortType::CV: + case PortType::AUDIO: if (_type == _factory.uris().atom_Float) { return &get<LV2_Atom_Float>()->body; } else if (_type == _factory.uris().atom_Sound) { return static_cast<Sample*>(_buf) + offset; } break; - case PortType::ID::ATOM: + case PortType::ATOM: if (_type != _factory.uris().atom_Sound) { return _buf; } @@ -207,8 +213,7 @@ Buffer::port_data(PortType port_type, SampleCount offset) const void* Buffer::port_data(PortType port_type, SampleCount offset) const { - return const_cast<void*>( - const_cast<Buffer*>(this)->port_data(port_type, offset)); + return const_cast<Buffer*>(this)->port_data(port_type, offset); } #ifdef __SSE__ @@ -435,7 +440,7 @@ void* Buffer::aligned_alloc(size_t size) { #if USE_POSIX_MEMALIGN void* buf = nullptr; - if (!posix_memalign(static_cast<void**>(&buf), 16, size)) { + if (!posix_memalign(&buf, 16, size)) { memset(buf, 0, size); return buf; } |