Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  Tests adjustment.
  Minor adjustment using latest C# syntax.
  Version bump to v8.30.0
  • Loading branch information
AddictedCS committed Oct 25, 2023
2 parents dcb2520 + 7969229 commit 86185c0
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/SoundFingerprinting.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("4cac962e-ebc5-4006-a1e0-7ffb3e2483c2")]
[assembly: AssemblyVersion("8.28.0.100")]
[assembly: AssemblyInformationalVersion("8.28.0.100")]
[assembly: AssemblyVersion("8.30.0.100")]
[assembly: AssemblyInformationalVersion("8.30.0.100")]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.4" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace SoundFingerprinting.Tests.Unit.Utils
{
using System;
using System.Linq;
using System.Threading.Tasks;

using NUnit.Framework;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
[TestFixture]
public class QuickSelectAlgorithmTest
{
private readonly QuickSelectAlgorithm algorithm = new QuickSelectAlgorithm();

[Test]
public void ShouldProperlyTestAccuracy()
{
Expand All @@ -35,8 +33,8 @@ public void ShouldGenerateSameSignatureDuringMultipleRuns()
ushort[] indexes1 = Range(0, count);
ushort[] indexes2 = Range(0, count);

int akth = algorithm.Find(topWavelets - 1, a, indexes1, 0, a.Length - 1);
int bkth = algorithm.Find(topWavelets - 1, b, indexes2, 0, b.Length - 1);
int akth = QuickSelectAlgorithm.Find(topWavelets - 1, a, indexes1, 0, a.Length - 1);
int bkth = QuickSelectAlgorithm.Find(topWavelets - 1, b, indexes2, 0, b.Length - 1);

Assert.AreEqual(akth, bkth);
AssertFingerprintsAreSame(topWavelets, a, b);
Expand Down Expand Up @@ -71,7 +69,7 @@ public void ShouldFindTop200Element()
float[] floats = GenerateRandomArray(count, random);
ushort[] indexes = Enumerable.Range(0, count).Select(i => (ushort)i).ToArray();

int kth = algorithm.Find(topWavelets - 1, floats, indexes, 0, floats.Length - 1);
int kth = QuickSelectAlgorithm.Find(topWavelets - 1, floats, indexes, 0, floats.Length - 1);

Assert.AreEqual(topWavelets - 1, kth);
for (int i = 0; i < topWavelets; ++i)
Expand All @@ -90,7 +88,7 @@ public void ShouldProperlySelectCorrectKthOrderStatistic()
for (int i = 0; i < 10; ++i)
{
float[] values = { 3, 4, 5, 1, 6, 7, 8, 9, 2, 0 };
int value = algorithm.Find(i, values, Enumerable.Range(0, 10).Select(k => (ushort)k).ToArray(), 0, values.Length - 1);
int value = QuickSelectAlgorithm.Find(i, values, Enumerable.Range(0, 10).Select(k => (ushort)k).ToArray(), 0, values.Length - 1);

Assert.AreEqual(value, i);
}
Expand Down
4 changes: 2 additions & 2 deletions src/SoundFingerprinting/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
[assembly: InternalsVisibleTo("SoundFingerprinting.FFT.FFTW")]
[assembly: InternalsVisibleTo("SoundFingerprinting.FFT.FFTW.Tests")]

[assembly: AssemblyVersion("8.28.0.100")]
[assembly: AssemblyInformationalVersion("8.28.0.100")]
[assembly: AssemblyVersion("8.30.0.100")]
[assembly: AssemblyInformationalVersion("8.30.0.100")]
3 changes: 1 addition & 2 deletions src/SoundFingerprinting/SoundFingerprinting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
<RepositoryUrl>https://github.com/AddictedCS/soundfingerprinting</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>
Hiding some of the methods related to realtime pass filters that can lead to memory leaks.
No changes in the core functionality.
Version bump to v8.30.0 accomodating SoundFingerprinting.Emy version upgrade.
</PackageReleaseNotes>
<PackageTags>Audio Video Identification Fingerprinting Digital Signal Processing Music Recognition Data Mining Content Sound Shazam</PackageTags>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 1 addition & 3 deletions src/SoundFingerprinting/Utils/FastFingerprintDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
{
internal class FastFingerprintDescriptor : FingerprintDescriptor
{
private readonly QuickSelectAlgorithm quickSelect = new ();

public override IEncodedFingerprintSchema ExtractTopWavelets(float[] frames, int topWavelets, ushort[] indexes)
{
quickSelect.Find(topWavelets - 1, frames, indexes, 0, frames.Length - 1);
QuickSelectAlgorithm.Find(topWavelets - 1, frames, indexes, 0, frames.Length - 1);
return EncodeFingerprint(frames, topWavelets, indexes);
}
}
Expand Down
28 changes: 9 additions & 19 deletions src/SoundFingerprinting/Utils/QuickSelectAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
internal class QuickSelectAlgorithm
{
public int Find(int kth, float[] list, ushort[] indexes, int lo, int hi)
public static int Find(int kth, float[] list, ushort[] indexes, int lo, int hi)
{
while (lo != hi)
{
Expand Down Expand Up @@ -30,14 +30,14 @@ public int Find(int kth, float[] list, ushort[] indexes, int lo, int hi)
return lo;
}

private int Partition(float[] list, ushort[] indexes, int pivotIndex, int lo, int hi)
private static int Partition(float[] list, ushort[] indexes, int pivotIndex, int lo, int hi)
{
float pivotValue = Abs(list[pivotIndex]);
float pivotValue = System.Math.Abs(list[pivotIndex]);
Swap(list, indexes, pivotIndex, hi);
int storeIndex = lo;
for (int i = lo; i < hi; ++i)
{
if (Abs(list[i]) > pivotValue)
if (System.Math.Abs(list[i]) > pivotValue)
{
Swap(list, indexes, storeIndex, i);
storeIndex++;
Expand All @@ -48,31 +48,21 @@ private int Partition(float[] list, ushort[] indexes, int pivotIndex, int lo, in
return storeIndex;
}

private void Swap(float[] list, ushort[] indexes, int i, int j)
private static void Swap(float[] list, ushort[] indexes, int i, int j)
{
float tmp = list[i];
list[i] = list[j];
list[j] = tmp;

ushort indexTmp = indexes[i];
indexes[i] = indexes[j];
indexes[j] = indexTmp;
(list[i], list[j]) = (list[j], list[i]);
(indexes[i], indexes[j]) = (indexes[j], indexes[i]);
}

private void SwapIfGreater(float[] list, ushort[] indexes, int a, int b)
private static void SwapIfGreater(float[] list, ushort[] indexes, int a, int b)
{
if (a != b)
{
if (Abs(list[a]) > Abs(list[b]))
if (System.Math.Abs(list[a]) > System.Math.Abs(list[b]))
{
Swap(list, indexes, a, b);
}
}
}

private float Abs(float x)
{
return System.Math.Abs(x);
}
}
}

0 comments on commit 86185c0

Please sign in to comment.