Example #1
0
        private int OverlapSamples()
        {
            // window
            var window = _mode.GetWindow(_prevFlag, _nextFlag);
            // this is applied as part of the lapping operation

            // now lap the data into the buffer...

            var sizeW  = _mode.BlockSize;
            var right  = sizeW;
            var center = right >> 1;
            var left   = 0;
            var begin  = -center;
            var end    = center;

            if (_mode.BlockFlag)
            {
                // if the flag is true, it's a long block
                // if the flag is false, it's a short block
                if (!_prevFlag)
                {
                    // previous block was short
                    left   = Block1Size / 4 - Block0Size / 4; // where to start in pcm[][]
                    center = left + Block0Size / 2;           // adjust the center so we're correctly clearing the buffer...
                    begin  = Block0Size / -2 - left;          // where to start in _outputBuffer[,]
                }

                if (!_nextFlag)
                {
                    // next block is short
                    right -= sizeW / 4 - Block0Size / 4;
                    end    = sizeW / 4 + Block0Size / 4;
                }
            }
            // short blocks don't need any adjustments

            var idx = _outputBuffer.Length / _channels + begin;

            for (var c = 0; c < _channels; c++)
            {
                _outputBuffer.Write(c, idx, left, center, right, _residue[c], window);
            }

            var newPrepLen     = _outputBuffer.Length / _channels - end;
            var samplesDecoded = newPrepLen - _preparedLength;

            _preparedLength = newPrepLen;

            return(samplesDecoded);
        }