From 032e76da70f30560bee14003dadadb2f3e08ab66 Mon Sep 17 00:00:00 2001 From: Abhi Date: Sun, 21 Sep 2014 18:06:47 -0400 Subject: [PATCH] add StkFrames::operator+ --- include/Stk.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/Stk.h b/include/Stk.h index 9e753b0..3c3a222 100644 --- a/include/Stk.h +++ b/include/Stk.h @@ -303,6 +303,14 @@ public: checking is performed unless _STK_DEBUG_ is defined. */ StkFloat operator[] ( size_t n ) const; + + //! Sum operator + /*! + The dimensions of the argument are expected to be the same as + self. No range checking is performed unless _STK_DEBUG_ is + defined. + */ + StkFrames operator+(const StkFrames &frames) const; //! Assignment by sum operator into self. /*! @@ -469,6 +477,25 @@ inline StkFloat StkFrames :: operator() ( size_t frame, unsigned int channel ) c return data_[ frame * nChannels_ + channel ]; } + +inline StkFrames StkFrames::operator+(const StkFrames &f) const +{ +#if defined(_STK_DEBUG_) + if ( f.frames() != nFrames_ || f.channels() != nChannels_ ) { + std::ostringstream error; + error << "StkFrames::operator+: frames argument must be of equal dimensions!"; + Stk::handleError( error.str(), StkError::MEMORY_ACCESS ); + } +#endif + StkFrames sum(nFrames_,nChannels_); + StkFloat *sumPtr = &sum[0]; + const StkFloat *fptr = f.data_; + const StkFloat *dPtr = data_; + for (unsigned int i = 0; i < size_; i++) { + *sumPtr++ = *fptr++ + *dPtr++; + } + return sum; +} inline void StkFrames :: operator+= ( StkFrames& f ) {