Click here to Skip to main content
15,886,258 members
Articles / Desktop Programming / WPF

Duplicate songs detector via audio fingerprinting

Rate me:
Please Sign up or sign in to vote.
4.96/5 (337 votes)
23 Jun 2020MIT44 min read 1.3M   20.4K   533  
Explains sound fingerprinting algorithm, with a practical example of detecting duplicate files on the user's local drive.
The aim of this article is to show an efficient algorithm of signal processing which will allow one to have a competent system of sound fingerprinting and signal recognition. I'll try to come with some explanations of the article's algorithm, and also speak about how it can be implemented using the C# programming language. Additionally, I'll try to cover topics of digital signal processing that are used in the algorithm, thus you'll be able to get a clearer image of the entire system. And as a proof of concept, I'll show you how to develop a simple WPF MVVM application.
// Sound Fingerprinting framework
// git://github.com/AddictedCS/soundfingerprinting.git
// Code license: CPOL v.1.02
// ciumac.sergiu@gmail.com
using System;
using Soundfingerprinting.Fingerprinting.FFT;

namespace Soundfingerprinting.Fingerprinting.Windows
{
    /// <summary>
    ///   Hanning window function
    /// </summary>
    public class HanningWindow : IWindowFunction
    {
        #region IWindowFunction Members

        /// <summary>
        ///   Window the outer space by Hanning window function
        /// </summary>
        /// <param name = "outerspace">Array to be windowed</param>
        /// <param name = "length">Window length</param>
        /// <remarks>
        ///   For additional explanation please consult http://en.wikipedia.org/wiki/Hann_function
        /// </remarks>
        public void WindowInPlace(float[] outerspace, int length)
        {
#if SAFE
            if (outerspace == null)
                throw new ArgumentNullException("outerspace");
            if (outerspace.Length <= 1)
                throw new ArgumentException("Length of outer space parameter should be bigger than 1, otherwise division by zero will occur");
            if (outerspace.Length < length)
                throw new ArgumentException("Length of the outer space parameter should be bigger of equal to window length");
#endif
            //Hanning window of the whole signal
            for (int i = 0, n = length; i < n; i++)
                outerspace[i] *= (float) (0.5*(1 - Math.Cos(2*Math.PI*i/(n - 1))));
        }

        /// <summary>
        ///   Window the outer space by Hanning window function
        /// </summary>
        /// <param name = "outerspace">Array to be windowed</param>
        /// <param name = "length">Window length</param>
        /// <remarks>
        ///   For additional explanation please consult http://en.wikipedia.org/wiki/Hann_function
        /// </remarks>
        public void WindowInPlace(Complex[] outerspace, int length)
        {
#if SAFE
            if (outerspace == null)
                throw new ArgumentNullException("outerspace");
            if (outerspace.Length <= 1)
                throw new ArgumentException("Length of outer space parameter should be bigger than 1, otherwise division by zero will occur");
            if (outerspace.Length < length)
                throw new ArgumentException("Length of the outer space parameter should be bigger of equal to window length");
#endif
            //Hanning window of the whole signal
            for (int i = 0, n = length; i < n; i++)
                outerspace[i] *= 0.5*(1 - Math.Cos(2*Math.PI*i/(n - 1)));
        }

        /// <summary>
        ///   Gets the corresponding window function
        /// </summary>
        /// <param name = "length">Length of the window</param>
        /// <returns>Window function</returns>
        public double[] GetWindow(int length)
        {
            double[] array = new double[length];
            //Hanning window of the whole signal
            for (int i = 0; i < length; i++)
                array[i] = 0.5*(1 - Math.Cos(2*Math.PI*i/(length - 1)));
            return array;
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer
Moldova (Republic of) Moldova (Republic of)
Interested in computer science, math, research, and everything that relates to innovation. Fan of agnostic programming, don't mind developing under any platform/framework if it explores interesting topics. In search of a better programming paradigm.

Comments and Discussions