0
votes

I have two audio tracks with a click sound (basically a short sine) approximately every second. The sample rate is 44.1kHz. One click takes about 1000 samples. There are about 20 - 30 clicks in each track. The corresponding clicks should have an error about a few samples (max. 48 samples).

enter image description here

I can detect the delay between the first clicks in the two tracks.

I know two different methods:

1.

[c, lags] = xcorr(Track1, Track2);
[max_c, I] = max(c);
delay = lags(I);

2.

delay = finddelay(Track1, Track2);

Both methods return the same value with inverted sign which is ok for now.

I want to detect the delays between all corresponding click sounds.

Here is another image with the start of the click from both tracks:

enter image description here

How can I achieve this?

PS: Sorry if the word corresponding is used wrong. What I mean by that is the clicks for the respective seconds.

1

1 Answers

0
votes

I came up with a simple function by myself. Based on the fact that the sounds are spaced by approximately one second I iterate over the PCM data and increment a counter by the sample rate.

function result = delays(filename)
    [pcm, samplerate] = audioread(filename);
    t1 = pcm(:,1);
    t2 = pcm(:,2);
    len = length(t1);
    cnt = 1;
    result = [];
    while cnt < len
        delay = finddelay(t1(cnt:end), t2(cnt:end));
        result = [result delay];
        cnt = cnt + samplerate;
    end
end