Skip to content

Commit fef4fbe

Browse files
committed
Constant filling
1 parent 0e0bfed commit fef4fbe

File tree

5 files changed

+11
-15
lines changed

5 files changed

+11
-15
lines changed

CavernUnity DLL/AudioSource3D_Output.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal static void WriteOutputApproxCP(float[] Samples, float[] Target, int Ch
3232
/// <summary>Output samples to a multichannel array with constant power.</summary>
3333
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3434
internal static void WriteOutputCP(float[] Samples, float[] Target, int ChannelLength, float Gain, int Channel, int Channels) {
35-
WriteOutput(Samples, Target, ChannelLength, Mathf.Sin(Gain * CavernUtilities.HalfPi), Channel, Channels);
35+
WriteOutput(Samples, Target, ChannelLength, Mathf.Sin(Mathf.PI / 2 * Gain), Channel, Channels);
3636
}
3737

3838
/// <summary>Output samples to a multichannel array, while trying to fix standing waves.</summary>
@@ -62,7 +62,7 @@ internal static void WriteFixedOutputApproxCP(float[] Samples, float[] Target, i
6262
/// <summary>Output samples to a multichannel array with constant power, while trying to fix standing waves.</summary>
6363
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6464
internal static void WriteFixedOutputCP(float[] Samples, float[] Target, int ChannelLength, float Gain, int Channel, int Channels) {
65-
WriteFixedOutput(Samples, Target, ChannelLength, Mathf.Sin(Gain * CavernUtilities.HalfPi), Channel, Channels);
65+
WriteFixedOutput(Samples, Target, ChannelLength, Mathf.Sin(Mathf.PI / 2 * Gain), Channel, Channels);
6666
}
6767
}
6868
}

