AAX SDK  2.4.1
Avid Audio Extensions Development Kit
AAX_RandomGen.h
Go to the documentation of this file.
1 /*================================================================================================*/
2 /*
3  * Copyright 2013-2015 by Avid Technology, Inc.
4  * All rights reserved.
5  *
6  * CONFIDENTIAL: This document contains confidential information. Do not
7  * read or examine this document unless you are an Avid Technology employee
8  * or have signed a non-disclosure agreement with Avid Technology which protects
9  * the confidentiality of this document. DO NOT DISCLOSE ANY INFORMATION
10  * CONTAINED IN THIS DOCUMENT TO ANY THIRD-PARTY WITHOUT THE PRIOR WRITTEN CONSENT
11  * OF Avid Technology, INC.
12  */
13 
20 /*================================================================================================*/
21 #pragma once
22 
23 #ifndef AAX_RANDOMGEN_H
24 #define AAX_RANDOMGEN_H
25 
26 // Standard headers
27 #include <stdlib.h>
28 #include <time.h>
29 #include <stdint.h>
30 
32 #include "AAX_Constants.h"
33 
34 namespace AAX
35 {
36 
37 const float cSeedDivisor = 1/127773.0f;
38 
39 const int32_t cInitialSeedValue=0x00F54321;
40 
41 /*===================================================================================================*/
42 inline int32_t GetInt32RPDF(int32_t* iSeed)
43 {
44  // Requirement: iSeed param must be a static in the calling function.
45 
46  int32_t k = int32_t((*iSeed)*cSeedDivisor);
47  *iSeed = 16807 * (*iSeed - k * 127773) - 2836 * k + 7395;
48  if (*iSeed < 0)
49  *iSeed += 2147483647;
50  return (*iSeed - 1073741824) * 2; // -2147483647..+2147483647
51 }
52 
53 /*===================================================================================================*/
54 
55 
68 inline int32_t GetFastInt32RPDF(int32_t* iSeed)
69 {
70  *iSeed = (*iSeed * 196314165) + 907633515;
71  return *iSeed;
72 }
73 
74 /*===================================================================================================*/
75 inline float GetRPDFWithAmplitudeOneHalf(int32_t* iSeed) //An amplitude of 0.5 = 1 LSBs
76 {
77  // Requirement: iSeed param must be a static in the calling function.
78  return float(cNormalizeLongToAmplitudeOneHalf) * float(GetInt32RPDF(iSeed));
79 }
80 
81 /*===================================================================================================*/
82 inline float GetRPDFWithAmplitudeOne(int32_t* iSeed) //An amplitude of 1.0 = 2 LSBs
83 {
84  // Requirement: iSeed param must be a static in the calling function.
85  return float(cNormalizeLongToAmplitudeOne) * float(GetInt32RPDF(iSeed));
86 }
87 
88 /*===================================================================================================*/
89 inline float GetFastRPDFWithAmplitudeOne(int32_t* iSeed) //An amplitude of 1.0 = 2 LSBs
90 {
91  // Requirement: iSeed param must be a static in the calling function.
92  return float(cNormalizeLongToAmplitudeOne) * float(GetFastInt32RPDF(iSeed));
93 }
94 
95 /*===================================================================================================*/
96 inline float GetTPDFWithAmplitudeOne(int32_t* iSeed) //An amplitude of 1.0 = 2 LSBs
97 {
98  // Generate a random number with a triangular pdf (tpdf) using two
99  // separate rectangular pdf noise sources.
100 
101  // We are using only one seed input for both rect pdf noise generators,
102  // but because they are of course executed sequentially independent noise
103  // will be produced.
104 
105  return float(cNormalizeLongToAmplitudeOne) * (float(GetFastInt32RPDF(iSeed) + float(GetFastInt32RPDF(iSeed))));
106 }
107 
108 } // namespace AAX
109 
110 #endif // AAX_RANDOMGEN_H
111 
Signal processing constants.
Definition: AAX_Exception.h:42
const float cSeedDivisor
Definition: AAX_RandomGen.h:37
const int32_t cInitialSeedValue
Definition: AAX_RandomGen.h:39
float GetFastRPDFWithAmplitudeOne(int32_t *iSeed)
Definition: AAX_RandomGen.h:89
float GetTPDFWithAmplitudeOne(int32_t *iSeed)
Definition: AAX_RandomGen.h:96
float GetRPDFWithAmplitudeOne(int32_t *iSeed)
Definition: AAX_RandomGen.h:82
float GetRPDFWithAmplitudeOneHalf(int32_t *iSeed)
Definition: AAX_RandomGen.h:75
const double cNormalizeLongToAmplitudeOneHalf
Definition: AAX_Constants.h:65
int32_t GetFastInt32RPDF(int32_t *iSeed)
CALL: Calculate pseudo-random 32 bit number based on linear congruential method.
Definition: AAX_RandomGen.h:68
const double cNormalizeLongToAmplitudeOne
Definition: AAX_Constants.h:66
int32_t GetInt32RPDF(int32_t *iSeed)
Definition: AAX_RandomGen.h:42