问题
I seem to be having a huge problem with something that seems very trivial.
Goal: Try to compare two Wav files and see if one(small file) is part of the other(large file).
Test: First, I took a 1 minute long piece of audio and exported 30 seconds of it to another file. I first tried to simply read in the byte[] data and look at it via logs, and there's absolutely no correlation even though they are both from the same source file? I then tried using libraries such as WavFile, and MusicG but I simply can't see any correlation between the two "fingerprints" or even the raw byte[] data that comes out of the two files?
Question: What is the simplest way to analyze these two Wav files for similarities? I have read around that if they're from the same source audio file they should be byte-byte identical. Thus take sample of each and they should be the same? That's NOT what is happening?
Now I have already searched quite a bit for this problem but almost all answers are only 25-50% complete so I feel like I'm missing a huge segment somewhere.
Thank you for any solutions that you may offer!
[EDIT] The source audio file is just a 1 minutes Wav file... which I extracted the first 30 seconds from to create the smaller file. Then I compare the short(30 seconds) to the long(1 minute). I exported both from Audacity at 1141kbps, 16bit, Wav. This was to try to avoid formatting issues... I Thought
For code look at this UNANSWERED question: Wav comparison, same file
回答1:
There are some odd things going on here. Without going into detail, I will just say that when some programs do a simple operation like what you are calling "extraction", they are not making exact copies. Libsndfile, for example, does not convert transparently when going from int sound files to float (which what Audacity uses internally) back to int. If Audacity uses libsndfile (I'm pretty sure it does), it won't make transparent copies of files, so your method won't work. eg: try the following: open a wav file, export it using the same parameters. Use diff to compare the input and output. In all likelihood, they will be different. For more details see here: http://blog.bjornroche.com/2009/12/int-float-int-its-jungle-out-there.html
The author of libsndfile defends his design decision here: http://www.mega-nerd.com/libsndfile/FAQ.html#Q010
You could try another app, but I suspect you want this to work even when people use audacity.
One of the comments suggested cross-correlation. You could also use audio fingerprinting. Both of these solutions are somewhat complex, though.
Probably the simplest solution is to read data in the native format. For example, if the file is 16 bit, then read 16-bit ints (not bytes). Then compare it against the shorter one, but compare allowing some error (off the top of my head, I am pretty sure you should never be off by more than one, but that's for each and every time it goes through audacity). So instead of asking "are these values equal" you'll have to ask "are these values within epsilon of each other." Of course for things with lots of silence in them, you'll want to make some sort of exception.
It is also possible that audacity is using dither, so make sure that's switched off. Dither can add significant noise, so if you want to work with that into equation you'll need a different solution.
来源:https://stackoverflow.com/questions/11812027/simple-wav-comparison-in-java