How know the long(duration) of .wav files, before play it?¿

Previous topic - Next topic

mentalthink

Well, I like if this it´s possible, how long in time it´s a audio file, before play it. I like to extract or know the duration ifo about the files witout playing them. This it´s possible witout inline... if not, someone can help me in the code.  :enc: :enc:

Thanks in advance.
Iván J.



Kitty Hello

samples/_Projects_/WaveIn:

Code (glbasic) Select


// parse the WAV file and get the play time in [ms]
FUNCTION WaveGetDuration: channel%, filename$
LOCAL val%, byte_per_sec%, contentlen%
IF OPENFILE(channel, filename$, TRUE)=FALSE THEN RETURN 0
READLONG channel, val // RIFF
READLONG channel, val // size
READLONG channel, val // WAVE
READLONG channel, val // FMT
READLONG channel, val // dw16 (must be 16, otherwise compressed)
READWORD channel, val // wOne_0 = 1
READWORD channel, val // channels
READLONG channel, val // sample rate [Hz]
READLONG channel, byte_per_sec // bytes per second
READWORD channel, val // block align =1
READWORD channel, val // bits per sample (8/16)
READLONG channel, val // DATA
READLONG channel, contentlen
CLOSEFILE channel

RETURN 1000*contentlen/byte_per_sec

ENDFUNCTION


mentalthink

Thanks Gernnot, a lot.
Kinds Regards,
Iván J.