Author Topic: Get the length of audio file  (Read 4743 times)

grh

  • Newbie
  • *
  • Posts: 9
    • View Profile
Get the length of audio file
« on: November 17, 2010, 08:56:06 »
Hallo!

Is it possible to get the length of the audio file which I want to analyze ?

In one algorithm I want to analyze the whole audio file at once and now I am thinking about a good way to do it:
a) I could set the blocksize to the length of the whole audio file (therefore I would need the length of the file)
b) or process the file in small blocks, save them and call getRemainingFeatures at the end

But also in b) I need the file length, because it would be nice to allocate the big buffer arrays before (and not always resize them each block).

Thanks for any hints how this could be achieved in a nice way,
LG
Georg

PS: I am using python/vampy, but I guess the same problem is valid for C++ plugins ...

cannam

  • Administrator
  • Sr. Member
  • *****
  • Posts: 273
    • View Profile
Re: Get the length of audio file
« Reply #1 on: November 19, 2010, 14:31:56 »
Hello there.

You can't get the length of the audio file ahead of processing it -- apart from anything else, the host does not necessarily know it (it could be reading from a stream, though most existing hosts use files).

You therefore need to take option (b), and work out the length of the file yourself by counting the frames that are passed to process() calls.


Chris

grh

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Get the length of audio file
« Reply #2 on: November 19, 2010, 17:38:18 »
Ok, that's sad .. then I have to reallocate the big buffer array all the time, because I don't know how big the file will be ...

However, thanks for the information and have a good weekend,
LG
Georg