[Stk] bug in RtWvOut

Stephen Sinclair sinclair at music.mcgill.ca
Wed, 03 Oct 2007 20:38:12 -0400


This is a multi-part message in MIME format.
--------------090402000502040508050606
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

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


--------------090402000502040508050606
Content-Type: text/plain;
 name="RtWvOut.cpp.writeindex.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="RtWvOut.cpp.writeindex.patch"

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

--------------090402000502040508050606--