annotate DPF-Prymula-audioplugins/dpf/distrho/DistrhoUtils.hpp @ 3:84e66ea83026

DPF-Prymula-audioplugins-0.231015-2
author prymula <prymula76@outlook.com>
date Mon, 16 Oct 2023 21:53:34 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
1 /*
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
2 * DISTRHO Plugin Framework (DPF)
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
3 * Copyright (C) 2012-2023 Filipe Coelho <falktx@falktx.com>
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
4 *
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
5 * Permission to use, copy, modify, and/or distribute this software for any purpose with
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
6 * or without fee is hereby granted, provided that the above copyright notice and this
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
7 * permission notice appear in all copies.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
8 *
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
10 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
11 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
15 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
16
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
17 #ifndef DISTRHO_UTILS_HPP_INCLUDED
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
18 #define DISTRHO_UTILS_HPP_INCLUDED
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
19
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
20 #include "src/DistrhoDefines.h"
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
21
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
22 #include <cstdarg>
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
23 #include <cstdio>
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
24 #include <cstdlib>
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
25 #include <cstring>
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
26
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
27 #include <cmath>
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
28 #include <limits>
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
29
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
30 #ifdef DISTRHO_PROPER_CPP11_SUPPORT
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
31 # include <cstdint>
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
32 #else
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
33 # include <stdint.h>
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
34 #endif
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
35
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
36 #if defined(DISTRHO_OS_WINDOWS) && defined(_MSC_VER)
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
37 #include <basetsd.h>
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
38 typedef SSIZE_T ssize_t;
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
39 #endif
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
40
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
41 #if ! defined(CARLA_MATH_UTILS_HPP_INCLUDED) && ! defined(DISTRHO_PROPER_CPP11_SUPPORT)
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
42 namespace std {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
43 inline float fmin(float __x, float __y)
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
44 { return __builtin_fminf(__x, __y); }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
45 inline float fmax(float __x, float __y)
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
46 { return __builtin_fmaxf(__x, __y); }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
47 inline float rint(float __x)
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
48 { return __builtin_rintf(__x); }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
49 inline float round(float __x)
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
50 { return __builtin_roundf(__x); }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
51 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
52 #endif
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
53
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
54 #ifndef M_PI
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
55 # define M_PI 3.14159265358979323846
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
56 #endif
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
57
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
58 #define DISTRHO_MACRO_AS_STRING_VALUE(MACRO) #MACRO
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
59 #define DISTRHO_MACRO_AS_STRING(MACRO) DISTRHO_MACRO_AS_STRING_VALUE(MACRO)
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
60
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
61 /* --------------------------------------------------------------------------------------------------------------------
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
62 * misc functions */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
63
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
64 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
65 @defgroup MiscellaneousFunctions Miscellaneous functions
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
66
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
67 @{
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
68 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
69
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
70 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
71 Return a 32-bit number from 4 8-bit numbers.@n
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
72 The return type is a int64_t for better compatibility with plugin formats that use such numbers.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
73 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
74 static inline constexpr
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
75 int64_t d_cconst(const uint8_t a, const uint8_t b, const uint8_t c, const uint8_t d) noexcept
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
76 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
77 return (a << 24) | (b << 16) | (c << 8) | (d << 0);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
78 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
79
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
80 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
81 Return an hexadecimal representation of a MAJ.MIN.MICRO version number.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
82 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
83 static inline constexpr
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
84 uint32_t d_version(const uint8_t major, const uint8_t minor, const uint8_t micro) noexcept
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
85 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
86 return uint32_t(major << 16) | uint32_t(minor << 8) | (micro << 0);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
87 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
88
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
89 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
90 Dummy, no-op function.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
91 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
92 static inline
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
93 void d_pass() noexcept {}
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
94
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
95 /** @} */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
96
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
97 /* --------------------------------------------------------------------------------------------------------------------
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
98 * string print functions */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
99
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
100 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
101 @defgroup StringPrintFunctions String print functions
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
102
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
103 @{
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
104 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
105
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
106 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
107 Print a string to stdout with newline (gray color).
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
108 Does nothing if DEBUG is not defined.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
109 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
110 #ifndef DEBUG
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
111 # define d_debug(...)
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
112 #else
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
113 static inline
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
114 void d_debug(const char* const fmt, ...) noexcept
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
115 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
116 try {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
117 va_list args;
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
118 va_start(args, fmt);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
119 std::fprintf(stdout, "\x1b[30;1m");
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
120 std::vfprintf(stdout, fmt, args);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
121 std::fprintf(stdout, "\x1b[0m\n");
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
122 va_end(args);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
123 } catch (...) {}
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
124 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
125 #endif
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
126
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
127 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
128 Print a string to stdout with newline.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
129 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
130 static inline
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
131 void d_stdout(const char* const fmt, ...) noexcept
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
132 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
133 try {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
134 va_list args;
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
135 va_start(args, fmt);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
136 std::vfprintf(stdout, fmt, args);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
137 std::fprintf(stdout, "\n");
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
138 va_end(args);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
139 } catch (...) {}
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
140 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
141
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
142 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
143 Print a string to stderr with newline.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
144 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
145 static inline
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
146 void d_stderr(const char* const fmt, ...) noexcept
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
147 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
148 try {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
149 va_list args;
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
150 va_start(args, fmt);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
151 std::vfprintf(stderr, fmt, args);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
152 std::fprintf(stderr, "\n");
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
153 va_end(args);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
154 } catch (...) {}
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
155 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
156
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
157 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
158 Print a string to stderr with newline (red color).
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
159 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
160 static inline
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
161 void d_stderr2(const char* const fmt, ...) noexcept
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
162 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
163 try {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
164 va_list args;
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
165 va_start(args, fmt);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
166 std::fprintf(stderr, "\x1b[31m");
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
167 std::vfprintf(stderr, fmt, args);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
168 std::fprintf(stderr, "\x1b[0m\n");
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
169 va_end(args);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
170 } catch (...) {}
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
171 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
172
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
173 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
174 Print a safe assertion error message.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
175 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
176 static inline
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
177 void d_safe_assert(const char* const assertion, const char* const file, const int line) noexcept
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
178 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
179 d_stderr2("assertion failure: \"%s\" in file %s, line %i", assertion, file, line);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
180 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
181
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
182 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
183 Print a safe assertion error message, with 1 extra signed integer value.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
184 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
185 static inline
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
186 void d_safe_assert_int(const char* const assertion, const char* const file,
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
187 const int line, const int value) noexcept
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
188 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
189 d_stderr2("assertion failure: \"%s\" in file %s, line %i, value %i", assertion, file, line, value);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
190 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
191
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
192 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
193 Print a safe assertion error message, with 1 extra unsigned integer value.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
194 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
195 static inline
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
196 void d_safe_assert_uint(const char* const assertion, const char* const file,
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
197 const int line, const uint value) noexcept
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
198 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
199 d_stderr2("assertion failure: \"%s\" in file %s, line %i, value %u", assertion, file, line, value);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
200 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
201
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
202 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
203 Print a safe assertion error message, with 2 extra signed integer values.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
204 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
205 static inline
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
206 void d_safe_assert_int2(const char* const assertion, const char* const file,
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
207 const int line, const int v1, const int v2) noexcept
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
208 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
209 d_stderr2("assertion failure: \"%s\" in file %s, line %i, v1 %i, v2 %i", assertion, file, line, v1, v2);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
210 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
211
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
212 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
213 Print a safe assertion error message, with 2 extra unsigned integer values.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
214 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
215 static inline
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
216 void d_safe_assert_uint2(const char* const assertion, const char* const file,
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
217 const int line, const uint v1, const uint v2) noexcept
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
218 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
219 d_stderr2("assertion failure: \"%s\" in file %s, line %i, v1 %u, v2 %u", assertion, file, line, v1, v2);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
220 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
221
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
222 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
223 Print a safe assertion error message, with a custom error message.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
224 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
225 static inline
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
226 void d_custom_safe_assert(const char* const message, const char* const assertion, const char* const file,
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
227 const int line) noexcept
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
228 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
229 d_stderr2("assertion failure: %s, condition \"%s\" in file %s, line %i", message, assertion, file, line);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
230 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
231
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
232 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
233 Print a safe exception error message.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
234 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
235 static inline
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
236 void d_safe_exception(const char* const exception, const char* const file, const int line) noexcept
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
237 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
238 d_stderr2("exception caught: \"%s\" in file %s, line %i", exception, file, line);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
239 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
240
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
241 /** @} */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
242
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
243 /* --------------------------------------------------------------------------------------------------------------------
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
244 * math functions */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
245
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
246 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
247 @defgroup MathFunctions Math related functions
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
248
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
249 @{
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
250 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
251
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
252 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
253 Safely compare two floating point numbers.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
254 Returns true if they match.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
255 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
256 template<typename T>
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
257 static inline constexpr
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
258 bool d_isEqual(const T& v1, const T& v2)
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
259 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
260 return std::abs(v1-v2) < std::numeric_limits<T>::epsilon();
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
261 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
262
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
263 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
264 Safely compare two floating point numbers.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
265 Returns true if they don't match.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
266 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
267 template<typename T>
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
268 static inline constexpr
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
269 bool d_isNotEqual(const T& v1, const T& v2)
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
270 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
271 return std::abs(v1-v2) >= std::numeric_limits<T>::epsilon();
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
272 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
273
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
274 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
275 Safely check if a floating point number is zero.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
276 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
277 template<typename T>
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
278 static inline constexpr
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
279 bool d_isZero(const T& value)
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
280 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
281 return std::abs(value) < std::numeric_limits<T>::epsilon();
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
282 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
283
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
284 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
285 Safely check if a floating point number is not zero.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
286 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
287 template<typename T>
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
288 static inline constexpr
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
289 bool d_isNotZero(const T& value)
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
290 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
291 return std::abs(value) >= std::numeric_limits<T>::epsilon();
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
292 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
293
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
294 /**
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
295 Get next power of 2.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
296 */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
297 static inline
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
298 uint32_t d_nextPowerOf2(uint32_t size) noexcept
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
299 {
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
300 DISTRHO_SAFE_ASSERT_RETURN(size > 0, 0);
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
301
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
302 // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
303 --size;
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
304 size |= size >> 1;
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
305 size |= size >> 2;
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
306 size |= size >> 4;
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
307 size |= size >> 8;
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
308 size |= size >> 16;
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
309 return ++size;
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
310 }
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
311
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
312 /** @} */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
313
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
314 /* --------------------------------------------------------------------------------------------------------------------
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
315 * math functions */
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
316
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
317 #ifndef DONT_SET_USING_DISTRHO_NAMESPACE
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
318 // If your code uses a lot of DISTRHO classes, then this will obviously save you
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
319 // a lot of typing, but can be disabled by setting DONT_SET_USING_DISTRHO_NAMESPACE.
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
320 namespace DISTRHO_NAMESPACE {}
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
321 using namespace DISTRHO_NAMESPACE;
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
322 #endif
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
323
84e66ea83026 DPF-Prymula-audioplugins-0.231015-2
prymula <prymula76@outlook.com>
parents:
diff changeset
324 #endif // DISTRHO_UTILS_HPP_INCLUDED