Files
UnrealEngineUWP/Engine/Source/Runtime/SignalProcessing/Private/Noise.cpp
Josh Markiewicz d79515867d Copying //UE4/Dev-Online to Dev-Main (//UE4/Dev-Main)
- Up to CL8320930 from DevOnline and 8311605 Merge Down from Main
- skipped some Fortnite content/plugins/code where it tried to reintegrate files that had been moved pending investigation
#rb none

[CL 8321295 by Josh Markiewicz in Main branch]
2019-08-26 18:35:22 -04:00

78 lines
1.3 KiB
C++

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#include "DSP/Noise.h"
namespace Audio
{
FWhiteNoise::FWhiteNoise(const float InScale, const float InAdd)
{
SetScaleAdd(InScale, InAdd);
}
void FWhiteNoise::SetScaleAdd(const float InScale, const float InAdd)
{
Scale = InScale;
Add = InAdd;
RandomStream.Initialize(HashCombine(GetTypeHash(Scale), GetTypeHash(Add)));
}
float FWhiteNoise::Generate()
{
return Add + Scale * RandomStream.FRand() * 2 - 1.0f;
}
FPinkNoise::FPinkNoise(const float InScale, const float InAdd)
{
InitFilter();
Noise.SetScaleAdd(InScale, InAdd);
}
void FPinkNoise::InitFilter()
{
for (int32 i = 0; i < 4; ++i)
{
X[i] = 0.0f;
Y[i] = 0.0f;
}
A[0] = 0.0f;
A[1] = -2.495f;
A[2] = 2.017;
A[3] = -0.522f;
B[0] = 0.041f;
B[1] = -0.96f;
B[2] = 0.051f;
B[3] = -0.004f;
}
/** Sets the output scale and add parameter. */
void FPinkNoise::SetScaleAdd(const float InScale, const float InAdd)
{
Noise.SetScaleAdd(InScale, InAdd);
}
float FPinkNoise::Generate()
{
X[0] = Noise.Generate();
float Output = 0.0f;
for (int32 i = 0; i < 4; ++i)
{
Output += (B[i] * X[i] - A[i] * Y[i]);
}
X[3] = X[2];
X[2] = X[1];
X[1] = X[0];
Y[3] = Y[2];
Y[2] = Y[1];
Y[1] = Y[0];
Y[0] = Output;
return Output;
}
}