When Logic Destroys Your Audio Files

This post is about a serious bug in Logic, which causes audio files to be damaged. The symptom of this bug is the following error message when opening a previously perfectly working project: One or more audio files changed in length.

Background

This is how I encountered the bug: we had recording sessions with our band and had completed the first session. In the studio, we could listen to all tracks without any problems. After some time, when our sound engineer opened the project again, he encountered the error message above for some files. After listening through the projects, he discovered that a large number of audio clips could not be played back anymore. We had one backup of the project we had made right after the recording session, but unfortunately it contained the same corrupted files. This meant that we had to repeat the recording session 🙁

We had a few more recording sessions, after which we made 3 or 4 backups right away. After we had recorded a whole album, the issue occurred again. The files were corrupted on all backups again, although we could listen to the tracks in the studio without problems. Consequently, the data was corrupted after the recording and before re-opening the Logic project.

Then, our sound engineer noticed the following: when he opened a project for the first time, logic reported 4 corrupted files. When opening the same project again, suddenly 24 files were corrupted. This leads to the conclusion that Logic itself is responsible for destroying the audio files.

Conditions under Which the Bug Occurs

According to internet sources, the bug occurs under the condition that the computer utilizes differently formatted hard disks, i.e. disks which are not all formatted with Mac OS X Journaled. The files are damaged when logic is closed, which means that even if the project works perfectly before closing the application, there is no guarantee that it will work when opened again.

We experienced these problems with Logic 9, but internet forum posts suggest that it can also happen with Logic Pro X. If someone can confirm or has any updates, please feel free to comment.

Error Analysis

Logic destroys the audio files in seemingly random order, e.g. in a sequence of 79 audio files recorded for one track the files with numbers 43, 48, 56, 57, 58, 59, 65, 74 and 79 were corrupted.

For a more thorough analysis, I compared working files with corrupted files using a Hex editor, in which each single byte in the file can be visualized in hexadecimal representation. The first bytes of an intact wave file look like this:

For a detailed description of each byte, refer to this page. In short, these are the contents of the wave file header:

  • Bytes 1-4: RIFF chunk descriptor
  • Bytes 5-8: chuck size (total number of bytes in the file after this block)
  • Bytes 9-12: format (in this case WAVE)
  • Bytes 13-16: fmt-subchunk header (contains fmt )
  • Bytes 17-20: subchunk 1 size (in this case 16 for PCM)
  • Bytes 21-22: audio format (1 = PCM)
  • Bytes 23-24: number of channels (1 = Mono, 2 = Stereo, etc.)
  • Bytes 25-28: sample rate (e.g. 44,100 Hz)
  • Bytes 29-32: byte rate: number of bytes required to store 1 second of audio for all channels (= sample rate * number of channels * bits per sample / 8)
  • Bytes 33-34: block align: number of bytes required to store one sample in all channels (= number of channels * bits per sample / 8)
  • Bytes 34-36: resolution in bits per sample, e.g. 8, 16 or 24 bits
  • Bytes 37-40: data chunk header (contains data)
  • Bytes 41-44: number of bytes representing the raw audio data
  • Bytes 45ff.: raw audio data

Now let’s have a look at a destroyed audio file:

If the bug occurs, Logic fails to write the wave header correctly. Instead, the file contains only zeroes in the first 44 bytes, which is exactly the length of the wave header. The good news: the raw audio data, starting at byte 45, is still intact (note that the hex editor starts counting bytes at index 0).

If such a corrupted wave file is opened, logic can’t read the header and assumes a default 8 bit setting, which leads to a misinterpretation of the audio data. Additionally, the length of the file will also be misinterpreted, because a wrong sample rate is assumed.

Repairing the Audio Files

As a preliminary fix, you can restore the destroyed files by copying a wave file header from a correct file (with matching sample rate and resolution) to a corrupted file in the hex editor. For example, wave files with a sample rate of 44.100 Hz and 24 bit resolution need to start with bytes similar to these (in hexadecimal representation):

1
52 49 46 46 5B 89 3E 00 57 41 56 45 66 6D 74 20 10 00 00 00 01 00 01 00 44 AC 00 00 CC 04 02 00 03 00 18 00 64 61 74 61 6B 5C 3E 00

However, one potential issue now could still be that the (sub)chunk sizes (bytes 5-8 and 41-44) are not correct, but most audio editors don’t check these values. If you want to correct these as well, make sure that you use the correct little endian representation for these byte groups. This means the byte order is reversed. A complete example is given below.

The formulas to calculate the correct values are:

  • chunk size = <file size in bytes> - 8
  • data chunk size = <file size in bytes> - 44

Integer to Little Endian Hex Conversion

