public virtual bool Seek(Timestamp where) { // Invalidate stream _blockLeft = 0; _curBlock = _blocks.Count; if (where > _length) { return(false); } // Search for the block containing the requested sample int seekSample = AudioStreamHelper.ConvertTimeToStreamPos(where, Rate, IsStereo).TotalNumberOfFrames; int curSample = 0; for (_curBlock = 0; _curBlock != _blocks.Count; ++_curBlock) { // Skip all none sample blocks for now if (_blocks[_curBlock].Code != 1 && _blocks[_curBlock].Code != 9) { continue; } var nextBlockSample = curSample + _blocks[_curBlock].Samples; if (nextBlockSample > seekSample) { break; } curSample = nextBlockSample; } if (_curBlock == _blocks.Count) { return((seekSample - curSample) == 0); } else { var offset = seekSample - curSample; _stream.Seek(_blocks[_curBlock].Offset + offset, SeekOrigin.Begin); _blockLeft = _blocks[_curBlock].Samples - offset; return(true); } }
public SubLoopingAudioStream(ISeekableAudioStream stream, uint loops, Timestamp loopStart, Timestamp loopEnd, bool disposeAfterUse = true) { _parent = stream; _loops = loops; _pos = new Timestamp(0, Rate * (IsStereo ? 2 : 1)); _loopStart = AudioStreamHelper.ConvertTimeToStreamPos(loopStart, Rate, IsStereo); _loopEnd = AudioStreamHelper.ConvertTimeToStreamPos(loopEnd, Rate, IsStereo); _done = false; Debug.Assert(loopStart < loopEnd); if (!_parent.Rewind()) { _done = true; } }
public bool Seek(Timestamp wh) { _endOfData = true; if (wh > _playtime) { return(false); } var seekSample = AudioStreamHelper.ConvertTimeToStreamPos(wh, Rate, IsStereo).TotalNumberOfFrames; _stream.Seek(seekSample * (_is16Bit ? 2 : 1), SeekOrigin.Begin); // In case of an error we will not continue stream playback. if (_stream.Position != _stream.Length) { _endOfData = false; } return(true); }