This sentence is false

functional programming, software, and emacs.

Converting RealMedia Audio to MP3

I used mplayer and lame. MPlayer decodes the input rm audio stream into a WAVE file; lame encodes that to an mp3.

Just save the following script to a file and run it on your favorite rm file.

#!/bin/bash

FILE="$1"

OUTDIR="mp3"
OUTPUT=$OUTDIR/`basename "$FILE" .rm`.mp3

# We use a fifo file so that encoding the mp3 with lame can start immediately
# after decoding with mplayer starts.
FIFO=rm2mp3.fifo

if ! test -f "$FILE"; then
    echo "error: '$FILE' does not exist"
    exit 1
fi
if ! test -p "$FIFO"; then
    mkfifo "$FIFO"
fi
if ! test -d "$OUTDIR"; then
    mkdir mp3
fi

echo "Input: '$FILE'"
echo "Output: '$OUTPUT'"
sleep 2 # Give time for user to kill if the input/output is wrong

# Show commands as they are executed.
set -x

# Send rm audio to fifo
mplayer -ao pcm:fast -ao pcm:file=$FIFO -vc null -vo null "$FILE" >/dev/null 2>&1 &

# Create MP3 from WAV
lame -h -V 6 $FIFO "$OUTPUT"

rm -f "$FIFO"

Please send along any improvements (such as better flags for mplayer/lame).

04 July 2009 Posted by dbueno | Uncategorized | , , | No Comments Yet

New Blogger

I have recently been preparing some posts that require typesetting some math. Blogger does not support this. I have seen other Blogger blogs try to use HTML to typeset math… it’s not pretty.

I’m trying out WordPress, which supports embedded LaTeX. Here’s my blog.

I may be switching blogs soon. If so, it will be obvious.

07 April 2007 Posted by dbueno | Uncategorized | | No Comments Yet

Trying this out

I’m looking for a blogging solution that lets me typeset mathematics. So… starting here.

06 April 2007 Posted by dbueno | Uncategorized | | No Comments Yet

1, 2, 3…

I would have found the following useful when I was first learning to count. Perhaps you would have found it useful, too.

I haven’t found any such matrix in any of the books I’ve studied on counting and probability. The information is all there, sure. But the matrix is helpful for the subtle distinctions.

04 May 2006 Posted by dbueno | Uncategorized | | 6 Comments

Liars & Truth-tellers

Finally some self-referential goodness from the Anti-Department Department:

There’s something you need to know about me.

11 April 2006 Posted by dbueno | Uncategorized | | 5 Comments

More Emma

Here are some recent pictures.

21 February 2006 Posted by dbueno | Uncategorized | | No Comments Yet

Emanuela Arcadia Bueno

Please welcome my first daughter into the world. She was born on 30 December at 0319, weighing 8lbs 10oz, and being 20 inches long. There are other pictures.

Mother is very glad that she was born (finally… it’s always finally) and father is glad that she was born between semesters (phew).

05 January 2006 Posted by dbueno | Uncategorized | | 2 Comments

a scholar’s legacy

Via a blog up with which I keep, I found this certainly fecund line of research: McNugget Numbers. To wit,

"A number which can be obtained by adding together orders of McDonald’s® Chicken McNuggetsTM (prior to consuming any), which originally came in boxes of 6, 9, and 20."

I’m banking on some DARPA funding for my idea: just which numbers are those which can be obtained by adding together the number of grilling lines on various types of Ruth’s Chris steak? I would certainly need a large sample size in order to guarantee my results.

02 January 2006 Posted by dbueno | Uncategorized | | 1 Comment

drawing names, take 2

It turns out, the consummate dunce who originally posted the Perl code mentioned in my previous post (and whose code I used as a model to write mine) was thoughtful enough to include the possibility of infinite recursion in some cases.

Suppose you have drawn n - 2 names, and Ann and Bill still need gift-recipients; Curtis The Dunce and Bill are the names in the hat. So, Ann reaches in and gets Curtis. (Of course, he is a bad little boy who won’t get any presents. But that’s another story.) Then Bill chooses… well, duh. Problem. This is the bug in Perl-boy’s code.

As a public service, I have updated my code to eliminate this possibility. Enjoy your bug-free gift-name-drawing.

