本文整理汇总了C#中Sample.ConvertToContiguousBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# Sample.ConvertToContiguousBuffer方法的具体用法?C# Sample.ConvertToContiguousBuffer怎么用?C# Sample.ConvertToContiguousBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sample
的用法示例。
在下文中一共展示了Sample.ConvertToContiguousBuffer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSamples
/// <summary>
/// Gets the decoded PCM samples. See remarks.
/// </summary>
/// <param name="startingPositionInSeconds">The starting position in seconds.</param>
/// <returns>An enumerator of pointer to PCM decoded data with the same format as returned by <see cref="WaveFormat"/>.</returns>
/// <remarks>
/// This method is only working as a single enumerator at a time.
/// The <see cref="SetSourceStream(System.IO.Stream)"/> must be set before calling <see cref="GetSamples()"/>
/// </remarks>
public IEnumerable<DataPointer> GetSamples(TimeSpan startingPositionInSeconds)
{
// A new reader is setup, so initialize it.
lock (sourceReaderLock)
{
// If the reader was changed
if (nextSourceReader != null)
{
if (sourceReader != null)
sourceReader.Dispose();
sourceReader = nextSourceReader;
nextSourceReader = null;
}
}
// Make sure that any prior call
CleanupAndDispose();
CheckIfDisposed();
// Set the position
sourceReader.SetCurrentPosition((long)(startingPositionInSeconds.TotalSeconds * 1e7));
while (true)
{
int streamIndex;
SourceReaderFlags flags;
long time;
CheckIfDisposed();
using (currentSample = sourceReader.ReadSample(SourceReaderIndex.FirstAudioStream, SourceReaderControlFlags.None, out streamIndex, out flags, out time))
{
if ((flags & SourceReaderFlags.Endofstream) != 0)
break;
CheckIfDisposed();
using (currentBuffer = currentSample.ConvertToContiguousBuffer())
{
int bufferMaxLength;
int bufferCurrentLength;
CheckIfDisposed();
var ptr = currentBuffer.Lock(out bufferMaxLength, out bufferCurrentLength);
yield return new DataPointer(ptr, bufferCurrentLength);
// Warning, because the yield could never return here, currentBuffer and currentSample should be disposed when disposing this object or when
// calling it again on the GetSamples method.
// In case a Dispose occured while decoding
if (currentBuffer == null)
break;
currentBuffer.Unlock();
}
}
}
// They have been disposed, so we can just clear them
currentBuffer = null;
currentSample = null;
}