Voder-Vocoder

The Log of Hal Canary

Navigation: Home | THE LOG | Log Archives | Resume | Contact Info | Public Key | SSL | Math Applets | Site Map | WP Backend | RSS2 | Atom

Archive for 2009-08

gain

Back on the CD-ripping project. For popular music, the album titles and artists names are easy and the online databases almost always give me the right answer. But for classical music, there are always discrepancies. So I always change the artist field to be Composer, Performers.

After ripping a few CDs with Sound Juicer, I then run mp3gain (sudo apt-get install --yes mp3gain) on the album.

#!/bin/sh
## ~/bin/mp3gain-a-directory
## Written 2009 Hal Canary, #DTPD#
renice 10 $$ > /dev/null
for dir in "$@" ; do
  if [ ! -d "${dir}" ] ; then
    echo "'${dir}' is not a directory" >&2
  else
    if ( /bin/ls "${dir}/"*.mp3 > /dev/null 2>&1 ) ; then
      /usr/bin/mp3gain -k -a "${dir}/"*.mp3
    else
      echo "'${dir}' has no .mp3 files in it." >&2
    fi
  fi
done

That little script takes a list of directories as arguments, treats all of the mp3 files in a directory as an album and applies the same gain () to each mp3 file in the directory. The -k tells it “of course I don't want to clip the sound; don't ask me every time.” Since this operation is processor- and I/O-intensive, the renice is always appreciated.

Or, if I want to all of the directories at once, I can run this command:

find "${HOME}/Music/CDs" -type d -exec mp3gain-a-directory "{}" \;

mp3gain is nice in that it notices that it's already modified a mp3 and won't waste time on it again.

Hal Canary | Computers & Code, Music | 2009-08-29 09:49:02 UTC
Permanent Link | Comments Off

night

I watched STS-128 lift from 154 miles away last night. Since it was dark, I couldn't see the cloud trail, just an orange glow on the horizon that then turned into the familiar glowing exhaust before fading to a very bright star.

Hal Canary | Life | 2009-08-29 08:41:54 UTC
Permanent Link | Comments Off

unzip-nozipbomb

#!/bin/sh
## $HOME/bin/unzip-nozipbomb
## Written 2007 Hal Canary
## DTPD ##
for zipfile in "$@" ; do
    dir=$(basename "${zipfile}" .zip)
    if [ "${dir}" = "${zipfile}" ] ; then
	dir="${dir}.d"
    fi
    mkdir -p "${dir}"
    unzip -d "${dir}" "${zipfile}"
done

Hal Canary | Computers & Code | 2009-08-26 07:03:57 UTC
Permanent Link | Comments Off

Version 2.4 id3 tags

Since id3lib is incompatable with version 2.4 id3 tags produced by Sound Juicer, you need to use gstreamer and id3mux to grab the tag info to--for example--renormalize your filenames. Tags can themselves be edited in Rhythmbox.

#!/bin/sh
#~/bin/id3v24-info.sh
#DTPD
for file in "$@" ; do
  TMP=`/bin/tempfile`
  echo "$file"
  gst-launch-0.10 filesrc location=/proc/self/fd/0 \
    ! id3demux ! fakesink -t \
    < "${file}" > "$TMP" 2> /dev/null
  for tag in 'title' 'artist' 'album' 'genre' \
      'track count' 'track number' 'disc number' \
      'artist sortname' ; do
    grep "${tag}:" "$TMP" | \
      awk -F "${tag}: " "{ print \"  ${tag} = \" \$2 }"
  done
  rm "$TMP"
done

So my workflow is:

  1. Rip a stack of CDs in Sound Juicer.
  2. Notice that the tags aren't right or don't fit with the other tags in the collection
  3. Edit tags in rhythmbox
  4. Run a script to renormalize the filename.

Hal Canary | Computers & Code, Music | 2009-08-20 14:17:59 UTC
Permanent Link | Comments Off

timer.c