(* Draw randomly-selected names for each person in `nameList'. *)structure DrawNames = structlocaltype match = {name: string, match: string}

(* Set of strings. *)structure S = BinarySetFn(type ord_key = string                          val compare = String.compare)

(* List of all names. *)val nameList = ["Denis", "Lisa", "Dave", "Beth", "Tim", "Emma"]val names = S.addList (S.empty, nameList)

(* For the random-number generator seed. This seed is only sufficient. *)fun getpid () =    SysWord.toInt (Posix.Process.pidToWord (Posix.ProcEnv.getpid ()))fun now () =    let val time = Time.toMilliseconds (Time.now ())        val time' = case Int.maxInt                     of NONE => time                      | SOME x => LargeInt.mod (time, Int.toLarge x)    in Int.fromLarge time'    end

in

(* Match up all the names. *)fun match () =    let val seed = Random.rand (now (), getpid ())        fun randomElt l =            List.nth (l, (Random.randRange (0, (length l) - 1) seed))        fun getName set =            randomElt (S.listItems set)        fun getNameExcluding (excl, set) =            randomElt (S.listItems (S.difference (set, S.singleton excl)))

        (* Find a match for the given `name'. *)        fun findMatch (mapFrom, mapTo, matches) =            if S.isEmpty mapFrom            then matches            else let val name = getName mapFrom                     val match = getNameExcluding (name, mapTo)                     val mapFrom' = S.delete (mapFrom, name)                     val mapTo' = S.delete (mapTo, match)                 (* If the only choice is to map to oneself, we made the                  * wrong choice: try again. *)                 in if S.numItems mapFrom' = 1                       andalso S.equal (mapFrom', mapTo')                    then findMatch (mapFrom, mapTo, matches)                    else findMatch (mapFrom', mapTo',                                    {from=name, to=match} :: matches)                 end        fun printMatch {from, to} = print (from ^ " -> " ^ to ^ "\n")

        val matches = findMatch (names, names, [])    in app printMatch matches    end

end (* local *)end (* struct *)

22 December 2005 Posted by dbueno | Uncategorized | | 7 Comments

drawing names

A colleague of mine recently posted Perl (ugh) code to draw names for gift-giving purposes for Christmas. Because I felt like it*, I wrote a version in SML/NJ.

(* Draw randomly-selected names for each person in `nameList'. *)structure DrawNames = structlocaltype match = {name: string, match: string}

(* Set of strings. *)structure S = BinarySetFn(type ord_key = string                          val compare = String.compare)

(* List of all names. *)val nameList = ["Denis",                "Lisa",                "Dave",                "Beth",                "Tim",                "Emma"]val names = S.addList (S.empty, nameList)

(* For the random-number generator seed. *)fun getpid () =    SysWord.toInt (Posix.Process.pidToWord (Posix.ProcEnv.getpid ()))fun now () =    let val time = Time.toMilliseconds (Time.now ())        val time' = case Int.maxInt                     of NONE => time                      | SOME x => LargeInt.mod (time, Int.toLarge x)    in Int.fromLarge time'    end

in

(* Match up all the names. *)fun match () =    let val seed = Random.rand (now (), getpid ())        fun randomElt l =            List.nth (l, (Random.randRange (0, (length l) - 1) seed))        fun getName exclude =            randomElt (S.listItems (S.delete (names, exclude)))

        (* Find a match for the given `name'. *)        fun findMatch (name, (matches, mappedFrom, mappedTo)) =            if S.member (mappedFrom, name)            then (matches, mappedFrom, mappedTo)            else let val match = getName name                 in (if S.member (mappedTo, match)                     then findMatch (name, (matches, mappedFrom, mappedTo))                     else ({from=name, to=match} :: matches,                           S.add (mappedFrom, name),                           S.add (mappedTo, match)))                 end        fun printMatch {from, to} = print (from ^ " -> " ^ to ^ "\n")

        val (matches, _, _) =            S.foldl findMatch ([], S.empty, S.empty) names    in app printMatch matches    end

end (* local *)end (* struct *)

Update: For those who want to run this, but haven’t the slightest clue how:

  • Load the file into SML/NJ.
  • DrawNames.match()

* Doing what feels good is always right. After all, how can it be wrong, when it feels so right?

21 December 2005 Posted by dbueno | Uncategorized | | 2 Comments