Showing posts with label audio. Show all posts
Showing posts with label audio. Show all posts

Thursday, 17 October 2024

How to have a reasonable chance at getting correct album art in Mac OS Apple Music

TL;DR

Ignore the naysayers who claim it has nothing to do with the iTunes music store—they are wrong. Look up the album in iTunes and set the album title for your local files to the exact same title, with junk like “(Remaster)” and so on included. Then clear the artwork and download it again. Afterwards, you can rename the album back to what you want. If this doesn't work, then it will never work for that album, so stop wasting your time.

The Long Story

I still use Apple Music, the former iTunes, to manage an offline music library. I have never bought into the streaming game. It sucks for many reasons that I won't explain here. What also sucks, is how Apple Music handles album art, especially for music that has been ripped from CDs or obtained from somewhere else than the iTunes store. Very often, the album art is plain wrong. It will generally be from the correct artist, but older albums will often get the cover art of a very recent release, or a stupid compilation. I don't care about compilations, I want to know what album a song originally came from.

The cover art matching algorithm has always been bad, from the earlier days of iTunes to the latest Music app release in Mac OS Sonoma. The way in which it makes mistakes has changed over the years, but it has never made any sense. I would like to have a chat with the person who implemented it. I wonder how their mind works—if it works at all. Anyone with some vague sense of logic and a bit of programming experience can come up with a better algorithm than the current one.

And please don't tell me to add my own cover art by pasting it into the info window. Ever since it was first introduced in ID3 tags, I have hated this concept of copy-pasting the same JPEG or PNG file into the metadata tags of every single track of an album. What if I have an album with 50 tracks? Do I really need to duplicate the same image 50 times? That is conceptually idiotic. Album art should be stored once and then linked to the relevant tracks. It does not belong inside the music files themselves. This is one upside from how the artwork download system in iTunes/Music handles it, because it does exactly that: download a single file and then link it to each track. Now if only it would download the correct file…

Anyhow, I'll stop my rant and cut straight to the chase. How can one fix missing or incorrectly matched artwork even when you know the album is in the iTunes music store? After some experiments, I have found a way to fix some of the blatantly wrong album covers. For instance, practically all my Dire Straits albums got the same cover of some recent Mark Knopfler compilation with a red Stratocaster on a blue background. When using the “Show in iTunes Store” option on songs from those albums, it will indeed always send me to that compilation album in iTunes. However, the actual correct albums are also in the store. However, they will often be remasters, or “bonus track editions.” The title of the album in the store is for instance “Communiqué (Remastered),” while in my collection it is simply called “Communiqué” (because I care as much about what particular remaster a track came from as I care about compilations—I don't give a 💩.)

Therefore, despite many people claiming that the cover art matching has nothing to do with the iTunes store, I decided to clear the wrong artwork, rename the album to “Communiqué (Remastered),” and try to download the cover art again. And behold, it works. (Of course afterwards I restored the original album name.) The same worked for Neko Case - “Fox Confessor Brings the Flood,” which I had to rename to the silly “Fox Confessor Brings the Flood (Bonus Track Edition)” because that is the version which is available in the iTunes store.

The bad news is that this does not always work. For the Belgian band dEUS, it is totally hopeless. The matching algorithm gets stuck on linking all albums to Following Sea. I have no clue why. Again, I'd like to see the implementation of this “algorithm”—I really could use a good laugh. How can it be so bad? How can it break on stuff between brackets? Anyone who takes a quick glance at album naming should know that if something doesn't match exactly, but it does match when omitting stuff between brackets, it is likely a good match. And what about just giving the user the option to pick the correct match from multiple options if there is ambiguity? Oh no, that is totally un-Apple of course, because everything needs to be dumb and simple. Apple expects all their users to be dumb and simple.

It is rather obvious that Apple doesn't care about the ever shrinking niche of users who want to manage their own music library. This fares against their streaming income model. I even suspect this is why they subtly break functionality in the Music app, or refuse to fix bugs, like the failure to update the last played status in many cases, or the hiccups that make the whole Mac OS choke every 7 seconds when playing music on older Intel machines—see my older blog post about this.

Anyhow, if you are as masochistic as me and want to stick to the Music app to manage an offline music collection, now you have at least some chance to fix some of your broken artwork. However, it is likely I will not only ditch the Music app for something else, but the whole Apple ecosystem in the near future, because I have figured out that I have switched to open source alternatives for pretty much everything lately. Ironically, iTunes/Music was one of the few remaining things that I liked and kept me on the platform, but since they are now also enshittifying this, it leaves me with no real reason to stick with MacOS…

