Extracting audio above threshold to new buffer?

Hello all,
aiming to reduce the size of source buffer and hence shorten the (potentially very long) processing time with FluidBufNMFCross i was wondering if one could use FluidBufAmpGate & FluidBufCompose to extract the audio material above a certain threshold to a new buffer (as an offline process) so to only supply that shortened buffer as spectral templates?
Like this all the silence and very low noises could be sorted out and make processing faster.
(I also wonder though if the clicks between the slices (as theres no envelope) could be negative in the supply of spectral bases or rather negligible?)
Or maybe theres other similar approaches for the same goal?
Thanks,
Jan

Hi @jan,

Here’s a bit of code that will analyse a buffer to find where there is material above a certain threshold, then concatenate those segments into a new buffer. I’m using one of the audio files supplied with the FluCoMa package, so feel free to play around with that one if you like. When you put in a new buffer to analyse and slice, you’ll likely have to tweak the FluidBufAmpGate parameters to get it to work the way you want. I’m also using FluidWaveform here to eyeball the slices and get a sense of what the algorithm is doing.

(note that although the two FluidWaveforms we see are the same width, the bottom one is going to be a shorter buffer! They just look the same because the windows are the same width)

Regarding whether or not clicks will be a problem in FluidBufNMFCross, I’m not sure. I’d say give it a try and see! I’ll be very curious to hear what you find!

Let me know if this achieves what you’re looking to do!

Cheers,

T

(
s.waitForBoot{
	var buf = Buffer.read(s,FluidFilesPath("Olencki-TenTromboneLongTones-M.wav"));
	var indices = Buffer(s);
	var concat_buf = Buffer(s);

	Window.closeAll;

	s.sync;
	FluidBufAmpGate.processBlocking(s,buf,indices:indices,onThreshold:-40,offThreshold:-60,minSliceLength:0.1*s.sampleRate,minSilenceLength:0.1*s.sampleRate,rampDown:0.01*s.sampleRate);
	FluidWaveform(buf,indices,bounds:Rect(0,400,1600,400));
	indices.loadToFloatArray(action:{
		arg fa;
		var current_frame = 0;

		// this array is initally flat, but is alternating [ onset0 , offset0 , onset1 , offset1 , onset2 ... ],
		// so by using .clump(2) we clump each onset and offest together to get an array like this:
		// [ [ onset0 , offset0 ] , [ onset1 , offset1 ] , [ onset2 , offset2 ] , ... ]
		fa = fa.clump(2);

		fa.size.postln;
		fa.do{
			arg arr, i;
			var startFrame = arr[0];
			var numFrames = arr[1] - startFrame;
			"%\tstart: %\tend: %".format(i,startFrame,numFrames).postln;
			FluidBufCompose.processBlocking(s,buf,startFrame,numFrames,destination:concat_buf,destStartFrame:current_frame);
			current_frame = current_frame + numFrames;
		};

		s.sync;

		FluidWaveform(concat_buf,bounds:Rect(0,0,1600,400));
	});
};
)

This works perfectly!! I still have to get a feeling for the sound qualities of fading between spectral templates with different parameters, but at first listens the clicks in the buffer don’t seem to be noticeable or obvious at all. And the method does help reducing the sometimes really long waits for processing results when crossing larger buffers.
Thanks again!
Jan