mirror of
https://github.com/thestk/stk
synced 2026-02-07 09:46:16 +00:00
Merge pull request #35 from Ahbee/copychannel
adds function StkFrames::copyChannel
This commit is contained in:
@@ -373,6 +373,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
void resize( size_t nFrames, unsigned int nChannels, StkFloat value );
|
void resize( size_t nFrames, unsigned int nChannels, StkFloat value );
|
||||||
|
|
||||||
|
//! Copies a single channel
|
||||||
|
/*!
|
||||||
|
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 channel,StkFrames& destinationFrames, unsigned int destinationChannel) const;
|
||||||
|
|
||||||
//! Return the number of channels represented by the data.
|
//! Return the number of channels represented by the data.
|
||||||
unsigned int channels( void ) const { return nChannels_; };
|
unsigned int channels( void ) const { return nChannels_; };
|
||||||
|
|
||||||
|
|||||||
28
src/Stk.cpp
28
src/Stk.cpp
@@ -316,6 +316,34 @@ void StkFrames :: resize( size_t nFrames, unsigned int nChannels, StkFloat value
|
|||||||
|
|
||||||
for ( size_t i=0; i<size_; i++ ) data_[i] = value;
|
for ( size_t i=0; i<size_; i++ ) data_[i] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StkFrames& StkFrames::copyChannel(unsigned int sourceChannel,StkFrames& destinationFrames, unsigned int destinationChannel) const
|
||||||
|
{
|
||||||
|
#if defined(_STK_DEBUG_)
|
||||||
|
if (sourceChannel > 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
|
StkFloat StkFrames :: interpolate( StkFloat frame, unsigned int channel ) const
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user