Barnoid’s Knowledge Base

Bits of Collected Wisdom

September 22nd, 2006

Linux: Burn Audio CDs

If your music is in mp3/ogg format, you’ll need to convert the files to PCM format first.

For mp3 files use one of the following two commands to convert song.mp3 to song.mp3.wav:

# lame --decode song.mp3 song.wav
# mpg123 -s song.mp3 | sox -t .raw -r 44100 -sw -c 2 - song.wav

And for ogg:

# ogg123 -d wav song.ogg -f song.wav

If necessary, convert your wav files to 16bit stereo, 44.1kHz with

# sox song.wav -r 44100 song.new.wav resample

Audio CDs can be written in TAO (track-at-once) or DAO/SAO (disk-at-once/session-at-once) mode. TAO mode introduces 2 second gaps between the tracks, whereas DAO/SAO does not.

To test-burn your wav files using DAO/SAO mode run (replace /dev/hdX with your CD-burner’s device node)

# cdrecord dev=/dev/hdX fs=4096k -v -useinfo -dao -pad -audio -dummy song1.wav song2.wav song3.wav [...]

If everything goes well, re-run the command withouth the -dummy argument to write your audio CD.

For TAO mode use:

# cdrecord dev=/dev/hdX -v -pad -audio -dummy song1.wav song2.wav song3.wav [...]

Remove the -dummy argument and re-run the command to burn the CD.

Links:

September 20th, 2006

On Pipes and Forks: Read (uncompressed) data directly from compressed files

Sometimes you’ve got data in a compressed form, but you need to read and process the (uncompressed) data in a program. If, as in my case, the uncompressed data (a program execution trace) is around 8 GB, and the compressed trace only 400MB big, uncompressing that data to disk, reading it and, after processing, deleting it is a big hassle.

It would be nice to directly uncompress and read the data from within the program…and luckly this is actually very simple:

Let’s say, we have a compressed file, trace.dat.gz, then we need to read from.

The code to read the decompressed data goes something like this:

FILE *trace = fopen(filename, "r");

while ((res = fscanf(trace, "%s "lx %lx", &status, &adr, &data)) == 3) {
    /* process data */
}

fclose(trace);

The trick to directly read from the compressed file is to execute a process that decompresses the data and directly feeds it into our program. That’s what pipes & fork are for:

int pfd[2];
FILE *trace = NULL;
if (pipe(pfd) != 0) return false;
pid_t cpid = fork();
if (cpid == 0) {
    // child process: redirect pipe to stdout & start the decompressor
    close(pfd[0]); dup2(pfd[1], 1); close(pfd[1]);
    excelp("gunzip", "gunzip", "-c", filename, NULL);
    exit(0);
} else {
    // parent: read from the pipe
    close(pfd[1]);
    trace = fdopen(pfd[0], "r");
}

while ((res = fscanf(trace, "%s "lx %lx", &status, &adr, &data)) == 3) {
    /* process data */
}

fclose(trace);
close(pfd[0]);

That’s it! Our program now automatically runs “gunzip” on the compressed data before piping it into our program.

September 20th, 2006

GCC: Compilation of 4.1.1 fails with HARDENED 3.4.6

ok, so you finally do the GCC 4.1.1 update that is basically forced upon us and end up with:

# emerge -uv gcc
/var/tmp/portage/gcc-4.1.1/work/build/i686-pc-linux-gnu/libstdc++-v3/include/limits:990: error: stray '\226' in program
/var/tmp/portage/gcc-4.1.1/work/build/i686-pc-linux-gnu/libstdc++-v3/include/limits:1047: error: stray '\374' in program
/var/tmp/portage/gcc-4.1.1/work/build/i686-pc-linux-gnu/libstdc++-v3/include/limits:1104: error: stray '\226' in program
...
!!! ERROR: sys-devel/gcc-4.1.1 failed.
Call stack:
ebuild.sh, line 1546:   Called dyn_compile
ebuild.sh, line 937:   Called src_compile
ebuild.sh, line 1255:   Called toolchain_src_compile
toolchain.eclass, line 24:   Called gcc_src_compile
toolchain.eclass, line 1534:   Called gcc_do_make
toolchain.eclass, line 1408:   Called die

!!! emake failed with profiledbootstrap
!!! If you need support, post the topmost build error, and the call stack if relevant.

It turns out that the “HARDENED” gcc 3.4.6 cannot compile gcc 4.1.1.

Solution: re-emerge the old gcc without the HARDENED flag

# emerge --oneshot =gcc-3.4.6-r1
# env-update && source /etc/profile

and then, finally

# emerge --auv gcc

Happy compiling!

September 19th, 2006

CUPS: Add Vendor-Supplied PPD Files

  • obtain the PPD for your printer, for example from http://www.linuxprinting.org/.
  • copy the file to /usr/share/cups/model/
  • restart CUPS
  • modify your printer in CUPS’ web interface to use the new PPD
  • done!