diff --git a/.gitignore b/.gitignore index a398387..cafeae8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ bin/ obj/ +BenchmarkDotNet.Artifacts/ # Ignore pre compiled web interface docker/dist diff --git a/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestAudioFingerprinting.cs b/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestAudioFingerprinting.cs index b74784e..6bc8f41 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestAudioFingerprinting.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestAudioFingerprinting.cs @@ -68,14 +68,14 @@ public class TestAudioFingerprinting { // 0 1 2 3 4 5 6 7 var fpr = new List(new uint[] { 1, 2, 3, 1, 5, 77, 42, 2 }).AsReadOnly(); - var expected = new Dictionary>() + var expected = new Dictionary() { - {1, new Collection{ 0, 3 } }, - {2, new Collection{ 1, 7 } }, - {3, new Collection{ 2 } }, - {5, new Collection{ 4 } }, - {42, new Collection{ 6 } }, - {77, new Collection{ 5 } }, + {1, 3}, + {2, 7}, + {3, 2}, + {5, 4}, + {42, 6}, + {77, 5}, }; var actual = Chromaprint.CreateInvertedIndex(fpr); diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Chromaprint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Chromaprint.cs index e417dce..2a28cb6 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Chromaprint.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Chromaprint.cs @@ -110,24 +110,21 @@ public static class Chromaprint } /// - /// Transforms a Chromaprint into an inverted index of fingerprint points to the indexes they appeared at. + /// Transforms a Chromaprint into an inverted index of fingerprint points to the last index it appeared at. /// /// Chromaprint fingerprint. /// Inverted index. - public static Dictionary> CreateInvertedIndex(ReadOnlyCollection fingerprint) + public static Dictionary CreateInvertedIndex(ReadOnlyCollection fingerprint) { - var invIndex = new Dictionary>(); + var invIndex = new Dictionary(); for (int i = 0; i < fingerprint.Count; i++) { // Get the current point. var point = fingerprint[i]; - // Create a new collection for points of this value if it doesn't exist already. - invIndex.TryAdd(point, new Collection()); - // Append the current sample's timecode to the collection for this point. - invIndex[point].Add((uint)i); + invIndex[point] = i; } return invIndex; diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs index 6389cbe..41e88ce 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs @@ -530,9 +530,8 @@ public class FingerprinterTask : IScheduledTask if (rhsIndex.ContainsKey(point)) { - // TODO: consider all timecodes before falling back - var lhsFirst = (int)lhsIndex[point][0]; - var rhsFirst = (int)rhsIndex[point][0]; + var lhsFirst = (int)lhsIndex[point]; + var rhsFirst = (int)rhsIndex[point]; indexShifts.Add(rhsFirst - lhsFirst); } }