This project has moved and is read-only. For the latest updates, please go here.

Problem with playing parts of an audio

Jan 30, 2016 at 3:38 PM
Hello, I'm new to NAudio, i'm doing project to be able to play an audio from t1 to t4 and then jump to t7 to t11 without lagging ,
i'm being able to do that if i minimize the latency but that is creating a problem with time the wav start buzzing , here is the code that i'm using;

to determine the position i'm using this
private long GetBitPosition(double time)
    {
        var bitPosition = (long)(WaveFormat.BlockAlign * WaveFormat.SampleRate * time);
        return (bitPosition);

    }
and than in the reading i'm doing the following
public override int Read(byte[] buffer, int offset, int count)
    {
         int bytesRead = 0;

        bytesRead = sourceStream.Read(buffer, offset ,count);
     var upperBound = (Position + count);
     if (upperBound >= _endBitPosition)
        {       
                    if (EnableLooping)
                    {
                        if (Math.Abs(_startBitPosition - sourceStream.Position) > count) 
                            sourceStream.Position = _startBitPosition;

                        if (tmpEnd != null)
                        {
                            EndSample = tmpEnd.Value;
                            OnPlayNext();
                        }
                        else
                            OnPlayLoop();
                    }
                    else
                    {
                        sourceStream.Position = sourceStream.Length;
                        OnPlayEnded();
                    }
        }
this is working fine if my buffer is small but with that i'm getting buzzes after 3 min of playing,
please it will be well appreciated if someone can help me , i used waveout and wasapi and asio out, but no luck
Feb 4, 2016 at 2:31 PM
make sure your repositions are block aligned (using the BlockAlign property of the WaveFormat)