Monthly Archives: April 2021

Ripping a CD, old-school style

I recently needed to rip an audio CD (yes, those things still exist). Here’s what it took using Linux command line on an Ubuntu derivative distribution.

Step 1. Install the necessary software:

sudo apt-get install cdparanoia lame

There are two pieces of software being installed here; cdparanoia will copy audio tracks from the CD into *.wav files, while lame will convert *.wav files to a more compact *.mp3 format.

Step 2. Insert the CD into the drive and see if cdparanoia can read it:

cdparanoia -vsQ

If the CD is readable, a bunch of data about the disk and a listing of tracks will be output.

Step 3. The actual ripping of the CD:

cdparanoia -B

This will create a series of *.wav files in the current directory. The files will be named track01.cdda.wavtrack02.cdda.wav, and so forth. They can be renamed if necessary, but for now, we’ll just let them be.

Step 4. Make the *.mp3 files using lame.

There’s a small problem with lame; it expects to work with one file at a time, like this:

lame track01.cdda.wav

To work around it, we can ask lame to work inside a loop. Say, we have a bunch of *.wav files in a directory and we want encode them all into *.mp3. This can be accomplished using a shell loop:

for t in *.wav; do lame $t; done

If we only want to encode, say, first three tracks we just ripped, we can specify a more restrictive track selection pattern:

for t in track{01..03}*.wav; do lame $t; done

When the command completes, the current directory will contain *.mp3 files with names matching the names of *.wav files we asked lame to encode. For example, there will be track01.cdda.mp3 next to track01.cdda.wavtrack02.cdda.mp3 next to  track02.cdda.wav, and so on.

Concluding note. Both cdparanoia and lame have plenty of command-line options not covered here. Using those options, one can rip selected tracks or even parts of a track, specify bitrate and mode for the encoding, and lots of other things…

Another networking adventure…

Situation

A no-name mini-PC is being prepared for use as a “headless” development/testing environment running Debian. The machine must connect to the local network using Wi-Fi.

Problem

The machine does not appear to have a Wi-Fi controller. Running

lspci -nn

provides no information about a Wi-Fi device of any kind. At the same time, a look into BIOS reveals that a Wi-Fi card is present; BIOS identifies it as AP6255. A quick Internet search later, another revelation: this is a Broadcom product licensed to a variety of third parties to sell under white labels. I should have known… Welcome to another Broadcom-themed adventure in networking!

Cause of the problem

The Wi-Fi controller is indeed present, but it does not communicate to the rest of the system via the customary PCI, so lspci cannot detect it. Rather. It uses an alternate communication method called “SDIO/USB”, aka “SDIO over USB”. So our system must have the firmware/drivers that support this method, rather than those that support the more conventional PCI.

Solution

We begin by connecting the machine to the local network (and the Internet) with an Ethernet cable; the machine will need an Internet connection to download the necessary software. Also, the administrator will need root-level access to the system. Commands given below assume that root access is available, but they can be used with sudo if necessary, and it shouldn’t make any difference.

STEP 0 (wasn’t necessary in my case, but may be needed if other solutions were tried before to no avail). Uninstall potentially conflicting packages:

apt-get remove broadcom-sta-common broadcom-sta-source firmware-b43*

Note the star symbol at the end; it tells apt-get to uninstall all packages whose names start with firmware-b43.

STEP 1. Install the package containing the appropriate firmware/driver:

apt-get install broadcom-sta-dkms

(Note: in Ubuntu, the equivalent package is named differently, so you should do apt-get install bcmwl-kernel-source instead.)

STEP 2. Enable the kernel module responsible for SDIO/USB communication between the Wi-Fi card and the rest of the system:

modprobe brcmfmac

STEP 3. Test the progress:

iwconfig

The output of this command should contain at least a mention of a Wi-Fi device (wlan0 or something similar). This will indicate that the system has recognized the Wi-Fi device. Note the name of the Wi-Fi device; it will be used in later steps. For the remainder of this solution, we will use wlan0.

STEP 4. Install WPA Supplicant:

apt-get install wpasupplicant

STEP 5. Edit the configuration file /etc/network/interfaces; add the following to the end of the file:

allow-hotplug wlan0
iface wlan0 inet dhcp
    wpa-ssid MyNetworkName
    wpa-psk MyNetworkPassword

Obviously, MyNetworkName and MyNetworkPassword should be replaced with the SSID name for the local wireless network and the password for this network, respectively. Also, remember to replace wlan0 with the name you learned in Step 3.

STEP 6. Bring up the Wi-Fi interface (again, remember to replace wlan0 with the name you learned in Step 3):

ifup wlan0

STEP 7. Verify that the system operates as desired. To so that, shut the system down:

shutdown now

When the system shuts down, disconnect the Ethernet cable and start the system again. It should connect to the specified local network and obtain a local IP address assigned to it by the local DHCP server. If you have a keyboard and monitor temporarily attached to the system, run ip a to see connection status, including the local IP address; if not, scan the network to determine your machine’s local IP address and use it to log in remotely.

The simplest URL rewrite ever?

This simple code snippet, if placed into an .htaccess file, would rewrite an alphanumerical “tail” of a URL into a variable accessible to an index.php residing in the same directory:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ index.php?tail=$1

For example, let’s say the the two files reside inside this directory:

http://mysite.com/myDir/

Then, a user accessing this URL:

http://mysite.com/myDir/ABC123xyz

would see the output of this script:

http://mysite.com/myDir/index.php?tail=ABC123xyz

Note that the “tail” must be alphanumerical (i.e., contain only letters and numbers).