AAX SDK 2.8.0
Avid Audio Extensions Development Kit
Loading...
Searching...
No Matches
AAX_RandomGen.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 * Copyright 2013-2015, 2023-2024 Avid Technology, Inc.
4 * All rights reserved.
5 *
6 * This file is part of the Avid AAX SDK.
7 *
8 * The AAX SDK is subject to commercial or open-source licensing.
9 *
10 * By using the AAX SDK, you agree to the terms of both the Avid AAX SDK License
11 * Agreement and Avid Privacy Policy.
12 *
13 * AAX SDK License: https://developer.avid.com/aax
14 * Privacy Policy: https://www.avid.com/legal/privacy-policy-statement
15 *
16 * Or: You may also use this code under the terms of the GPL v3 (see
17 * www.gnu.org/licenses).
18 *
19 * THE AAX SDK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 * EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 * DISCLAIMED.
22 */
23
30/*================================================================================================*/
31#pragma once
32
33#ifndef AAX_RANDOMGEN_H
34#define AAX_RANDOMGEN_H
35
36// Standard headers
37#include <stdlib.h>
38#include <time.h>
39#include <stdint.h>
40
42#include "AAX_Constants.h"
43
44namespace AAX
45{
46
47const float cSeedDivisor = 1/127773.0f;
48
49const int32_t cInitialSeedValue=0x00F54321;
50
51/*===================================================================================================*/
52inline int32_t GetInt32RPDF(int32_t* iSeed)
53{
54 // Requirement: iSeed param must be a static in the calling function.
55 int64_t seed = *iSeed;
56 int64_t k = static_cast<int64_t>(seed*cSeedDivisor);
57 seed = 16807 * (seed - k * 127773LL) - 2836 * k + 7395;
58 *iSeed = static_cast<int32_t>(seed);
59 if (*iSeed < 0)
60 *iSeed += 2147483647;
61 return (*iSeed - 1073741824) * 2; // -2147483647..+2147483647
62}
63
64/*===================================================================================================*/
65
66
79inline int32_t GetFastInt32RPDF(int32_t* iSeed)
80{
81 *iSeed = (*iSeed * 196314165) + 907633515;
82 return *iSeed;
83}
84
85/*===================================================================================================*/
86inline float GetRPDFWithAmplitudeOneHalf(int32_t* iSeed) //An amplitude of 0.5 = 1 LSBs
87{
88 // Requirement: iSeed param must be a static in the calling function.
89 return float(cNormalizeLongToAmplitudeOneHalf) * float(GetInt32RPDF(iSeed));
90}
91
92/*===================================================================================================*/
93inline float GetRPDFWithAmplitudeOne(int32_t* iSeed) //An amplitude of 1.0 = 2 LSBs
94{
95 // Requirement: iSeed param must be a static in the calling function.
96 return float(cNormalizeLongToAmplitudeOne) * float(GetInt32RPDF(iSeed));
97}
98
99/*===================================================================================================*/
100inline float GetFastRPDFWithAmplitudeOne(int32_t* iSeed) //An amplitude of 1.0 = 2 LSBs
101{
102 // Requirement: iSeed param must be a static in the calling function.
103 return float(cNormalizeLongToAmplitudeOne) * float(GetFastInt32RPDF(iSeed));
104}
105
106/*===================================================================================================*/
107inline float GetTPDFWithAmplitudeOne(int32_t* iSeed) //An amplitude of 1.0 = 2 LSBs
108{
109 // Generate a random number with a triangular pdf (tpdf) using two
110 // separate rectangular pdf noise sources.
111
112 // We are using only one seed input for both rect pdf noise generators,
113 // but because they are of course executed sequentially independent noise
114 // will be produced.
115
116 return float(cNormalizeLongToAmplitudeOne) * (float(GetFastInt32RPDF(iSeed) + float(GetFastInt32RPDF(iSeed))));
117}
118
119} // namespace AAX
120
121#endif // AAX_RANDOMGEN_H
122
Signal processing constants.
Definition: AAX_EnvironmentUtilities.h:72
const float cSeedDivisor
Definition: AAX_RandomGen.h:47
const int32_t cInitialSeedValue
Definition: AAX_RandomGen.h:49
float GetFastRPDFWithAmplitudeOne(int32_t *iSeed)
Definition: AAX_RandomGen.h:100
float GetTPDFWithAmplitudeOne(int32_t *iSeed)
Definition: AAX_RandomGen.h:107
float GetRPDFWithAmplitudeOne(int32_t *iSeed)
Definition: AAX_RandomGen.h:93
float GetRPDFWithAmplitudeOneHalf(int32_t *iSeed)
Definition: AAX_RandomGen.h:86
const double cNormalizeLongToAmplitudeOneHalf
Definition: AAX_Constants.h:75
int32_t GetFastInt32RPDF(int32_t *iSeed)
CALL: Calculate pseudo-random 32 bit number based on linear congruential method.
Definition: AAX_RandomGen.h:79
const double cNormalizeLongToAmplitudeOne
Definition: AAX_Constants.h:76
int32_t GetInt32RPDF(int32_t *iSeed)
Definition: AAX_RandomGen.h:52