Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Find flac sample rate in VBA (Read 2828 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Find flac sample rate in VBA

I want to query some flac files with VBA code to get their duration

From testing about 50 flac files the 3 bytes at offset 23 after "fLaC" seem to correctly return the Number of Samples.
Then this must be divided by the sample Rate for total number of Seconds
But I cannot locate the sample rate in the Stream info block, where I believe it is stored.

Can anyone help me find this?


Re: Find flac sample rate in VBA

Reply #2
Probably going to be easier and more reliable to use a library like libflac or ffmpeg to get the file metadata rather then try to parse the streams yourself. 

Re: Find flac sample rate in VBA

Reply #3
I am using metaflac.exe but want to get the duration into my own app, rather than Shell to DOS window.
I've spent a few hours reading the info in that link but can't understand it.  What are numbers inside  <> chars?
I did  a bit-compare of a 44100 and 96000 and found byte offset 29 (after fLaC) had the last 4 bits as 1001 for 44100 and 1011 for 96000. But this wasn't consistent with "0111" often found.
Can someone better interpret that link and explain it to me ?  Or tell me how I might find the sample rate. I have seen code for this but it's in a format (language) I don't know.


Re: Find flac sample rate in VBA

Reply #4
^^^ Metaflac calls libflac, which you can also do directly from your program.

Re: Find flac sample rate in VBA

Reply #5
That sounds ideal. Would you have any examples of calling libflac from VBA ?

Re: Find flac sample rate in VBA

Reply #6
The sampling rate is at offset 12h. It is backwards in big-endian format.

Re: Find flac sample rate in VBA

Reply #7
Thanks very much.  Off to see how I can implement that.

Re: Find flac sample rate in VBA

Reply #8
Sorry, I'm just not finding it.. perhaps compounded by the big endian translation (which I'm just figuring out).
If the image works, which bytes are offset 12h ?  It should convert to 44100.

Re: Find flac sample rate in VBA

Reply #9
These.

Re: Find flac sample rate in VBA

Reply #10
Brilliant. All sorted. Thanks very much j7n

Re: Find flac sample rate in VBA

Reply #11
I note this in the flac site

<3>    (number of channels)-1. FLAC supports from 1 to 8 channels

Does this mean byte 3 should be 1 if the file is mono (single channel) ? 


Re: Find flac sample rate in VBA

Reply #13
Not a whole byte but 3 bits just after the sampling rate at 14h. The remaining 1 bit is the most significant of the bit depth.

Re: Find flac sample rate in VBA

Reply #14
Thanks muchly it's a big help understanding the info at https://xiph.org/flac/format.html.
One other question - where it shows
METADATA_BLOCK_STREAMINFO
<16>    The minimum block size (in samples) used in the stream.

Does this mean the 16 bits immediately following "fLaC"  ?

 

Re: Find flac sample rate in VBA

Reply #15
After fLaC and 4 additional bytes of block_type and its length.