Problems with multiple functioncalls on the outputbuffer in a ScriptProcessorNode

I've been looking for over 4 hours at a problem that generates quite loud
ticks in my sound. I have simplified it all the way down, and i am
wondering if my approach can work at all.

What i'm trying to do is seemlessly stitch multiple audiobuffers together,
using a custom ScriptProcessorNode (with access to all buffers) to write
the correct samplevalues (from the correct position and the correct buffer)
to the output. I've trimmed it all down to just using 1 buffer, that should
seamlessly restart at the beginning, once it reaches the end.

This is in pseudocode my onaudioprocess-handler:

handleAudioProcessingEvent(event: AudioProcessingEvent): void
{
        // there are two cases: either the current writeloop reaches the
end of the source-buffer, or it doesnt

        if(endNotReached)
        {
                copySamples(bufferSize, 0, currentReadPosition);

                 // params are:
                 // the amount of samples to write (in this case the
buffersize of the scriptprocessor)
                 // the index to start writing in the outputbuffer
                 // the index to start reading from the sourcebuffer (a
loaded sample), which will be incremented in the writeloop in the
copySamples function
        }
        else
        {
                // the end of the source buffer will be reached in this
writingloop,
                // so write the remainig samples, then reset the
readposition, then write the remaining amount of samples
                // (so the amount of samples written equals the full
buffersize of the scriptprocessor)

                copySamples(numberOfSamplesLeftForSourceSound, 0,
currentReadPosition);
                currentReadPosition = 0;
                copySamples(bufferSize - numberOfSamplesLeftForSourceSound,
numberOfSamplesLeftForSourceSound, currentReadPosition);
        }
}

When the end is not reached, everything runs ok (although i have the
feeling i hear some small irregularities now and then), but when the end is
reached (2nd part of the if-statement), there's some big ticks in the
audiostream.

I am wondering if passing the outputbuffer to two functioncalls (both
partially writing in it) has anything to do with it, or that i'm
overlooking something else.


Peter

Received on Monday, 11 February 2013 20:01:03 UTC