unsilence

Hidden tracks on CDs used to be a pretty common thing. Not “real” hidden tracks: You could play tricks with the directory structure and put a track before the first one, so you have to skip back from 1 to get to 0.

No, the common way to do this is to pad the final track with, say, ten minutes of silence, and then the “hidden” song starts.

While the concept of hidden tracks is fun, in practice it’s really annoying, because it means that you’re sitting there listening to silence for ten minutes.

So once upon a time I wrote a little C program that would look for silences in the last track of all the CDs I have ripped, and if it finds (long) silences, then splitting happens.

As CDs are getting less popular as a means of distribution (to put it mildly), the hidden track thing has all but disappeared, too, but this week I got
the new Deathcrush album, and it employs this tactic.

I started looking around for the scripts to split the file, and then I discovered that it was in an obscure region of my home directory, not touched for ten years, and not put on Microsoft Github.

But now it is.

It’s probably a couple of decades too late to be useful to anybody, but there you go. It compiles and everything on the current Debian, which just amazes me. I mean, I wrote it in… like… 2003?

Go Linux.

Fun with DPMS; or, An Emacs-Based Screensaver

I’ve got a bunch of monitors, large and small, that (in general) are always on. Because I’m too lazy to switch stuff off and or.

They display some useful information, but are largely decorative (i.e, some of them display temperature data, and some use xscreensaver to show what albums are playing).

But I’ve got the rest of the lights and stuff in the apt to switch off when I push the “I’m going to bed” button on the wall. I thought it might be nice to have all the monitors also switch off at the same time? And then I could link the “I’m awake now” button on the wall to switching all the monitors on again.

So cyber.

I thought this was going to be really easy, but… you know… computers.

First of all: Switching a screen off is easy:

$ xset dpms force off

And then it’s off.

$ xset dpms force on; xset -dpms

to switch it on again and disable power management again (to avoid the monitors switching themselves off again on their own volition).

So far so good!

However, there’s like a dozen things that feel free to wake monitors up.

mpv

Easiest first: I’ve got a little monitor that plays Youtube 24/7 (and displays weather data).

It would switch itself on immediately, because it uses mpv to display the youtube vids. To switch that off, just say –no-stop-screensaver.

Stereo Computer

The screen on the computer I use to control the stereo would switch it self on whenever the song changed, and after a bit of trial and error and more code reading, I found this:

(set-mouse-pixel-position (selected-frame) 2000 0)

It’s code designed to just move the mouse pointer off the screen. And it turns out that that makes X wake the monitor up!

I guess that… makes sense? I mean, moving the mouse is supposed to wake the screen up, so…

I added the following guard:

(defun jukebox-monitor-on-p ()
  (with-temp-buffer
    (call-process "xset" nil t nil "q")
    (goto-char (point-min))
    (search-forward "Monitor is On" nil t)))

xscreensaver

Many of the larger screens use xscreensaver to display the sleeve of whatever album is playing, and xscreensaver wakes the monitor up after just a few seconds. Isn’t that ironic!

Don’t you think?

It’s like a screensaver that switches on a screen that’s already saved, it’s like

Oh, where was I…

xscreensaver has a bunch of DPMS-related options:

dpmsEnabled:	False
dpmsQuickOff:	False
dpmsStandby:	24:00:00
dpmsSuspend:	24:00:00
dpmsOff:	24:00:00

But none of them seem to help with this problem. xscreensaver stubbornly wakes shit up. What’s up with that, jwz?

So.

The only solution for this problem is to write an Emacs-based screensaver.

Obviously.

It uses the xelb library to query the idleness (to schedule when to start saving the screen) and to query/restore focus after closing the screensaver window.

Man. It’d be great if somebody could write a manual for xelb. Working with it is kinda frustrating because you just have to poke around, looking at examples, until you suddenly get something that works. I spent, like, seven thousand hours (approx.) trying to get the idleness out of it until I guessed (by looking at what exwm did with randr extensions) that you had to say

