GAudio.GATAsyncWavWriter.WriteStreamAsync C# (CSharp) Method

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
        public void WriteStreamAsync( float[] data, int offset, int numFrames )
        {
            if( !_vDoWrite )
                return;

            int length = numFrames * _numChannels;

            int appliedLength = length;

            if( offset + appliedLength > data.Length )
            {
                throw new GATException( "Cannot write, out of range!" );
            }

            if( appliedLength + _nextInputOffset >= _inputBufferSize )
            {
                appliedLength = _inputBufferSize - _nextInputOffset;
                System.Array.Copy( data, offset, _inputBuffer, _nextInputOffset, appliedLength );

                offset += appliedLength;
                appliedLength = length - appliedLength;
                _nextInputOffset = 0;
            }

            System.Array.Copy( data, offset, _inputBuffer, _nextInputOffset, appliedLength );
            _vReceivedFrames   += numFrames;
            _nextInputOffset   += appliedLength;
        }

Usage Example

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