Indices to Buffers?

Hi there -

I’m working with some FluidBuf processes in SuperCollider - and I’d like to iterate through all the indices into buffers that are then discretely saved in a folder.
Something like the following code - except the below just seems to leave a bunch of empty files in the destination folder.

indices.loadToFloatArray(action:{
    arg fa;
    var current_frame = 0;
    fa = fa.clump(2);
    fa.do{
        arg arr, i, x;
        var startFrame = arr[0];
        var numFrames = arr[1] - startFrame;
                FluidBufCompose.processBlocking(s, sourceBuffer,
				startFrame,
				numFrames,
				destination:saveBuffer,
				destStartFrame:0,
				action:{
					saveBuffer.write("/Users/a/Desktop/untitled folder/"++i++".aif", numFrames:numFrames, startFrame:startFrame);   });

		};

Hi @areacode and welcome,

I think the main thing there is that if you were recycling the saveBuffer as a global variable and then calling write, then the results could be unpredictable: I’ve a vague memory that Buffer read and write don’t dispatch from the server’s fifo queue but from the RT thread (if so, then the order that everything happens could be confusing).

Also, I think doAdjacentPairs is a simpler way to do the iteration into pairs of indicies.

Here’s a version that just uses a buffer for each slice (I appreciate you might not want the slicer, but just for the sake of a self-contained example):

(
var sourceBuffer = Buffer.read(s,"/Users/owen/dev/flucoma-core/Resources/AudioFiles/Nicol-LoopE-M.wav");  
var indices = Buffer.new(s); 
FluidBufOnsetSlice.processBlocking(s,sourceBuffer,indices:indices,action:{ 
	indices.loadToFloatArray(action:{ |array|
		array = [0] ++ array; //if you want the 0th slice, up to the first onset then pad with a 0
		array.doAdjacentPairs{|start,end,i|
			var dest = Buffer(s);		
			start.postln; 
			end.postln; 
			i.postln; 
			FluidBufCompose.processBlocking(s,sourceBuffer,
				startFrame:start,
				numFrames:end - start,
				destination:dest, 
				action:{
					dest.write("/Users/owen/Desktop/sctest/" ++ i ++ ".aif");
					dest.free;					
			});
		}	
	})
})
)
1 Like

the clump strategy and the doAdjacentPairs strategy have different behaviors. In this case though you are right, doAdjacentPairs might be the desired behavior (for use with with Fluid*Slice objects).

However, if @areacode is getting these indices from FluidBufAmpGate, then the interleaved onsets and offsets are best handled with the clump strategy as shown.

1 Like

Ah yeah, didn’t even occur to me!

1 Like