WriteStreamAsync() public method

Hand out data here sequentially. If PrepareToWrite has not been called before, this method will have no effect. Note that numFrames should not exceed WriteChunkFrames.
public WriteStreamAsync ( float data, int offset, int numFrames ) : void
data float
offset int
numFrames int
return void
Esempio n. 1
0
        void IGATAudioThreadStreamClient.HandleAudioThreadStream(float[] data, int offset, bool emptyData, IGATAudioThreadStream stream)
        {
            int framesToWrite = stream.BufferSizePerChannel;

            if (_writing == false)
            {
                double dspTime     = AudioSettings.dspTime;
                double nextDspTime = dspTime + GATInfo.AudioBufferDuration;

                if (_targetDspTime < dspTime)
                {
                    _targetDspTime = dspTime;
                }

                if (nextDspTime > _targetDspTime)
                {
                    if (_waiting)
                    {
                        _waiting = false;
                        _writing = true;

                        int frameOffsetInBuffer = ( int )((_targetDspTime - dspTime) * GATInfo.OutputSampleRate);
                        offset        += frameOffsetInBuffer * stream.NbOfChannels;
                        framesToWrite -= frameOffsetInBuffer;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            if (_recFixedFrames > 0 && (_writtenFrames + framesToWrite > _recFixedFrames))
            {
                framesToWrite = _recFixedFrames - _writtenFrames;
                _writer.WriteStreamAsync(data, offset, framesToWrite);
                EndWriting();

                return;
            }

            _writer.WriteStreamAsync(data, offset, framesToWrite);
            _writtenFrames += framesToWrite;
        }