Sunday, 3 February 2019

Enhancing headphones or earphones with Audio Hijack 3

Long ago there was an awesome audio enhancer for Mac OS X that could improve system-wide audio in various ways. It started out as ‘OSS 3D’ by Subband Technologies, later on it was bought by Joesoft and rebranded to ‘Hear,’ and it eventually migrated to the Prosoft brand name. This program offered various effects like 3D audio, a straightforward equalizer, a virtual subwoofer, and various other things that were both useful and gimmicky. Everything was fine until the program became unable to enhance audio coming from iTunes, arguably its most important target. Prosoft was never able to fix this and eventually the program stopped working altogether with the latest major OS X updates. Rest in peace, Hear.

I have been looking for a way to simulate at least part of Hear's functionality. I especially relied on it to obtain a more natural listening experience with headphones. If you have ever listened to e.g. Beatles songs on headphones, you will have noticed first-hand that headphones do not offer the same listening experience as loudspeakers. With loudspeakers, sound from the left speaker will not only reach your left ear but your right ear as well and vice versa, both directly and indirectly through reflections. With head- or earphones however, the left and right channels are fed strictly to the respective ear only. If the music was mixed with sound coming only from either left or right (as was often the case with the first stereo recordings like from the Beatles), this offers an unnatural experience. Even today a lot of music is mixed with loudspeakers in mind and will not sound ‘right’ when listening with headphones.


A good solution is to preprocess the music before sending it to the headphones, simulating it being played on loudspeakers. The most basic way to do this is to mix a bit of the right channel into the left and vice versa. This already makes Beatles songs less awkward to listen to but it's not quite it. To add more realism, the tiny delay caused by the longer audio path from the left loudspeaker to the right ear and vice versa must also be taken into account. From my DSP courses I remember that a realistic delay is 390µs (this can be derived from the geometry of a typical stereo setup and the shape of a human head). To further increase realism, there must be some low-pass filtering as well because higher frequencies will have a harder time reaching the opposite ear. And finally to get the sensation of listening in a real room, some reverb can be added.

This idea can be implemented with Audio Hijack from Rogue Amoeba Software. It is not for free but is well worth its price for anyone who needs to do more with audio than merely playing some music. So let's see how we can implement our fancy headphone enhancer with Audio Hijack.


The above image shows the setup. The upper part is the one that simulates a room. A slight reduction in volume is applied to compensate for the fact that we will be adding a cross-mix of the channels later on. A reverb effect makes the sound less ‘dry’ by simulating it bouncing off walls, floors and ceiling. The configuration of the reverb unit is a matter of personal taste. I started out with the defaults of the Matrix Reverb and reduced the ‘large’ parameters to have a faster drop-off.

The lower part is the most important one, it represents the cross-mix between loudspeakers and ears, the extra delay due to the longer audio path, and the attenuation of high frequencies. The 390µs delay cannot be obtained with the standard effects available in Audio Hijack, a custom plug-in is needed. I've found this free sound delay audio unit from Voxengo to be adequate. You need to reboot after installing the AU plugin to make it available in Audio Hijack. Enter a value of 0.39 msec in the effect configuration. People with really fat heads might try a larger value but it should never deviate much from this.
The exact value for the low-pass filter isn't crucial. This filter has two purposes: first, simulate the actual attenuation of higher frequencies that would occur in the situation depicted above, which is difficult to quantify anyway. Second, avoid interference between trebles in the original audio and the delayed copy. Without the low-pass filtering, there would be a comb filter effect that can make some trebles sound weird. If you still notice this, you may want to use a lower frequency than the 6 kHz I used here.

After mixing everything together, there is another volume control and an equalizer. These are optional but unless you have extremely high-end headphones, a little extra EQ can get that bit of extra fidelity out of them. The reason why you may need to precede the EQ with a volume reduction is that if you need a considerable bass boost, you'll need to attenuate the input to avoid sending the audio into overdrive. You may add other effects to your liking, e.g. a dynamic range compressor in case you're listening in a noisy environment (although a lot of modern music has no dynamic range to begin with…)

Friday, 19 May 2017

Making Prosoft Hear work again with iTunes 12.6

