Skip to content

Commit

Permalink
Clipping detection
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Aug 3, 2024
1 parent bc3a693 commit 4bd1d2b
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions CavernUnity DLL/QuickEQ/SpeakerSweeper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ public void RegenerateSweep() {
Measurements.OffbandGain(sweepFFTlow, StartFreq, EndFreqLFE, sampleRate, 100);
}

/// <summary>
/// Get if any channel was clipping while measuring.
/// </summary>
/// <returns>For each channel if it was clipping.</returns>
public bool[] GetClippingChannels(bool parallel = true) {
bool[] result = new bool[ExcitementResponses.Length];
if (parallel) {
Parallelizer.For(0, result.Length, i => result[i] = WaveformUtils.GetPeakSigned(ExcitementResponses[i]) >= 1);
} else for (int i = 0; i < result.Length; i++) {
result[i] = WaveformUtils.GetPeakSigned(ExcitementResponses[i]) >= 1;
}
return result;
}

/// <summary>
/// Get the frequency response of an external measurement that was performed with the current <see cref="sweepFFT"/>.
/// </summary>
Expand Down Expand Up @@ -285,7 +299,7 @@ void Update() {
if (!measurementStarted) {
measurementStarted = true;
sweepers = new SweepChannel[Listener.Channels.Length];
for (int i = 0; i < Listener.Channels.Length; ++i) {
for (int i = 0; i < Listener.Channels.Length; i++) {
sweepers[i] = gameObject.AddComponent<SweepChannel>();
sweepers[i].Channel = i;
sweepers[i].Sweeper = this;
Expand All @@ -310,15 +324,15 @@ void Update() {
workers[Channel] = new Task<WorkerResult>(() => new WorkerResult(fft, sweepFFTCache, result, sampleRate));
workers[Channel].Start();
if (++Channel == Listener.Channels.Length) {
for (int channel = 0; channel < Listener.Channels.Length; ++channel) {
for (int channel = 0; channel < Listener.Channels.Length; channel++) {
workers[channel].Wait();
}
for (int channel = 0; channel < Listener.Channels.Length; ++channel) {
for (int channel = 0; channel < Listener.Channels.Length; channel++) {
FreqResponses[channel] = workers[channel].Result.FreqResponse;
ImpResponses[channel] = workers[channel].Result.ImpResponse;
Destroy(sweepers[channel]);
}
for (int channel = 0; channel < Listener.Channels.Length; ++channel) {
for (int channel = 0; channel < Listener.Channels.Length; channel++) {
workers[channel].Dispose();
}
sweepers = null;
Expand All @@ -336,7 +350,7 @@ void Update() {
[SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "Used by Unity lifecycle")]
void OnDisable() {
if (sweepers != null && sweepers[0]) {
for (int channel = 0; channel < Listener.Channels.Length; ++channel) {
for (int channel = 0; channel < Listener.Channels.Length; channel++) {
Destroy(sweepers[channel]);
}
}
Expand Down

0 comments on commit 4bd1d2b

Please sign in to comment.