title: Working out sample rate and bit depth of aiff audio from file size
body: <p>I need some help with Maths/logic here.  Working with aif files.</p>
  
  <p>I have written the following: </p>
  
  <pre><code>        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
  </code></pre>
  
  <p>ToCheck is the current file when looping through a folder of files. </p>
  
  <p>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). </p>
  
  <p>Time_Secs = Length of the file in seconds.</p>
  
  <p>FSize = File size based on 24/48kHz using the Time_Secs</p>
  
  <p>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... </p>
  
  <p>Assuming 24/48k should give 144,000 Bytes per second</p>
  
  <p>Assuming 16/48k should give 96,000 Bytes per second</p>
  
  <p>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.</p>
  
  <p>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. </p>
  
  <p>Hope that makes sense. </p>
  
  <p>Many Thanks in advance!</p>