The only reason why I stick with iTunes is that I have been suckered into it from the start when it still was a pretty good application for managing an offline collection of music files. Lately, the app has shifted towards cloud-based stuff and artificial stupidity algorithms that try to suck all the joy out of being your own virtual DJ. It is still usable for its original intent however so I haven't tried to move to an alternative… yet.

Lately, Apple has done two more stabs at endlessly annoying me and making me regret that even my alarm clock is tightly coupled to iTunes by means of Koingo's Alarm Clock Pro. The first thing they did was break the visualizer plug-ins, in the typical Apple fashion that has since many years made me shy away from developing anything specific for OS X. This fashion is of course doing it in total silence, without warning anyone or even mentioning it in the release notes. Starting with iTunes 12.6 the visualizer menu simply only shows the two built-in visualisers, ignoring any installed plugins. I am pretty glad I never took the effort to polish up my now obsolete Spectrograph plug-in. Maybe I unconsciously saw it coming.

The second thing they did, and what this post really is about, is that they also broke the Hear audio enhancer from Prosoft. I heavily rely on Hear to make listening with headphones more enjoyable. When properly set up, Hear can make even the cheapest headphones sound like expensive Sennheisers. Or in my case, make mid-priced Sennheisers sound like an explosion of aural bliss. It can also squeeze extra fidelity out of simple Bluetooth speakers or other sound systems. Great was my frustration when I noticed the controls had no effect anymore after iTunes had sneakily upgraded itself to 12.6.1, and it was even greater when I saw on the Hear product page that Prosoft officially does not support iTunes anymore. That's right, they admit that their product primarily geared towards enhancing your music experience, does not work with the de facto standard for music playback in Mac OS. I commend them for that, but it doesn't make the fact less annoying.

My guess is that iTunes has become yet another application in the row of ‘sandboxed’ apps like Safari, which are nailed shut to avoid exploits from malware and the like. After all, iTunes is linked to a store and the store is linked to credit card details. Why this also has to break the ability to manipulate the audio stream, beats me. I contacted Prosoft and they are looking if the problem can be fixed, but I'm not sure if they'll be able to circumvent the sandbox restriction.

However, I noticed that applications like Nicecast still work fine with iTunes. This made me pretty confident that I can still make the audio go through Hear after all, albeit by means of a pretty clumsy roundabout. And indeed, after the necessary cursing and kludging I made it work as follows.

Making it work

The strategy is quite simple: re-route iTunes' audio output through another non-sandboxed program that plays the stream on standard output. We can do this by means of two different free, open source projects: SoundFlower and Audacity.

  1. First install SoundFlower, the current 2.0b2 release from mattingalls' GitHub seems to work fine, at least in El Capitan. Don't bother with trying to get the Soundflowerbed application to work, you don't need it.
  2. In your Sound system preferences, set the ‘Soundflower (2ch)’ device as output device.
  3. Open Audacity and select the ‘Soundflower (2ch)’ device as the microphone device. Select the ‘Built-in Output’ as your output device.
  4. In Audacity's preferences, Recording, enable ‘Software Playthrough’.
  5. Drag both the input and output volume sliders in the top-right corner of Audacity's main window to maximum. Now press ‘Click to Start Monitoring’ and start playing some music. You should see Audacity's VU meter start to move, and hear the sound as usual. You may need to give the Hear control panel a kick by toggling the on/off button or nudging a slider to make it hook itself to the audio output, but it should work.

Of course this has some disadvantages, like needing to keep Audacity open, and a noticeable extra delay on the audio as well. You will have no sound at all if you break any component in the whole chain. This can be pretty annoying if like me, you use your Mac as an alarm clock (it will be trying to wake you with silence which results in you being late for work). Moreover, when you switch back to direct playback through internal speakers, two things require attention. First, your volume will be at 100%, which can lead to unpleasant surprises if you forget to turn it down. Next, when you have switched back to internal speakers in the Sound control panel and plug or unplug something from the headphone jack, OS X will once more switch back to Soundflower output, and you must again select internal speakers.
In other words, not only do you need a whole ritual to set up this workaround, you also need to do a little dance to tear it down. For all these reasons I hope Prosoft manages to find a solution. I wouldn't mind if it would simply implement this workaround under the hood and have some extra delay, if only it is reliable.

This hack does have some extra advantages however, for instance Hear will also work with Safari or any other sandboxed application's audio. And, if at any time you would want to record what's playing, all you have to do is hit the record button in Audacity.