mirror of
https://github.com/thestk/stk
synced 2026-02-04 00:26:15 +00:00
Bugfix in DelayL::setDelay(); Updated tick() functions in RtWvIn and InetWvIn to support channel offset
This commit is contained in:
@@ -133,6 +133,33 @@ inline StkFloat DelayL :: nextOut( void )
|
|||||||
return nextOutput_;
|
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 )
|
inline StkFloat DelayL :: tick( StkFloat input )
|
||||||
{
|
{
|
||||||
inputs_[inPoint_++] = input * gain_;
|
inputs_[inPoint_++] = input * gain_;
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ public:
|
|||||||
|
|
||||||
//! Fill the StkFrames object with computed sample frames, starting at the specified channel and return the same reference.
|
//! 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
|
be less than the number of channels in the StkFrames argument (the
|
||||||
first channel is specified by 0). However, range checking is only
|
first channel is specified by 0). However, range checking is only
|
||||||
performed if _STK_DEBUG_ is defined during compilation, in which
|
performed if _STK_DEBUG_ is defined during compilation, in which
|
||||||
|
|||||||
@@ -96,17 +96,18 @@ public:
|
|||||||
*/
|
*/
|
||||||
StkFloat tick( unsigned int channel = 0 );
|
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
|
The \c channel argument plus the number of channels specified
|
||||||
number of channels specified in the listen() function. However,
|
in the listen() function must be less than the number of channels
|
||||||
this is only checked if _STK_DEBUG_ is defined during compilation,
|
in the StkFrames argument (the first channel is specified by 0).
|
||||||
in which case an incompatibility will trigger an StkError
|
However, this is only checked if _STK_DEBUG_ is defined during
|
||||||
exception. If no connection exists, the function does
|
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
|
nothing (a warning will be issued if _STK_DEBUG_ is defined during
|
||||||
compilation).
|
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
|
// 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
|
// and fill the socket buffer. This is not intended for general use but
|
||||||
|
|||||||
@@ -83,15 +83,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
StkFloat tick( unsigned int channel = 0 );
|
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
|
If the device is "stopped", it is "started". The \c channel
|
||||||
channels in the StkFrames argument must equal the number of
|
argument plus the number of input channels must be less than the
|
||||||
channels specified during instantiation. However, this is only
|
number of channels in the StkFrames argument (the first channel is
|
||||||
checked if _STK_DEBUG_ is defined during compilation, in which
|
specified by 0). However, range checking is only performed if
|
||||||
case an incompatibility will trigger an StkError exception.
|
_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
|
// This function is not intended for general use but must be
|
||||||
// public for access from the audio callback function.
|
// public for access from the audio callback function.
|
||||||
|
|||||||
@@ -52,30 +52,6 @@ void DelayL :: setMaximumDelay( unsigned long delay )
|
|||||||
inputs_.resize(delay + 1, 1, 0.0);
|
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 )
|
StkFloat DelayL :: tapOut( unsigned long tapDelay )
|
||||||
{
|
{
|
||||||
long tap = inPoint_ - tapDelay - 1;
|
long tap = inPoint_ - tapDelay - 1;
|
||||||
|
|||||||
@@ -245,14 +245,14 @@ StkFrames& FileWvIn :: tick( StkFrames& frames, unsigned int channel)
|
|||||||
if ( nChannels == 1 ) {
|
if ( nChannels == 1 ) {
|
||||||
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
|
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
|
||||||
*samples++ = tick();
|
*samples++ = tick();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
|
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
|
||||||
*samples++ = tick();
|
*samples++ = tick();
|
||||||
for ( j=1; j<nChannels; j++ )
|
for ( j=1; j<nChannels; j++ )
|
||||||
*samples++ = lastFrame_[j];
|
*samples++ = lastFrame_[j];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return frames;
|
return frames;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -288,11 +288,11 @@ StkFloat InetWvIn :: tick( unsigned int channel )
|
|||||||
return lastFrame_[channel];
|
return lastFrame_[channel];
|
||||||
}
|
}
|
||||||
|
|
||||||
StkFrames& InetWvIn :: tick( StkFrames& frames )
|
StkFrames& InetWvIn :: tick( StkFrames& frames, unsigned int channel )
|
||||||
{
|
{
|
||||||
#if defined(_STK_DEBUG_)
|
#if defined(_STK_DEBUG_)
|
||||||
if ( data_.channels() != frames.channels() ) {
|
if ( channel > frames.channels() - data_.channels() ) {
|
||||||
oStream_ << "InetWvIn::tick(): StkFrames argument is incompatible with streamed channels!";
|
oStream_ << "InetWvIn::tick(): channel and StkFrames arguments are incompatible!";
|
||||||
handleError( StkError::FUNCTION_ARGUMENT );
|
handleError( StkError::FUNCTION_ARGUMENT );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -306,11 +306,12 @@ StkFrames& InetWvIn :: tick( StkFrames& frames )
|
|||||||
return frames;
|
return frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int j, counter = 0;
|
StkFloat *samples = &frames[channel];
|
||||||
for ( unsigned int i=0; i<frames.frames(); i++ ) {
|
unsigned int j, hop = frames.channels() - data_.channels();
|
||||||
|
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
|
||||||
this->tick();
|
this->tick();
|
||||||
for ( j=0; j<lastFrame_.channels(); j++ )
|
for ( j=0; j<lastFrame_.channels(); j++ )
|
||||||
frames[counter++] = lastFrame_[j];
|
*samples++ = lastFrame_[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
return frames;
|
return frames;
|
||||||
|
|||||||
@@ -145,12 +145,12 @@ StkFloat RtWvIn :: tick( unsigned int channel )
|
|||||||
return lastFrame_[channel];
|
return lastFrame_[channel];
|
||||||
}
|
}
|
||||||
|
|
||||||
StkFrames& RtWvIn :: tick( StkFrames& frames )
|
StkFrames& RtWvIn :: tick( StkFrames& frames, unsigned int channel )
|
||||||
{
|
{
|
||||||
unsigned int nChannels = lastFrame_.channels();
|
unsigned int nChannels = lastFrame_.channels();
|
||||||
#if defined(_STK_DEBUG_)
|
#if defined(_STK_DEBUG_)
|
||||||
if ( nChannels != frames.channels() ) {
|
if ( channel > frames.channels() - nChannels ) {
|
||||||
oStream_ << "RtWvIn::tick(): StkFrames argument is incompatible with adc channels!";
|
oStream_ << "RtWvIn::tick(): channel and StkFrames arguments are incompatible!";
|
||||||
handleError( StkError::FUNCTION_ARGUMENT );
|
handleError( StkError::FUNCTION_ARGUMENT );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -173,7 +173,17 @@ StkFrames& RtWvIn :: tick( StkFrames& frames )
|
|||||||
nFrames = frames.frames() - framesRead;
|
nFrames = frames.frames() - framesRead;
|
||||||
bytes = nFrames * nChannels * sizeof( StkFloat );
|
bytes = nFrames * nChannels * sizeof( StkFloat );
|
||||||
StkFloat *samples = &data_[readIndex_ * nChannels];
|
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<frames.frames(); i++, fSamples += hop ) {
|
||||||
|
for ( j=1; j<nChannels; j++ )
|
||||||
|
*fSamples++ = *samples++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
readIndex_ += nFrames;
|
readIndex_ += nFrames;
|
||||||
if ( readIndex_ == data_.frames() ) readIndex_ = 0;
|
if ( readIndex_ == data_.frames() ) readIndex_ = 0;
|
||||||
@@ -186,7 +196,7 @@ StkFrames& RtWvIn :: tick( StkFrames& frames )
|
|||||||
|
|
||||||
unsigned long index = (frames.frames() - 1) * nChannels;
|
unsigned long index = (frames.frames() - 1) * nChannels;
|
||||||
for ( unsigned int i=0; i<lastFrame_.size(); i++ )
|
for ( unsigned int i=0; i<lastFrame_.size(); i++ )
|
||||||
lastFrame_[i] = frames[index++];
|
lastFrame_[i] = frames[channel+index++];
|
||||||
|
|
||||||
return frames;
|
return frames;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user