Click here to Skip to main content
15,867,453 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
// https://code.google.com/p/soundfingerprinting/
// Code license: GNU General Public License v2
// ciumac.sergiu@gmail.com
using System;
using System.Diagnostics;

namespace SoundfingerprintingLib.DbStorage.Entities
{
    /// <summary>
    ///   Track entity object
    /// </summary>
    [Serializable]
    [DebuggerDisplay("Title={_title}, Artist={_artist}")]
    public class Track
    {
        #region Private fields

        /// <summary>
        ///   Album id of the track
        /// </summary>
        [DebuggerBrowsable(DebuggerBrowsableState.Never)] private Int32 _albumId;

        /// <summary>
        ///   Artist of the track
        /// </summary>
        [DebuggerBrowsable(DebuggerBrowsableState.Never)] private string _artist;

        /// <summary>
        ///   Title of the track
        /// </summary>
        [DebuggerBrowsable(DebuggerBrowsableState.Never)] private string _title;

        /// <summary>
        ///   Track length
        /// </summary>
        [DebuggerBrowsable(DebuggerBrowsableState.Never)] private int _trackLength;

        #endregion

        #region Constructors

        /// <summary>
        ///   Parameter less Constructor
        /// </summary>
        public Track()
        {
            Id = Int32.MinValue;
        }

        /// <summary>
        ///   Track constructor
        /// </summary>
        /// <param name="id">Id of the track</param>
        /// <param name = "artist">Artist's name</param>
        /// <param name = "title">Title</param>
        /// <param name = "albumId">Album's identifier</param>
        public Track(int id, string artist, string title, Int32 albumId) 
        {
            Id = id;
            Artist = artist;
            Title = title;
            AlbumId = albumId;
        }

        /// <summary>
        ///   Track constructor
        /// </summary>
        /// <param name="id">Id of the track</param>
        /// <param name = "artist">Artist's name</param>
        /// <param name = "title">Title</param>
        /// <param name = "albumId">Album's identifier</param>
        /// <param name = "trackLength">Track length</param>
        public Track(int id, string artist, string title, Int32 albumId, int trackLength)
            : this(id, artist, title, albumId)
        {
            TrackLength = trackLength;
        }

        #endregion

        #region Properties

        /// <summary>
        ///   Track's id
        /// </summary>
        /// <remarks>
        /// Once inserted into the database the object will be given a unique identifier
        /// </remarks>
        public Int32 Id
        {
            get;
            set;
        }

        /// <summary>
        ///   Artist's name
        /// </summary>
        public string Artist
        {
            get { return _artist; }
            set
            {
                if (value.Length > 255)
                    throw new FingerprintEntityException("Artist's length cannot exceed a predefined value. Check the documentation");
                _artist = value;
            }
        }

        /// <summary>
        ///   Track's title
        /// </summary>
        public string Title
        {
            get { return _title; }
            set
            {
                if (value.Length > 255)
                    throw new FingerprintEntityException("Title's length cannot exceed a predefined value. Check the documentation");
                _title = value;
            }
        }

        /// <summary>
        ///   Album's Id, in which the track is included
        /// </summary>
        public Int32 AlbumId
        {
            get { return _albumId; }
            set { _albumId = value; }
        }

        /// <summary>
        ///   Track's Length
        /// </summary>
        public int TrackLength
        {
            get { return _trackLength; }
            set
            {
                if (value < 0)
                    throw new FingerprintEntityException("Track's Length cannot be less than 0");
                _trackLength = value;
            }
        }

        #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