Click here to Skip to main content
15,885,949 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;

namespace DuplicateTracks.Fingerprinting.MathUtils
{
    /// <summary>
    ///   Haar wavelet decomposition algorithm
    /// </summary>
    public class HaarWavelet : IWaveletDecomposition
    {
        #region IWaveletDecomposition Members

        /// <summary>
        ///   Apply Haar Wavelet decomposition on the frames
        /// </summary>
        /// <param name = "frames">Frames to be decomposed</param>
        public void DecomposeImageInPlace(float[][] frames)
        {
            DecomposeImage(frames);
        }

        #endregion

        /// <summary>
        ///   Decomposition taken from
        ///   Wavelets for Computer Graphics: A Primer Part by Eric J. Stollnitz Tony D. DeRose David H. Salesin
        /// </summary>
        /// <param name = "array">Array to be decomposed</param>
        private static void DecomposeArray(float[] array)
        {
            int h = array.Length;
            //for (int i = 0; i < h; i++)
            //    array[i] /= (float)Math.Sqrt(h);
            float[] temp = new float[h];

            while (h > 1)
            {
                h /= 2;
                for (int i = 0; i < h; i++)
                {
                    temp[i] = (float) ((array[2*i] + array[2*i + 1])/Math.Sqrt(2));
                    temp[h + i] = (float) ((array[2*i] - array[2*i + 1])/Math.Sqrt(2));
                }
                for (int i = 0; i < 2*h; i++)
                {
                    array[i] = temp[i];
                }
            }
        }

        /// <summary>
        ///   The standard 2-dimensional Haar wavelet decomposition involves one-dimensional decomposition of each row
        ///   followed by a one-dimensional decomposition of each column of the result.
        /// </summary>
        /// <param name = "image">Image to be decomposed</param>
        private static void DecomposeImage(float[][] image)
        {
            int rows = image.GetLength(0); /*128*/
            int cols = image[0].Length; /*32*/

            for (int col = 0; col < cols /*32*/; col++) /*Decomposition of each column*/
            {
                float[] column = new float[rows]; /*Length of each column is equal to number of rows*/
                for (int row = 0; row < rows; row++)
                    column[row] = image[row][col]; /*Copying Column vector*/
                DecomposeArray(column);
                for (int row = 0; row < rows; row++)
                    image[row][col] = column[row];
            }

            for (int row = 0; row < rows /*128*/; row++) /*Decomposition of each row*/
                DecomposeArray(image[row]);
        }
    }
}

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