diff options
author | McCabe Maxsted | 2010-11-02 21:32:04 -0700 |
---|---|---|
committer | McCabe Maxsted | 2010-11-02 21:32:04 -0700 |
commit | b5074f1a8e3306f1be9e93172d26c97ff088cea0 (patch) | |
tree | a53d5cc54a1f339b7637a9d7d8248eca42995af2 /linden/indra/llaudio/llwindgen.h | |
parent | Revert "Fix Bug #671 (aka VWR-1603): Duckwalk is too fast" (diff) | |
parent | Uploaded the linux64 libraries created by Aleric to imprudenceviewer.org (diff) | |
download | meta-impy-b5074f1a8e3306f1be9e93172d26c97ff088cea0.zip meta-impy-b5074f1a8e3306f1be9e93172d26c97ff088cea0.tar.gz meta-impy-b5074f1a8e3306f1be9e93172d26c97ff088cea0.tar.bz2 meta-impy-b5074f1a8e3306f1be9e93172d26c97ff088cea0.tar.xz |
Merged webkit_plugins into weekly. Huzzah! The weekly branch now has browser/media plugin support
Diffstat (limited to 'linden/indra/llaudio/llwindgen.h')
-rw-r--r-- | linden/indra/llaudio/llwindgen.h | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/linden/indra/llaudio/llwindgen.h b/linden/indra/llaudio/llwindgen.h new file mode 100644 index 0000000..847bfa6 --- /dev/null +++ b/linden/indra/llaudio/llwindgen.h | |||
@@ -0,0 +1,136 @@ | |||
1 | /** | ||
2 | * @file windgen.h | ||
3 | * @brief Templated wind noise generation | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2002&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2002-2009, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at | ||
21 | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
22 | * | ||
23 | * By copying, modifying or distributing this software, you acknowledge | ||
24 | * that you have read and understood your obligations described above, | ||
25 | * and agree to abide by those obligations. | ||
26 | * | ||
27 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
28 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
29 | * COMPLETENESS OR PERFORMANCE. | ||
30 | * $/LicenseInfo$ | ||
31 | */ | ||
32 | #ifndef WINDGEN_H | ||
33 | #define WINDGEN_H | ||
34 | |||
35 | #include "llcommon.h" | ||
36 | #include "llrand.h" | ||
37 | |||
38 | template <class MIXBUFFERFORMAT_T> | ||
39 | class LLWindGen | ||
40 | { | ||
41 | public: | ||
42 | LLWindGen() : | ||
43 | mTargetGain(0.f), | ||
44 | mTargetFreq(100.f), | ||
45 | mTargetPanGainR(0.5f), | ||
46 | mbuf0(0.0), | ||
47 | mbuf1(0.0), | ||
48 | mbuf2(0.0), | ||
49 | mbuf3(0.0), | ||
50 | mbuf4(0.0), | ||
51 | mbuf5(0.0), | ||
52 | mY0(0.0), | ||
53 | mY1(0.0), | ||
54 | mCurrentGain(0.f), | ||
55 | mCurrentFreq(100.f), | ||
56 | mCurrentPanGainR(0.5f) {}; | ||
57 | |||
58 | static const U32 getInputSamplingRate() {return mInputSamplingRate;} | ||
59 | |||
60 | // newbuffer = the buffer passed from the previous DSP unit. | ||
61 | // numsamples = length in samples-per-channel at this mix time. | ||
62 | // stride = number of bytes between start of each sample. | ||
63 | // NOTE: generates L/R interleaved stereo | ||
64 | MIXBUFFERFORMAT_T* windGenerate(MIXBUFFERFORMAT_T *newbuffer, int numsamples, int stride) | ||
65 | { | ||
66 | U8 *cursamplep = (U8*)newbuffer; | ||
67 | |||
68 | double bandwidth = 50.0F; | ||
69 | double a0,b1,b2; | ||
70 | |||
71 | // calculate resonant filter coeffs | ||
72 | b2 = exp(-(F_TWO_PI) * (bandwidth / mInputSamplingRate)); | ||
73 | |||
74 | while (numsamples--) | ||
75 | { | ||
76 | mCurrentFreq = (float)((0.999 * mCurrentFreq) + (0.001 * mTargetFreq)); | ||
77 | mCurrentGain = (float)((0.999 * mCurrentGain) + (0.001 * mTargetGain)); | ||
78 | mCurrentPanGainR = (float)((0.999 * mCurrentPanGainR) + (0.001 * mTargetPanGainR)); | ||
79 | b1 = (-4.0 * b2) / (1.0 + b2) * cos(F_TWO_PI * (mCurrentFreq / mInputSamplingRate)); | ||
80 | a0 = (1.0 - b2) * sqrt(1.0 - (b1 * b1) / (4.0 * b2)); | ||
81 | double nextSample; | ||
82 | |||
83 | // start with white noise | ||
84 | nextSample = ll_frand(2.0f) - 1.0f; | ||
85 | |||
86 | // apply pinking filter | ||
87 | mbuf0 = 0.997f * mbuf0 + 0.0126502f * nextSample; | ||
88 | mbuf1 = 0.985f * mbuf1 + 0.0139083f * nextSample; | ||
89 | mbuf2 = 0.950f * mbuf2 + 0.0205439f * nextSample; | ||
90 | mbuf3 = 0.850f * mbuf3 + 0.0387225f * nextSample; | ||
91 | mbuf4 = 0.620f * mbuf4 + 0.0465932f * nextSample; | ||
92 | mbuf5 = 0.250f * mbuf5 + 0.1093477f * nextSample; | ||
93 | |||
94 | nextSample = mbuf0 + mbuf1 + mbuf2 + mbuf3 + mbuf4 + mbuf5; | ||
95 | |||
96 | // do a resonant filter on the noise | ||
97 | nextSample = (double)( a0 * nextSample - b1 * mY0 - b2 * mY1 ); | ||
98 | mY1 = mY0; | ||
99 | mY0 = nextSample; | ||
100 | |||
101 | nextSample *= mCurrentGain; | ||
102 | |||
103 | MIXBUFFERFORMAT_T sample; | ||
104 | |||
105 | sample = llfloor(((F32)nextSample*32768.f*(1.0f - mCurrentPanGainR))+0.5f); | ||
106 | *(MIXBUFFERFORMAT_T*)cursamplep = llclamp(sample, (MIXBUFFERFORMAT_T)-32768, (MIXBUFFERFORMAT_T)32767); | ||
107 | cursamplep += stride; | ||
108 | |||
109 | sample = llfloor(((F32)nextSample*32768.f*mCurrentPanGainR)+0.5f); | ||
110 | *(MIXBUFFERFORMAT_T*)cursamplep = llclamp(sample, (MIXBUFFERFORMAT_T)-32768, (MIXBUFFERFORMAT_T)32767); | ||
111 | cursamplep += stride; | ||
112 | } | ||
113 | |||
114 | return newbuffer; | ||
115 | } | ||
116 | |||
117 | F32 mTargetGain; | ||
118 | F32 mTargetFreq; | ||
119 | F32 mTargetPanGainR; | ||
120 | |||
121 | private: | ||
122 | static const U32 mInputSamplingRate = 44100; | ||
123 | F64 mbuf0; | ||
124 | F64 mbuf1; | ||
125 | F64 mbuf2; | ||
126 | F64 mbuf3; | ||
127 | F64 mbuf4; | ||
128 | F64 mbuf5; | ||
129 | F64 mY0; | ||
130 | F64 mY1; | ||
131 | F32 mCurrentGain; | ||
132 | F32 mCurrentFreq; | ||
133 | F32 mCurrentPanGainR; | ||
134 | }; | ||
135 | |||
136 | #endif | ||