summaryrefslogtreecommitdiff
path: root/indra/llaudio/llwindgen.h
diff options
context:
space:
mode:
authorMonty Brandenberg <monty@lindenlab.com>2013-05-13 18:34:54 -0400
committerMonty Brandenberg <monty@lindenlab.com>2013-05-13 18:34:54 -0400
commit73f474d886d2430db3d5c8f7729f769b389730a4 (patch)
tree5b1f481284a030c72ac08d8b3027ed608bc3ceb6 /indra/llaudio/llwindgen.h
parent81ffd3fccac709a5903dd0d7572db50c50850347 (diff)
parent180dd12ed637c1f63a5013d25fbac002e1d94c93 (diff)
Merge. Refresh from /lindenlab/viewer-cat prior to pushing.
Diffstat (limited to 'indra/llaudio/llwindgen.h')
-rwxr-xr-x[-rw-r--r--]indra/llaudio/llwindgen.h34
1 files changed, 16 insertions, 18 deletions
diff --git a/indra/llaudio/llwindgen.h b/indra/llaudio/llwindgen.h
index b9cecb60a1..719b0ecbf2 100644..100755
--- a/indra/llaudio/llwindgen.h
+++ b/indra/llaudio/llwindgen.h
@@ -27,6 +27,7 @@
#define WINDGEN_H
#include "llcommon.h"
+#include "llrand.h"
template <class MIXBUFFERFORMAT_T>
class LLWindGen
@@ -54,7 +55,9 @@ public:
}
const U32 getInputSamplingRate() { return mInputSamplingRate; }
-
+ const F32 getNextSample();
+ const F32 getClampedSample(bool clamp, F32 sample);
+
// newbuffer = the buffer passed from the previous DSP unit.
// numsamples = length in samples-per-channel at this mix time.
// NOTE: generates L/R interleaved stereo
@@ -89,7 +92,7 @@ public:
// Start with white noise
// This expression is fragile, rearrange it and it will break!
- next_sample = (F32)rand() * (1.0f / (F32)(RAND_MAX / (U16_MAX / 8))) + (F32)(S16_MIN / 8);
+ next_sample = getNextSample();
// Apply a pinking filter
// Magic numbers taken from PKE method at http://www.firstpr.com.au/dsp/pink-noise/
@@ -126,23 +129,13 @@ public:
for (U8 i=mSubSamples; i && numsamples; --i, --numsamples)
{
mLastSample = mLastSample + delta;
- S32 sample_right = (S32)(mLastSample * mCurrentPanGainR);
- S32 sample_left = (S32)mLastSample - sample_right;
+ MIXBUFFERFORMAT_T sample_right = (MIXBUFFERFORMAT_T)getClampedSample(clip, mLastSample * mCurrentPanGainR);
+ MIXBUFFERFORMAT_T sample_left = (MIXBUFFERFORMAT_T)getClampedSample(clip, mLastSample - (F32)sample_right);
- if (!clip)
- {
- *cursamplep = (MIXBUFFERFORMAT_T)sample_left;
- ++cursamplep;
- *cursamplep = (MIXBUFFERFORMAT_T)sample_right;
- ++cursamplep;
- }
- else
- {
- *cursamplep = (MIXBUFFERFORMAT_T)llclamp(sample_left, (S32)S16_MIN, (S32)S16_MAX);
- ++cursamplep;
- *cursamplep = (MIXBUFFERFORMAT_T)llclamp(sample_right, (S32)S16_MIN, (S32)S16_MAX);
- ++cursamplep;
- }
+ *cursamplep = sample_left;
+ ++cursamplep;
+ *cursamplep = sample_right;
+ ++cursamplep;
}
}
@@ -173,4 +166,9 @@ private:
F32 mLastSample;
};
+template<class T> inline const F32 LLWindGen<T>::getNextSample() { return (F32)rand() * (1.0f / (F32)(RAND_MAX / (U16_MAX / 8))) + (F32)(S16_MIN / 8); }
+template<> inline const F32 LLWindGen<F32>::getNextSample() { return ll_frand()-.5f; }
+template<class T> inline const F32 LLWindGen<T>::getClampedSample(bool clamp, F32 sample) { return clamp ? (F32)llclamp((S32)sample,(S32)S16_MIN,(S32)S16_MAX) : sample; }
+template<> inline const F32 LLWindGen<F32>::getClampedSample(bool clamp, F32 sample) { return sample; }
+
#endif