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

Smeulf

Retired Team Member
  • Premium Supporter
  • October 27, 2010
    672
    454
    France
    Home Country
    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

    • AudioRingBuffer_2.patch
      1.9 KB

    Smeulf

    Retired Team Member
  • Premium Supporter
  • October 27, 2010
    672
    454
    France
    Home Country
    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

    • 0001-Fix-AudioRingBuffer-Read-and-Peek-methods-to-avoid-s.patch
      3.2 KB

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    47
    Freiburg im Breisgau, Germany
    Home Country
    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

    Similar threads

    Those folder's last modified time isn't really accurate it seems. Latest change was a merge from PR #384 on may 3rd which was exactly that fix, see f.e. MediaPortal-1/mediaportal/MediaPortal.Application/MediaPortal.cs at 8fa4ccca20059a5534a029266efa596e83387f5b · MediaPortal/MediaPortal-1
    Those folder's last modified time isn't really accurate it seems. Latest change was a merge from PR #384 on may 3rd which was...
    Now that MediaPortal has gone 64-bit, any references to lParam should be converted to int64 rather than int32 or compared to zero...
    Replies
    7
    Views
    1K
    If you’re planning to submit a pull request, let’s go through the list of issues and their solutions. I or someone from the team will create a Jira ticket, and for each ticket, you’ll make the changes and submit a pull request. This will be transparent and straightforward.
    If you’re planning to submit a pull request, let’s go through the list of issues and their solutions. I or someone from the team...
    I'm very glad to see that mediaportal 1 is on github, where ordinary devs with github accounts can make contributions. Please can...
    Replies
    7
    Views
    1K
    No issues here, still working.
    No issues here, still working.
    EDIT on Feb 17 2026: There is a solution: User Antidot created a new program: newZap2it.exe which works to get EPG data from...
    Replies
    122
    Views
    44K
    Thanks very much, Jasmeet. Worked. But note that this setting has moved, apparently, to: Settings > TV (not Plugins)
    Thanks very much, Jasmeet. Worked. But note that this setting has moved, apparently, to: Settings > TV (not Plugins)
    I recently did a fresh install of 2.5 on a new Windows 11 PC. My previous (Windows 10) version of 2.5 gave my broadcast TV channel...
    Replies
    2
    Views
    2K
    I should point out that the developers have not formally left the project, and development has not formally stopped. The developers have instead simply "faded away", gradually spending less and less time on MP2 until the present, when they spend no time on MP2. But one or more of the developers might return next week! It is impossible...
    I should point out that the developers have not formally left the project, and development has not formally stopped. The developers...
    Hi Folks, I need some help with fixing the Problem that MP2 doesn't keep the sorted Order of Channels in TV-Configuraiton. I am...
    Replies
    10
    Views
    3K
    Top Bottom