| AAX SDK 2.6.1 Avid Audio Extensions Development Kit

- Welcome
- Manual
- Classes
- Files
- Lists
- Support

- File List
- File Members

Loading...
Searching...
No Matches
AAX_RandomGen.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 * Copyright 2013-2015, 2023 Avid Technology, Inc.
4 * All rights reserved.
5 *
6 * CONFIDENTIAL: this document contains confidential information of Avid. Do
7 * not disclose to any third party. Use of the information contained in this
8 * document is subject to an Avid SDK license.
9 */
10
17/*================================================================================================*/
18#pragma once
19
20#ifndef AAX_RANDOMGEN_H
21#define AAX_RANDOMGEN_H
22
23// Standard headers
24#include <stdlib.h>
25#include <time.h>
26#include <stdint.h>
27
28#include "AAX_PlatformOptimizationConstants.h"
29#include "AAX_Constants.h"
30
31 namespace AAX
32{
33
34 const float cSeedDivisor = 1/127773.0f;
35
36 const int32_t cInitialSeedValue=0x00F54321;
37
38/*===================================================================================================*/
39 inline int32_t GetInt32RPDF(int32_t* iSeed)
40{
41 // Requirement: iSeed param must be a static in the calling function.
42 int64_t seed = *iSeed;
43 int64_t k = static_cast<int64_t>(seed*cSeedDivisor);
44 seed = 16807 * (seed - k * 127773LL) - 2836 * k + 7395;
45 *iSeed = static_cast<int32_t>(seed);
46 if (*iSeed < 0)
47 *iSeed += 2147483647;
48 return (*iSeed - 1073741824) * 2; // -2147483647..+2147483647
49}
50
51/*===================================================================================================*/
52
53
66 inline int32_t GetFastInt32RPDF(int32_t* iSeed)
67{
68 *iSeed = (*iSeed * 196314165) + 907633515;
69 return *iSeed;
70}
71
72/*===================================================================================================*/
73 inline float GetRPDFWithAmplitudeOneHalf(int32_t* iSeed) //An amplitude of 0.5 = 1 LSBs
74{
75 // Requirement: iSeed param must be a static in the calling function.
76 return float(cNormalizeLongToAmplitudeOneHalf) * float(GetInt32RPDF(iSeed));
77}
78
79/*===================================================================================================*/
80 inline float GetRPDFWithAmplitudeOne(int32_t* iSeed) //An amplitude of 1.0 = 2 LSBs
81{
82 // Requirement: iSeed param must be a static in the calling function.
83 return float(cNormalizeLongToAmplitudeOne) * float(GetInt32RPDF(iSeed));
84}
85
86/*===================================================================================================*/
87 inline float GetFastRPDFWithAmplitudeOne(int32_t* iSeed) //An amplitude of 1.0 = 2 LSBs
88{
89 // Requirement: iSeed param must be a static in the calling function.
90 return float(cNormalizeLongToAmplitudeOne) * float(GetFastInt32RPDF(iSeed));
91}
92
93/*===================================================================================================*/
94 inline float GetTPDFWithAmplitudeOne(int32_t* iSeed) //An amplitude of 1.0 = 2 LSBs
95{
96 // Generate a random number with a triangular pdf (tpdf) using two
97 // separate rectangular pdf noise sources.
98
99 // We are using only one seed input for both rect pdf noise generators,
100 // but because they are of course executed sequentially independent noise
101 // will be produced.
102
103 return float(cNormalizeLongToAmplitudeOne) * (float(GetFastInt32RPDF(iSeed) + float(GetFastInt32RPDF(iSeed))));
104}
105
106} // namespace AAX
107
108#endif // AAX_RANDOMGEN_H
109
AAX_Constants.h
Signal processing constants.
AAX_PlatformOptimizationConstants.h
Constants descriptor...
AAX
Definition: AAX_EnvironmentUtilities.h:59
AAX::cSeedDivisor
const float cSeedDivisor
Definition: AAX_RandomGen.h:34
AAX::cInitialSeedValue
const int32_t cInitialSeedValue
Definition: AAX_RandomGen.h:36
AAX::GetFastRPDFWithAmplitudeOne
float GetFastRPDFWithAmplitudeOne(int32_t *iSeed)
Definition: AAX_RandomGen.h:87
AAX::GetTPDFWithAmplitudeOne
float GetTPDFWithAmplitudeOne(int32_t *iSeed)
Definition: AAX_RandomGen.h:94
AAX::GetRPDFWithAmplitudeOne
float GetRPDFWithAmplitudeOne(int32_t *iSeed)
Definition: AAX_RandomGen.h:80
AAX::GetRPDFWithAmplitudeOneHalf
float GetRPDFWithAmplitudeOneHalf(int32_t *iSeed)
Definition: AAX_RandomGen.h:73
AAX::cNormalizeLongToAmplitudeOneHalf
const double cNormalizeLongToAmplitudeOneHalf
Definition: AAX_Constants.h:62
AAX::GetFastInt32RPDF
int32_t GetFastInt32RPDF(int32_t *iSeed)
CALL: Calculate pseudo-random 32 bit number based on linear congruential method.
Definition: AAX_RandomGen.h:66
AAX::cNormalizeLongToAmplitudeOne
const double cNormalizeLongToAmplitudeOne
Definition: AAX_Constants.h:63
AAX::GetInt32RPDF
int32_t GetInt32RPDF(int32_t *iSeed)
Definition: AAX_RandomGen.h:39