void IGATAudioThreadStreamClient.HandleAudioThreadStream( float[] data, int offset, bool emptyData, IGATAudioThreadStream stream )
{
int pos = _vPosition;
int framesToCopy = _numFramesPerRead;
int i;
int numCaches = _caches.Length;
double dspTime = AudioSettings.dspTime;
if( _vDoCache == false )
{
if( _targetDspTime < dspTime )
{
_targetDspTime = dspTime;
}
if( _targetDspTime >= dspTime && _targetDspTime < dspTime + GATInfo.AudioBufferDuration )
{
if( _waiting )
{
_waiting = false;
_vDoCache = true;
int frameOffsetInBuffer = ( int )( ( _targetDspTime - dspTime ) * GATInfo.OutputSampleRate );
framesToCopy = stream.BufferSizePerChannel - frameOffsetInBuffer;
offset += frameOffsetInBuffer * stream.NbOfChannels;
}
else
{
return;
}
}
else
{
return;
}
}
if( pos + _numFramesPerRead >= _cacheFrames )
{
framesToCopy = _cacheFrames - pos;
if( Loop )
{
for( i = 0; i < numCaches; i++ )
{
if( _overdub )
{
_caches[ i ].MixFromInterlaced( data, offset, framesToCopy, pos, i, numCaches );
}
else
{
_caches[ i ].CopyFromInterlaced( data, offset, framesToCopy, pos, i, numCaches );
}
}
pos = 0;
offset += framesToCopy * stream.NbOfChannels;
framesToCopy = _numFramesPerRead - framesToCopy;
}
else
{
_vDoCache = false;
_stream.RemoveAudioThreadStreamClient( this );
}
if( _onEnd != null )
_onEnd( _caches, Loop );
}
for( i = 0; i < numCaches; i++ )
{
if( _overdub )
{
_caches[ i ].MixFromInterlaced( data, offset, framesToCopy, pos, i, numCaches );
}
else
{
_caches[ i ].CopyFromInterlaced( data, offset, framesToCopy, pos, i, numCaches );
}
}
pos += framesToCopy;
_vPosition = pos;
}