[Stk] bug in RtWvOut
Stephen Sinclair
sinclair at music.mcgill.ca
Wed Oct 3 17:38:12 PDT 2007
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
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: RtWvOut.cpp.writeindex.patch
URL: <https://cm-mail.stanford.edu/pipermail/stk/attachments/20071003/47b7c17e/attachment.ksh>
More information about the Stk
mailing list