diff --git a/src/common/RingBuffer.h b/src/common/RingBuffer.h deleted file mode 100644 index 455540fd..00000000 --- a/src/common/RingBuffer.h +++ /dev/null @@ -1,119 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * aamas@stud.ntnu.no * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef RINGBUFFER_H -#define RINGBUFFER_H - -#include "array.h" -#include -#include -#include - -template class RingBuffer -{ - Array buf; - std::size_t sz; - std::size_t rpos; - std::size_t wpos; - - public: - RingBuffer(const std::size_t sz_in = 0) : sz(0), rpos(0), wpos(0) - { - reset(sz_in); - } - - std::size_t avail() const - { - return (wpos < rpos ? 0 : sz) + rpos - wpos - 1; - } - - void clear() - { - wpos = rpos = 0; - } - - void fill(T value); - - void read(T *out, std::size_t num); - - void reset(std::size_t sz_in); - - std::size_t size() const - { - return sz - 1; - } - - std::size_t used() const - { - return (wpos < rpos ? sz : 0) + wpos - rpos; - } - - void write(const T *in, std::size_t num); -}; - -template void RingBuffer::fill(const T value) -{ - std::fill(buf + 0, buf + sz, value); - rpos = 0; - wpos = sz - 1; -} - -template void RingBuffer::read(T *out, std::size_t num) -{ - if (rpos + num > sz) { - const std::size_t n = sz - rpos; - - std::memcpy(out, buf + rpos, n * sizeof(T)); - - rpos = 0; - num -= n; - out += n; - } - - std::memcpy(out, buf + rpos, num * sizeof(T)); - - if ((rpos += num) == sz) - rpos = 0; -} - -template void RingBuffer::reset(const std::size_t sz_in) -{ - sz = sz_in + 1; - rpos = wpos = 0; - buf.reset(sz_in ? sz : 0); -} - -template void RingBuffer::write(const T *in, std::size_t num) -{ - if (wpos + num > sz) { - const std::size_t n = sz - wpos; - - std::memcpy(buf + wpos, in, n * sizeof(T)); - - wpos = 0; - num -= n; - in += n; - } - - std::memcpy(buf + wpos, in, num * sizeof(T)); - - if ((wpos += num) == sz) - wpos = 0; -} - -#endif diff --git a/src/common/SoundSDL.h b/src/common/SoundSDL.h index 58f4e0d0..d5efb989 100644 --- a/src/common/SoundSDL.h +++ b/src/common/SoundSDL.h @@ -18,7 +18,7 @@ #ifndef __VBA_SOUND_SDL_H__ #define __VBA_SOUND_SDL_H__ -#include "RingBuffer.h" +#include "ringbuffer.h" #include "SoundDriver.h" #include "SDL.h" diff --git a/src/common/ringbuffer.h b/src/common/ringbuffer.h new file mode 100644 index 00000000..e6d129b9 --- /dev/null +++ b/src/common/ringbuffer.h @@ -0,0 +1,95 @@ +#ifndef RINGBUFFER_H +#define RINGBUFFER_H + +#include +#include +#include +#include "array.h" + + +template class RingBuffer +{ + public: + typedef T value_type; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef T &reference; + typedef const T &const_reference; + typedef T *pointer; + typedef const T *const_pointer; + typedef T *iterator; + typedef const T *const_iterator; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + private: + Array m_buffer; + size_type m_size, m_pos_read, m_pos_write; + + public: + RingBuffer(size_type size = 0) : m_size(0), m_pos_read(0), m_pos_write(0) + { + this->reset(size); + } + + void reset(size_type size) + { + this->m_size = size+1; + this->m_pos_read = this->m_pos_write = 0; + this->m_buffer.reset(size ? this->m_size : 0); + } + + size_type size() const + { + return(this->m_size-1); + } + + void clear() + { + this->m_pos_read = this->m_pos_write = 0; + } + + void fill(T value) + { + std::fill(this->m_buffer+0, this->m_buffer+this->m_buffer->size(), value); + this->m_pos_read = 0; + this->m_pos_write = this->size(); + } + + size_type avail() const + { + return(this->m_size - this->used()); + } + + size_type used() const + { + return + ( + (this->m_pos_write < this->m_pos_read) ? + this->m_pos_write + (this->m_size - this->m_pos_read) : + this->m_pos_write - this->m_pos_read + ); + } + + void read(pointer buffer, size_type size) + { + size_type amount = std::min(size, this->m_size-this->m_pos_read); + std::copy(this->m_buffer+this->m_pos_read, this->m_buffer+this->m_pos_read+amount, buffer); + this->m_pos_read = (this->m_pos_read + amount) % this->m_size; + size -= amount; + std::copy(this->m_buffer+this->m_pos_read, this->m_buffer+this->m_pos_read+size, buffer+amount); + this->m_pos_read = (this->m_pos_read + size) % this->m_size; + } + + void write(const_pointer buffer, size_type size) + { + size_type amount = std::min(size, this->m_size-this->m_pos_write); + std::copy(buffer, buffer+amount, this->m_buffer+m_pos_write); + this->m_pos_write = (this->m_pos_write + amount) % this->m_size; + std::copy(buffer+amount, buffer+size, this->m_buffer+m_pos_write); + size -= amount; + this->m_pos_write = (this->m_pos_write + size) % this->m_size; + } +}; + +#endif diff --git a/src/debian/copyright b/src/debian/copyright index f0912871..8b4a4013 100644 --- a/src/debian/copyright +++ b/src/debian/copyright @@ -6,22 +6,22 @@ Comment: This package was debianized by Files: * -Copyright: 2007-2015 VBA-M development team +Copyright: 2007-2017 VBA-M development team 2004-2006 VBA development team 1999-2006 Forgotten License: GPL-2+ Files: src/gtk/* -Copyright: 2008-2015 VBA-M development team +Copyright: 2008-2017 VBA-M development team 2004 VBA development team License: GPL-2+ Files: src/sdl/* -Copyright: 2007-2015 VBA-M development team +Copyright: 2007-2017 VBA-M development team License: GPL-2+ Files: src/wx/* -Copyright: 2011-2015 VBA-M development team +Copyright: 2011-2017 VBA-M development team 2011 Thomas J. Moore (aka tjm, aka darktjm) License: GPL-2+ @@ -62,11 +62,6 @@ Copyright: 2007, 2009, 2011, 2012, 2013, 2015 VBA-M development team 1995-2002 Jean-loup Gailly License: Zlib -Files: src/common/Array.h - src/common/RingBuffer.h -Copyright: 2008 by Sindre Aamås -License: GPL-2 - Files: src/filters/hq/asm/hq3x_16.asm src/filters/hq/asm/hq3x_32.asm src/filters/hq/asm/hq4x_16.asm @@ -77,7 +72,7 @@ License: GPL-2+ Files: src/filters/hq/asm/macros.mac Copyright: 1997-2007 ZSNES Team (zsKnight, _Demo_, pagefault, Nach) -License: GPL-2 +License: GPL-2+ Files: src/filters/xBRZ/* Copyright: 2012-2015 Zenju (zenju AT gmx DOT de)