Load part of file into buffer?

james d's icon

I'm building a patch that loads large files (30 mins+) into a buffer, but only requires a small snippet from each file for playback. Since loading files this big takes a long time, I would like to load only the required part of the file into a buffer. Like:

read <path_name> <start_sample_index> <length_in_samples>

Is something like that possible? I've seen some seek functionality, but haven't seen anything for buffers.

Thanks!

11OLSEN's icon

Hi James, I was in a similar situation once where i couldn't accept that [buffer~] and also [sfplay~] are blocking playback until a complete file is loaded / decoded. I was choosing the hard way and wrote my own C++ external using ffmpeg that keeps on writing to the buffer~ while i could start playback of the already written parts. ffmpeg can also skip audio and load only parts of a file. You're probably looking for a faster way to solve this. My only idea then is to use some kind of command line tool outside of Max to split a part from a bigger file and load that into buffer~ as there's still no way to do it in Max :(

Source Audio's icon

I am not sure when that was added to buffer~ ,
but one can set file offset and length to import,
as well as number of channels to read.

Check buffer~ reference - import chapter

11OLSEN's icon

Oh wow thanks @Source Audio, I never noticed this. There you have it @James.
Unfortunately it doesn't help with my problem. If you want the complete file, you have to wait for seconds before any other action is possible.

james d's icon

Oh crazy! That's awesome, totally missed that. Was getting ready to build an node/ffmpeg service for this. Working great, so fast, and much less cpu!