mirror of
https://github.com/thestk/stk
synced 2026-01-11 20:11:52 +00:00
Merge pull request #37 from Ahbee/feature-operator+
add StkFrames::operator+
This commit is contained in:
@@ -304,6 +304,14 @@ public:
|
||||
*/
|
||||
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.
|
||||
/*!
|
||||
The dimensions of the argument are expected to be the same as
|
||||
@@ -478,6 +486,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 )
|
||||
{
|
||||
#if defined(_STK_DEBUG_)
|
||||
|
||||
Reference in New Issue
Block a user