示例#1
0
        public void Seek(long position)
        {
            providers.Clear();

            SourceStream.Position = position;

            if (position > start && position < end)
            {
                providers.Enqueue(new OffsetSampleProvider(SourceStream.ToSampleProvider())
                {
                    TakeSamples = (end - (int)position) * 2
                });
            }
            else if (position < start)
            {
                providers.Enqueue(new OffsetSampleProvider(SourceStream.ToSampleProvider())
                {
                    TakeSamples = (start - (int)position) * 2
                });
            }
            else
            {
                providers.Enqueue(new OffsetSampleProvider(SourceStream.ToSampleProvider()));
            }

            currentProvider = providers.Dequeue();
        }
示例#2
0
        public int Read(float[] buffer, int offset, int count)
        {
            int read = 0;

            while (read < count)
            {
                int readThisTime = currentProvider.Read(buffer, offset + read, count - read);

                if (readThisTime == 0)
                {
                    Console.WriteLine("Ended at     :" + SourceStream.Position * 2);
                    Console.WriteLine("Loop start   :" + start * 2);
                    Console.WriteLine("Loop end     :" + end * 2);
                    Console.WriteLine();

                    if (Loop)
                    {
                        if (SourceStream.Position > start)
                        {
                            SourceStream.Position = start;
                        }

                        providers.Enqueue(new OffsetSampleProvider(SourceStream.ToSampleProvider())
                        {
                            TakeSamples = loopLength
                        });

                        currentProvider = providers.Dequeue();
                    }
                    else
                    {
                        providers.Enqueue(new OffsetSampleProvider(SourceStream.ToSampleProvider()));

                        currentProvider = providers.Dequeue();
                    }
                }

                read += readThisTime;
            }

            return(read);
        }