From 35f66c806e64f5369299c8d2325fbce10f2e8df5 Mon Sep 17 00:00:00 2001 From: Gary Scavone Date: Mon, 3 Nov 2014 15:33:44 -0500 Subject: [PATCH] Bugfix in DelayL::setDelay(); Updated tick() functions in RtWvIn and InetWvIn to support channel offset --- include/DelayL.h | 27 +++++++++++++++++++++++++++ include/FileWvIn.h | 2 +- include/InetWvIn.h | 15 ++++++++------- include/RtWvIn.h | 15 ++++++++------- src/DelayL.cpp | 24 ------------------------ src/FileWvIn.cpp | 4 ++-- src/InetWvIn.cpp | 13 +++++++------ src/RtWvIn.cpp | 20 +++++++++++++++----- 8 files changed, 68 insertions(+), 52 deletions(-) diff --git a/include/DelayL.h b/include/DelayL.h index f7e7d01..0b1809b 100644 --- a/include/DelayL.h +++ b/include/DelayL.h @@ -133,6 +133,33 @@ inline StkFloat DelayL :: nextOut( void ) return nextOutput_; } +inline void DelayL :: setDelay( StkFloat delay ) +{ + if ( delay + 1 > inputs_.size() ) { // The value is too big. + oStream_ << "DelayL::setDelay: argument (" << delay << ") greater than maximum!"; + handleError( StkError::WARNING ); return; + } + + if (delay < 0 ) { + oStream_ << "DelayL::setDelay: argument (" << delay << ") less than zero!"; + handleError( StkError::WARNING ); return; + } + + StkFloat outPointer = inPoint_ - delay; // read chases write + delay_ = delay; + + while ( outPointer < 0 ) + outPointer += inputs_.size(); // modulo maximum length + + outPoint_ = (long) outPointer; // integer part + + alpha_ = outPointer - outPoint_; // fractional part + omAlpha_ = (StkFloat) 1.0 - alpha_; + + if ( outPoint_ == inputs_.size() ) outPoint_ = 0; + doNextOut_ = true; +} + inline StkFloat DelayL :: tick( StkFloat input ) { inputs_[inPoint_++] = input * gain_; diff --git a/include/FileWvIn.h b/include/FileWvIn.h index c05495b..edb112c 100644 --- a/include/FileWvIn.h +++ b/include/FileWvIn.h @@ -152,7 +152,7 @@ public: //! Fill the StkFrames object with computed sample frames, starting at the specified channel and return the same reference. /*! - The \c channel argument plus the number of output channels must + The \c channel argument plus the number of input channels must be less than the number of channels in the StkFrames argument (the first channel is specified by 0). However, range checking is only performed if _STK_DEBUG_ is defined during compilation, in which diff --git a/include/InetWvIn.h b/include/InetWvIn.h index 3a07ced..a899d4e 100644 --- a/include/InetWvIn.h +++ b/include/InetWvIn.h @@ -96,17 +96,18 @@ public: */ StkFloat tick( unsigned int channel = 0 ); - //! Fill the StkFrames argument with computed frames and return the same reference. + //! Fill the StkFrames object with computed sample frames, starting at the specified channel and return the same reference. /*! - The number of channels in the StkFrames argument must equal the - number of channels specified in the listen() function. However, - this is only checked if _STK_DEBUG_ is defined during compilation, - in which case an incompatibility will trigger an StkError - exception. If no connection exists, the function does + The \c channel argument plus the number of channels specified + in the listen() function must be less than the number of channels + in the StkFrames argument (the first channel is specified by 0). + However, this is only checked if _STK_DEBUG_ is defined during + compilation, in which case an incompatibility will trigger an + StkError exception. If no connection exists, the function does nothing (a warning will be issued if _STK_DEBUG_ is defined during compilation). */ - StkFrames& tick( StkFrames& frames ); + StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ); // Called by the thread routine to receive data via the socket connection // and fill the socket buffer. This is not intended for general use but diff --git a/include/RtWvIn.h b/include/RtWvIn.h index e837622..24e8e54 100644 --- a/include/RtWvIn.h +++ b/include/RtWvIn.h @@ -83,15 +83,16 @@ public: */ StkFloat tick( unsigned int channel = 0 ); - //! Fill the StkFrames argument with computed frames and return the same reference. + //! Fill the StkFrames object with computed sample frames, starting at the specified channel and return the same reference. /*! - If the device is "stopped", it is "started". The number of - channels in the StkFrames argument must equal the number of - channels specified during instantiation. However, this is only - checked if _STK_DEBUG_ is defined during compilation, in which - case an incompatibility will trigger an StkError exception. + If the device is "stopped", it is "started". The \c channel + argument plus the number of input channels must be less than the + number of channels in the StkFrames argument (the first channel is + specified by 0). However, range checking is only performed if + _STK_DEBUG_ is defined during compilation, in which case an + out-of-range value will trigger an StkError exception. */ - StkFrames& tick( StkFrames& frames ); + StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ); // This function is not intended for general use but must be // public for access from the audio callback function. diff --git a/src/DelayL.cpp b/src/DelayL.cpp index 7990bb7..2c4ea52 100644 --- a/src/DelayL.cpp +++ b/src/DelayL.cpp @@ -52,30 +52,6 @@ void DelayL :: setMaximumDelay( unsigned long delay ) inputs_.resize(delay + 1, 1, 0.0); } -void DelayL :: setDelay( StkFloat delay ) -{ - if ( delay + 1 > inputs_.size() ) { // The value is too big. - oStream_ << "DelayL::setDelay: argument (" << delay << ") greater than maximum!"; - handleError( StkError::WARNING ); return; - } - - if (delay < 0 ) { - oStream_ << "DelayL::setDelay: argument (" << delay << ") less than zero!"; - handleError( StkError::WARNING ); return; - } - - StkFloat outPointer = inPoint_ - delay; // read chases write - delay_ = delay; - - while ( outPointer < 0 ) - outPointer += inputs_.size(); // modulo maximum length - - outPoint_ = (long) outPointer; // integer part - if ( outPoint_ == inputs_.size() ) outPoint_ = 0; - alpha_ = outPointer - outPoint_; // fractional part - omAlpha_ = (StkFloat) 1.0 - alpha_; -} - StkFloat DelayL :: tapOut( unsigned long tapDelay ) { long tap = inPoint_ - tapDelay - 1; diff --git a/src/FileWvIn.cpp b/src/FileWvIn.cpp index 34fd0c9..280d33f 100644 --- a/src/FileWvIn.cpp +++ b/src/FileWvIn.cpp @@ -245,14 +245,14 @@ StkFrames& FileWvIn :: tick( StkFrames& frames, unsigned int channel) if ( nChannels == 1 ) { for ( unsigned int i=0; i frames.channels() - data_.channels() ) { + oStream_ << "InetWvIn::tick(): channel and StkFrames arguments are incompatible!"; handleError( StkError::FUNCTION_ARGUMENT ); } #endif @@ -306,11 +306,12 @@ StkFrames& InetWvIn :: tick( StkFrames& frames ) return frames; } - unsigned int j, counter = 0; - for ( unsigned int i=0; itick(); for ( j=0; j frames.channels() - nChannels ) { + oStream_ << "RtWvIn::tick(): channel and StkFrames arguments are incompatible!"; handleError( StkError::FUNCTION_ARGUMENT ); } #endif @@ -173,7 +173,17 @@ StkFrames& RtWvIn :: tick( StkFrames& frames ) nFrames = frames.frames() - framesRead; bytes = nFrames * nChannels * sizeof( StkFloat ); StkFloat *samples = &data_[readIndex_ * nChannels]; - memcpy( &frames[framesRead * nChannels], samples, bytes ); + unsigned int hop = frames.channels() - nChannels; + if ( hop == 0 ) + memcpy( &frames[framesRead * nChannels], samples, bytes ); + else { + StkFloat *fSamples = &frames[channel]; + unsigned int j; + for ( unsigned int i=0; i