/* Copyright 2009 Hal Canary, http://halcanary.org/
   Dedicated to the Public Domain.

   cc -o timer timer.c
*/
#include <stdio.h>
#include <sys/time.h>
int main(int argc, char *argv[]) {
  int totalminutes, totalseconds; /* args */
  int minute, second; /* counter */
  if (argc <= 1) {
    fprintf(stderr, "Usage: timer MINUTES [SECONDS]\n\n");
    return(1);
  }
  totalminutes = atoi(argv[1]); /* FIRST ARGUMENT */
  if (argc >= 3) {
    totalseconds = atoi(argv[2]); /* FIRST ARGUMENT */
  } else {
    totalseconds = 0;
  }
  printf("%02i:%02i ",totalminutes,totalseconds);
  for(minute=totalminutes; minute >= 0; minute--) {
    for(second=totalseconds-1; second >= 0; second--) {
      printf("\b\b\b\b\b\b\b%02i:%02i ",minute,second);
      fflush(stdout);
      sleep(1);
    }
    totalseconds=60;
  }
  printf("\n");
  return(0);
}

Hal Canary | Computers & Code | 2009-08-18 20:33:59 UTC
Permanent Link | Comments Off

security check: what word am i thinking of?

[fgdgfgbfgnb]

Hal Canary | Life | 2009-08-18 07:15:30 UTC
Permanent Link | Comments Off

rounding functions for POSIX bc.

$ echo 'scale=10; 1/3*3;'|bc
.9999999999

A work in progress, rounding functions for POSIX bc.

/* DTPD */
define round(x,dec) {
  oscale = scale;
  x = x * (10 ^ dec);
  scale = 0;
  tmp = x / 1;
  if (x-tmp >= 0.5) {
    x = tmp + 1 ;
  } else {
    x = tmp ;
  }
  scale = oscale;
  x = x / (10 ^ dec);
  return x;
}
define round(x) {
  oscale = scale;
  dec = oscale-1;
  x = x * (10 ^ dec);
  scale = 0;
  tmp = x / 1;
  if (x-tmp >= 0.5) {
    x = tmp + 1 ;
  } else {
    x = tmp ;
  }
  scale = oscale;
  x = x / (10 ^ dec);
  return x;
}

Hal Canary | Computers & Code | 2009-08-14 12:26:54 UTC
Permanent Link | Comments Off

guitar chord charts

I'm fooling around with a guitar and wanted to take notes on a blank page of guitar chord charts, so I post-scripted this one: pdf file.

%!
%% Written 2009 Hal Canary
%% Dedicated to the Public Domain
/Times-Roman findfont
14 scalefont setfont
/inch {72 mul} def
/tabu {
  newpath
  moveto
  90 0 rlineto   0 115 rlineto
  -90 0 rlineto  0 -115 rlineto
  0 23 rmoveto   90 0 rlineto
  0 23 rmoveto   -90 0 rlineto
  0 23 rmoveto   90 0 rlineto
  0 23 rmoveto   -90 0 rlineto
  18 23 rmoveto  0 -115 rlineto
  18 0 rmoveto   0 115 rlineto
  18 0 rmoveto   0 -115 rlineto
  18 0 rmoveto   0 115 rlineto
  -76 3 rmoveto  (E) show
  9 0 rmoveto    (A) show
  8 0 rmoveto    (D) show
  8 0 rmoveto    (G) show
  8 0 rmoveto    (B) show
  8 0 rmoveto    (E) show
  closepath
  stroke
} def
/trow {
  inch dup dup dup
  2.5 inch exch tabu
  0.5 inch exch tabu
  4.5 inch exch tabu
  6.5 inch exch tabu
} def
1 trow
3.5 trow
6 trow
8.5 trow
showpage

Hal Canary | Music | 2009-08-12 18:59:01 UTC
Permanent Link | Comments Off

the energy-efficient future

In the energy-efficient future:

Picture a Manhattan block in mid-December, crammed with high-rise apartment buildings full of lights, people, and warmth. Several thousand people live on the block. All of their electricity, the fuel for their daily lives, comes from a compact natural gas turbine running in an underground installation in the center of the blcok., The heat produced from the turbine is used to create hot water and warm the entire block. Each one of these people would have an energy footprint with an efficiency above 90%, compared with the current 33% Americans now live at.

From $20 per Gallon: How the Inevitable Rising Cost of Gas Will Change Our Lives for the Better by Christopher Steiner (9780446549547)

Hal Canary | Books, Energy Policy | 2009-08-01 08:51:25 UTC
Permanent Link | Comments Off

Copyright 1997-2007 by Hal Canary.
mailto: h3 at halcanary dot org
xmpp:halcanary@jabber.org
aim:halwcanary
http://halcanary.org