Click here to Skip to main content
15,886,578 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 System.Collections.Generic;

namespace Soundfingerprinting.NeuralHashing.MMI
{
    /// <summary>
    ///   A group of indeces that represents the hash function
    /// </summary>
    [Serializable]
    public class MinimalMutualInfoGroup
    {
        private readonly List<int> _members = new List<int>();
        private int _groupSize;

        #region Propreties

        /// <summary>
        ///   Gets the element of the hash function that coresponds 
        ///   to a network output on the specified index
        /// </summary>
        /// <param name = "index">Index to get the element at</param>
        /// <returns>The element</returns>
        public int this[int index]
        {
            get
            {
                if (index >= _members.Count)
                    throw new ArgumentException("Index is outside of bounds");
                return _members[index];
            }
        }

        /// <summary>
        ///   Group size
        /// </summary>
        public int GroupSize
        {
            get { return _groupSize; }
            set { _groupSize = value; }
        }

        /// <summary>
        ///   Number of elements currently in the group
        /// </summary>
        public int Count
        {
            get { return _members.Count; }
        }

        #endregion

        #region Constructors

        /// <summary>
        ///   Parameterless constructor
        ///   Default group size is 22
        /// </summary>
        public MinimalMutualInfoGroup()
        {
            _groupSize = 22;
            _members = new List<int>();
        }

        /// <summary>
        ///   Constructor
        /// </summary>
        /// <param name = "groupSize">Size of the group [22]</param>
        public MinimalMutualInfoGroup(int groupSize)
        {
            _groupSize = groupSize;
        }

        /// <summary>
        ///   Constructor
        /// </summary>
        /// <param name = "groupSize">Size of the group [22]</param>
        /// <param name = "startMemberIndex">First element, Highest unconditional entropy</param>
        public MinimalMutualInfoGroup(int groupSize, int startMemberIndex)
        {
            _groupSize = groupSize;
            _members.Add(startMemberIndex);
        }

        #endregion

        /// <summary>
        ///   Tries to add an element to the group
        /// </summary>
        /// <param name = "memberIndex">Element to add</param>
        /// <returns>If the addition was succesfull, return true, otherwise - false</returns>
        public bool AddToGroup(int memberIndex)
        {
            if (_members.Count < _groupSize)
            {
                _members.Add(memberIndex);
                return true;
            }
            return false;
        }

        public bool Contains(int element)
        {
            return _members.Contains(element);
        }

        public void Clear()
        {
            _members.Clear();
        }
    }
}

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