Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace rand() with realtime-safe pcg-rand #28 #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

x42
Copy link

@x42 x42 commented Jun 1, 2021

On unices (Linux and macOS) the call to rand() takes a
lock (preserve global random seed) and is hence not realtime-safe.

On Windows this is less of an issue since rand() uses a thread-local
variable by default. However PCG-rand is still a preferable alternative.

--
NOTE: THIS CODE IS UNTESTED!
Other plugins using rand() should be updated likewise.

x42 added 2 commits June 1, 2021 22:47
On unices (Linux and macOS) the call to rand() takes a
lock (preserve global random seed) and is hence not realtime-safe.

On Windows this is less of an issue since rand() uses a thread-local
variable by default. However PCG-rand is still a preferable alternative.
The motivation for 6 calls was likely because default Windows
rand() provides only 15 bits (RAND_MAX = 32768), which is
is insufficient for float (23 bit mantissa). This is no longer
needed with the given pcg-random.org implementation.
@x42
Copy link
Author

x42 commented Jun 1, 2021

I do not know how you manage the replicated source code (LinuxVST, WinVST, MacVST, MacAU etc). This is just an proof-of-concept to hopefully get the ball rolling.

Note: before replicating this to all other plugins, consider a shared include, in a dedicated namespace (so it does not interfere with symbols of other plugins).

on macOS and Linux (really gcc, clang), override the default visibility. e.g

namespace AirWindows {
  class  __attribute__ ((visibility ("hidden")) PCGRand 
  {
    /* ... */
  };
} // namespace

Alternatively you could #include"" the implementation directly in each PluginProc's header files as private class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant