I have a soundfile of 524288 samples and i would like to subdivide it into 256 parts of 2048 samples each and load them into 256 different buffers. Does anyone know how? SoundFile unfortunately does not have a startFrame and numFrames arg so i could specify which part of it to write on the buffer. Any ideas?
I had the exact same need . Apparently, you don’t need to use the SoundFile class for this. I think this class is designed to get metadata about a file rather than manipulating it.
Actually, you can use the Buffer class directly to do this, because its method read allows to specify a file, a startFrame and a numFrames argument.
Here is what I tried, just change the values to fit your needs :
(
var filePath = Platform.userHomeDir ++ "/SC/AudioFiles/celloMono.wav";
var buffersNumber = 4;
var buffersSize = 256;
var buffers = Array.newClear(buffersNumber);
buffersNumber.do( { |n|
var buffer = Buffer.read(
s,
filePath,
startFrame: buffersSize * n,
numFrames: buffersSize
);
buffers.put(n, buffer);
CmdPeriod.doOnce({ buffer.free });
} );
)
Please note that writing into a buffer is an asynchronous task, so the example above isn’t really usable as it is. You might have to store the buffers inside a global variable (i.e. declare the Array as a global variable), or recursively load buffers until they’re all done using the action argument of the read method.