locked
Comparing Two Sound Files RRS feed

  • Question

  • How to compare two sound files in c# .net..

    in my project i would like to set password as sound files... so i need to know how to compare sound files ..

    Thursday, July 26, 2012 11:58 AM

Answers

  • Compare them as you would any two files, byte by byte.  If all bytes match, there are the same, otherwise they aren't.
    Thursday, July 26, 2012 12:16 PM

All replies

  • Compare them as you would any two files, byte by byte.  If all bytes match, there are the same, otherwise they aren't.
    Thursday, July 26, 2012 12:16 PM
  • Or maybe by using GetGashCode method.

    Get both hash codes, then compare their equalities. I will show you an example with 2 strings (you do the same with 2 sound files):

                //inside some method:
    
                string a = "abc";
                string b = "abc";
    
                var a1 = GetHashing(a);
                var b1 = GetHashing(b);
                if (a1.Equals(b1))
                { 
                
                }            
       //method:
       private int GetHashing(string input)
       {
            return input.GetHashCode();
       }



    Mitja

    Thursday, July 26, 2012 1:03 PM
  • Sijon,

    If you are talking about comparing sound files for exact sameness, the previous two posters are correct.  If you are looking at more challenging topics, such as "Did the user speak the correct passphrase?" or "Does the voiceprint of this user match the one we have on file?", then you are probably in the wrong place.  Those are much more complex topics to which experts spend years developing appropriate algorithms.  I would suggest finding one of those algorithms, or even implementations and adapting that to your needs.

    Thursday, July 26, 2012 4:23 PM
  • Hi,

    Convert them into byte[] arrays and then compare those bytes.

    For conversion into byte[], check this out: http://www.codeproject.com/Articles/4889/A-full-duplex-audio-player-in-C-using-the-waveIn-w

    Hope this helps you!

    Thanks

    Friday, July 27, 2012 5:04 AM
  • Hi

    keep in mind that comparing HashCodes isn't always safe for
    doing reliable equality comparison.
    Two items may return the same HashCode but still be different.
    Also the opposite is possible, two objects may hold the same data
    but return different HashCodes.
    As for strings the implementation is quite strong, as you have shown
    however byte arrays - the most likely data type for binary comparison -
    just return a random int, two byte arrays that hold the same data will
    still return different HashCodes!

    byte [] b1 = { 1, 2, 3 };
    byte [] b2 = { 1, 2, 3 };

    int h1 = b1.GetHashCode(); //random int: 37121646 likely sth like the "address"
    int h2 = b2.GetHashCode(); //random int: 45592480

    So when using GetHashCode be sure the
    internal algorithm is based on the data you focus on.

    Chris

    Friday, July 27, 2012 11:50 PM