Generational loss in MP3 re-encoding

Okay, name this tune:

madplay / lame – 1000 iterations

(You’ll have to scroll about half way in before anything starts)

Didn’t get it? Try this:

madplay 24-bit / lame – 1000 iterations

(Again, you’ll have to scroll about half way in before anything starts)

Missed that one? Okay then, how about:

lame / lame – 1000 iterations

(no need to scroll here.)

Unless you’ve been living under a rock, it’s a clip from Adele‘s Someone Like You. Sure, you can’t make out the words too well in the last one, but at least they don’t sound like some dire paen to Cthulhu, like the first two do.

All of the above samples are the same source file re-encoded 1000 times. I’d heard that there was some loss to encoding MP3s, but thought that if you kept about the same bitrate, there wouldn’t be too much loss. I wanted to test out my theory, so I took:

  • LAME — a quality mp3 encoder (that can also decode to WAV)
  • madplay — a decent mp3 decoder that uses fixed point for speed
  • a shell script (see below) that encodes an MP3 1000 times, feeding the output of the last run as the input of the next.
  • a sample clip; in this case, ganked from Amazon.com: 21: Adele: Music using Audio Hijack Pro.

The original sample looks pretty clean; it’s not the highest quality, but it’s clear:

The first thing that strikes about the multiply-reencoded file is that it’s much longer:

This is because LAME adds padding to the beginning and end of each song. All this padding adds up over 1000 runs.

I’d used madplay extensively before, so I knew it worked reliably. First, I tried it using an intermediate sample size of 16 bits (same as the source) and no dithering. Just after 100 runs, Ms Adkins’ plaintive voice becomes hard to understand:
madplay / lame – 100 iterations

I’d turned dithering off in the first test, as I thought it would overcome the signal. As the signal was pretty much gone, I didn’t think I had much to lose, so I tried it at madplay’s full capability of 24 bit internal processing. Again, 100 runs was where things started to go really sideways:
madplay 24-bit / lame – 100 iterations

LAME can also decode MP3s, and remarkably, the lyrics remained discernable after 1000 interations (so go and see the third sample up top). Sure, it sounds scratchy, but the piano sounds like a piano and not like some underwater harp. LAME is clearly able to recognize its own input, and decode it accordingly. madplay, on the other hand, just treats an MP3 as a generic MP3, hence the over-compression and extra silences.

So really, if you’re going to re-encode music, it matters more what you use to decode your MP3s. If you can use the same tool for both, all the better.

how does he do that?

Someone asked how the automatic podcast works. It’s a bit complex, and they probably will be sorry they asked.

I have all my music saved as MP3s on a server running Firefly Media Server. It stores all its information about tracks in a SQLite database, so I can very easily grab a random selection of tracks.

Since I know the name of the track and the artist from the Firefly database, I have a selection of script lines that I can feed to flite, a very simple speech synthesizer. Each of these spoken lines is stored as as wav file, and then each candidate MP3 is converted to wav, and the whole mess is joined together using SoX. SoX also created the nifty (well, I think so) intro and outro sweeps.

The huge wav file of the whole show is converted to MP3 using LAME and uploaded to my webhost with scp. All of this process is done by one Perl script – it also creates the web page, the RSS feed, and even logs the tracks on Last.fm.

Couldn’t be simpler.

m4a2mp3

m4a2mp3 – convert AAC to MP3. Uses Perl, LAME and faad. Semi-gracefully converts weird iTunes genres to ID3v2, or to “Other” if it’s something else. Uses lame’s new VBR settings, so you end up with an MP3 not massively bigger than the source M4A.

PS: broke the 8000 tunes on the Firefly server …

mame is lame

I suddenly got a retrogaming jones on, and had a strong need to play Robotron. So I downloaded MAME and some ROMs, but no dice — every archive was missing files. Seems that to get the few games I need, I have to download a 16GB torrent of ever game that MAME supports.

My arcade game sensors withered about 18 years ago, so nothing past about 1988 registers with me. You could probably fit every pre-’88 ROM onto a couple of floppies. And it’s not like I’m not allowed to play the ancient Williams games; I have the Arcade Classics CD somewhere which has the games in licensed (but MAME-incompatible) form.