Example: Converting the number 44,100 to a little endian hex number:

  1. Convert number to hex using a scientific calculator or an online converter such as this one. The result is: AC 44. Note that this result comprises two bytes and is encoded big endian (most significant byte first).
  2. Make sure the result is padded to the correct byte size. If the field in the header is 4 bytes, we have to add two zero bytes at the beginning: 00 00 AC 44
  3. Reverse the byte order: 44 AC 00 00. The result is now little endian (least significant byte first), as required by the wave header specification.

To confirm, you can open a working wave file with 44,100 Hz sample rate in a hex editor and check bytes 25-28, which will contain 44 AC 00 00.

Using Wave Recovery Tool to Restore the Wave File Headers

Because quite many files were damaged in our case, I did not want to fix all wave headers manually. Therefore, I developed a program which can fix the wave files all at once. Wave Recovery Tool is available on github and is published under the terms of the GNU General Public Licence.

Conclusion

This post reveals a serious bug in Logic, which can potentially destroy hours and weeks of hard work. Fortunately, the data can be restored completely either manually or using a Wave Recovery Tool I developed. I seriously hope that this bug will be fixed soon or is already fixed in recent versions of Logic.

16 thoughts on “When Logic Destroys Your Audio Files

  1. Huge thank you for this, Dave. I’m hoping this will save the files that have been corrupted in my project. So much work will be lost otherwise. Question: I’m reading the instructions on GitHub, and it seems one would need to have some cursory knowledge of interpreting hexadecimal or software coding or things of that sort. Unfortunately I have basically zero knowledge in that department. Will I need a computer geek at my side when I do this, or will I be okay just following your instructions? My apologies for my ignorance. There will certainly be a donation attached to whatever success I have with your software. Thanks for your time!

      • Hi Loren, the tool can restore wave files with any bit depth (e.g. 16/24 bit), sample rate (including 44.1, 48 and 96 kHz) and number of channels (Mono, Stereo and even more). You basically have to tell the program these three parameters, and it will write these information (among the other required stuff) into the wave header.
        You do not need any knowledge of hexadecimal number representation, nor do you need programming skills. However, you have to start the program from the Terminal of your operating system providing the mentioned parameters, a folder where the broken wave files are stored, and a new empty folder in which the repaired files should be stored. I tried to document this on the github page as exact as possible, however if you run into problems or error messages you can contact me under the email address provided on github. Good luck and best regards, Dave

  2. This just happened to me using Logic Pro X on a brand new Macbook Pro. I created a comp vocal track. I continued recording other tracks and somewhere along the way I realized I accidentally deleted the first comp track. Once I realized it had disappeared, I clicked ‘command Z’ over and over until it reappeared again. Unfortunately the comp track now wouldn’t produce any audio. It looks completely normal on the screen but it’s silent. 🙁

  3. And just to add, yes, I got the message “One or more audio files changed in length!” At first it was 24, then later it turned into 36, but all my other tracks seem to be intact. Very strange.

  4. Hi Dave! I’m glad somebody with your expertise ran into this problem too, as I’ve been discouraged from making music ever since encountering this bug, and losing so many files to it.

    Would you be a godsend and please post instructions for dummies like myself who know nothing about Python and exactly what I need to do?

  5. Hi,

    This just happened to me on the company I work for. 32 hours of work with a hired voice actor down the drain… The amount of damaged files goes up every time i restart the project. And even if I were to recover the files, the time it would take to reassemble the tracks would be ridiculous because of all the punch-ins I´ve done during the session. This is a very serious issue! We´ll lose a hefty amount of money on this project. I´m still to contact Apple though, but I doubt they´ll have anything to say about it. And I´m very hesitant to even use Logic pro X again in a workrelated session. I worked with Logic 9 for years and never had any issues of this kind.

    Thank you for addressing this issue!

    • If you restore the audio files and put them in the corresponding folder (named Media/Audio Files or similar), you can open the project again and all your edits will not be lost. To find the directory, you have to right-click your .logicx container and choose “Show Package Contents”.

      • I have the same issue but we’re working with aiff files in logic :\
        aiff header is a bit different from wave ones

        • I think the main difference is the byte order, so it might be possible to extend the tool to support AIFF files. Currently I do not have the time for this, but I will keep it in mind for future enhancements. Of course, if you know Python you are welcome to add the required code since it is an open source project.

  6. I have the same problem. I know repair any files (aiff) with hex editor, but is there files without informations. This files is not possible repair:(
    Do you know why is there problem in LOGIC PRO X?
    thank you.

  7. Where’s the link for the wave recovery tool? Was it removed? I see no “clone or download” link on its page.

Leave a Reply

Your email address will not be published. Required fields are marked *