Is there a way to find the common audio in two wav files?

Viewed 49

If you have two wav files of the same length with a repeating electronic drum hit playing consistently throughout both files (in exactly the same points). With the only difference being a piano playing different chords layered with the drum. Is there a way to extract only the audio that is perfectly consistent to both files (in this case the drum hits)?

2 Answers

yes ... open up both audio files and iterate across both files simultaneously to retrieve each audio sample pulled from each input file ... for each audio sample pair ( one audio sample from each input file ) then subtract value of one sample from the other sample ( sampleA - sampleB ) which will give you only the difference namely only the piano signal lets call this output audio sample piano ... save each output sample generated from doing above diff into an output file called piano ... when done doing above you have a new audio file called piano ... then do similar to above this time open up the input file containing both drum and piano as well as the piano file created above ... as you iterate across this new pair of audio files again retrieve the samples one by one in parallel just as done above ... again subtract the samples ( sampleDrumAndPiano - sampleOnlyPiano ) and save this difference in a new second output file

this second output file will contain the difference between sampleDrumAndPiano and sampleOnlyPiano which will leave you with only the drum track ... this should be same as the other source audio file which also happens to also contain only the drum track

Your problem statement is:

z1 = x + y1
z2 = x + y2

Short answer: you have yourself a system of 2 equations with 3 unknowns x, y1, y2, so no straightfoward way to get x back.

Long answer: you can improve the SNR by doing (reference)

sum = z1+z2
diff = z1-z2
SUM = abs(fft(sum))
DIFF = abs(fft(diff))
X_HAT = (SUM-DIFF).*(fft(sum))./SUM
x_hat = real(ifft(X_HAT))
Related