diff options
Diffstat (limited to 'libs/evoral/evoral/RingBuffer.hpp')
-rw-r--r-- | libs/evoral/evoral/RingBuffer.hpp | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/libs/evoral/evoral/RingBuffer.hpp b/libs/evoral/evoral/RingBuffer.hpp index 3e47042679..37a7096511 100644 --- a/libs/evoral/evoral/RingBuffer.hpp +++ b/libs/evoral/evoral/RingBuffer.hpp @@ -1,15 +1,15 @@ /* This file is part of Evoral. * Copyright (C) 2008 Dave Robillard <http://drobilla.net> - * + * * Evoral 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. - * + * * Evoral 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., * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -43,7 +43,7 @@ public: assert(read_space() == 0); assert(write_space() == size - 1); } - + virtual ~RingBuffer() { delete[] _buf; } @@ -61,7 +61,7 @@ public: size_t write_space() const { const size_t w = g_atomic_int_get(&_write_ptr); const size_t r = g_atomic_int_get(&_read_ptr); - + if (w > r) { return ((r - w + _size) % _size) - 1; } else if (w < r) { @@ -70,13 +70,13 @@ public: return _size - 1; } } - + /** Calculate how much still can be read */ size_t read_space() const { const size_t w = g_atomic_int_get(&_write_ptr); const size_t r = g_atomic_int_get(&_read_ptr); - + if (w > r) { return w - r; } else { @@ -89,7 +89,7 @@ public: size_t capacity() const { return _size; } /** Peek at the ringbuffer (read w/o advancing read pointer). - * @return how much has been peeked (read cannot exceed the end + * @return how much has been peeked (read cannot exceed the end * of the buffer): * <pre> * |-------------------------R=============================| @@ -109,7 +109,7 @@ public: bool full_peek(size_t size, Time* dst); /** Read from the ringbuffer. (advances read pointer) - * @return how much has been read (read cannot exceed the end + * @return how much has been read (read cannot exceed the end * of the buffer): */ size_t read(size_t size, Time* dst); @@ -123,13 +123,13 @@ public: /** Advance read pointer by size */ bool skip(size_t size); - + void write(size_t size, const Time* src); protected: mutable int _write_ptr; mutable int _read_ptr; - + size_t _size; ///< Size (capacity) in bytes Time* _buf; ///< size, event, size, event... }; @@ -138,7 +138,7 @@ protected: /** Peek at the ringbuffer (read w/o advancing read pointer). * * Note that a full read may not be done if the data wraps around. - * Caller must check return value and call again if necessary, or use the + * Caller must check return value and call again if necessary, or use the * full_peek method which does this automatically. */ template<typename Time> @@ -150,7 +150,7 @@ RingBuffer<Time>::peek(size_t size, Time* dst) const size_t read_size = (priv_read_ptr + size < _size) ? size : _size - priv_read_ptr; - + memcpy(dst, &_buf[priv_read_ptr], read_size); return read_size; @@ -166,7 +166,7 @@ RingBuffer<Time>::full_peek(size_t size, Time* dst) } const size_t read_size = peek(size, dst); - + if (read_size < size) { peek(size - read_size, dst + read_size); } @@ -178,7 +178,7 @@ RingBuffer<Time>::full_peek(size_t size, Time* dst) /** Read from the ringbuffer. * * Note that a full read may not be done if the data wraps around. - * Caller must check return value and call again if necessary, or use the + * Caller must check return value and call again if necessary, or use the * full_read method which does this automatically. */ template<typename Time> @@ -190,9 +190,9 @@ RingBuffer<Time>::read(size_t size, Time* dst) const size_t read_size = (priv_read_ptr + size < _size) ? size : _size - priv_read_ptr; - + memcpy(dst, &_buf[priv_read_ptr], read_size); - + g_atomic_int_set(&_read_ptr, (priv_read_ptr + read_size) % _size); return read_size; @@ -208,7 +208,7 @@ RingBuffer<Time>::full_read(size_t size, Time* dst) } const size_t read_size = read(size, dst); - + if (read_size < size) { read(size - read_size, dst + read_size); } @@ -225,7 +225,7 @@ RingBuffer<Time>::skip(size_t size) std::cerr << "WARNING: Attempt to skip past end of MIDI ring buffer" << std::endl; return false; } - + const size_t priv_read_ptr = g_atomic_int_get(&_read_ptr); g_atomic_int_set(&_read_ptr, (priv_read_ptr + size) % _size); @@ -238,7 +238,7 @@ inline void RingBuffer<Time>::write(size_t size, const Time* src) { const size_t priv_write_ptr = g_atomic_int_get(&_write_ptr); - + if (priv_write_ptr + size <= _size) { memcpy(&_buf[priv_write_ptr], src, size); g_atomic_int_set(&_write_ptr, (priv_write_ptr + size) % _size); @@ -252,7 +252,7 @@ RingBuffer<Time>::write(size_t size, const Time* src) } } - + } // namespace Evoral #endif // EVORAL_RING_BUFFER_HPP |