From 98fe0e7056e6697396249531785d3899f94d79be Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 10 Jun 2006 01:52:02 +0000 Subject: More juggling git-svn-id: http://svn.drobilla.net/lad/grauph@15 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/engine/Buffer.h | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/libs/engine/Buffer.h (limited to 'src/libs/engine/Buffer.h') diff --git a/src/libs/engine/Buffer.h b/src/libs/engine/Buffer.h new file mode 100644 index 00000000..13d62727 --- /dev/null +++ b/src/libs/engine/Buffer.h @@ -0,0 +1,91 @@ +/* This file is part of Om. Copyright (C) 2006 Dave Robillard. + * + * Om is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Om is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef BUFFER_H +#define BUFFER_H + +#include +#include +#include "util/types.h" + +namespace Om { + + +template +class Buffer +{ +public: + Buffer(size_t size); + + void clear(); + void set(T val, size_t start_sample); + void set(T val, size_t start_sample, size_t end_sample); + void scale(T val, size_t start_sample, size_t end_sample); + void copy(const Buffer* src, size_t start_sample, size_t end_sample); + void accumulate(const Buffer* src, size_t start_sample, size_t end_sample); + + void join(Buffer* buf); + void unjoin(); + + inline T& value_at(size_t offset) { assert(offset < m_size); return m_data[offset]; } + + void prepare(samplecount nframes); + + void filled_size(size_t size) { m_filled_size = size; } + size_t filled_size() const { return m_filled_size; } + bool is_joined() const { return m_is_joined; } + size_t size() const { return m_size; } + T* data() const { return m_data; } + +protected: + enum BufferState { OK, HALF_SET_CYCLE_1, HALF_SET_CYCLE_2 }; + + void allocate(); + void deallocate(); + + size_t m_size; ///< Allocated buffer size + size_t m_filled_size; ///< Usable buffer size (for MIDI ports etc) + bool m_is_joined; ///< Whether or not @ref m_data is shares with another Buffer + BufferState m_state; ///< State of buffer for setting values next cycle + T m_set_value; ///< Value set by @ref set (may need to be set next cycle) + + T* m_data; ///< Buffer to be returned by data() (not equal to m_local_data if joined) + T* m_local_data; ///< Locally allocated buffer +}; + + +/** Less robust Buffer for Driver's use. + * + * Does not allocate an array by default, and allows direct setting of + * data pointer for zero-copy processing. + */ +template +class DriverBuffer : public Buffer +{ +public: + DriverBuffer(size_t size); + + void set_data(T* data); + +private: + using Buffer::m_data; + using Buffer::m_is_joined; +}; + + +} // namespace Om + +#endif // BUFFER_H -- cgit v1.2.1