CavernUnity DLL/CavernizeRT.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ void OnAudioFilterRead(float[] data, int channels) {
9999
Height = Mathf.LerpUnclamped(Height, MaxHeight, SmoothFactor);
100100
// Output
101101
float UpperMix = (MaxHeight - BottomSpeakerHeight) / (TopSpeakerHeight - BottomSpeakerHeight),
102-
LowerMix = Mathf.Sin((1f - UpperMix) * CavernUtilities.HalfPi);
103-
UpperMix = Mathf.Sin(UpperMix * CavernUtilities.HalfPi);
102+
LowerMix = Mathf.Sin(Mathf.PI / 2 * (1f - UpperMix));
103+
UpperMix = Mathf.Sin(Mathf.PI / 2 * UpperMix);
104104
int OutputPos = (int)Divert % channels - channels;
105105
Array.Clear(data, 0, Samples);
106106
for (int Sample = 0; Sample < UpdateRate; ++Sample) // Base channel

CavernUnity DLL/QuickEQ/Measurements.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace Cavern.QuickEQ {
44
/// <summary>Tools for measuring frequency response.</summary>
55
public static class Measurements {
6-
internal const float Pix2 = Mathf.PI * 2f, NegPix2 = -Pix2;
7-
86
/// <summary>Fast Fourier transform a real signal.</summary>
97
public static Complex[] FFT(float[] Samples) {
108
int Length = Samples.Length;
@@ -25,7 +23,7 @@ public static Complex[] FFT(Complex[] Samples) {
2523
Odd[Sample] = Samples[Pair++];
2624
}
2725
Complex[] EvenFFT = FFT(Even), OddFFT = FFT(Odd);
28-
float Step = NegPix2 / Length;
26+
float Step = -2 * Mathf.PI / Length;
2927
for (int i = 0; i < HalfLength; ++i)
3028
OddFFT[i].Rotate(Step * i);
3129
for (int i = 0; i < HalfLength; ++i) {
@@ -46,7 +44,7 @@ static Complex[] ProcessIFFT(Complex[] Samples) {
4644
Odd[Sample] = Samples[Pair++];
4745
}
4846
Complex[] EvenFFT = ProcessIFFT(Even), OddFFT = ProcessIFFT(Odd);
49-
float Step = Pix2 / Length;
47+
float Step = 2 * Mathf.PI / Length;
5048
for (int i = 0; i < HalfLength; ++i)
5149
OddFFT[i].Rotate(Step * i);
5250
for (int i = 0; i < HalfLength; ++i) {
@@ -108,7 +106,7 @@ public static float[] LinearSweep(float StartFreq, float EndFreq, int Samples, i
108106
float Chirpyness = (EndFreq - StartFreq) / (2 * Samples / (float)SampleRate);
109107
for (int Sample = 0; Sample < Samples; ++Sample) {
110108
float Position = Sample / (float)SampleRate;
111-
Output[Sample] = Mathf.Sin(Pix2 * (StartFreq * Position + Chirpyness * Position * Position));
109+
Output[Sample] = Mathf.Sin(2 * Mathf.PI * (StartFreq * Position + Chirpyness * Position * Position));
112110
}
113111
return Output;
114112
}
@@ -126,7 +124,7 @@ public static float[] LinearSweepFreqs(float StartFreq, float EndFreq, int Sampl
126124
public static float[] ExponentialSweep(float StartFreq, float EndFreq, int Samples, int SampleRate) {
127125
float[] Output = new float[Samples];
128126
float Chirpyness = Mathf.Pow(EndFreq / StartFreq, SampleRate / (float)Samples),
129-
LogChirpyness = Mathf.Log(Chirpyness), SinConst = Pix2 * StartFreq;
127+
LogChirpyness = Mathf.Log(Chirpyness), SinConst = 2 * Mathf.PI * StartFreq;
130128
for (int Sample = 0; Sample < Samples; ++Sample)
131129
Output[Sample] =
132130
Mathf.Sin(SinConst * (Mathf.Pow(Chirpyness, Sample / (float)SampleRate) - 1) / LogChirpyness);

CavernUnity DLL/QuickEQ/Utils/Windowing.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void ApplyWindow(float[] Samples, Window Function) {
4040
/// <param name="End">End of the window in samples</param>
4141
public static void ApplyWindow(float[] Samples, Window Left, Window Right, int Start, int Splitter, int End) {
4242
int LeftSpan = Splitter - Start, RightSpan = End - Splitter, EndMirror = Splitter - (End - Splitter), PosSplitter = Math.Max(Splitter, 0);
43-
float LeftSpanDiv = Measurements.Pix2 / (LeftSpan * 2), RightSpanDiv = Measurements.Pix2 / (RightSpan * 2);
43+
float LeftSpanDiv = 2 * Mathf.PI / (LeftSpan * 2), RightSpanDiv = 2 * Mathf.PI / (RightSpan * 2);
4444
if (Left != Window.Disabled) {
4545
WindowFunction LeftFunc = GetWindowFunction(Left);
4646
for (int Sample = 0; Sample < Start; ++Sample)
@@ -74,7 +74,7 @@ public static void ApplyWindow(Complex[] Samples, Window Function) {
7474
/// <param name="End">End of the window in samples</param>
7575
public static void ApplyWindow(Complex[] Samples, Window Left, Window Right, int Start, int Splitter, int End) {
7676
int LeftSpan = Splitter - Start, RightSpan = End - Splitter, EndMirror = Splitter - (End - Splitter), PosSplitter = Math.Max(Splitter, 0);
77-
float LeftSpanDiv = Measurements.Pix2 / (LeftSpan * 2), RightSpanDiv = Measurements.Pix2 / (RightSpan * 2);
77+
float LeftSpanDiv = 2 * Mathf.PI / (LeftSpan * 2), RightSpanDiv = 2 * Mathf.PI / (RightSpan * 2);
7878
if (Left != Window.Disabled) {
7979
WindowFunction LeftFunc = GetWindowFunction(Left);
8080
for (int Sample = 0; Sample < Start; ++Sample)
@@ -129,7 +129,7 @@ static float TukeyWindow(float x) {
129129
if (x < FlatLeft)
130130
return (Mathf.Cos(x * Positioner - Mathf.PI) + 1) * .5f;
131131
else if (x > FlatRight)
132-
return (Mathf.Cos((Measurements.Pix2 - x) * Positioner - Mathf.PI) + 1) * .5f;
132+
return (Mathf.Cos((2 * Mathf.PI - x) * Positioner - Mathf.PI) + 1) * .5f;
133133
else
134134
return 1;
135135
}

CavernUnity DLL/Utilities/CavernUtilities.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public static string Info {
1818
}
1919
}
2020

21-
/// <summary>pi / 2</summary>
22-
internal const float HalfPi = Mathf.PI * .5f;
2321
/// <summary>sqrt(2) / 2</summary>
2422
internal const float Sqrt2p2 = .7071067811f;
2523
/// <summary>sqrt(2) / -2</summary>

0 commit comments

Comments
 (0)