SamBee
SamBee

Reputation: 3

Working out sample rate and bit depth of aiff audio from file size

I need some help with Maths/logic here. Working with aif files.

I have written the following:

        LnByte = FileLen(ToCheck)                                                   'Returns Filesize in Bytes
        LnBit = LnByte * 8                                                          'Get filesize in Bits
        Chan = 1                                                                    'Channels in audio: mono = 1
        BDpth = 24                                                                  'Bit Detph
        SRate = 48000                                                               'Sample Rate
        BRate = 1152000                                                             'Expected Bit Rate

              Time_Secs = LnBit / Chan / BDpth / SRate                              'Size in Bits / Channels / Bit Depth / Sample Rate
              FSize = (BRate / 8) * Time_Secs                                    '(Bitrate / 8) * Length of file in seconds

ToCheck is the current file when looping through a folder of files.

So I'm finding the length of audio based on the file size in bits / channels / bit depth / sample rate. This assumes that the bit depth and sample rate are correct (I need the files to be 24-bit/48kHz).

Time_Secs = Length of the file in seconds.

FSize = File size based on 24/48kHz using the Time_Secs

Probably because the FSize uses Time_Secs, I can't work out how to, from this, work out if the file sample rate and/or bit depth are indeed correct...

Assuming 24/48k should give 144,000 Bytes per second

Assuming 16/48k should give 96,000 Bytes per second

If I check a file that is 16-bit/48 kHz using the above code it gives the incorrect time in secs (naturally) but the correct file size... even though the Bit Rate is 1,152,000 should be wrong. -- It would seem that the difference in time is making up for the difference in Bit Rate - or I'm looking at it wrong.

How would I adapt my formula, or do the maths to work out if the sample rate/bit depth of a file is actually 48,000 Hz /24-bit? Or is there a different way entirely? Remembering that they are aif files, not wavs.

Hope that makes sense.

Many Thanks in advance!

Upvotes: 0

Views: 424

Answers (0)

Related Questions