This project has moved. For the latest updates, please go here.

Looping WAV and length

Nov 1, 2011 at 7:45 PM

Forgive me if this is a basic question but...

I have used the looping code that was posted a while ago and it works perfect. I have it so I can change the loop in realtime which is exactly what I wanted to do. Now I need some way to change the end point of the WAV file. Ideally it would be nice to adjust it in realtime but that isn't totally necessary. Here is the code I added to the LoopStream class

/// <summary>
/// loop point
/// </summary>

public int loopPoint {get; set;}

and then

public override int Read(byte[] buffer, int offset, int count)
    {
        int totalBytesRead = 0;
 		
        while (totalBytesRead < count)
        {
            int bytesRead = sourceStream.Read(buffer, offset + totalBytesRead, count - totalBytesRead);
            if (bytesRead == 0)
            {
                if (sourceStream.Position == 0 || !EnableLooping)
                {
                    // something wrong with the source stream
                    break;
                }
                // loop
                sourceStream.Position = loopPoint;
            }
            totalBytesRead += bytesRead;
        }
        return totalBytesRead;
    }

Then I just assigned a trackbar to control the loopPoint variable

I would like a second control bar to control the total length. Any ideas?

Coordinator
Nov 15, 2011 at 9:50 AM

instead of (bytesRead == 0) you would test (bytesRead == 0 || sourceStream.Position >= endPoint)

Nov 15, 2011 at 10:22 PM

well that was pretty easy! :)  I will test it out tonight and see how it goes. Thanks.