title: difference between audio data in .aac and .m4a files at the byte level
body: <p>This is for trying to understand the aac file structure  </p>
  
  <p>For simplicity we can assume m4a file with only aac audio (that is, no video)  </p>
  
  <p>I am comparing an m4a file and an aac file made from the m4a file using the faac library  </p>
  
  <p>A screenshot of the byte level comparison of the two files is given below: </p>
  
  <p><a href="https://i.stack.imgur.com/uPrEc.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/uPrEc.jpg" alt="enter image description here"></a>  </p>
  
  <p>the upper part is the m4a file and the lower part is the aac file  </p>
  
  <p>For the very first frame, from the lower part the AAC ADTS header is <code>FF F9 4C 80 12 3F FC</code> and from <a href="https://wiki.multimedia.cx/index.php?title=ADTS" rel="noreferrer">here</a> and <a href="http://www.p23.nl/projects/aac-header/" rel="noreferrer">here</a> the actual aac audio data should have 138 bytes  </p>
  
  <p>From the lower part we can see that the bytes from <code>DE</code> to <code>80</code> match a block of data in the upper window (the green coloured part)  </p>
  
  <p>I had assumed that I had found the offset in the m4a file, from where the actual aac audio data is stored. I though that the bytes <code>21 4C ...</code> in the upper window contained all the bytes of the next frame of aac audio, and if we look at the lower window, we can indeed see that <code>... a3 80</code> (end of the green coloured part in the lower window) is followed by another ADTS header (<code>FF F9 4C 80 12 1F FC</code>, which says the number of audio in the next aac frame should be 137 bytes)  </p>
  
  <p>However, the bytes read from the aac file do not match those in the m4a file as expected, as shown in the screenshot below:  </p>
  
  <p><a href="https://i.stack.imgur.com/guoyd.png" rel="noreferrer"><img src="https://i.stack.imgur.com/guoyd.png" alt="enter image description here"></a>  </p>
  
  <p>They match up to a certain point but everything after that looks random.  </p>
  
  <p><strong>What is the relationship between m4a file and the corresponding aac file created from it, at the byte level?</strong>  </p>
  
  <p>The main goal is to be able to modify <a href="https://www.mathworks.com/matlabcentral/fileexchange/28028-mpeg-4-aac-lc-decoder" rel="noreferrer">this matlab project</a> (which takes m4a input and decodes to raw wav data) to read aac audio data directly from aac file, then use the aac decoder functions from that matlab project unchanged.</p>