I just spent a day investigating a really baffling bug that occurred when I installed Equalizer APO on a new Windows machine. (Equalizer APO is a free equalizer that plugs into the Windows Audio subsystem, which lets you, among other things, correct the acoustic flaws of your room to dramatically improve the quality of all audio playing on your computer. Maybe I’ll write a post about it some day — it’s awesome.)
Equalizer APO uses a plain text config file (config.txt) that it constantly monitors for changes using a mechanism provided by Windows. Normally, you can hear the sound playing on your PC change within a few seconds of saving the file. Soon after installing Equalizer APO on a fresh Windows installation, I noticed that the changes I was making in config.txt were often being ignored. For example, the first two changes after reboot might get applied, but subsequent changes would be ignored. I tried fiddling around with folder permissions and moving the config.txt file to various locations on the hard drive, which seemed to fix the issue for some time (usually until the next reboot).
The weirdest thing was that whenever I changed config.txt, Equalizer APO wrote the following message to its log:
Error while reading configuration file: The system cannot find the file specified.
This did not make any sense at all. How could Equalizer APO not find a file that was clearly there? And why was it unable to find the file only some of the time? After spending an hour studying the source code for Equalizer APO, I grew convinced that the only possible reason was a bug in Equalizer APO which somehow blocks access to the config.txt file (after all, weird contention issues are not unheard of in multithreaded apps) combined with an obscure Windows bug which results in CreateFile() reporting a sharing violation as a missing file.
After submitting a lengthy and detailed bug report to the author of Equalizer APO, I accidentally opened config.txt in Notepad instead of Sublime Text 3, my go-to text editor…
Impossible. The problem was gone. I could edit the file as much as I wanted, and every change was applied. Back to Sublime Text 3 — it stopped working. I tried opening the file in Komodo Edit — it worked just like it did in Notepad.
A-ha! Clearly Sublime Text 3 was doing something weird with the file. Could it somehow be hiding the file from Equalizer APO?
It turns out, when you save a file in Sublime Text 3, in its default configuration, it doesn’t simply overwrite it like all other editors. Instead, it does the following:
- Write the modified text into a temporary file.
- Delete the original file.
- Rename the temporary file so that it looks like the original file.
At the exact moment when ST3 deleted the original file, Windows would notify Equalizer APO about the “change” and cause it to re-read the file. If the read operation was quick enough (which would have depended on things like the overall disk load), Equalizer APO would find the file missing.
Why does Sublime Text 3 save your files in such a weird way? It’s supposed to be a safety feature. If ST3 simply overwrote the original file and something really bad happened during the overwrite, you could lose data. Making a temporary file first guarantees that you will always be able to get your data back.
However, this roundabout way of modifying files can cause problems with software that monitors file changes. I’m not just talking about the scenario that gave me the headache which occasioned this post, but other scenarios as well. For example, there are backup and versioning apps which monitor filesystem changes. To such an app, a save operation in ST3 will look like a file got deleted, and then a new file got created, which may ruin the association between the current version of the file and its earlier versions. For real-life reports of problems like that, see the previously linked thread on the ST forum and this StackOverflow question.
According to the above sources, the “atomic save” feature can be disabled in ST3 by editing user preferences, but I could not get it to work (in build 3065). In the end I simply downgraded to ST2.
John "I hate EQ APO" Lardinois Dec 21, 2014 at 4:17 am
I need help. I’m going fucking insane. I cannot run Equalizer APO at all and nobody else on the internet seems to want to tell me how.
There is NO exe, NO batch file, and Peace doesn’t work, Room EQ Wizard creates wonderful config files, but the config files won’t run because nobody has documented how to run EQ APO anywhere on the known fricken internet!!!!!
It’s a command line EQ? Ok, then somebody MUST KNOW the actual command line COMMAND used to run the goddamn thing!!!!!
I could use a regular command line command to run the APO if there were an EXE or a BATCH file involved, but no matter how many times I download the fucking EQ APO, there is NO SUCH THING. It is not possible in the known fucking universe to “run” a text file. You can read one, you can’t run one. Because when I download EQ APO, all I get are text files. That doesn’t get me anywhere.
God fucking dammit I’m going to punch a baby seal
Tomasz Dec 21, 2014 at 6:45 pm
Funny, when I go to https://sourceforge.net/projects/equalizerapo/ I get a nice big green button that downloads an EXE file.
Marksu Oct 25, 2016 at 11:30 am
Old post, but regarding the problem “John “I hate EQ APO” Lardinois” had…
To change between different configuations you simply need to replace the “main configuration” file with another configuration file.
For example if your configuration file is in: C:\Program Files\EqualizerAPO\config\config.txt you just replace that file with another configuration file and the new settings will be active instantly.
So you can use the editor to create config and save that to another file. And then use batch file or whatever to change the configuration by overwriting the config.txt with another configuration.