A Weird Imagination

Volume via shell

Posted in

The problem

Sometimes a GUI is not the best way to control a computer's volume. Usually if you care about the volume of your computer, you're probably nearby but perhaps would rather be using a remote or other shortcut way of changing the volume. The specific use case that prompted this blog post was binding the volume up and volume down keys on my keyboard to the global volume control (as opposed to separately binding them in each application).

Read more…

Application bypassing PulseAudio

Posted in

The problem

Recently I ran a game1 and instead of the expected music, got distorted noise. At first I thought there was something physically wrong with my speakers or the connection to them, but running any other program resulted in normal sound, albeit mixed with the distorted sound of the game. Even more strangely, changing the volume in the game changed the volume of the distorted noise, implying the game was in fact generating the right thing but it was being misinterpreted, so the culprit was neither the game nor the sound driver but somewhere in between them.

As I had recently set up PulseAudio2, I suspected it was to blame. I opened up pavucontrol to find the game omitted from the list of applications producing sound, which suggested the problem was caused by the game trying to use some way to produce sound that PulseAudio was not capturing.

The solution

The short version is that the problem was solved by restarting PulseAudio:

$ killall -9 pulseaudio

Read more…

Emotional error messages

Posted in

Cowardly tar

$ tar c
tar: Cowardly refusing to create an empty archive
Try 'tar --help' or 'tar --usage' for more information.

That's what the GNU implementation of tar says. For comparison, Debian includes FreeBSD's implementation of tar in the bsdtar package as the bsdtar command:

$ bsdtar c
bsdtar: no files or directories specified

Clingy lynx

In the text-only web browser lynx (not to be confused with links), if you press q to quit, it asks

Are you sure you want to quit? (y)

Most keys quit the program, but if you decide not to quit and press n for no, lynx shows the message


which goes away after a couple seconds allowing you to continue browsing.

Emulating Xbox controllers on Linux

Posted in

The problem

The Xbox 360 controller has become the defacto standard controller in PC gaming in recent years, likely due to both the popularity of the Xbox and the fact that the controller can easily be used with a computer. One downside of this is that some games assume you have one. If the game supports it and is running through Steam, then Steam's controller settings will let you use any controller, but that doesn't work for all games, and you might not be using Steam. The game that prompted this blog post actually does have Steam controller support promised in the future, but it's in early access and they are busy developing other parts of the game.1


The solution is xboxdrv, the userspace Xbox controller driver. In addition to supporting actual Xbox controllers, it can also simulate Xbox controllers based on inputs from other devices like a PlayStation controller or some less common controller.

Read more…

Shadowrun's text compression

The problem

Several years ago, I was in a ROM hacking IRC room where another regular Alchemic was reverse engineering the text system of the SNES game Shadowrun. He figured it out and wrote a python script to decompress the text but had some questions about why it was designed the way it was. So we're going to walk through figuring out how the code works, with some help from his notes, and try to understand the design.

If you don't want spoilers and would rather try to reverse engineer it yourself, just read up to the end of the Trace format section and see how much you can figure out on your own.

Read more…

Identifying joystick devices

Posted in

Too many input devices

On a modern computer there are often many input devices,

$ ls /dev/input/event* | wc -l

They are just identified by numbers, so it can be difficult to choose the right one and trial-and-error can get tiresome with so many. There is some help from the by-id and by-path listings:

$ ls -go --time-style=+ /dev/input/by-id/
lrwxrwxrwx 1 10  usb-045e_0291-if06-event-joystick -> ../event26
lrwxrwxrwx 1  6  usb-045e_0291-if06-joystick -> ../js6
lrwxrwxrwx 1 10  usb-0b43_0003-event-if00 -> ../event20
lrwxrwxrwx 1 10  usb-0b43_0003-event-joystick -> ../event19
lrwxrwxrwx 1  6  usb-0b43_0003-joystick -> ../js1
lrwxrwxrwx 1  9  usb-BTC_USB_Multimedia_Keyboard-event-if01 -> ../event2
lrwxrwxrwx 1  9  usb-BTC_USB_Multimedia_Keyboard-event-kbd -> ../event1

