From 40f59fd18dc8e84f28760b30bfcce6b7e8c460f3 Mon Sep 17 00:00:00 2001 From: Sergiu Ciumac Date: Fri, 17 May 2024 12:57:38 +0300 Subject: [PATCH 1/2] Simplifying the code with an equivalent implementation. --- build.sh | 2 +- .../LCS/QueryPathReconstructionStrategy.cs | 53 ++++++++----------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/build.sh b/build.sh index e53b48bc..7689df67 100755 --- a/build.sh +++ b/build.sh @@ -6,7 +6,7 @@ else TARGET=$1 fi -dotnet test src/SoundFingerprinting.Tests/SoundFingerprinting.Tests.csproj -c $TARGET +dotnet test src/SoundFingerprinting.Tests/SoundFingerprinting.Tests.csproj -c $TARGET -v n if [ "$?" != "0" ]; then echo Tests failed. Check logs for details. diff --git a/src/SoundFingerprinting/LCS/QueryPathReconstructionStrategy.cs b/src/SoundFingerprinting/LCS/QueryPathReconstructionStrategy.cs index 5ad925f1..fbd7c5e9 100644 --- a/src/SoundFingerprinting/LCS/QueryPathReconstructionStrategy.cs +++ b/src/SoundFingerprinting/LCS/QueryPathReconstructionStrategy.cs @@ -40,8 +40,6 @@ private IEnumerable> GetIncreasingSequences(IEnumerable return bestPaths.OrderByDescending(_ => _.Count()); } - - private MaxAt[] MaxIncreasingQuerySequenceOptimal(IReadOnlyList matches, double maxGap, out int max, out int maxIndex) { var maxs = matches.Select(_ => new MaxAt(1, _)).ToArray(); @@ -111,41 +109,34 @@ private LongestIncreasingSequence GetLongestIncreasingSequence(IEnumerable max) - { - TryUpdateResultSelection(result, candidate, excluded); - } - else - { - // start of a shorter sequence, we should exclude it - excluded.Add(candidate); - } - } - continue; } - - max--; - do + if (candidate!.Length > max) + { + // check if we previously picked a sequence with the same length, if yes we should try picking the best one based on the distance to the diagonal + lastPicked = TryUpdateResultSelection(result, candidate, excluded); + continue; + } + + if (candidate.Length < max) { - switch (IsQuerySequenceDecreasing(candidate, lastPicked)) - { - case true when IsSameSequence(candidate, lastPicked, maxGap): - lastPicked = TryUpdateResultSelection(result, candidate, excluded); - break; - case false when IsSameSequence(candidate, lastPicked, maxGap): - excluded.Add(candidate); - break; - } + // start of a shorter sequence, we should exclude it + excluded.Add(candidate); + continue; } - while (maxs.TryPeek(out var lookAhead) && EqualMaxLength(candidate!, lookAhead!) && maxs.TryPop(out candidate!)); + + if (!IsQuerySequenceDecreasing(candidate, lastPicked)) + { + // the candidate is part of a different decreasing sequence + excluded.Add(candidate); + continue; + } + + max--; + lastPicked = TryUpdateResultSelection(result, candidate, excluded); } return new LongestIncreasingSequence(result.OrderBy(_ => _.Key).Select(_ => _.Value.MatchedWith), excluded.Select(_ => _.MatchedWith)); From ccee26d120b4ab4227b521f163bb31b7fc1dd191 Mon Sep 17 00:00:00 2001 From: Sergiu Ciumac Date: Fri, 17 May 2024 16:15:44 +0300 Subject: [PATCH 2/2] Version bump to v10.3.1 --- src/SoundFingerprinting.Tests/Properties/AssemblyInfo.cs | 4 ++-- src/SoundFingerprinting/Properties/AssemblyInfo.cs | 4 ++-- src/SoundFingerprinting/SoundFingerprinting.csproj | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SoundFingerprinting.Tests/Properties/AssemblyInfo.cs b/src/SoundFingerprinting.Tests/Properties/AssemblyInfo.cs index 114ab638..6506e776 100644 --- a/src/SoundFingerprinting.Tests/Properties/AssemblyInfo.cs +++ b/src/SoundFingerprinting.Tests/Properties/AssemblyInfo.cs @@ -11,5 +11,5 @@ [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("4cac962e-ebc5-4006-a1e0-7ffb3e2483c2")] -[assembly: AssemblyVersion("10.3.0.100")] -[assembly: AssemblyInformationalVersion("10.3.0.100")] +[assembly: AssemblyVersion("10.3.1.100")] +[assembly: AssemblyInformationalVersion("10.3.1.100")] diff --git a/src/SoundFingerprinting/Properties/AssemblyInfo.cs b/src/SoundFingerprinting/Properties/AssemblyInfo.cs index 16205e02..f4a37924 100644 --- a/src/SoundFingerprinting/Properties/AssemblyInfo.cs +++ b/src/SoundFingerprinting/Properties/AssemblyInfo.cs @@ -19,5 +19,5 @@ [assembly: InternalsVisibleTo("SoundFingerprinting.FFT.FFTW")] [assembly: InternalsVisibleTo("SoundFingerprinting.FFT.FFTW.Tests")] -[assembly: AssemblyVersion("10.3.0.100")] -[assembly: AssemblyInformationalVersion("10.3.0.100")] +[assembly: AssemblyVersion("10.3.1.100")] +[assembly: AssemblyInformationalVersion("10.3.1.100")] diff --git a/src/SoundFingerprinting/SoundFingerprinting.csproj b/src/SoundFingerprinting/SoundFingerprinting.csproj index a0fde2ed..442fa038 100644 --- a/src/SoundFingerprinting/SoundFingerprinting.csproj +++ b/src/SoundFingerprinting/SoundFingerprinting.csproj @@ -4,7 +4,7 @@ true false enable - 10.3.0 + 10.3.1 Sergiu Ciumac SoundFingerprinting is a C# framework that implements an efficient algorithm of audio fingerprinting and identification. Designed for developers, enthusiasts, researchers in the fields of audio processing, data mining, digital signal processing. https://github.com/addictedcs/soundfingerprinting