1
$\begingroup$

I have two roughly similar (not identical) audio files, both being recordings of the same audio source material, but made independently of each other.

I need to calculate the time offset between each file, for instance one recording would be started at time A and the other at time B. By inspecting and processing the audio wave forms in each of the files I need to calculate the offset (A - B).

What are typical and effective ways of achieving this?

It can be assumed that both files are mono and that the sampling rate is consistent between the two files.

$\endgroup$
1
  • $\begingroup$ "It can be assumed that .. the sampling rate is consistent between the two files." That's very unlikely, actually, unless they were recorded with the same equipment, in which case they'd already be synchronized $\endgroup$ – endolith Dec 25 '20 at 0:15
0
$\begingroup$

Both answers you got regarding the cross-correlation function are quite valid and, as Hilmar states, there may be some (small or large depends on the recording system and other possibly topological and environmental factors) drifts/inconsistencies in the speeds and/or captured samples.

There are a plethora of scientific articles regarding cross-correlation and its use in the estimation of the delays, many of which are used for Direction-of-Arrival (DoA) estimation in microphone arrays.

In general, you could use the generalised cross-correlation function (for more info you can have a look at "Microphone Array Signal Processing" by Benesty, Chen and Huang, or a general Digital Signal Processing textbook such as "Digital Signal Processing - Principles, Algorithms and Applications" by Proakis and Manolakis) to estimate the delay. You could possibly do that for the whole recording if you are confident enough about the stability of your equipment, or you could possibly do the same thing for chunks of the recording in order to estimate the delay for every frame. This could provide some insight into the variability of the speed/delay between the two recordings. Of course, if you choose too small frames of data you could possibly run into erroneous estimation, as the correlation algorithms need enough data to give "good" results (they are originally derived on a statistical base).

The index of the maximum of the cross-correlation function should provide the estimate for the delay (in samples) between the two recordings, with negative values stating that the reference lags the second recording. In addition to that, many authors (for example in "Statistical and Adaptive Signal Processing - Spectral Estimation, Signal Modelling, Adaptive Filtering and Array Processing" by Manolakis, Ingle and Kogon) state that only part of the cross-correlation function is valid, as for large lags the correlation between samples is very weak for audio signals (briefly stated). Of course, since we are talking about the exact same recording this assumption may not hold for your case, but it is a good practice to "not trust" large lag values.

Furthermore, you could also have a look at a paper ("Synchronization Ambiguity in Audio Content Generated by Users Attending the Same Public Event" by Stefanakis and Mouchtaris) stating some ambiguities when trying to synchronise different recordings of the same event. This may or may not be relevant to your application though.

$\endgroup$
3
$\begingroup$

Crosscorrelation, find the maximum, and use that to offset one file vs the other.

$\endgroup$
2
  • 1
    $\begingroup$ the offset might change due to the two sample rates not being exactly identical. so cross-correlation to determine the offset will have to be done periodically and one recording or the other would need to be slowed down or sped up slightly. $\endgroup$ – robert bristow-johnson Dec 25 '20 at 2:29
  • $\begingroup$ I think that the question might have been rephrased since I wrote my answer? If the two recordings are «similar but not identical», then it depends on the kind of dissimilarity. Is it the kind of variation that one might see by playing the same recording in different rooms («Shazaam»)? Or is it the variation between violinists interpreting a piece of Bach differently? Restrict the expected variation and one might come up with a synchronization scheme. $\endgroup$ – Knut Inge Dec 26 '20 at 8:46
2
$\begingroup$

Two different recordings of the same piece of music will typically have slightly different speeds. What exactly do you want to synchronize: the beginning, the end or both?

You use cross correlation to find the difference in the beginnings and the difference in the ends. If you want sync both you need to time stretch one of the files to match the length of the other.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.