Click here to Skip to main content
15,892,737 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.ComponentModel;
using System.Diagnostics;
using DuplicateTracks.Services;

namespace DuplicateTracks.ViewModel
{
    /// <summary>
    ///   Base class for ViewModels
    /// </summary>
    public abstract class ViewModelBase : INotifyPropertyChanged, IDisposable
    {
        /// <summary>
        ///   Throw on invalid property name
        /// </summary>
        private const bool THROW_ON_INVALID_PROPERTY_NAME = true;

        /// <summary>
        ///   Check if already disposed
        /// </summary>
        private bool _alreadyDisposed;

        #region IDisposable Members

        /// <summary>
        ///   Dispose resources
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        #endregion

        #region INotifyPropertyChanged Members

        /// <summary>
        ///   Property changed event
        /// </summary>
        /// <remarks>
        ///   Whenever a property on a ViewModel object has a new value, 
        ///   it can raise the PropertyChanged event to notify the WPF binding 
        ///   system of the new value. Upon receiving that notification, the 
        ///   binding system queries the property, and the bound property on 
        ///   some UI element receives the new value.
        /// </remarks>
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        /// <summary>
        ///   On property changed, tell UI to refresh binding elements
        /// </summary>
        /// <param name = "propertyName">Changed property</param>
        protected virtual void OnPropertyChanged(string propertyName)
        {
            VerifyPropertyName(propertyName);
            PropertyChangedEventHandler temp = PropertyChanged;
            if (temp != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        /// <summary>
        ///   Dispose
        /// </summary>
        /// <param name = "isDisposing">Is disposing by client call</param>
        protected virtual void Dispose(bool isDisposing)
        {
            if (!_alreadyDisposed)
            {
                if (!isDisposing)
                {
                    /*Dispose managed resources*/
                }
                /*Dispose unmanaged resources*/
            }
            _alreadyDisposed = true;
        }

        /// <summary>
        ///   Finalizer
        /// </summary>
        ~ViewModelBase()
        {
            Dispose(false);
        }

        /// <summary>
        ///   Verify if there is such a property on the ViewModelBase
        /// </summary>
        /// <param name = "propertyName"></param>
        [Conditional("DEBUG")]
        [DebuggerStepThrough]
        public void VerifyPropertyName(string propertyName)
        {
            // Verify that the property name matches a real,  
            // public, instance property on this object.
            if (TypeDescriptor.GetProperties(this)[propertyName] == null)
            {
                string msg = "Invalid property name: " + propertyName;

                if (THROW_ON_INVALID_PROPERTY_NAME)
                    throw new Exception(msg);
                else
                    Debug.Fail(msg);
            }
        }

        /// <summary>
        ///   Get service contract implementation of a specific type
        /// </summary>
        /// <typeparam name = "TServiceContract">Type of the service contract</typeparam>
        /// <returns>Implementation of service contract</returns>
        public TServiceContract GetService<TServiceContract>() where TServiceContract : class
        {
            return ServiceContainer.Instance.GetService<TServiceContract>();
        }
    }
}

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