diff options
author | David Robillard <d@drobilla.net> | 2015-10-24 19:27:39 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2015-10-24 19:27:39 +0000 |
commit | 732bfb33105b4a534bc17caae9a50a1ccfcd7570 (patch) | |
tree | bad9715a99f11d17342adaef372361c3697beee9 /src/server/Buffer.hpp | |
parent | ade7143eb2af64fd6743a64ebf1786dd5bbe1092 (diff) | |
download | ingen-732bfb33105b4a534bc17caae9a50a1ccfcd7570.tar.gz ingen-732bfb33105b4a534bc17caae9a50a1ccfcd7570.tar.bz2 ingen-732bfb33105b4a534bc17caae9a50a1ccfcd7570.zip |
Zero-copy to/from driver ports where possible
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5778 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/server/Buffer.hpp')
-rw-r--r-- | src/server/Buffer.hpp | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/server/Buffer.hpp b/src/server/Buffer.hpp index ada8a43d..11037dd1 100644 --- a/src/server/Buffer.hpp +++ b/src/server/Buffer.hpp @@ -45,7 +45,9 @@ public: Buffer(BufferFactory& bufs, LV2_URID type, LV2_URID value_type, - uint32_t capacity); + uint32_t capacity, + bool external = false, + void* buf = NULL); void clear(); void resize(uint32_t size); @@ -73,18 +75,12 @@ public: return _type == _factory.uris().atom_Sequence; } - inline bool empty() const { - return (_atom->type != _type || - (_type == _factory.uris().atom_Sequence && - _atom->size <= sizeof(LV2_Atom_Sequence_Body))); - } - - /// Audio buffers only + /// Audio or float buffers only inline const Sample* samples() const { if (is_control()) { - return (const Sample*)LV2_ATOM_BODY_CONST(atom()); + return (const Sample*)LV2_ATOM_BODY_CONST(get<LV2_Atom_Float>()); } else if (is_audio()) { - return (const Sample*)LV2_ATOM_CONTENTS_CONST(LV2_Atom_Vector, atom()); + return (const Sample*)_buf; } return NULL; } @@ -92,9 +88,9 @@ public: /// Audio buffers only inline Sample* samples() { if (is_control()) { - return (Sample*)LV2_ATOM_BODY(atom()); + return (Sample*)LV2_ATOM_BODY(get<LV2_Atom_Float>()); } else if (is_audio()) { - return (Sample*)LV2_ATOM_CONTENTS(LV2_Atom_Vector, atom()); + return (Sample*)_buf; } return NULL; } @@ -104,7 +100,7 @@ public: if (is_control()) { return 1; } else if (is_audio()) { - return (_capacity - sizeof(LV2_Atom_Vector)) / sizeof(Sample); + return (_capacity / sizeof(Sample)); } return 0; } @@ -152,8 +148,9 @@ public: { if (add) { add_block(val, start, end); + } else { + set_block(val, start, end); } - set_block(val, start, end); } /// Audio buffers only @@ -184,11 +181,13 @@ public: /// Set/add to audio buffer from the Sequence of Float in `src` void render_sequence(const Context& context, const Buffer* src, bool add); - LV2_Atom* atom() { return _atom; } - const LV2_Atom* atom() const { return _atom; } - void set_capacity(uint32_t capacity) { _capacity = capacity; } + void set_buffer(void* buf) { assert(_external); _buf = buf; } + + template<typename T> const T* get() const { return reinterpret_cast<const T*>(_buf); } + template<typename T> T* get() { return reinterpret_cast<T*>(_buf); } + inline void ref() { ++_refs; } inline void deref() { @@ -199,7 +198,7 @@ public: protected: BufferFactory& _factory; - LV2_Atom* _atom; + void* _buf; LV2_URID _type; LV2_URID _value_type; uint32_t _capacity; @@ -213,8 +212,9 @@ protected: private: void recycle(); - Buffer* _next; ///< Intrusive linked list for BufferFactory - std::atomic<unsigned> _refs; ///< Intrusive reference count + Buffer* _next; ///< Intrusive linked list for BufferFactory + std::atomic<unsigned> _refs; ///< Intrusive reference count + bool _external; ///< Buffer is externally allocated }; } // namespace Server |