This is an alternative way to the way described on the original site. Thanks to Alyce who shared the ReverseString$() function.
NOTICE: It seems like sometimes (about 5% or less) the length is bugged (much smaller than it should be. I didn't notice it was bigger than the original though). I am trying to fix this ASAP, the updated code will be on this site.
EDIT: Found the bug. The problem was, that the dechex$() function didn't return the 0 before the other letter/number. It should work now!
function getWavLength(file$)open file$ for binary as#wav
content$ =input$(#wav,32)close#wav
size$ =mid$(content$,5,4)'Get the 4 bytes which contain the size of the file
size$ = ReverseString$(size$)'Reverse those bytes because they are Little-Endian
size =hexdec(tohex$(asc(size$))+ tohex$(asc(right$(size$,3)))+ tohex$(asc(right$(size$,2)))+ tohex$(asc(right$(size$,1))))
size = size -36'Subtract 36 bytes because the actual sound data starts at byte 44, but the size in the header has already 8 bytes subtraced
bitrate$ =mid$(content$,29,4)
bitrate$ = ReverseString$(bitrate$)
bitrate =hexdec(tohex$(asc(bitrate$))+ tohex$(asc(right$(bitrate$,3)))+ tohex$(asc(right$(bitrate$,2)))+ tohex$(asc(right$(bitrate$,1))))
getWavLength =int(size / bitrate)endfunctionfunction ReverseString$(string$)for i =len(string$)to1 step -1
ReverseString$=ReverseString$+mid$(string$,i,1)next i
endfunctionfunction tohex$(val)
tohex$ =dechex$(val)iflen(tohex$)=1then
tohex$ ="0"; tohex$
endifendfunction
This is an alternative way to the way described on the original site. Thanks to Alyce who shared the ReverseString$() function.
NOTICE: It seems like sometimes (about 5% or less) the length is bugged (much smaller than it should be. I didn't notice it was bigger than the original though). I am trying to fix this ASAP, the updated code will be on this site.
EDIT: Found the bug. The problem was, that the dechex$() function didn't return the 0 before the other letter/number. It should work now!