Skip to content

Commit

Permalink
Code quality improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Dec 23, 2024
1 parent d15c404 commit e6eaf7d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
15 changes: 9 additions & 6 deletions CavernUnity DLL/QuickEQ/MeasurementImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,17 @@ void ProcessRecording(float[] data) {
Channels = (end - offset) / samplesPerCh;
offset = Math.Clamp(offset, 0, data.Length - Channels * samplesPerCh);

sweeper.OverwriteSweeper(Channels, FFTSize);
sweeper?.OverwriteSweeper(Channels, FFTSize);
Status = MeasurementImporterStatus.Processing;
for (; ProcessedChannel < Channels; ProcessedChannel++) {
float[] samples = new float[samplesPerCh];
Array.Copy(data, offset + ProcessedChannel * samplesPerCh, samples, 0, samplesPerCh);
sweeper.OverwriteChannel(ProcessedChannel, samples);
if (sweeper) {
for (; ProcessedChannel < Channels; ProcessedChannel++) {
float[] samples = new float[samplesPerCh];
Array.Copy(data, offset + ProcessedChannel * samplesPerCh, samples, 0, samplesPerCh);
sweeper.OverwriteChannel(ProcessedChannel, samples);
}
sweeper.ResultAvailable = true;
}
sweeper.ResultAvailable = true;
OnMeasurement?.Invoke(0, 1);
}

/// <summary>
Expand Down
20 changes: 18 additions & 2 deletions Tests/Test.CavernUnity/QuickEQ/MeasurementImporter_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace Test.Cavern.QuickEQ {
/// </summary>
[TestClass]
public class MeasurementImporter_Tests {
/// <summary>
/// Blocks execution while the import is running.
/// </summary>
ManualResetEvent blocker;

/// <summary>
/// Tests if a manual test file is imported.
/// </summary>
Expand All @@ -16,9 +21,20 @@ public class MeasurementImporter_Tests {
public void LoadTestFile() {
const string testFile = "B:\\Downloads\\test.wav";
AudioReader reader = AudioReader.Open(testFile);
var data = new MultichannelWaveform(reader.ReadMultichannel());
MultichannelWaveform data = new MultichannelWaveform(reader.ReadMultichannel());
blocker = new ManualResetEvent(false);
MeasurementImporter importer = new(data, reader.SampleRate, null);
while (importer.Status != MeasurementImporterStatus.Done) ;
importer.OnMeasurement += AfterTest;
blocker.WaitOne();
}

/// <summary>
/// Sets the <see cref="blocker"/> when the import has finished.
/// </summary>
void AfterTest(int measurement, int measurements) {
if (measurement == measurements - 1) {
blocker.Set();
}
}
}
}

0 comments on commit e6eaf7d

Please sign in to comment.