Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Is it possible to get the length(duration) of a WAV file?

Author
Message
billy777
23
Years of Service
User Offline
Joined: 9th Jan 2003
Location:
Posted: 24th Jun 2011 01:59 Edited at: 24th Jun 2011 01:59
Here's some code I found... but it doesnt seem to work - can anyone give me a better solution? Thanks.




lengthSeconds seems to be the khz rate showing 22050
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Jun 2011 11:51
Try this. I've just tested it on a mono .wav file of duration 0.5 seconds and a stereo .wav file of duration 4 minutes.

I haven't tested it with all .wav formats so I'm not sure how accurate it is.



This will only work for .wav files. I attach a sample stereo wav file for you to test.

If that fails could you post a small clip of the offending file and I'll investigate?
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Jun 2011 12:32 Edited at: 24th Jun 2011 12:38
www.wotsit.org is always good to get file formats.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Jun 2011 16:55
That's no help. The .wav format doesn't contain the length as far as I can tell.
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 24th Jun 2011 19:33
Use the enhanced audio plugin which has commands for this. I use it all the time, and the same method will work on many supported audio files.

My signature is NOT a moderator plaything! Stop changing it!
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 24th Jun 2011 23:40 Edited at: 24th Jun 2011 23:43
Here's a "mini tutorial" on sound memblocks I wrote for another thread a while back. Among other things, it shows how to determine the duration of a wave file:


And here is a pre-written set of functions to just get the duration of a loaded sound using a temporary memblock:

(If you have it, it is probably favourable to use IanM's find free memblock function instead of the one in there).

Hope that helps


Rudolpho


"Why do programmers get Halloween and Christmas mixed up?"

Login to post a reply

Server time is: 2026-07-10 17:19:11
Your offset time is: 2026-07-10 17:19:11