Yesterday, I bought this Black Cab EP off of Bandcamp, but when I played it today, all I got was silence.
A new form of Extreme Australian Minimalism or a bug?
My music interface is Emacs, and it uses flac123 to play FLAC files. It’s not a very er supported program, but I find it convenient since it uses the same command format as mpg123/321.
I have encountered FLAC files before that it couldn’t play, but I’ve never taken the time to try to debug the problem.
$ file /music/repository/Black\ Cab/Empire\ States\ EP/01-Empire\ States.flac /music/repository/Black Cab/Empire States EP/01-Empire States.flac: FLAC audio bitstream data, 24 bit, stereo, 44.1 kHz, 29760127 samples
Huh… so it’s 24 bits, while the rest of the FLAC files I’ve got are 16 bits?
Hm! Spot the problem!
Yes, if the format is anything other than 8 or 16 bits, then no samples are copied over from the FLAC decompression library to the libao player function, resulting in very hi-fi silent silence.
So this should be easy to fix, I thought: Just copy over, like, more bytes in the 24 bits per sample case, right?
Right.
But… the libao documentation is er uhm what’s the word oh yeah fucked up. It doesn’t really say whether ao_play expects three bytes per sample in the 24 bit case or four bytes. I tried all kinds of weird and awkward byte order manipulation, and got various forms of quite interesting noises squeaking out of the stereo, but nothing really musical.
So I wondered whether libao just doesn’t support 24 bits “natively”, and I added some “if 24 bits, then open as 32 bits” logic and presto!
Beautiful music! With so many bits!
I’ve pushed the resulting code to my fork on Microsoft Github.
The four people out there in the world playing 24 bit FLAC files on Linux from the command line or in Emacs: You’re welcome.