I'm trying to solve the following problem:
Let's say I have a reference sound and a recording that I know contains at least one occurrence of the reference sound. How can I determine the positions in the audio where the sound was played? It's possible that the longer recording could have noise, and I cannot assume perfect time alignment with the sound that's playing in the recording (meaning, if I knew the content of the sound played in the recording other than the reference sound, I cannot just subtract that from the recording itself).
The method I'm experimenting with is as follows:
- Grab windows the size of the reference sound from the recorded sound
- For each window, compute the N dominant frequencies (by finding peak magnitudes in the FFT results)
- Assign points to the dominant frequencies of the reference sound (where the most dominant gets a score of N, and the least gets a score of 1)
- Compare the window's dominant frequencies to these and score it
The next few parts are just experimental, and used to narrow down results.
- Do some filtering on the matches (for instance, a match with a score lower than half the possible score gets filtered out)
- Look at overlapping matches and compute the cross correlation with the reference sound (using every possible time shift, prefer the maximum result). Prefer the match which requires the smaller shift
- Perform that shift on the match's endpoints
The problem is that I want to also detect if part of the reference sound was played, and step 6 would not allow that if the reference sound was played two times in quick succession where one was cut off.
It seems like there has to be a solution that's not as ad-hoc as this. I'm very new to the field of DSP, so there may be something simple that I don't know about.