Bugfix in DelayL::setDelay(); Updated tick() functions in RtWvIn and InetWvIn to support channel offset

This commit is contained in:
Gary Scavone
2014-11-03 15:33:44 -05:00
parent 0a7c541cdc
commit 35f66c806e
8 changed files with 68 additions and 52 deletions

View File

@@ -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_;

View File

@@ -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

View File

@@ -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

View File

@@ -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.

View File

@@ -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;

View File

@@ -288,11 +288,11 @@ StkFloat InetWvIn :: tick( unsigned int channel )
return lastFrame_[channel];
}
StkFrames& InetWvIn :: tick( StkFrames& frames )
StkFrames& InetWvIn :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( data_.channels() != frames.channels() ) {
oStream_ << "InetWvIn::tick(): StkFrames argument is incompatible with streamed channels!";
if ( channel > 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; i<frames.frames(); i++ ) {
StkFloat *samples = &frames[channel];
unsigned int j, hop = frames.channels() - data_.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
this->tick();
for ( j=0; j<lastFrame_.channels(); j++ )
frames[counter++] = lastFrame_[j];
*samples++ = lastFrame_[j];
}
return frames;

View File

@@ -145,12 +145,12 @@ StkFloat RtWvIn :: tick( unsigned int channel )
return lastFrame_[channel];
}
StkFrames& RtWvIn :: tick( StkFrames& frames )
StkFrames& RtWvIn :: tick( StkFrames& frames, unsigned int channel )
{
unsigned int nChannels = lastFrame_.channels();
#if defined(_STK_DEBUG_)
if ( nChannels != frames.channels() ) {
oStream_ << "RtWvIn::tick(): StkFrames argument is incompatible with adc channels!";
if ( channel > 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];
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<frames.frames(); i++, fSamples += hop ) {
for ( j=1; j<nChannels; j++ )
*fSamples++ = *samples++;
}
}
readIndex_ += nFrames;
if ( readIndex_ == data_.frames() ) readIndex_ = 0;
@@ -186,7 +196,7 @@ StkFrames& RtWvIn :: tick( StkFrames& frames )
unsigned long index = (frames.frames() - 1) * nChannels;
for ( unsigned int i=0; i<lastFrame_.size(); i++ )
lastFrame_[i] = frames[index++];
lastFrame_[i] = frames[channel+index++];
return frames;
}