(xcb:get-extension-data x 'xcb:screensaver)

before trying to call the xcb:screensaver:QueryInfo function.

[Edit: Emacs give me almost all events that’s given to the frame (mouse and keystrokes), but not when the user presses shift, etc. Is there a way to get something like xcb_wait_for_event out of the xelb library?]

SO THERE YOU ARE

Isn’t it weird how these trivial projects tend to spiral out of control?

Especially for certain people?

Don’t you think?

For Flacs Sake

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.

Useful Consumer Review

I needed a new scanner, and I wanted one that was significantly faster than the one I’ve been using until now. After some Googling, I landed on the Epson DS-50000, which is an A3+ scanner with a promise of being able to scan an A3 300DPI page in four seconds.

The web site I bought it from said that it’s a 4PPM scanner.

THOSE ARE NOT THE SAME THING!

So I was excited when I finally got it, two months after I ordered it. Was it going to be 4PPM or 4SPP?

The latter! From hitting “enter” on my USB-connected laptop to having the scanned page up in my Emacs, it takes 3.5 seconds. Very impressive, I think. It’s only USB2, and I thought that might be a bottleneck, perhaps, but apparently not. It also feels very sturdy and it doesn’t have a fan, so it’s quite silent. It’s very nice. And it makes good-quality scans, too.

But.

Yes, I connected it to a Linux laptop and you all knows what comes next: A tale of woe.

$ scanimage -d epsonds:libusb:001:019 --resolution 300dpi > /tmp/file

Worked perfectly the first time I tried it, so I thought I was in luck for once. But then I tried it again:

$ scanimage -d epsonds:libusb:001:019 --resolution 300dpi > /tmp/file
scanimage: open of device epsonds:libusb:001:019 failed: Error during device I/O

Gah! Basically, nothing helped. And it’s not just when scanning: Any command that talks to the scanner works the first time:

$ scanimage -L
device `epsonds:libusb:001:019' is a Epson DS-50000 ESC/I-2

But the second time:

$ scanimage -L

No scanners were identified. If you were expecting something different,
check that the scanner is plugged in, turned on and detected by the
sane-find-scanner tool (if appropriate). Please read the documentation
which came with this software (README, FAQ, manpages).

If I unplug it and replug it, then it works again.

After googling a bit, it seems that somebody had the same issue some years back with a different scanner, and the way to fix it was to build scanimage and friends from the current source tree, but that didn’t help.

So after some head scratching, I thought of a different approach: Obviously, something scanimage is doing is leaving the scanner in a bad state. What if I just reset the USB interface? Is that something that’s even possible?

Yes!

I added a Makefile and put it on Microsoft Github for your convenience. All the code does is basically:

ioctl(fd, USBDEVFS_RESET, 0);

And this resets just the single USB port, so nothing else wonky happens to the USB sub-subsystem. And the command is extremely fast, so it adds no delay to the scanning process.

You do get a lot of these messages in your kern.log, though:

Oct 28 21:03:06 corrigan kernel: [972003.683893] usb 1-2: reset high-speed USB device number 19 using xhci_hcd

But who cares.

It’s truly the year of Linux on the Laptop.

Innovations in Emacs Touch Interfacing

I’ve long attempted to hack some touch interfaces for laptops in non-keyboard configurations.

The sad thing is that there aren’t really any good solutions in GNU/Linux. If you want to be able to respond to more complex events like “two finger drag”, you have to hack GTK and use Touchégg, and then it turns out that doesn’t really work on Wayland, and then most of the events disappeared from the X driver, and then…

In short, the situation is still a mess. And then my lug-around-the-apt-while-washing-TV-laptop died (ish), so I had to get a new one (a Lenovo X1 Yoga (2nd gen (which I had to buy from Australia, because nobody would sell it with the specs I wanted (i.e., LTE modem if I wanted to also take it travelling (the 3rd gen has an LTE modem that’s not supported by Linux))))):

And now, with Ubuntu 18.04, everything is even worse, and I’m not able to get any multi finger events at all! All the touch events are just translated into mouse events! Aaaargh!

After despairing for an eternity (OK, half a day), I remembered another touch interface that I quite like: The Perfect Reader.

It’s a bit hard to tell here, but the idea is that you divide the screen into areas, and then you just tap one of the areas to have the associated action happen.

Surely even Linux can’t have fucked up something so basic: It must be possible to get that kind of access.

And it’s possible! Behold!

Er… What’s going on on the other side of the backyard?

Eeek! Kitten! Go back inside!

That’s not a safe place to play! … *phew* It sat down, and turned around and went back inside. *heart attack averted*

ANYWAY!

The idea is that there’s one action grid overlay when Emacs is in the forefront, and another when the mpv video player is.  All the events go via Emacs, though, which controls mpv via the mpv socket interface.  (And, by the way, I have to say that I’m really impressed with mpv.  It has all the commands you want it to have.  The documentation is somewhat lacking, though.)

Here’s a demo:

Basically, I’m just reading the output from libinput-debug-events (which outputs everything that goes through /dev/input/event* (so you have to add your user to the input group to access them)), and then execute things based on that. libinput is allegedly the new hotness, and replaces libev and the synaptics X driver, and is supposed to be supported on both Wayland and Xorg, so hopefully this attempt at an interface will last a bit longer than the previous ones.

I wrote the controlling thing in Emacs, of course, and you can find it on Github. I’ve been using an Emacs-based movie/TV viewer since 2004, and I’m not giving up now! So there.

mpv Is Nice

I’ve been watching movies and TV using an Emacs interface since 2004, according to the movie.el file.  Under the hood, though, I’ve hacked away at mplayer to make it do what I want, which includes a convenient way to switch audio outputs and output progress info so that I can store that to restart the video in the same place I left off.

And various bits and bobs.

But with the advent of 4K Bluray, it seems like mplayer just doesn’t hack it anymore.  So I started watching 4K material with mpv and the rest with mplayer.

And then I got a new TV machine (because the old one wasn’t fast enough to play Crouching Tiger, Hidden Dragon in 4K) and, as usual, mplayer didn’t really want to compile on the new Debian version, so I thought it was time to switch completely to mpv.

I thought I was going to have to do the same hacking on mpv as mplayer, but it turns out that mpv is really nice: It has almost all the features I need, and in a very pleasant-to-work-with interface: Just talk to mpv by sending JSON via a Unix-domain socket.

The only thing it didn’t have was a way to set the screensaving prefix on-the-fly (which I need for making GIFs), so I hacked that in.  The mpv people have really cleaned up the mplayer source code, I have to say.  Everything is nice and logical and clean, apparently, and I adding the feature took like 15 minutes.  Kudos.  I’ll try upstreaming the patch… if I can figure out how the mpv people like receiving patches.

Just one note on building mplayer and FFmpeg: Some things in Debian break if you have the new FFmpeg libraries in /usr/local, so put it somewhere else.  In case somebody needs to build mpv from git in Debian, this is what works for me, and is non-breakey:

/usr/src/FFmpeg $ ./configure --prefix=/usr/plocal --enable-gnutls 
/usr/src/FFmpeg $ make
/usr/src/FFmpeg $ sudo make install
/usr/src/FFmpeg $ cd /usr/src/mpv
/usr/src/mpv $ ./bootstrap.py
/usr/src/mpv $ PKG_CONFIG_PATH=/usr/plocal/lib/pkgconfig ./waf configure
/usr/src/mpv $ ./waf build

And then the mpv executable is in /usr/src/mpv/build/mpv, and can just live there without being installed.

So Much 4K

I got a 4K TV a while back, but I haven’t had any 4K media.

Until yesterday!

A couple of months ago, the encryption on 4K Bluray media was partially broken. It’s not just rip’n’go as it is with DVDs and 2K Bluerays, but, basically, you can anyway. You just download this file that has some hashes in it, and then you can use the wonderful makemkv program to rip the DVDs.

If your disc isn’t covered by the hash file, makemkv will create a dump file which you can then mail to the makemkv guy, who will then do some magic and a couple of days later the hash file will be updated with the necessary stuff to rip it. People are speculating about just what’s going on: Perhaps there’s a hardware thing that’s been “compromised” and can output the required data based on the dump file? Or perhaps the makemkv guy doesn’t feel comfortable releasing the full software because of reasons?

In any case, this means that I can finally watch 4K media on my Linux setup! Yay!

You need a “friendly” drive, though. I’ve got a drive that identifies itself as “BD-RE ASUS BW-16D1HT 3.01”, and it’s a SATA drive that I use a USB3-to-SATA interface to connect to the computer.

See? Totes gorge.

What drives work changes all the time, and the first one I bought (a USB3 LG drive) refused to play along. And things may change at any point, so if you find one that works, never upgrade the firmware.

I tested by ripping Thor: Ragnarok, and the resulting file was 50GB big. (The normal 2K Bluray is 25GB. Logical.)

But then the problem is: How do you play this stuff? It’s way too large to decode and render in software, so you need hardware support, and that support is only in the latest version of some of the players.

I chose mpv, because they seem to be most up-to-date. The versions that are distributed in Debian are way too old. So you have to build from source.

You need mpv itself, ffmpeg and libav, apparently, and all quite recent. Clone them all, build and install ffmpeg and libav, and then build mpv using that weirdo waf build system. (The instructions are on the mpv page.)

And now I can watch Thor! On Linux! Whoho!

I have an Nvidia card, so my command line is “mpv –vo=opengl –hwdec=cuda-copy”. And is 4K better than 2K?

Just look at Chris Whatsisname’s eyebrows in 4K:

Compare to 2K:

Ewww! You can’t even count the hairs in 2K! So horrible!

And now… I’m going to watch some more Bergman sourced from an 80s VHS tape upconverted to DVD.