Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WAV Length
#1
Is there an easy way to determine the length of a wav file, as in playback time, not file size?
In the beginning, there is darkness – the emptiness of a matrix waiting for the light. Then a single photon flares into existence. Then another. Soon, thousands more. Optronic pathways connect, subroutines emerge from the chaos, and a holographic consciousness is born." -The Doctor
Reply
#2
Yeah, maths. But you have to know bit depth/number of channels/samples per second.

size_in_bytes = bytes_per_sample * channels * samples_per_second * seconds

So:

seconds = size_in_bytes / (bytes_per_sample * channels * samples_per_second).

For example, for a typical CD-quality file (44100 Hz, 16 bits, 2 channels):

seconds = size_in_bytes / (2 * 2 * 44100)

(more or less, there's a header in the file - I can't remember its size - assuming it's "X" just change that "size_in_bytes" in the above formulae for "(size_in_bytes - X)").
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
Problem is that there can be a lot of different "chunks" in a wave file, besides the actual wave data - such as cues, notes, lyrics and what not. I guess they're rarely used (and if you made your own mp3's you could make sure they dont go there), but the potential's there.

Have a look here for the file format: http://www.sonicspot.com/guide/wavefiles.html

The most secure way would be to read the header, look thru the chunks for data ones, and add up the size of those, then calculate with the bits/sec from the header.

But as I said, if you're only reading your own waves (or converted by you), going by nathan's suggestion you should be fine.
url=http://www.copy-pasta.com]CopyPasta[/url] - FilePasta
Reply
#4
Yup, the optimal solution would be reading the header, extracting data about the different chunks in the file, and adding everything up. All the needed data I mentioned above (bit depth, n. of channels, etc...) is in there.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)