From f905623d103bd3b4287630a5ead62fe48407e42a Mon Sep 17 00:00:00 2001 From: Abhi Date: Tue, 16 Sep 2014 17:53:18 -0400 Subject: [PATCH 1/3] added StkFrames::copyChannel --- include/Stk.h | 8 ++++++++ src/Stk.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/Stk.h b/include/Stk.h index 7a050d4..dfe5b40 100644 --- a/include/Stk.h +++ b/include/Stk.h @@ -373,6 +373,14 @@ public: */ void resize( size_t nFrames, unsigned int nChannels, StkFloat value ); + //! Copies a single channel + /*! + Copies the \c sourceChannel into \c destination's \c destinationChannel. \c destinationChannel must be between 0 and destination.channels() - 1 and + sourceChannel must be between 0 and channels() - 1. destination.frames() must be >= frames(). + No range checking is performed unless _STK_DEBUG_ is defined. + */ + StkFrames& copyChannel(unsigned int sourceChannel,StkFrames& destinationFrames, unsigned int destinationChannel) const; + //! Return the number of channels represented by the data. unsigned int channels( void ) const { return nChannels_; }; diff --git a/src/Stk.cpp b/src/Stk.cpp index 02079b3..7a2cf57 100644 --- a/src/Stk.cpp +++ b/src/Stk.cpp @@ -316,6 +316,34 @@ void StkFrames :: resize( size_t nFrames, unsigned int nChannels, StkFloat value for ( size_t i=0; i channels() - 1) { + std::ostringstream error; + error << "StkFrames::copyChannel invalid sourceChannel (" << sourceChannel << ")"; + Stk::handleError( error.str(), StkError::FUNCTION_ARGUMENT); + } + if (destinationChannel > destinationFrames.channels() - 1) { + std::ostringstream error; + error << "StkFrames::copyChannel invalid destinationChannel (" << destinationChannel << ")"; + Stk::handleError( error.str(), StkError::FUNCTION_ARGUMENT ); + } + if (destinationFrames.frames() < frames()) { + std::ostringstream error; + error << "StkFrames::copyChannel destination.frames() < frames()"; + Stk::handleError( error.str(), StkError::MEMORY_ACCESS); + } +#endif + int sourceHop = nChannels_; + int destinationHop = destinationFrames.nChannels_; + for (int i = sourceChannel, j= destinationChannel; i < nFrames_ * nChannels_; i+=sourceHop,j+=destinationHop) { + destinationFrames[j] = data_[i]; + } + return destinationFrames; + +} StkFloat StkFrames :: interpolate( StkFloat frame, unsigned int channel ) const { From a2fb59f4760be991bde7187a1636a3821d69b29b Mon Sep 17 00:00:00 2001 From: Abhi Date: Tue, 16 Sep 2014 17:57:30 -0400 Subject: [PATCH 2/3] Fixed spelling --- include/Stk.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Stk.h b/include/Stk.h index dfe5b40..d0d15d5 100644 --- a/include/Stk.h +++ b/include/Stk.h @@ -375,7 +375,7 @@ public: //! Copies a single channel /*! - Copies the \c sourceChannel into \c destination's \c destinationChannel. \c destinationChannel must be between 0 and destination.channels() - 1 and + Copies the \c sourceChannel into \c destinationFrames's \c destinationChannel. \c destinationChannel must be between 0 and destination.channels() - 1 and sourceChannel must be between 0 and channels() - 1. destination.frames() must be >= frames(). No range checking is performed unless _STK_DEBUG_ is defined. */ From 6094f403991998d586730b5cc0aad90b7bad1a16 Mon Sep 17 00:00:00 2001 From: Abhi Date: Tue, 16 Sep 2014 19:24:29 -0400 Subject: [PATCH 3/3] renamed argument sourceChannel to channel --- include/Stk.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/Stk.h b/include/Stk.h index d0d15d5..9e753b0 100644 --- a/include/Stk.h +++ b/include/Stk.h @@ -375,11 +375,11 @@ public: //! Copies a single channel /*! - Copies the \c sourceChannel into \c destinationFrames's \c destinationChannel. \c destinationChannel must be between 0 and destination.channels() - 1 and - sourceChannel must be between 0 and channels() - 1. destination.frames() must be >= frames(). + Copies the specified \c channel into \c destinationFrames's \c destinationChannel. \c destinationChannel must be between 0 and destination.channels() - 1 and + \c channel must be between 0 and channels() - 1. destination.frames() must be >= frames(). No range checking is performed unless _STK_DEBUG_ is defined. */ - StkFrames& copyChannel(unsigned int sourceChannel,StkFrames& destinationFrames, unsigned int destinationChannel) const; + StkFrames& copyChannel(unsigned int channel,StkFrames& destinationFrames, unsigned int destinationChannel) const; //! Return the number of channels represented by the data. unsigned int channels( void ) const { return nChannels_; };