Transient detection

Hello,
I´d like to measure the timing of a sample until its first transient. Any hints ?
Thanks !

Depends on the sample. Under certain assumptions then the problem is quite easy. For very general cases the problem is a bit harder but still not too tough.

If the sample is a short one-shot percussive sample with a fast attack, then you can divide it into windows (say 1024-sample windows with 2x overlap) and find the window which has maximum RMS. Simple but should work fine for that special case.

A more sophisticated method would be to use a long and a short windowed RMS. For stationary signals, the amplitudes detected of the two windows will be roughly proportional, but during transients the amplitude detected by the shorter window will be larger than usual. If the the ratio of the short-term amplitude to the long-term amplitude is unusually high, and the absolute amplitudes are not too close to 0, then you have a transient. To tune the thresholds it’s best to gather some training data to find the best settings.

1 Like

Indeed there are a few approaches depending on the context. This is why FluCoMa has so many ‘attack’ detectors with various precisions… what the detection is for, and what the signal is, will change what fits best. Feel free to feed a bit more context!

1 Like

FluCoMa is perfect for this

~src = Buffer.read(...); //your sample

~ind = Buffer(s); //an empty buffer to hold transient analysis

(
FluidBufTransientSlice.process(s, ~src, 
	indices: ~ind,
	action: {|indices|
		var array = indices.loadToFloatArray(0, 1, {|t|
			"Transient detected at % samples".format(t[0]).postln;
		});
	}
);
)

Thanks - I´ll try FluCoMa - so far I can´t get it to run (FAILURE IN SERVER /cmd failed) but judging from the code you´ve sent it looks like what I´m looking for.

Thanks - I´m trying to align many (short) samples from different sources (synths, percussions etc). I´m looking for a way to automate the process instead of doing it by hand in ProTools or Reaper, that both have a well working transient detectors.

Where did you install from? My plugin is from Releases | sc3-plugins and I’ve not had any issues. Download the repo, drop the FluCoMa folder into your SC Extensions directory and see if that works.

I got it from here
Unfortunately the link you´ve send does not seem to include FluCoMa

FluCoMa is up and running - looks great! I guess the main parameters to find the transients with FluidBufTransientSlice are skew, threshFwd and threshBack, right? Can it also return the index for further use instead of posting it?

Sure!

(
FluidBufTransientSlice.process(s, ~src, 
	indices: ~ind,
	action: {|indices|
		var array = indices.loadToFloatArray(0, 1, {|t|
			~firstTransient = t[0];
		});
	}
);
)

~firstTransient;

And the arguments depend on the context so it’s hard to generalize. You could test it by using the first value as a starting point for playing the buffer at that frame. There are a lot of resources on the FluCoMa site that discuss the parameters in more detail than the SC documentation and those resources are often very helpful for clarifying how arguments might influence the result:
https://learn.flucoma.org/reference/transientslice/

I´ve tried

(
f = {
	var transients; 
	
	FluidBufTransientSlice.process(s, ~src, 
		threshFwd: 1,
		indices: ~ind,
		action: {|indices|
			var array = indices.loadToFloatArray(0, 1, {|t|
				transients = t;
			});
		}
	);
	transients;
};

f.();
)

without success, but with the global variable it works as expected.

Thanks a lot ! FluCoMa seems to have a lot of great features and will keep me busy for a while… next step: sort samples by similarity.

1 Like

There is a tutorial that does exactly that on youtube, in sc. The fantastic @tedmoore did it. Check it out here:

2 Likes