EnsureSize() private method

private EnsureSize ( int size ) : void
size int
return void
        internal int ReadSamples(float[] buffer, int offset, int count)
        {
            int num = 0;

            lock (_seekLock)
            {
                if (_prevBuffer != null)
                {
                    int num2 = Math.Min(count, _prevBuffer.Length);
                    Buffer.BlockCopy(_prevBuffer, 0, buffer, offset, num2 * 4);
                    if (num2 < _prevBuffer.Length)
                    {
                        float[] array = new float[_prevBuffer.Length - num2];
                        Buffer.BlockCopy(_prevBuffer, num2 * 4, array, 0, (_prevBuffer.Length - num2) * 4);
                        _prevBuffer = array;
                    }
                    else
                    {
                        _prevBuffer = null;
                    }
                    count  -= num2;
                    offset += num2;
                    num     = num2;
                }
                else if (_isParameterChange)
                {
                    throw new InvalidOperationException("Currently pending a parameter change.  Read new parameters before requesting further samples!");
                }
                int size = count + Block1Size * _channels;
                _outputBuffer.EnsureSize(size);
                while (_preparedLength * _channels < count && !_eosFound && !_isParameterChange)
                {
                    DecodeNextPacket();
                    if (_prevBuffer != null)
                    {
                        return(ReadSamples(buffer, offset, _prevBuffer.Length));
                    }
                }
                if (_preparedLength * _channels < count)
                {
                    count = _preparedLength * _channels;
                }
                _outputBuffer.CopyTo(buffer, offset, count);
                _preparedLength  -= count / _channels;
                _reportedPosition = _currentPosition - _preparedLength;
            }
            return(num + count);
        }
Esempio n. 2
0
        internal int ReadSamples(float[] buffer, int offset, int count)
        {
            int samplesRead = 0;

            lock (_seekLock)
            {
                if (_prevBuffer != null)
                {
                    // get samples from the previous buffer's data
                    var cnt = Math.Min(count, _prevBuffer.Length);
                    Buffer.BlockCopy(_prevBuffer, 0, buffer, offset, cnt * sizeof(float));

                    // if we have samples left over, rebuild the previous buffer array...
                    if (cnt < _prevBuffer.Length)
                    {
                        var buf = new float[_prevBuffer.Length - cnt];
                        Buffer.BlockCopy(_prevBuffer, cnt * sizeof(float), buf, 0, (_prevBuffer.Length - cnt) * sizeof(float));
                        _prevBuffer = buf;
                    }
                    else
                    {
                        // if no samples left over, clear the previous buffer
                        _prevBuffer = null;
                    }

                    // reduce the desired sample count & increase the desired sample offset
                    count      -= cnt;
                    offset     += cnt;
                    samplesRead = cnt;
                }
                else if (_isParameterChange)
                {
                    throw new InvalidOperationException("Currently pending a parameter change.  Read new parameters before requesting further samples!");
                }

                int minSize = count + Block1Size * _channels;
                _outputBuffer.EnsureSize(minSize);

                while (_preparedLength * _channels < count && !_eosFound && !_isParameterChange)
                {
                    DecodeNextPacket();

                    // we can safely assume the _prevBuffer was null when we entered this loop
                    if (_prevBuffer != null)
                    {
                        // uh-oh... something is wrong...
                        return(ReadSamples(buffer, offset, _prevBuffer.Length));
                    }
                }

                if (_preparedLength * _channels < count)
                {
                    // we can safely assume we've read the last packet...
                    count = _preparedLength * _channels;
                }

                _outputBuffer.CopyTo(buffer, offset, count);
                _preparedLength  -= count / _channels;
                _reportedPosition = _currentPosition - _preparedLength;
            }

            return(samplesRead + count);
        }
Esempio n. 3
0
        internal int ReadSamples(float[] buffer, int offset, int count)
        {
            int samplesRead = 0;

            if (_prevBuffer != null)
            {
                // get samples from the previous buffer's data
                var cnt = Math.Min(count, _prevBuffer.Length);
                Buffer.BlockCopy(_prevBuffer, 0, buffer, offset, cnt * sizeof(float));

                // if we have samples left over, rebuild the previous buffer array...
                if (cnt < _prevBuffer.Length)
                {
                    var buf = new float[_prevBuffer.Length - cnt];
                    Buffer.BlockCopy(_prevBuffer, cnt * sizeof(float), buf, 0, (_prevBuffer.Length - cnt) * sizeof(float));
                    _prevBuffer = buf;
                }
                else
                {
                    // if no samples left over, clear the previous buffer
                    _prevBuffer = null;
                }

                // reduce the desired sample count & increase the desired sample offset
                count      -= cnt;
                offset     += cnt;
                samplesRead = cnt;
            }

            int minSize = count + Block1Size * _channels;

            _outputBuffer.EnsureSize(minSize);

            while (_preparedLength * _channels < count && !_eosFound)
            {
                try
                {
                    DecodeNextPacket();

                    // we can safely assume the _prevBuffer was null when we entered this loop
                    if (_prevBuffer != null)
                    {
                        // uh-oh... something is wrong...
                        return(ReadSamples(buffer, offset, _prevBuffer.Length));
                    }
                }
                catch (EndOfStreamException)
                {
                    _eosFound = true;
                    break;
                }
            }

            if (_preparedLength * _channels < count)
            {
                // we can safely assume we've read the last packet...
                count = _preparedLength * _channels;
            }

            _outputBuffer.CopyTo(buffer, offset, count);
            _preparedLength -= count / _channels;

            return(samplesRead + count);
        }