2 Copyright (c) 2015, John Hurst
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 /*! \file ST2095_PinkNoise.h
29 \brief Pink Noise filter and LCG generator
33 #ifndef _ST2095_PINKNOISE_H_
34 #define _ST2095_PINKNOISE_H_
36 #include <KM_fileio.h>
40 // No attempt will be made here to explain the theory of operation of
41 // this noise source since all of the gory detail can be found in SMPTE
42 // ST 2095-1:2015. Get your copy from SMPTE today!
48 // A source of pseudo-random numbers suitable for use in generating
49 // noise signals. NOT TO BE USED FOR CRYPTOGRAPHIC FUNCTIONS as its
50 // output is 100% deterministic.
51 class LinearCongruentialGenerator
53 ui32_t m_Seed, m_RandMax;
56 KM_NO_COPY_CONSTRUCT(LinearCongruentialGenerator);
60 LinearCongruentialGenerator(const ui32_t sample_rate);
61 float GetNextSample();
65 float const PinkFilterHighPassConstant = 10.0; // Hz
66 float const PinkFilterLowPassConstant = 22400.0; // Hz
71 // storage for biquad coefficients for bandpass filter components
73 float hp1_b0, hp1_b1, hp1_b2;
75 float hp2_b0, hp2_b1, hp2_b2;
77 float lp1_b0, lp1_b1, lp1_b2;
79 float lp2_b0, lp2_b1, lp2_b2;
81 // storage for delay line variables for bandpass filter and initialize to zero
82 float hp1w1, hp1w2, hp2w1, hp2w2;
83 float lp1w1, lp1w2, lp2w1, lp2w2;
85 // storage for delay lines for pink filter network and initialize to zero
86 float lp1, lp2, lp3, lp4, lp5, lp6;
88 KM_NO_COPY_CONSTRUCT(PinkFilter);
92 PinkFilter(const i32_t SampleRate, const float HpFc, const float LpFc);
94 // Using a white noise sample as input, produce a pink noise sample
95 // having properties as defined by SMPTE ST 2095-1:2015.
96 float GetNextSample(const float white);
99 // Create a little-endian integer audio sample of the sepcified word size
100 // (1-4 bytes) from the normalized input value, write it to the buffer at p.
101 void ScalePackSample(float sample, byte_t* p, ui32_t word_size);
108 #endif // _ST2095_PINKNOISE_H_
112 // end ST2095_PinkNoise.h