# What are typical audio waveform synchronization methods?

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.

• "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 Dec 25, 2020 at 0:15

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.

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

• 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. Dec 25, 2020 at 2:29
• 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. Dec 26, 2020 at 8:46

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.