[Approved] AudioPlayer : Fix to avoid scratches (1 Viewer)

Smeulf

Retired Team Member
  • Premium Supporter
  • October 27, 2010
    672
    454
    France
    France France
    This patch is intended to fix the audioringbuffer Read() method to prevent scratches.

    It's a totally different better way to fix the problem than my first appempt.

    Cheers.
     

    Attachments

    Smeulf

    Retired Team Member
  • Premium Supporter
  • October 27, 2010
    672
    454
    France
    France France
    This patch is intended to fix the audioringbuffer Read() method to prevent scratches.
    New patch, fix both Read() and Peek() methods.

    Be carrefull please to edit AudioRingBuffer.cs to convert CR/LF, I really can't find the good option to avoid this problem with TurtoiseGit :(
     

    Attachments

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    41
    Freiburg im Breisgau, Germany
    Germany Germany
    AW: AudioPlayer : Fix to avoid scratches

    Hi Smeulf!
    Thank you very much for your work!
    In fact, the fix of the crackle-problem can be done much simpler than in your code; this is the original code, that you can find in methods Read and Peek:

    Code:
            int count2 = Math.Min(requested - count1, writePointer);
            if (count2 > 0)
            {
              if (buffer != IntPtr.Zero)
              {
                IntPtr ptr = new IntPtr(
                    _Is32bit ? buffer.ToInt32() : buffer.ToInt64() + (count1*BassConstants.FloatBytes));
                Marshal.Copy(_buffer, 0, ptr, count2);
              }
              readPointer = count2;
            }
            read = count1 + count2;
    Here are two problems:
    1) The ternary expression _Is32bit ? buffer.ToInt32() : buffer.ToInt64() must be put into parentheses because the + operator binds stronger than the : of the ternary operator.
    2) In case count2 < 0, the last line returns the wrong result.

    So, the correct solution is:

    Code:
            int count2 = Math.Min(requested - count1, writePointer);
            if (count2 > 0)
            {
              if (buffer != IntPtr.Zero)
              {
                IntPtr ptr = new IntPtr(
                    (_Is32bit ? buffer.ToInt32() : buffer.ToInt64()) + (count1*BassConstants.FloatBytes));
                Marshal.Copy(_buffer, 0, ptr, count2);
              }
              readPointer = count2;
            }
            else
              count2 = 0;
            read = count1 + count2;
    Smeulf, it seems that you have found our audioplayer problem! Thank you very much!
     

    Users Who Are Viewing This Thread (Users: 0, Guests: 1)

    Top Bottom