Audio file cropping

Wondering what is the most efficient way to ‘crop’ an audio file?.. i.e. given a desired start and end sample number, remove the rest of the audio outside the range.

I can definitely imagine implementing it by first renaming the original file, then using looped calls to an AudioFormatReader and an AudioFormatWriter writing to the original filename location, but I’m wondering if there’s something more efficient that I don’t know about.

I think the safest is to write into a new file and rename it afterwards. I am not sure, if an in-place rewriting exists, but even if it would, I would advise against it, since if your program is interrupted, you lost your source and destination file with no way to recover the original audio.

True enough. Thanks!