Get File Size in Samples Without Buffer


    Apr 07 2022 | 4:37 pm
    I'm looking for a way to get determine the size of a file in samples, ideally using javascript.
    I am currently doing this using `new Buffer(bufferName).framecount()`, however the files I'm using are quite large (20-40 minutes long) and they can take a long time to load into a buffer, so I'm curious if there's a way to get the sample length without having to wait for a buffer to load? I'd ideally like to fill out my UI with some file data, and then load the buffer.
    I see there is a way to get the location of the end of file in bytes using `new File(path).eof`, is that value something I could use? I don't know much about how to calculate this unfortunately.

    • Apr 07 2022 | 6:52 pm
      Hi, did you try [sfinfo~]? I don't know how well it handles very big files. But if it does, it will give you length in ms and samplerate to calculate length in samples.
    • Apr 07 2022 | 6:55 pm
      To use the bytesize to calculate length in samples you have to know some attributes of the soundfile before.
    • Apr 22 2022 | 7:46 pm
      Thanks 11OLSEN!
      [sfinfo~] works well. I'd ideally like to be able to do it all in javascript, but I was able to write a function that messages an sfinfo and listens for it's output.