$ ls -go --time-style=+ /dev/input/by-path/
lrwxrwxrwx 1  9  pci-0000:00:1a.2-usb-0:2:1.0-event-kbd -> ../event1
lrwxrwxrwx 1  9  pci-0000:00:1a.2-usb-0:2:1.1-event -> ../event2
lrwxrwxrwx 1 10  pci-0000:00:1d.0-usb-0:1:1.6-event-joystick -> ../event26
lrwxrwxrwx 1  6  pci-0000:00:1d.0-usb-0:1:1.6-joystick -> ../js6
lrwxrwxrwx 1 10  pci-0000:00:1d.0-usb-0:2:1.0-event -> ../event20
lrwxrwxrwx 1 10  pci-0000:00:1d.0-usb-0:2:1.0-event-joystick -> ../event19

But, for the most part, those names aren't very helpful, especially since many joystick devices support 2 or 4 joysticks connected to the same device.


Enter identify_evdev.py:

$ identify_evdev.py

Where /dev/input/event22 is the device of the joystick I touched after running identify_evdev.py.

Read more…

Read-only filesystem errors

Linux has a tendency to give very unhelpful error messages when it is unable to create a file. I previously blogged about a few different reasons Linux might report a disk is full, but all of the reasons included the disk actually not having space for more files. Yet another reason to get similar errors is if the partition is mounted readonly (ro):

$ mount | grep -F /usr
/dev/sdc2 on /usr type ext4 (ro,nodev,noatime,data=ordered)

mount without any options lists all of the mounted partitions along with their mount options.

Many programs will show a helpful error message:

$ touch test
touch: cannot touch ‘test’: Read-only file system

But some others won't:

rtorrent: Could not lock session directory: "./session/", held by "<error>".

That error is normally caused by ./session/rtorrent.lock not being writable due to being held by another process, but in this case it's not writable due to the filesystem being readonly. rtorrent doesn't distinguish the two.

For that reason, when running into weird behavior from a program on Linux, it's a good idea to check that the directories the program might try to write to are actually writable.

How not to fix USB HID errors

The error

I was having trouble with a USB joystick adapter (an EMS Playstation controller adapter, to be specific). When I plugged it in, it wouldn't work and checking dmesg showed the same error getting generated over and over again (at least once per second):

$ dmesg
[81700.968873] usbhid 6-1:1.0: can't add hid device: -71
[81700.968885] usbhid: probe of 6-1:1.0 failed with error -71
[81700.968986] usb usb6-port1: disabled by hub (EMI?), re-enabling...
[81700.968991] usb 6-1: USB disconnect, device number 53
[81701.208025] usb 6-1: new low-speed USB device number 54 using uhci_hcd
[81701.384866] usb 6-1: string descriptor 0 read error: -32

The wrong fix

I decided the sensible thing to do was to reload the driver:

$ sudo modprobe -r usbhid  # Bad idea, don't run this

Read more…


Posted in

PulseAudio is what most modern Linux distributions use as a sound server, the part of the sound subsystem that sits between applications and the sound driver supporting features like allowing multiple applications to output sound simultaneously. PulseAudio adds various features not present in other Linux sound servers like per-application volume controls and easily outputting to different audio devices (for instance, using HDMI audio instead of the normal audio jack).

PulseAudio can be controlled using pavucontrol, which is a GUI audio mixer. It shows a volume meter and control for every application producing sound as well as an option to choose which audio device it is outputting to. It additionally lists all of the hardware input and output devices, as you would expect from an audio mixer.

Fixing problems

Restarting PulseAudio

If PulseAudio is not working properly, you can restart it by running

$ killall -9 pulseaudio

No, really, that's what Debian's PulseAudio page says to do.

When I initially installed PulseAudio, it didn't have my sound cards listed and just had the default null outuput, making it not very useful. Running that command to restart it fixed it.

Muted devices

PulseAudio seems to mute my sound card all by itself. Currently, I just go into pavucontrol and unmute it.

Detachable X sessions

X forwarding

Normally with X, it's easy to run an application on a remote computer just by using X forwarding:

local:~$ ssh -X host
host:~$ echo $DISPLAY
host:~$ xterm

The xterm will appear on your local computer.

But if you want to continue working with that application on a different remote computer (or once you are physically in front of the computer it is running on), then you're out of luck.

For an application running in the terminal, you can start it inside a GNU Screen (or tmux) session which you can detach and then attach to again on another ssh connection.

GNU Screen for X

xpra (X Persistent Remote Applications) lets you move graphical applications from one computer to another in addition to fixing other problems with X forwarding. If you instead use xpra for the forwarding, then you can detach and reattach to the session at will.

Read more…