From 644441168c06c1b8e34e909e9245b43a228cf0e8 Mon Sep 17 00:00:00 2001 From: sinamas Date: Thu, 25 Aug 2011 17:35:27 +0000 Subject: [PATCH] refactoring. git-svn-id: https://gambatte.svn.sourceforge.net/svnroot/gambatte@256 9dfb2916-2d38-0410-aef4-c5fe6c9ffc24 --- common/array.h | 10 ++--- common/resample/src/blackmansinc.h | 12 ++--- common/resample/src/chainresampler.cpp | 22 ++++----- common/resample/src/chainresampler.h | 10 ++--- common/resample/src/cic2.h | 12 ++--- common/resample/src/cic3.h | 20 ++++----- common/resample/src/cic4.h | 12 ++--- common/resample/src/convoluter.h | 18 ++++---- common/resample/src/hammingsinc.h | 12 ++--- common/resample/src/kaiser50sinc.h | 12 ++--- common/resample/src/kaiser70sinc.h | 12 ++--- common/resample/src/linint.h | 10 ++--- common/resample/src/makesinckernel.cpp | 9 ++-- common/resample/src/rectsinc.h | 12 ++--- common/resample/src/resamplerinfo.cpp | 8 ++-- common/resample/src/upsampler.h | 2 +- common/videolink/rgb32conv.cpp | 57 +++++++++++++++--------- common/videolink/vfilterinfo.cpp | 6 +-- common/videolink/vfilterinfo.h | 6 ++- common/videolink/vfilters/catrom2x.cpp | 27 +++++------ common/videolink/vfilters/catrom2x.h | 8 +++- common/videolink/vfilters/catrom3x.cpp | 27 +++++------ common/videolink/vfilters/catrom3x.h | 8 +++- common/videolink/vfilters/kreed2xsai.cpp | 26 +++++------ common/videolink/vfilters/kreed2xsai.h | 8 +++- common/videolink/vfilters/maxsthq2x.cpp | 30 ++++++------- common/videolink/vfilters/maxsthq2x.h | 8 +++- common/videolink/vfilters/maxsthq3x.cpp | 26 +++++------ common/videolink/vfilters/maxsthq3x.h | 8 +++- common/videolink/videolink.h | 10 ++--- gambatte_qt/src/gambattesource.cpp | 2 + gambatte_sdl/src/blitterwrapper.h | 2 +- libgambatte/include/gambatte.h | 2 +- libgambatte/include/{int.h => gbint.h} | 0 libgambatte/src/bitmap_font.h | 2 +- libgambatte/src/cpu.h | 1 - libgambatte/src/memory.cpp | 24 +++++----- libgambatte/src/memory.h | 1 - libgambatte/src/osd_element.h | 2 +- libgambatte/src/sound.h | 1 - libgambatte/src/sound/channel1.h | 2 +- libgambatte/src/sound/channel2.h | 2 +- libgambatte/src/sound/channel3.h | 2 +- libgambatte/src/sound/channel4.h | 2 +- libgambatte/src/statesaver.cpp | 2 +- libgambatte/src/statesaver.h | 2 +- libgambatte/src/video/ppu.h | 2 +- 47 files changed, 263 insertions(+), 236 deletions(-) rename libgambatte/include/{int.h => gbint.h} (100%) diff --git a/common/array.h b/common/array.h index e52f888..629198e 100644 --- a/common/array.h +++ b/common/array.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Sindre Aam�s * + * Copyright (C) 2008 by Sindre Aamås * * aamas@stud.ntnu.no * * * * This program is free software; you can redistribute it and/or modify * @@ -28,14 +28,12 @@ class Array : Uncopyable { std::size_t sz; public: - Array(const std::size_t size = 0) : a(size ? new T[size] : 0), sz(size) {} + explicit Array(const std::size_t size = 0) : a(size ? new T[size] : 0), sz(size) {} ~Array() { delete []a; } void reset(const std::size_t size = 0) { delete []a; a = size ? new T[size] : 0; sz = size; } std::size_t size() const { return sz; } - T * get() { return a; } - const T * get() const { return a; } - operator T*() { return a; } - operator const T*() const { return a; } + T * get() const { return a; } + operator T*() const { return a; } }; #endif diff --git a/common/resample/src/blackmansinc.h b/common/resample/src/blackmansinc.h index 8657823..1d870d1 100644 --- a/common/resample/src/blackmansinc.h +++ b/common/resample/src/blackmansinc.h @@ -23,13 +23,14 @@ #include "subresampler.h" #include "makesinckernel.h" #include "cic4.h" +#include "array.h" #include #include template class BlackmanSinc : public SubResampler { PolyPhaseConvoluter convoluters[channels]; - short *kernel; + Array kernel; static double blackmanWin(const long i, const long M) { static const double PI = 3.14159265358979323846; @@ -64,16 +65,15 @@ public: BlackmanSinc(unsigned div, unsigned phaseLen, double fc) { init(div, phaseLen, fc); } BlackmanSinc(unsigned div, RollOff ro) { init(div, ro.taps, ro.fc); } - ~BlackmanSinc() { delete[] kernel; } std::size_t resample(short *out, const short *in, std::size_t inlen); void adjustDiv(unsigned div); unsigned mul() const { return MUL; } unsigned div() const { return convoluters[0].div(); } }; -template +template void BlackmanSinc::init(const unsigned div, const unsigned phaseLen, const double fc) { - kernel = new short[phaseLen * phases]; + kernel.reset(phaseLen * phases); makeSincKernel(kernel, phases, phaseLen, fc, blackmanWin); @@ -81,7 +81,7 @@ void BlackmanSinc::init(const unsigned div, const unsigned pha convoluters[i].reset(kernel, phaseLen, div); } -template +template std::size_t BlackmanSinc::resample(short *const out, const short *const in, const std::size_t inlen) { std::size_t samplesOut; @@ -91,7 +91,7 @@ std::size_t BlackmanSinc::resample(short *const out, const sho return samplesOut; } -template +template void BlackmanSinc::adjustDiv(const unsigned div) { for (unsigned i = 0; i < channels; ++i) convoluters[i].adjustDiv(div); diff --git a/common/resample/src/chainresampler.cpp b/common/resample/src/chainresampler.cpp index 6836a05..911f755 100644 --- a/common/resample/src/chainresampler.cpp +++ b/common/resample/src/chainresampler.cpp @@ -38,6 +38,11 @@ float ChainResampler::get3ChainCost(const float ratio, const float rollOff, cons return ratio1 * ratio / ((ratio1 - 1) * 2) + ratio2 * ratio1 / ((ratio2 - 1) * 2) + ratio2 / rollOff; } +ChainResampler::ChainResampler() +: bigSinc(0), buffer2(0), periodSize(0) +{ +} + std::size_t ChainResampler::reallocateBuffer() { std::size_t bufSz[2] = { 0, 0 }; std::size_t inSz = periodSize; @@ -55,12 +60,10 @@ std::size_t ChainResampler::reallocateBuffer() { if (inSz >= bufSz[i&1]) bufSz[i&1] = 0; - if (bufferSize < bufSz[0] + bufSz[1]) { - delete[] buffer; - buffer = (bufferSize = bufSz[0] + bufSz[1]) ? new short[bufferSize * channels] : NULL; - } + if (buffer.size() < (bufSz[0] + bufSz[1]) * channels) + buffer.reset((bufSz[0] + bufSz[1]) * channels); - buffer2 = bufSz[1] ? buffer + bufSz[0] * channels : NULL; + buffer2 = bufSz[1] ? buffer + bufSz[0] * channels : 0; return (maxOut_ = inSz); } @@ -93,7 +96,7 @@ std::size_t ChainResampler::resample(short *const out, const short *const in, st short *const buf2 = buffer2 ? buffer2 : out; const short *inbuf = in; - short *outbuf = NULL; + short *outbuf = 0; for (list_t::iterator it = list.begin(); it != list.end(); ++it) { outbuf = ++list_t::iterator(it) == list.end() ? out : (inbuf == buf ? buf2 : buf); @@ -105,11 +108,10 @@ std::size_t ChainResampler::resample(short *const out, const short *const in, st } void ChainResampler::uninit() { - delete[] buffer; - buffer2 = buffer = NULL; - bufferSize = 0; + buffer2 = 0; + buffer.reset(); periodSize = 0; - bigSinc = NULL; + bigSinc = 0; for (list_t::iterator it = list.begin(); it != list.end(); ++it) delete *it; diff --git a/common/resample/src/chainresampler.h b/common/resample/src/chainresampler.h index 9cc2811..c18b93f 100644 --- a/common/resample/src/chainresampler.h +++ b/common/resample/src/chainresampler.h @@ -24,6 +24,7 @@ #include #include #include +#include "array.h" #include "subresampler.h" #include "../resampler.h" #include "upsampler.h" @@ -33,9 +34,8 @@ class ChainResampler : public Resampler { list_t list; SubResampler *bigSinc; - short *buffer; + Array buffer; short *buffer2; - std::size_t bufferSize; std::size_t periodSize; std::size_t maxOut_; @@ -56,14 +56,14 @@ class ChainResampler : public Resampler { template class Sinc> std::size_t downinit(long inRate, long outRate, std::size_t periodSize); - std::size_t reallocateBuffer(); - template class Sinc> std::size_t upinit(long inRate, long outRate, std::size_t periodSize); + std::size_t reallocateBuffer(); + public: enum { channels = 2 }; - ChainResampler() : bigSinc(NULL), buffer(NULL), buffer2(NULL), bufferSize(0), periodSize(0) {} + ChainResampler(); ~ChainResampler() { uninit(); } void adjustRate(long inRate, long outRate); diff --git a/common/resample/src/cic2.h b/common/resample/src/cic2.h index fba871e..8b24e0f 100644 --- a/common/resample/src/cic2.h +++ b/common/resample/src/cic2.h @@ -35,7 +35,7 @@ class Cic2Core { // unsigned bufpos; public: - Cic2Core(const unsigned div = 2) { + explicit Cic2Core(const unsigned div = 2) { reset(div); } @@ -44,7 +44,7 @@ public: void reset(unsigned div); }; -template +template void Cic2Core::reset(const unsigned div) { sum2 = sum1 = 0; prev2 = prev1 = 0; @@ -53,7 +53,7 @@ void Cic2Core::reset(const unsigned div) { // bufpos = div - 1; } -template +template std::size_t Cic2Core::filter(short *out, const short *const in, std::size_t inlen) { // const std::size_t produced = (inlen + div_ - (bufpos + 1)) / div_; const std::size_t produced = (inlen + div_ - nextdivn) / div_; @@ -173,19 +173,19 @@ class Cic2 : public SubResampler { public: enum { MAX_DIV = 64 }; - Cic2(unsigned div); + explicit Cic2(unsigned div); std::size_t resample(short *out, const short *in, std::size_t inlen); unsigned mul() const { return 1; } unsigned div() const { return cics[0].div(); } }; -template +template Cic2::Cic2(const unsigned div) { for (unsigned i = 0; i < channels; ++i) cics[i].reset(div); } -template +template std::size_t Cic2::resample(short *const out, const short *const in, const std::size_t inlen) { std::size_t samplesOut; diff --git a/common/resample/src/cic3.h b/common/resample/src/cic3.h index 27b05ce..06c6eb5 100644 --- a/common/resample/src/cic3.h +++ b/common/resample/src/cic3.h @@ -37,7 +37,7 @@ class Cic3Core { // unsigned bufpos; public: - Cic3Core(const unsigned div = 1) { + explicit Cic3Core(const unsigned div = 1) { reset(div); } @@ -46,7 +46,7 @@ public: void reset(unsigned div); }; -template +template void Cic3Core::reset(const unsigned div) { sum3 = sum2 = sum1 = 0; prev3 = prev2 = prev1 = 0; @@ -55,7 +55,7 @@ void Cic3Core::reset(const unsigned div) { // bufpos = div - 1; } -template +template std::size_t Cic3Core::filter(short *out, const short *const in, std::size_t inlen) { // const std::size_t produced = (inlen + div_ - (bufpos + 1)) / div_; const std::size_t produced = (inlen + div_ - nextdivn) / div_; @@ -210,7 +210,7 @@ public: void reset(unsigned div); }; -template +template void Cic3EvenOddCore::reset(const unsigned div) { sum3 = sum2 = sum1 = 0; prev3 = prev2 = prev1 = 0; @@ -218,7 +218,7 @@ void Cic3EvenOddCore::reset(const unsigned div) { nextdivn = div; } -template +template void Cic3EvenOddCore::filterEven(short *out, const short *s, std::size_t n) { const int mul = getMul(div_); unsigned long sm1 = sum1; @@ -255,7 +255,7 @@ void Cic3EvenOddCore::filterEven(short *out, const short *s, std::size sum3 = sm3; } -template +template void Cic3EvenOddCore::filterOdd(short *out, const short *s, std::size_t n) { const int mul = getMul(div_); unsigned long sm1 = sum1; @@ -297,7 +297,7 @@ void Cic3EvenOddCore::filterOdd(short *out, const short *s, std::size_ sum3 = sm3; } -template +template std::size_t Cic3EvenOddCore::filter(short *out, const short *const in, std::size_t inlen) { short *const outStart = out; const short *s = in; @@ -357,19 +357,19 @@ class Cic3 : public SubResampler { public: enum { MAX_DIV = 23 }; - Cic3(unsigned div); + explicit Cic3(unsigned div); std::size_t resample(short *out, const short *in, std::size_t inlen); unsigned mul() const { return 1; } unsigned div() const { return cics[0].div(); } }; -template +template Cic3::Cic3(const unsigned div) { for (unsigned i = 0; i < channels; ++i) cics[i].reset(div); } -template +template std::size_t Cic3::resample(short *const out, const short *const in, const std::size_t inlen) { std::size_t samplesOut; diff --git a/common/resample/src/cic4.h b/common/resample/src/cic4.h index d81989c..694a50d 100644 --- a/common/resample/src/cic4.h +++ b/common/resample/src/cic4.h @@ -39,7 +39,7 @@ class Cic4Core { unsigned bufpos; public: - Cic4Core(const unsigned div = 1) { + explicit Cic4Core(const unsigned div = 1) { reset(div); } @@ -48,7 +48,7 @@ public: void reset(unsigned div); }; -template +template void Cic4Core::reset(const unsigned div) { sum4 = sum3 = sum2 = sum1 = 0; prev4 = prev3 = prev2 = prev1 = 0; @@ -57,7 +57,7 @@ void Cic4Core::reset(const unsigned div) { bufpos = div - 1; } -template +template std::size_t Cic4Core::filter(short *out, const short *const in, std::size_t inlen) { const std::size_t produced = (inlen + div_ - (bufpos + 1)) / div_; // const std::size_t produced = (inlen + div_ - nextdivn) / div_; @@ -212,19 +212,19 @@ class Cic4 : public SubResampler { public: enum { MAX_DIV = 13 }; - Cic4(unsigned div); + explicit Cic4(unsigned div); std::size_t resample(short *out, const short *in, std::size_t inlen); unsigned mul() const { return 1; } unsigned div() const { return cics[0].div(); } }; -template +template Cic4::Cic4(const unsigned div) { for (unsigned i = 0; i < channels; ++i) cics[i].reset(div); } -template +template std::size_t Cic4::resample(short *const out, const short *const in, const std::size_t inlen) { std::size_t samplesOut; diff --git a/common/resample/src/convoluter.h b/common/resample/src/convoluter.h index ddf95e5..209330f 100644 --- a/common/resample/src/convoluter.h +++ b/common/resample/src/convoluter.h @@ -21,39 +21,36 @@ #include #include +#include "array.h" #include "rshift16_round.h" template class PolyPhaseConvoluter { const short *kernel; - short *prevbuf; + Array prevbuf; - unsigned phaseLen; unsigned div_; unsigned x_; public: - PolyPhaseConvoluter() : kernel(NULL), prevbuf(NULL), phaseLen(0), div_(0), x_(0) {} + PolyPhaseConvoluter() : kernel(0), div_(0), x_(0) {} PolyPhaseConvoluter(const short *kernel, unsigned phaseLen, unsigned div) { reset(kernel, phaseLen, div); } - ~PolyPhaseConvoluter() { delete[] prevbuf; } void reset(const short *kernel, unsigned phaseLen, unsigned div); std::size_t filter(short *out, const short *in, std::size_t inlen); void adjustDiv(const unsigned div) { this->div_ = div; } unsigned div() const { return div_; } }; -template +template void PolyPhaseConvoluter::reset(const short *const kernel, const unsigned phaseLen, const unsigned div) { this->kernel = kernel; - this->phaseLen = phaseLen; this->div_ = div; x_ = 0; - delete[] prevbuf; - prevbuf = new short[phaseLen]; - std::fill(prevbuf, prevbuf + phaseLen, 0); + prevbuf.reset(phaseLen); + std::fill(prevbuf.get(), prevbuf.get() + phaseLen, 0); } -template +template std::size_t PolyPhaseConvoluter::filter(short *out, const short *const in, std::size_t inlen) { if (!kernel || !inlen) return 0; @@ -86,6 +83,7 @@ std::size_t PolyPhaseConvoluter::filter(short *out, const shor } while (--n); }*/ + const std::size_t phaseLen = prevbuf.size(); const std::size_t M = phaseLen * phases - 1; inlen *= phases; std::size_t x = x_; diff --git a/common/resample/src/hammingsinc.h b/common/resample/src/hammingsinc.h index bb50dae..f143cb8 100644 --- a/common/resample/src/hammingsinc.h +++ b/common/resample/src/hammingsinc.h @@ -23,13 +23,14 @@ #include "subresampler.h" #include "makesinckernel.h" #include "cic3.h" +#include "array.h" #include #include template class HammingSinc : public SubResampler { PolyPhaseConvoluter convoluters[channels]; - short *kernel; + Array kernel; static double hammingWin(const long i, const long M) { static const double PI = 3.14159265358979323846; @@ -64,16 +65,15 @@ public: HammingSinc(unsigned div, unsigned phaseLen, double fc) { init(div, phaseLen, fc); } HammingSinc(unsigned div, RollOff ro) { init(div, ro.taps, ro.fc); } - ~HammingSinc() { delete[] kernel; } std::size_t resample(short *out, const short *in, std::size_t inlen); void adjustDiv(unsigned div); unsigned mul() const { return MUL; } unsigned div() const { return convoluters[0].div(); } }; -template +template void HammingSinc::init(const unsigned div, const unsigned phaseLen, const double fc) { - kernel = new short[phaseLen * phases]; + kernel.reset(phaseLen * phases); makeSincKernel(kernel, phases, phaseLen, fc, hammingWin); @@ -81,7 +81,7 @@ void HammingSinc::init(const unsigned div, const unsigned phas convoluters[i].reset(kernel, phaseLen, div); } -template +template std::size_t HammingSinc::resample(short *const out, const short *const in, const std::size_t inlen) { std::size_t samplesOut; @@ -91,7 +91,7 @@ std::size_t HammingSinc::resample(short *const out, const shor return samplesOut; } -template +template void HammingSinc::adjustDiv(const unsigned div) { for (unsigned i = 0; i < channels; ++i) convoluters[i].adjustDiv(div); diff --git a/common/resample/src/kaiser50sinc.h b/common/resample/src/kaiser50sinc.h index 4fcdda2..6cc6a56 100755 --- a/common/resample/src/kaiser50sinc.h +++ b/common/resample/src/kaiser50sinc.h @@ -24,13 +24,14 @@ #include "makesinckernel.h" #include "i0.h" #include "cic3.h" +#include "array.h" #include #include template class Kaiser50Sinc : public SubResampler { PolyPhaseConvoluter convoluters[channels]; - short *kernel; + Array kernel; static double kaiserWin(const long n, const long M) { static const double beta = 4.62; @@ -71,16 +72,15 @@ public: Kaiser50Sinc(unsigned div, unsigned phaseLen, double fc) { init(div, phaseLen, fc); } Kaiser50Sinc(unsigned div, RollOff ro) { init(div, ro.taps, ro.fc); } - ~Kaiser50Sinc() { delete[] kernel; } std::size_t resample(short *out, const short *in, std::size_t inlen); void adjustDiv(unsigned div); unsigned mul() const { return MUL; } unsigned div() const { return convoluters[0].div(); } }; -template +template void Kaiser50Sinc::init(const unsigned div, const unsigned phaseLen, const double fc) { - kernel = new short[phaseLen * phases]; + kernel.reset(phaseLen * phases); makeSincKernel(kernel, phases, phaseLen, fc, kaiserWin); @@ -88,7 +88,7 @@ void Kaiser50Sinc::init(const unsigned div, const unsigned pha convoluters[i].reset(kernel, phaseLen, div); } -template +template std::size_t Kaiser50Sinc::resample(short *const out, const short *const in, const std::size_t inlen) { std::size_t samplesOut; @@ -98,7 +98,7 @@ std::size_t Kaiser50Sinc::resample(short *const out, const sho return samplesOut; } -template +template void Kaiser50Sinc::adjustDiv(const unsigned div) { for (unsigned i = 0; i < channels; ++i) convoluters[i].adjustDiv(div); diff --git a/common/resample/src/kaiser70sinc.h b/common/resample/src/kaiser70sinc.h index 4799103..90b7aa0 100755 --- a/common/resample/src/kaiser70sinc.h +++ b/common/resample/src/kaiser70sinc.h @@ -24,13 +24,14 @@ #include "makesinckernel.h" #include "i0.h" #include "cic4.h" +#include "array.h" #include #include template class Kaiser70Sinc : public SubResampler { PolyPhaseConvoluter convoluters[channels]; - short *kernel; + Array kernel; static double kaiserWin(const long n, const long M) { static const double beta = 6.9; @@ -71,16 +72,15 @@ public: Kaiser70Sinc(unsigned div, unsigned phaseLen, double fc) { init(div, phaseLen, fc); } Kaiser70Sinc(unsigned div, RollOff ro) { init(div, ro.taps, ro.fc); } - ~Kaiser70Sinc() { delete[] kernel; } std::size_t resample(short *out, const short *in, std::size_t inlen); void adjustDiv(unsigned div); unsigned mul() const { return MUL; } unsigned div() const { return convoluters[0].div(); } }; -template +template void Kaiser70Sinc::init(const unsigned div, const unsigned phaseLen, const double fc) { - kernel = new short[phaseLen * phases]; + kernel.reset(phaseLen * phases); makeSincKernel(kernel, phases, phaseLen, fc, kaiserWin); @@ -88,7 +88,7 @@ void Kaiser70Sinc::init(const unsigned div, const unsigned pha convoluters[i].reset(kernel, phaseLen, div); } -template +template std::size_t Kaiser70Sinc::resample(short *const out, const short *const in, const std::size_t inlen) { std::size_t samplesOut; @@ -98,7 +98,7 @@ std::size_t Kaiser70Sinc::resample(short *const out, const sho return samplesOut; } -template +template void Kaiser70Sinc::adjustDiv(const unsigned div) { for (unsigned i = 0; i < channels; ++i) convoluters[i].adjustDiv(div); diff --git a/common/resample/src/linint.h b/common/resample/src/linint.h index 809beb9..ed8064c 100644 --- a/common/resample/src/linint.h +++ b/common/resample/src/linint.h @@ -40,7 +40,7 @@ public: std::size_t resample(short *out, const short *in, std::size_t inlen); }; -template +template void LinintCore::init(const long inRate, const long outRate) { adjustRate(inRate, outRate); pos_ = (ratio >> 16) + 1; @@ -48,7 +48,7 @@ void LinintCore::init(const long inRate, const long outRate) { prevSample_ = 0; } -template +template std::size_t LinintCore::resample(short *const out, const short *const in, const std::size_t inlen) { std::size_t opos = 0; std::size_t pos = pos_; @@ -101,7 +101,7 @@ public: std::size_t resample(short *out, const short *in, std::size_t inlen); }; -template +template Linint::Linint(const long inRate, const long outRate) { setRate(inRate, outRate); @@ -109,7 +109,7 @@ Linint::Linint(const long inRate, const long outRate) { cores[i].init(inRate, outRate); } -template +template void Linint::adjustRate(const long inRate, const long outRate) { setRate(inRate, outRate); @@ -117,7 +117,7 @@ void Linint::adjustRate(const long inRate, const long outRate) { cores[i].adjustRate(inRate, outRate); } -template +template std::size_t Linint::resample(short *const out, const short *const in, const std::size_t inlen) { std::size_t outlen = 0; diff --git a/common/resample/src/makesinckernel.cpp b/common/resample/src/makesinckernel.cpp index 1ab68c6..9a121ba 100755 --- a/common/resample/src/makesinckernel.cpp +++ b/common/resample/src/makesinckernel.cpp @@ -17,13 +17,14 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "makesinckernel.h" +#include "array.h" void makeSincKernel(short *const kernel, const unsigned phases, const unsigned phaseLen, double fc, double (*win)(long m, long M)) { static const double PI = 3.14159265358979323846; fc /= phases; /*{ - double *const dkernel = new double[phaseLen * phases]; + const Array dkernel(phaseLen * phases); const long M = static_cast(phaseLen) * phases - 1; for (long i = 0; i < M + 1; ++i) { @@ -61,15 +62,13 @@ void makeSincKernel(short *const kernel, const unsigned phases, const unsigned p for (long i = 0; i < M + 1; ++i) kernel[i] = std::floor(dkernel[i] * gain + 0.5); - - delete[] dkernel; }*/ // The following is equivalent to the more readable version above const long M = static_cast(phaseLen) * phases - 1; - double *const dkernel = new double[M / 2 + 1]; + const Array dkernel(M / 2 + 1); { double *dk = dkernel; @@ -140,6 +139,4 @@ void makeSincKernel(short *const kernel, const unsigned phases, const unsigned p for (long i = ph; i < M / 2 + 1; i += phases) *km-- = *k++ = std::floor(*dk++ * gain + 0.5); } - - delete[] dkernel; } diff --git a/common/resample/src/rectsinc.h b/common/resample/src/rectsinc.h index 9f99ed6..2f281b3 100644 --- a/common/resample/src/rectsinc.h +++ b/common/resample/src/rectsinc.h @@ -23,13 +23,14 @@ #include "subresampler.h" #include "makesinckernel.h" #include "cic2.h" +#include "array.h" #include #include template class RectSinc : public SubResampler { PolyPhaseConvoluter convoluters[channels]; - short *kernel; + Array kernel; static double rectWin(const long /*i*/, const long /*M*/) { return 1; @@ -63,16 +64,15 @@ public: RectSinc(unsigned div, unsigned phaseLen, double fc) { init(div, phaseLen, fc); } RectSinc(unsigned div, RollOff ro) { init(div, ro.taps, ro.fc); } - ~RectSinc() { delete[] kernel; } std::size_t resample(short *out, const short *in, std::size_t inlen); void adjustDiv(unsigned div); unsigned mul() const { return MUL; } unsigned div() const { return convoluters[0].div(); } }; -template +template void RectSinc::init(const unsigned div, const unsigned phaseLen, const double fc) { - kernel = new short[phaseLen * phases]; + kernel.reset(phaseLen * phases); makeSincKernel(kernel, phases, phaseLen, fc, rectWin); @@ -80,7 +80,7 @@ void RectSinc::init(const unsigned div, const unsigned phaseLe convoluters[i].reset(kernel, phaseLen, div); } -template +template std::size_t RectSinc::resample(short *const out, const short *const in, const std::size_t inlen) { std::size_t samplesOut; @@ -90,7 +90,7 @@ std::size_t RectSinc::resample(short *const out, const short * return samplesOut; } -template +template void RectSinc::adjustDiv(const unsigned div) { for (unsigned i = 0; i < channels; ++i) convoluters[i].adjustDiv(div); diff --git a/common/resample/src/resamplerinfo.cpp b/common/resample/src/resamplerinfo.cpp index 0cf41aa..27fb26f 100644 --- a/common/resample/src/resamplerinfo.cpp +++ b/common/resample/src/resamplerinfo.cpp @@ -39,12 +39,12 @@ struct ChainSincInfo { }; const ResamplerInfo ResamplerInfo::resamplers[] = { - { "2-tap linear interpolation", LinintInfo::create }, - { "Rectangular windowed sinc (~20 dB SNR)", ChainSincInfo::create }, + { "Fast", LinintInfo::create }, + { "High quality (CIC + sinc chain)", ChainSincInfo::create }, // { "Hamming windowed sinc (~50 dB SNR)", ChainSincInfo::create }, // { "Blackman windowed sinc (~70 dB SNR)", ChainSincInfo::create }, - { "Kaiser windowed sinc (~50 dB SNR)", ChainSincInfo::create }, - { "Kaiser windowed sinc (~70 dB SNR)", ChainSincInfo::create } + { "Very high quality (CIC + sinc chain)", ChainSincInfo::create }, + { "Highest quality (CIC + sinc chain)", ChainSincInfo::create } }; const unsigned ResamplerInfo::num_ = sizeof(ResamplerInfo::resamplers) / sizeof(ResamplerInfo); diff --git a/common/resample/src/upsampler.h b/common/resample/src/upsampler.h index 8bf88d8..a56127c 100644 --- a/common/resample/src/upsampler.h +++ b/common/resample/src/upsampler.h @@ -33,7 +33,7 @@ public: unsigned div() const { return 1; } }; -template +template std::size_t Upsampler::resample(short *out, const short *in, std::size_t inlen) { if (inlen) { std::memset(out, 0, inlen * mul_ * sizeof(short) * channels); diff --git a/common/videolink/rgb32conv.cpp b/common/videolink/rgb32conv.cpp index 18d3551..8947cd8 100755 --- a/common/videolink/rgb32conv.cpp +++ b/common/videolink/rgb32conv.cpp @@ -18,7 +18,8 @@ ***************************************************************************/ #include "rgb32conv.h" #include "videolink.h" -#include +#include "array.h" +#include "gbint.h" #include namespace { @@ -36,7 +37,7 @@ class Rgb32ToUyvy { public: Rgb32ToUyvy(); void operator()(const gambatte::uint_least32_t *s, gambatte::uint_least32_t *d, - unsigned w, unsigned h, unsigned srcPitch, unsigned dstPitch); + unsigned w, unsigned h, int srcPitch, int dstPitch); }; Rgb32ToUyvy::Rgb32ToUyvy() { @@ -48,7 +49,9 @@ Rgb32ToUyvy::Rgb32ToUyvy() { std::fill(cache, cache + cache_size, c); } -void Rgb32ToUyvy::operator()(const gambatte::uint_least32_t *s, gambatte::uint_least32_t *d, const unsigned w, unsigned h, const unsigned s_pitch, const unsigned d_pitch) { +void Rgb32ToUyvy::operator()(const gambatte::uint_least32_t *s, + gambatte::uint_least32_t *d, const unsigned w, unsigned h, const int s_pitch, const int d_pitch) +{ while (h--) { unsigned n = w >> 1; @@ -80,13 +83,13 @@ void Rgb32ToUyvy::operator()(const gambatte::uint_least32_t *s, gambatte::uint_l d += 2; } while (--n); - s += s_pitch - w; - d += d_pitch - w; + s += s_pitch - static_cast(w); + d += d_pitch - static_cast(w); } } static void rgb32ToRgb16(const gambatte::uint_least32_t *s, gambatte::uint_least16_t *d, - const unsigned w, unsigned h, const unsigned srcPitch, const unsigned dstPitch) + const unsigned w, unsigned h, const int srcPitch, const int dstPitch) { do { unsigned n = w; @@ -96,41 +99,51 @@ static void rgb32ToRgb16(const gambatte::uint_least32_t *s, gambatte::uint_least ++s; } while (--n); - s += srcPitch - w; - d += dstPitch - w; + s += srcPitch - static_cast(w); + d += dstPitch - static_cast(w); } while (--h); } class Rgb32ToUyvyLink : public VideoLink { + const Array inbuf_; Rgb32ToUyvy rgb32ToUyvy; const unsigned width_; const unsigned height_; public: - Rgb32ToUyvyLink(unsigned width, unsigned height) : - VideoLink(new gambatte::uint_least32_t[width * height], width), - width_(width), height_(height) {} - ~Rgb32ToUyvyLink() { delete[] static_cast(inBuf()); } + Rgb32ToUyvyLink(unsigned width, unsigned height) + : inbuf_(static_cast(width) * height), + width_(width), + height_(height) + { + } - void draw(void *dst, unsigned dstpitch) { - rgb32ToUyvy(static_cast(inBuf()), - static_cast(dst), width_, height_, inPitch(), dstpitch); + virtual void* inBuf() const { return inbuf_; } + virtual int inPitch() const { return width_; } + + virtual void draw(void *dst, int dstpitch) { + rgb32ToUyvy(inbuf_, static_cast(dst), width_, height_, inPitch(), dstpitch); } }; class Rgb32ToRgb16Link : public VideoLink { + const Array inbuf_; const unsigned width_; const unsigned height_; public: - Rgb32ToRgb16Link(unsigned width, unsigned height) : - VideoLink(new gambatte::uint_least32_t[width * height], width), - width_(width), height_(height) {} - ~Rgb32ToRgb16Link() { delete[] static_cast(inBuf()); } + Rgb32ToRgb16Link(unsigned width, unsigned height) + : inbuf_(static_cast(width) * height), + width_(width), + height_(height) + { + } - void draw(void *dst, unsigned dstpitch) { - rgb32ToRgb16(static_cast(inBuf()), - static_cast(dst), width_, height_, inPitch(), dstpitch); + virtual void* inBuf() const { return inbuf_; } + virtual int inPitch() const { return width_; } + + virtual void draw(void *dst, int dstpitch) { + rgb32ToRgb16(inbuf_, static_cast(dst), width_, height_, inPitch(), dstpitch); } }; } diff --git a/common/videolink/vfilterinfo.cpp b/common/videolink/vfilterinfo.cpp index 9285d16..539703a 100755 --- a/common/videolink/vfilterinfo.cpp +++ b/common/videolink/vfilterinfo.cpp @@ -39,10 +39,10 @@ static const VfilterInfo vfinfos[] = { VFINFO("MaxSt's hq3x", MaxStHq3x) }; -unsigned VfilterInfo::numVfilters() { - return (sizeof(vfinfos) / sizeof(VfilterInfo)); +std::size_t VfilterInfo::numVfilters() { + return sizeof(vfinfos) / sizeof(vfinfos[0]); } -const VfilterInfo& VfilterInfo::get(unsigned n) { +const VfilterInfo& VfilterInfo::get(std::size_t n) { return vfinfos[n]; } diff --git a/common/videolink/vfilterinfo.h b/common/videolink/vfilterinfo.h index 14b46c7..57a6e20 100755 --- a/common/videolink/vfilterinfo.h +++ b/common/videolink/vfilterinfo.h @@ -19,6 +19,8 @@ #ifndef VFILTERINFO_H #define VFILTERINFO_H +#include + class VideoLink; struct VfilterInfo { @@ -30,8 +32,8 @@ struct VfilterInfo { unsigned outHeight; VideoLink* (*create)(); - static const VfilterInfo& get(unsigned n); - static unsigned numVfilters(); + static const VfilterInfo& get(std::size_t n); + static std::size_t numVfilters(); }; #endif diff --git a/common/videolink/vfilters/catrom2x.cpp b/common/videolink/vfilters/catrom2x.cpp index cd772f6..23c9a6a 100755 --- a/common/videolink/vfilters/catrom2x.cpp +++ b/common/videolink/vfilters/catrom2x.cpp @@ -17,18 +17,13 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "catrom2x.h" -#include -#include +#include namespace { enum { WIDTH = VfilterInfo::IN_WIDTH }; enum { HEIGHT = VfilterInfo::IN_HEIGHT }; enum { PITCH = WIDTH + 3 }; -static inline gambatte::uint_least32_t* buffer(const Catrom2x *c2x) { - return static_cast(c2x->inBuf()) - (PITCH + 1); -} - struct Colorsum { gambatte::uint_least32_t r, g, b; }; @@ -99,7 +94,7 @@ static void merge_columns(gambatte::uint_least32_t *dest, const Colorsum *sums) } } -static void filter(gambatte::uint_least32_t *dline, const unsigned pitch, const gambatte::uint_least32_t *sline) { +static void filter(gambatte::uint_least32_t *dline, const int pitch, const gambatte::uint_least32_t *sline) { Colorsum sums[PITCH]; for (unsigned h = HEIGHT; h--;) { @@ -165,14 +160,20 @@ static void filter(gambatte::uint_least32_t *dline, const unsigned pitch, const } } -Catrom2x::Catrom2x() : VideoLink((new gambatte::uint_least32_t[(HEIGHT + 3UL) * PITCH]) + (PITCH + 1), PITCH) { - std::memset(buffer(this), 0, (HEIGHT + 3UL) * PITCH * sizeof(gambatte::uint_least32_t)); +Catrom2x::Catrom2x() +: buffer_((HEIGHT + 3UL) * PITCH) +{ + std::fill_n(buffer_.get(), buffer_.size(), 0); } -Catrom2x::~Catrom2x() { - delete[] buffer(this); +void* Catrom2x::inBuf() const { + return buffer_ + PITCH + 1; } -void Catrom2x::draw(void *const dbuffer, const unsigned pitch) { - ::filter(static_cast(dbuffer), pitch, buffer(this) + PITCH); +int Catrom2x::inPitch() const { + return PITCH; +} + +void Catrom2x::draw(void *const dbuffer, const int pitch) { + ::filter(static_cast(dbuffer), pitch, buffer_ + PITCH); } diff --git a/common/videolink/vfilters/catrom2x.h b/common/videolink/vfilters/catrom2x.h index 76b37a2..ac0d53b 100755 --- a/common/videolink/vfilters/catrom2x.h +++ b/common/videolink/vfilters/catrom2x.h @@ -21,15 +21,19 @@ #include "../videolink.h" #include "../vfilterinfo.h" +#include "array.h" +#include "gbint.h" class Catrom2x : public VideoLink { + const Array buffer_; public: enum { OUT_WIDTH = VfilterInfo::IN_WIDTH * 2 }; enum { OUT_HEIGHT = VfilterInfo::IN_HEIGHT * 2 }; Catrom2x(); - ~Catrom2x(); - void draw(void *dst, unsigned dstpitch); + virtual void* inBuf() const; + virtual int inPitch() const; + virtual void draw(void *dst, int dstpitch); }; #endif diff --git a/common/videolink/vfilters/catrom3x.cpp b/common/videolink/vfilters/catrom3x.cpp index e853252..9d854ee 100755 --- a/common/videolink/vfilters/catrom3x.cpp +++ b/common/videolink/vfilters/catrom3x.cpp @@ -17,18 +17,13 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "catrom3x.h" -#include -#include +#include namespace { enum { WIDTH = VfilterInfo::IN_WIDTH }; enum { HEIGHT = VfilterInfo::IN_HEIGHT }; enum { PITCH = WIDTH + 3 }; -static inline gambatte::uint_least32_t* buffer(const Catrom3x *c3x) { - return static_cast(c3x->inBuf()) - (PITCH + 1); -} - struct Colorsum { gambatte::uint_least32_t r, g, b; }; @@ -226,7 +221,7 @@ static void merge_columns(gambatte::uint_least32_t *dest, const Colorsum *sums) } } -static void filter(gambatte::uint_least32_t *dline, const unsigned pitch, const gambatte::uint_least32_t *sline) { +static void filter(gambatte::uint_least32_t *dline, const int pitch, const gambatte::uint_least32_t *sline) { Colorsum sums[PITCH]; for (unsigned h = HEIGHT; h--;) { @@ -331,14 +326,20 @@ static void filter(gambatte::uint_least32_t *dline, const unsigned pitch, const } } -Catrom3x::Catrom3x() : VideoLink((new gambatte::uint_least32_t[(HEIGHT + 3UL) * PITCH]) + (PITCH + 1), PITCH) { - std::memset(buffer(this), 0, (HEIGHT + 3UL) * PITCH * sizeof(gambatte::uint_least32_t)); +Catrom3x::Catrom3x() +: buffer_((HEIGHT + 3UL) * PITCH) +{ + std::fill_n(buffer_.get(), buffer_.size(), 0); } -Catrom3x::~Catrom3x() { - delete[] buffer(this); +void* Catrom3x::inBuf() const { + return buffer_ + PITCH + 1; } -void Catrom3x::draw(void *const dbuffer, const unsigned pitch) { - ::filter(static_cast(dbuffer), pitch, buffer(this) + PITCH); +int Catrom3x::inPitch() const { + return PITCH; +} + +void Catrom3x::draw(void *const dbuffer, const int pitch) { + ::filter(static_cast(dbuffer), pitch, buffer_ + PITCH); } diff --git a/common/videolink/vfilters/catrom3x.h b/common/videolink/vfilters/catrom3x.h index ca15864..5ab0bfd 100755 --- a/common/videolink/vfilters/catrom3x.h +++ b/common/videolink/vfilters/catrom3x.h @@ -21,15 +21,19 @@ #include "../videolink.h" #include "../vfilterinfo.h" +#include "array.h" +#include "gbint.h" class Catrom3x : public VideoLink { + const Array buffer_; public: enum { OUT_WIDTH = VfilterInfo::IN_WIDTH * 3 }; enum { OUT_HEIGHT = VfilterInfo::IN_HEIGHT * 3 }; Catrom3x(); - ~Catrom3x(); - void draw(void *dst, unsigned dstpitch); + virtual void* inBuf() const; + virtual int inPitch() const; + virtual void draw(void *dst, int dstpitch); }; #endif diff --git a/common/videolink/vfilters/kreed2xsai.cpp b/common/videolink/vfilters/kreed2xsai.cpp index 8fababc..d758a95 100755 --- a/common/videolink/vfilters/kreed2xsai.cpp +++ b/common/videolink/vfilters/kreed2xsai.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007 by Sindre Aam�s * + * Copyright (C) 2007 by Sindre Aamås * * aamas@stud.ntnu.no * * * * Copyright (C) 1999 Derek Liauw Kie Fa (Kreed) * @@ -19,8 +19,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "kreed2xsai.h" -#include -#include +#include namespace { @@ -71,8 +70,7 @@ static inline unsigned long qInterpolate(const unsigned long a, const unsigned l } template -static void filter(gambatte::uint_least32_t *dstPtr, const unsigned dstPitch, - const gambatte::uint_least32_t *srcPtr) +static void filter(gambatte::uint_least32_t *dstPtr, const int dstPitch, const gambatte::uint_least32_t *srcPtr) { unsigned h = height; @@ -215,20 +213,22 @@ enum { PITCH = WIDTH + 3 }; enum { BUF_SIZE = (HEIGHT + 3) * PITCH }; enum { BUF_OFFSET = PITCH + 1 }; -static inline gambatte::uint_least32_t* buffer(const Kreed2xSaI *c2x) { - return static_cast(c2x->inBuf()) - BUF_OFFSET; } +Kreed2xSaI::Kreed2xSaI() +: buffer_(BUF_SIZE) +{ + std::fill_n(buffer_.get(), buffer_.size(), 0); } -Kreed2xSaI::Kreed2xSaI() : VideoLink(new gambatte::uint_least32_t[BUF_SIZE] + BUF_OFFSET, PITCH) { - std::memset(buffer(this), 0, BUF_SIZE * sizeof(gambatte::uint_least32_t)); +void* Kreed2xSaI::inBuf() const { + return buffer_ + BUF_OFFSET; } -Kreed2xSaI::~Kreed2xSaI() { - delete[] buffer(this); +int Kreed2xSaI::inPitch() const { + return PITCH; } -void Kreed2xSaI::draw(void *const dbuffer, const unsigned pitch) { - ::filter(static_cast(dbuffer), pitch, buffer(this) + BUF_OFFSET); +void Kreed2xSaI::draw(void *const dbuffer, const int pitch) { + ::filter(static_cast(dbuffer), pitch, buffer_ + BUF_OFFSET); } diff --git a/common/videolink/vfilters/kreed2xsai.h b/common/videolink/vfilters/kreed2xsai.h index 27dba33..5076651 100755 --- a/common/videolink/vfilters/kreed2xsai.h +++ b/common/videolink/vfilters/kreed2xsai.h @@ -21,15 +21,19 @@ #include "../videolink.h" #include "../vfilterinfo.h" +#include "array.h" +#include "gbint.h" class Kreed2xSaI : public VideoLink { + const Array buffer_; public: enum { OUT_WIDTH = VfilterInfo::IN_WIDTH * 2 }; enum { OUT_HEIGHT = VfilterInfo::IN_HEIGHT * 2 }; Kreed2xSaI(); - ~Kreed2xSaI(); - void draw(void *dst, unsigned dstpitch); + virtual void* inBuf() const; + virtual int inPitch() const; + virtual void draw(void *dst, int dstpitch); }; #endif diff --git a/common/videolink/vfilters/maxsthq2x.cpp b/common/videolink/vfilters/maxsthq2x.cpp index 32cbfbc..fb78315 100755 --- a/common/videolink/vfilters/maxsthq2x.cpp +++ b/common/videolink/vfilters/maxsthq2x.cpp @@ -20,8 +20,6 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "maxsthq2x.h" -#include -#include static /*inline*/ unsigned long Interp1(const unsigned long c1, const unsigned long c2) { const unsigned long lowbits = ((c1 & 0x030303) * 3 + (c2 & 0x030303)) & 0x030303; @@ -48,13 +46,13 @@ static /*inline*/ unsigned long Interp7(const unsigned long c1, const unsigned l } static /*inline*/ unsigned long Interp9(unsigned long c1, const unsigned long c2, const unsigned long c3) { - const unsigned lowbits = ((c1 * 2 & 0x070707) + ((c2 & 0x070707) + (c3 & 0x070707)) * 3) & 0x070707; + const unsigned long lowbits = ((c1 * 2 & 0x070707) + ((c2 & 0x070707) + (c3 & 0x070707)) * 3) & 0x070707; return (c1 * 2 + (c2 + c3) * 3 - lowbits) >> 3; } static /*inline*/ unsigned long Interp10(const unsigned long c1, const unsigned long c2, const unsigned long c3) { - const unsigned lowbits = ((c1 & 0x0F0F0F) * 14 + (c2 & 0x0F0F0F) + (c3 & 0x0F0F0F)) & 0x0F0F0F; + const unsigned long lowbits = ((c1 & 0x0F0F0F) * 14 + (c2 & 0x0F0F0F) + (c3 & 0x0F0F0F)) & 0x0F0F0F; return (c1 * 14 + c2 + c3 - lowbits) >> 4; } @@ -119,8 +117,7 @@ static /*inline*/ bool Diff(const unsigned long w1, const unsigned long w2) { } template -static void filter(gambatte::uint_least32_t *pOut, const unsigned dstPitch, - const gambatte::uint_least32_t *pIn) +static void filter(gambatte::uint_least32_t *pOut, const int dstPitch, const gambatte::uint_least32_t *pIn) { unsigned long w[10]; @@ -2836,20 +2833,23 @@ static void filter(gambatte::uint_least32_t *pOut, const unsigned dstPitch, ++pIn; pOut += 2; } - pOut += dstPitch * 2 - Xres * 2; + pOut += dstPitch * 2 - static_cast(Xres * 2); } } -static inline gambatte::uint_least32_t* buffer(const MaxStHq2x *hq2x) { - return static_cast(hq2x->inBuf()); +MaxStHq2x::MaxStHq2x() +: buffer_(VfilterInfo::IN_HEIGHT * VfilterInfo::IN_WIDTH) +{ } -MaxStHq2x::MaxStHq2x() : VideoLink(new gambatte::uint_least32_t[VfilterInfo::IN_HEIGHT * VfilterInfo::IN_WIDTH], VfilterInfo::IN_WIDTH) {} - -MaxStHq2x::~MaxStHq2x() { - delete[] buffer(this); +void* MaxStHq2x::inBuf() const { + return buffer_; } -void MaxStHq2x::draw(void *const dbuffer, const unsigned pitch) { - ::filter(static_cast(dbuffer), pitch, buffer(this)); +int MaxStHq2x::inPitch() const { + return VfilterInfo::IN_WIDTH; +} + +void MaxStHq2x::draw(void *const dbuffer, const int pitch) { + ::filter(static_cast(dbuffer), pitch, buffer_); } diff --git a/common/videolink/vfilters/maxsthq2x.h b/common/videolink/vfilters/maxsthq2x.h index 74325f3..73517b2 100755 --- a/common/videolink/vfilters/maxsthq2x.h +++ b/common/videolink/vfilters/maxsthq2x.h @@ -21,15 +21,19 @@ #include "../videolink.h" #include "../vfilterinfo.h" +#include "array.h" +#include "gbint.h" class MaxStHq2x : public VideoLink { + const Array buffer_; public: enum { OUT_WIDTH = VfilterInfo::IN_WIDTH * 2 }; enum { OUT_HEIGHT = VfilterInfo::IN_HEIGHT * 2 }; MaxStHq2x(); - ~MaxStHq2x(); - void draw(void *dst, unsigned dstpitch); + virtual void* inBuf() const; + virtual int inPitch() const; + virtual void draw(void *dst, int dstpitch); }; #endif diff --git a/common/videolink/vfilters/maxsthq3x.cpp b/common/videolink/vfilters/maxsthq3x.cpp index 4ed09bb..8d9284b 100755 --- a/common/videolink/vfilters/maxsthq3x.cpp +++ b/common/videolink/vfilters/maxsthq3x.cpp @@ -20,8 +20,6 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "maxsthq3x.h" -#include -#include static /*inline*/ unsigned long Interp1(const unsigned long c1, const unsigned long c2) { const unsigned long lowbits = ((c1 & 0x030303) * 3 + (c2 & 0x030303)) & 0x030303; @@ -116,8 +114,7 @@ static /*inline*/ bool Diff(const unsigned long w1, const unsigned long w2) { } template -static void filter(gambatte::uint_least32_t *pOut, const unsigned dstPitch, - const gambatte::uint_least32_t *pIn) +static void filter(gambatte::uint_least32_t *pOut, const int dstPitch, const gambatte::uint_least32_t *pIn) { unsigned long w[10]; @@ -3806,20 +3803,23 @@ static void filter(gambatte::uint_least32_t *pOut, const unsigned dstPitch, ++pIn; pOut += 3; } - pOut += dstPitch * 3 - Xres * 3; + pOut += dstPitch * 3 - static_cast(Xres * 3); } } -static inline gambatte::uint_least32_t* buffer(const MaxStHq3x *hq3x) { - return static_cast(hq3x->inBuf()); +MaxStHq3x::MaxStHq3x() +: buffer_(VfilterInfo::IN_HEIGHT * VfilterInfo::IN_WIDTH) +{ } -MaxStHq3x::MaxStHq3x() : VideoLink(new gambatte::uint_least32_t[VfilterInfo::IN_HEIGHT * VfilterInfo::IN_WIDTH], VfilterInfo::IN_WIDTH) {} - -MaxStHq3x::~MaxStHq3x() { - delete[] buffer(this); +void* MaxStHq3x::inBuf() const { + return buffer_; } -void MaxStHq3x::draw(void *const dbuffer, const unsigned pitch) { - ::filter(static_cast(dbuffer), pitch, buffer(this)); +int MaxStHq3x::inPitch() const { + return VfilterInfo::IN_WIDTH; +} + +void MaxStHq3x::draw(void *const dbuffer, const int pitch) { + ::filter(static_cast(dbuffer), pitch, buffer_); } diff --git a/common/videolink/vfilters/maxsthq3x.h b/common/videolink/vfilters/maxsthq3x.h index ed17777..8f38a01 100755 --- a/common/videolink/vfilters/maxsthq3x.h +++ b/common/videolink/vfilters/maxsthq3x.h @@ -21,15 +21,19 @@ #include "../videolink.h" #include "../vfilterinfo.h" +#include "array.h" +#include "gbint.h" class MaxStHq3x : public VideoLink { + const Array buffer_; public: enum { OUT_WIDTH = VfilterInfo::IN_WIDTH * 3 }; enum { OUT_HEIGHT = VfilterInfo::IN_HEIGHT * 3 }; MaxStHq3x(); - ~MaxStHq3x(); - void draw(void *dst, unsigned dstpitch); + virtual void* inBuf() const; + virtual int inPitch() const; + virtual void draw(void *dst, int dstpitch); }; #endif diff --git a/common/videolink/videolink.h b/common/videolink/videolink.h index ae6bae7..0901132 100755 --- a/common/videolink/videolink.h +++ b/common/videolink/videolink.h @@ -20,15 +20,11 @@ #define VIDEOLINK_H class VideoLink { - void *const inbuf; - const unsigned inpitch; -protected: - VideoLink(void *inbuf, unsigned inpitch) : inbuf(inbuf), inpitch(inpitch) {} public: - void* inBuf() const { return inbuf; } - unsigned inPitch() const { return inpitch; } virtual ~VideoLink() {} - virtual void draw(void *dst, unsigned dstpitch) = 0; + virtual void* inBuf() const = 0; + virtual int inPitch() const = 0; + virtual void draw(void *dst, int dstpitch) = 0; }; #endif diff --git a/gambatte_qt/src/gambattesource.cpp b/gambatte_qt/src/gambattesource.cpp index 44c9f2c..3fd10e6 100644 --- a/gambatte_qt/src/gambattesource.cpp +++ b/gambatte_qt/src/gambattesource.cpp @@ -41,6 +41,7 @@ dpadLeftLast(false) { std::fill(inputState, inputState + 8, false); } +namespace { static const InputDialog::Button constructButtonInfo(InputDialog::Button::Action *action, const char *label, const char *category, int defaultKey = Qt::Key_unknown, int defaultAltKey = Qt::Key_unknown) { InputDialog::Button b = { label: label, category: category, defaultKey: defaultKey, @@ -65,6 +66,7 @@ struct GbDirAct : InputDialog::Button::Action { }; enum { A_BUT, B_BUT, SELECT_BUT, START_BUT, RIGHT_BUT, LEFT_BUT, UP_BUT, DOWN_BUT }; +} InputDialog* GambatteSource::createInputDialog() { std::vector v; diff --git a/gambatte_sdl/src/blitterwrapper.h b/gambatte_sdl/src/blitterwrapper.h index 1eeb95d..b885e1c 100755 --- a/gambatte_sdl/src/blitterwrapper.h +++ b/gambatte_sdl/src/blitterwrapper.h @@ -20,7 +20,7 @@ #define BLITTERWRAPPER_H #include "sdlblitter.h" -#include "int.h" +#include "gbint.h" #include "videolink/videolink.h" #include diff --git a/libgambatte/include/gambatte.h b/libgambatte/include/gambatte.h index d460aee..05634d0 100644 --- a/libgambatte/include/gambatte.h +++ b/libgambatte/include/gambatte.h @@ -20,7 +20,7 @@ #define GAMBATTE_H #include "inputgetter.h" -#include "int.h" +#include "gbint.h" #include namespace gambatte { diff --git a/libgambatte/include/int.h b/libgambatte/include/gbint.h similarity index 100% rename from libgambatte/include/int.h rename to libgambatte/include/gbint.h diff --git a/libgambatte/src/bitmap_font.h b/libgambatte/src/bitmap_font.h index a92d4ef..35b29fa 100644 --- a/libgambatte/src/bitmap_font.h +++ b/libgambatte/src/bitmap_font.h @@ -19,7 +19,7 @@ #ifndef BITMAP_FONT_H #define BITMAP_FONT_H -#include "int.h" +#include "gbint.h" namespace bitmapfont { enum Char { diff --git a/libgambatte/src/cpu.h b/libgambatte/src/cpu.h index bb3f099..e94f099 100644 --- a/libgambatte/src/cpu.h +++ b/libgambatte/src/cpu.h @@ -19,7 +19,6 @@ #ifndef CPU_H #define CPU_H -#include "int.h" #include "memory.h" namespace gambatte { diff --git a/libgambatte/src/memory.cpp b/libgambatte/src/memory.cpp index d1541c6..e87f968 100644 --- a/libgambatte/src/memory.cpp +++ b/libgambatte/src/memory.cpp @@ -25,17 +25,17 @@ namespace gambatte { -Memory::Memory(const Interrupter &interrupter_in) : -vrambank(vram), -getInput(0), -divLastUpdate(0), -lastOamDmaUpdate(DISABLED_TIME), -display(ioamhram, vram, VideoInterruptRequester(&intreq)), -interrupter(interrupter_in), -dmaSource(0), -dmaDestination(0), -oamDmaPos(0xFE), -blanklcd(false) +Memory::Memory(const Interrupter &interrupter_in) +: vrambank(vram), + getInput(0), + divLastUpdate(0), + lastOamDmaUpdate(DISABLED_TIME), + display(ioamhram, vram, VideoInterruptRequester(&intreq)), + interrupter(interrupter_in), + dmaSource(0), + dmaDestination(0), + oamDmaPos(0xFE), + blanklcd(false) { intreq.setEventTime(144*456ul); intreq.setEventTime(0); @@ -758,7 +758,7 @@ void Memory::nontrivial_ff_write(const unsigned P, unsigned data, const unsigned if (data & 0x80) { intreq.setEventTime(display.nextMode1IrqTime() + (blanklcd ? 0 : 70224 << isDoubleSpeed())); } else { - ioamhram[0x141] |= lyc; //Mr. Do! needs conicidence flag preserved. + ioamhram[0x141] |= lyc; intreq.setEventTime(cycleCounter + (456 * 4 << isDoubleSpeed())); if (hdmaEnabled) diff --git a/libgambatte/src/memory.h b/libgambatte/src/memory.h index 26727ba..19689c0 100644 --- a/libgambatte/src/memory.h +++ b/libgambatte/src/memory.h @@ -20,7 +20,6 @@ #define MEMORY_H #include "mem/cartridge.h" -#include "int.h" #include "video.h" #include "sound.h" #include "interrupter.h" diff --git a/libgambatte/src/osd_element.h b/libgambatte/src/osd_element.h index a2f2442..722d3f0 100644 --- a/libgambatte/src/osd_element.h +++ b/libgambatte/src/osd_element.h @@ -19,7 +19,7 @@ #ifndef OSD_ELEMENT_H #define OSD_ELEMENT_H -#include "int.h" +#include "gbint.h" namespace gambatte { diff --git a/libgambatte/src/sound.h b/libgambatte/src/sound.h index de9f2ac..71d5cdc 100644 --- a/libgambatte/src/sound.h +++ b/libgambatte/src/sound.h @@ -19,7 +19,6 @@ #ifndef SOUND_H #define SOUND_H -#include "int.h" #include "sound/channel1.h" #include "sound/channel2.h" #include "sound/channel3.h" diff --git a/libgambatte/src/sound/channel1.h b/libgambatte/src/sound/channel1.h index 942c444..e42cf38 100644 --- a/libgambatte/src/sound/channel1.h +++ b/libgambatte/src/sound/channel1.h @@ -19,7 +19,7 @@ #ifndef SOUND_CHANNEL1_H #define SOUND_CHANNEL1_H -#include "int.h" +#include "gbint.h" #include "master_disabler.h" #include "length_counter.h" #include "duty_unit.h" diff --git a/libgambatte/src/sound/channel2.h b/libgambatte/src/sound/channel2.h index 2b477ea..a0df882 100644 --- a/libgambatte/src/sound/channel2.h +++ b/libgambatte/src/sound/channel2.h @@ -19,7 +19,7 @@ #ifndef SOUND_CHANNEL2_H #define SOUND_CHANNEL2_H -#include "int.h" +#include "gbint.h" #include "length_counter.h" #include "duty_unit.h" #include "envelope_unit.h" diff --git a/libgambatte/src/sound/channel3.h b/libgambatte/src/sound/channel3.h index 4fb2edf..2a93d9d 100644 --- a/libgambatte/src/sound/channel3.h +++ b/libgambatte/src/sound/channel3.h @@ -19,7 +19,7 @@ #ifndef SOUND_CHANNEL3_H #define SOUND_CHANNEL3_H -#include "int.h" +#include "gbint.h" #include "master_disabler.h" #include "length_counter.h" diff --git a/libgambatte/src/sound/channel4.h b/libgambatte/src/sound/channel4.h index 7f7dcec..d428062 100644 --- a/libgambatte/src/sound/channel4.h +++ b/libgambatte/src/sound/channel4.h @@ -19,7 +19,7 @@ #ifndef SOUND_CHANNEL4_H #define SOUND_CHANNEL4_H -#include "int.h" +#include "gbint.h" #include "master_disabler.h" #include "length_counter.h" #include "envelope_unit.h" diff --git a/libgambatte/src/statesaver.cpp b/libgambatte/src/statesaver.cpp index 74682f1..0c57066 100644 --- a/libgambatte/src/statesaver.cpp +++ b/libgambatte/src/statesaver.cpp @@ -437,7 +437,7 @@ bool StateSaver::loadState(SaveState &state, const std::string &filename) { file.ignore(); file.ignore(get24(file)); - Array labelbuf(list.maxLabelsize()); + const Array labelbuf(list.maxLabelsize()); const Saver labelbufSaver = { label: labelbuf, save: 0, load: 0, labelsize: list.maxLabelsize() }; SaverList::const_iterator done = list.begin(); diff --git a/libgambatte/src/statesaver.h b/libgambatte/src/statesaver.h index 7bea5c1..013caae 100644 --- a/libgambatte/src/statesaver.h +++ b/libgambatte/src/statesaver.h @@ -19,7 +19,7 @@ #ifndef STATESAVER_H #define STATESAVER_H -#include "int.h" +#include "gbint.h" #include namespace gambatte { diff --git a/libgambatte/src/video/ppu.h b/libgambatte/src/video/ppu.h index a0ef945..f48c922 100644 --- a/libgambatte/src/video/ppu.h +++ b/libgambatte/src/video/ppu.h @@ -21,7 +21,7 @@ #include "video/ly_counter.h" #include "video/sprite_mapper.h" -#include "int.h" +#include "gbint.h" namespace gambatte {