[Stk] bug in RtWvOut

Gary Scavone gary at ccrma.Stanford.EDU
Thu, 4 Oct 2007 10:29:33 -0400


Thanks Stephen for the bug reports!  I made the appropriate fixes and  
posted the new files under the "Updates" section of the STK download  
page (http://ccrma.stanford.edu/software/stk/download.html).

Regards,

--gary

On 3-Oct-07, at 8:38 PM, Stephen Sinclair wrote:

> Hi,
>
> I found another problem tonight.
> I'm using RtWvOut, and getting a crash after a few ticks have gone by.
> It seems that in RtWvOut::computerSample(), there is this code:
>
>  writeIndex_++;
> if ( writeIndex_ == data_.frames() )
>    writeIndex_ = 0;
>
>
> and also this:
>  unsigned long index = writeIndex_ * nChannels;
>
> So it seems to me that writeIndex_ is intended to be a frame count,  
> not an index count.
> However, in the RtWvOut constructor, we have:
>
>  unsigned int offset = (unsigned int ) (data_.size() / 2.0);
>  writeIndex_ = offset;    // start writing half-way into buffer
>  framesFilled_ = offset;
>
>
> This is causing a problem because when nChannels = 2, writeIndex_  
> is equal to nFrames.
> So then it increments writeIndex_++ before checking if it is equal  
> to data_.frames().
> This makes it miss the boundary and not wrap to zero, eventually  
> writing way past the end of the array.
>
> I think the fix is to set offset = data_.frames() / 2, which is the  
> included patch.  Anyways it fixes it for me, but I'm not sure if  
> this is the intended semantics of writeIndex_.
>
> Steve
>
> --- RtWvOut.cpp.orig	2007-08-07 16:34:03.000000000 -0400
> +++ RtWvOut.cpp	2007-10-03 20:27:56.515625000 -0400
> @@ -104,7 +104,7 @@
>    }
>
>    data_.resize( size * nBuffers, nChannels );
> -  unsigned int offset = (unsigned int ) (data_.size() / 2.0);
> +  unsigned int offset = (unsigned int ) (data_.frames() / 2.0);
>    writeIndex_ = offset;    // start writing half-way into buffer
>    framesFilled_ = offset;
>  }