Home

Advertisement

Miscellaneous Lisp Hackery

  • Jul. 1st, 2009 at 1:49 AM
oscar
Here's a few things I've been working on lately which may be of broader interest:

Bordeaux-FFT is a small library for computing the FFT/IFFT on complex data, originally written by Robert Strandh (and/or Sylvain Marchand and Martin Raspaud), with contributions by Paul Khuong and myself. Last summer I did some audio processing experiments, originally using the FFT code from Sapaclisp. Robert helpfully volunteered his FFT implementation, which I cleaned up slightly and have been cheerfully employing in various audio hacks ever since. Several versions have changed hands through email, lisppaste, and my web server, so I've finally come around to collecting the changes, writing a brief manual, and tarring up a release. It's surprisingly fast, particularly with Paul Khuong's recent work on SBCL, although I don't know how it stacks up against some of the highly tuned assembly language implementations out there. I use it along with my fledgling task queuing code to grind out batches of FFTs across four CPU cores.

Shuffletron is a simple music player in CL, with a few interesting features. I've been running this program full time for several weeks now as my preferred music player. It snuck on to the lisp subreddit before I really announced it, and I'm sure folks on IRC are already sick of hearing about it, so I won't say much. I began with plans for a much more ambitious player, with a fancy graphical interface, and wrote the first version of this one Saturday realizing I needed something simple to put the audio code through its paces while I wrote the full player, intending to include this one as an example program with Mixalot. It worked better than expected, so I ended up fleshing out the feature set instead and decided that it was really all I needed. The code is lean and mean.

I've had a number of problems trying to produce redistributable binaries of this which I believe I've finally solved (although new binaries are forthcoming). I hope to write about these later.

Mixalot is the audio back-end of Shuffletron, factored into its own system(s) because it might be useful for other purposes. It includes a mixer which pulls audio from any number of streamer objects and outputs them to ALSA. It also includes FFI definitions for libmpg123 with some helpers for decoding MP3 files and reading ID3 tags, and a streamer class for decoding and playing MP3 files in real time. The libmpg123 portions are usable independently of the audio mixing/output code.

Tags:

eMusic misses the mark

  • Jun. 17th, 2009 at 7:38 PM
oscar
I'm a couple weeks behind in noticing the announcement by eMusic of their subscription plans and the imminent arrival of the Sony Music back catalog and its promised roster of vapid radio detritus. The cost, apparently, is that they're raising prices by 50% across the board (or more like 100% for the longtime members with grandfathered subscription plans from the early days of the service), to roughly $0.40 per song. I've been a devoted customer of eMusic for several years now, eagerly burning through 200 downloads at a time on one of the $50/month "Connoisseur" plans for much of that time, yet I thought their prices were already too high. This latest move is too much for me to bear, and I immediately used my remaining downloads and cancelled my subscription.

Perhaps eMusic feels that access to the wider catalog of music will offset the increased cost. If they think their existing subscribers will understand, they are gravely mistaken. Given the option, I'd rather Sony Music go out of business, their back catalog be destroyed in a fire, and their CEO choke to death on his breakfast. This article puts it nicely:

Most eMusic fans I've heard from are real music nuts, and are there to sample a wide range of music from relatively unknown cutting-edge acts, not to download music they could find anywhere. Imagine the clerks in High Fidelity suddenly being told that their favorite mail-order distributor is raising prices, but in exchange will now let them order ABBA and Chili Peppers records just like the chain stores in the mall.

In my brief investigations so far, I haven't found another music service that is competitive with eMusic, even (perhaps) at their new price point. I don't consider that an argument for staying with eMusic rather than defecting to another service, though. Given that I consider $0.40/song roughly twice what I'd call a reasonable price, I instead take it as an argument for not buying music online at all. It isn't like there aren't alternatives.

Tags:

XMMS, music players, and a lisp hack

  • Sep. 4th, 2008 at 5:51 AM
oscar
Funny me forgetting that Debian doesn't package xmms anymore. This is a shame, as I'm not aware of a superior alternative. As recently as a year or two ago, I was using packaged xmms and plugins, and everything was wonderful - there were plugins for all the oddball stuff, modules and half a dozen chiptune formats, and everything worked swimmingly. Lately, I'm stuck using half a dozen different players from the command line, usually through aoss, and some of them (such as adplay) stutter and spit unless the machine is otherwise completely idle (just clicking around in firefox is enough to glitch the audio, four cores or no).

Audacious - No, this one is a step backward. The file dialog (which I suppose is just the Gtk2 file dialog, tarted up with their obnoxious theme) is noticeably slower than the one you get in xmms (the old Gtk 1.2 file selector, which responds practically instantaneously under any reasonable circumstance), and the loss of the "Add selected files" button destroys the workflow - I'm not going to make ten round trips in and out of that dialog just to pick a handful of files in different directories. This program would be much more useful to me if this feature were restored.

xmms2 - Imagine my dismay when installing xmms2 didn't yield any UI except a command-line interface, and expected me to run a separate server process. A client/server music player? Thanks, but no thanks. Enough with the servers. Trying to be a good sport, I apt-got a graphical client, gxmms2, and attempted to play a song. Oops, "xmms2d" isn't running - why can't it start the goddamn thing itself? The UI is a bit clumsy, but I poked around and added an mp3 to the playlist, or so I thought. Upon hitting play, it instead played "/usr/share/xmms2/mind.in.a.box-lament_snippet.ogg" very loudly, a noise so horrible and unexpected that I slammed the "kill window" shortcut as fast as I could and hastened to torch the whole mess. This is probably a great system for people who enjoy configuring sendmail.

iTunes style players - These don't really compete - the style of use is different. I often run Quod Libet and xmms at the same time, but most music is played through xmms, for at least two reasons - first,  iTunes-alikes have large windows that deserve a whole desktop to themselves, whereas xmms is tiny and fits on whichever desktop I'm working without cluttering it, such that I use xmms just because it's closer. Second, having organized my music into a reasonable tree on the disk, I can find whatever I want just as quickly as you might using a fancy overengineered browser based on id3 tags, and without the headaches of bad or missing tags, multiple spellings of artists names (plus the mess of various artist + collaborator combinations), etc. Indeed, even in Quod Libet, I usually use the "Filesystem Browser" mode.

Although think Quod Libet is the most usable of the iTunes-style players, it's been a couple years since I last surveyed them and settled on it, and there are some very irritating things about the UI - that the volume and seek bars are hidden inside of little popup menus, or the height of the "queue" not being resizable (such that if you want to rearrange songs in the queue, you can only move them a few spaces at a time between scrolling, like some kind of goddamn bubble sort).

In fact, the whole reason I reached for xmms is because I'd been using Quod Libet on this machine to sort through some new music, but this particular instance of it frequently misbehaves such that I'd just prefer something simpler.

Search seems like a promising way to find files to play, but I haven't used a player that embraces this concept. I used the search in iTunes on occasion, but it was unnecessarily sluggish. Quod has a search feature too, but it's hidden in another tab with no obvious keyboard short cut, and is outrageously slow (many seconds to conduct a search). I never understood why this sort of thing should be anything less than instantaneous, even over many tens of thousands of files, so one day a couple years ago I quickly hacked together something in Lisp that used a Boyer-Moore search across the filenames and showed the matches interactively as you typed with a simple mcclim gui, and it didn't take more than a few hours of effort to get this fast enough to feel instantaneous, even running synchronously inside the text field's "value changed" event handler. So all the really fun stuff I imagined implementing, like doing the searching in a background thread, and pipelining the search to refine the results of previous searches as you continued to type (rather than searching the whole data set on every keystroke, as it currently does), turned out to be completely unnecessary! So you'd type, and as you did the matches would appear in a list below the search line, and you could click one to play it in xmms. Very simple. I used this on and off for a few weeks, and had some ambitions of turning it into a genuinely useful music player, but never got around to it due to short attention span and various mcclim issues which I am unable or unwilling to fix, such as the focus insanity and difficulty in establishling workable keyboard controls. I think I'll just wait until I have a better substrate for the UI. A fuller implementation would have to do several times as much work due to searching metadata in addition to filenames, but several times a small number might still be a fairly small number, so no problem.  Anyway, with Lisp's reputation for being slow (or within the Lisp community, mcclim's reputation for being slow ;), maybe the authors of the more ambitious music players can be shamed into improving their search and making it fast.

And now I'm off to compile xmms and see how many of the plugins I can 1) locate and 2) succeed in compiling.

Tags:

Favorite Chiptunes

  • Jul. 11th, 2008 at 12:15 AM
oscar
I like chiptunes, and there's a virtually unlimited supply of them. I also like lists. By combining the two, I cement my memory while providing motivation to dig around and find new stuff to listen to.

These are the first things that leap to mind when attempting to enumerate my favorite chiptunes:

  • Highscore (Adlib), composed by Drax and Metal of Vibrants for the game Lollypop, but not used. I peeked at the 'source' in Edlib so I could play it on piano. Too bad there isn't a longer version. [mp3]
  • Breaking Wind (Adlib), another by Drax/Metal. I'm not normally fond of the OPL2, but these guys really make it sing. [mp3]
I don't really count modules as qualifying as chiptunes, but if I had to, I'd probably add Unreal 2 (Scirreal mix) to the list. Oddly, several of the copies of this found via Google were corrupt.

I could list more, but I think I'm already cheating by including music from well-known games. Time to get my players in order and find another list worth of tunes. Kohina is a start.

Tags:

Amazon MP3 Downloads

  • Dec. 9th, 2007 at 3:19 PM
oscar
I consume a lot of music. I pay for one of the "Connoisseur" plans at emusic.com, and regularly use two to three hundred downloads per month. I was excited by the prospect of the Amazon MP3 store, hoping it would fill the more mainstream gaps in the predominantly indie selection of emusic, for which I currently must resort to buying CDs. At $0.99 per song, the prices are as unreasonable as the iTMS, but at least I can play resulting purchase, and for just a few songs here or there I'd be willing to pay it.

I approach the store from the worst possible angle - I use Linux as my desktop OS, and so am unable to run Amazon's download manager, and further I use the adblock and no-script plugins, which wreak havoc with hostile and poorly designed web sites. While it might be unfair passing judgement on the service from this perspective, i already use emusic from the same configuration, and despite there being a linux version of the emusic download manager, I don't bother with it.

The Good:
  • Uncrippled, high-quality mp3 files, with sane file names
  • As an existing Amazon customer, I could immediately purchase MP3 downloads with no fuss or registration.
The Bad:
  • Everything else.
This service is a total loss. I searched for several things (nothing difficult - two Nas songs, a Prince song, a certain version of a Notorious BIG song) and never found what I wanted. I attempted to purchase a Decemberists album which it suggested to me, but the "purchase whole album" option was only available to people using the download manager. Why it can't simply serve me a zip file containing the tracks, I don't understand (this complaint applies to emusic, too). Further, even individual track purchases require clicking a series of pages not unlike placing a physical order, and resulting in an emailed receipt for a single song. It's a cumbersome process. Rather than presenting you with a clickable download link at the end of this, some bastardized javascript is employed to start the download automatically. It didn't work in my browser at all unless I disabled NoScript across the entire browser - setting amazon.com and its related domains to trusted was not sufficient. This is the first site I've had such extraordinary trouble with, and however they've implemented this page, they are doing it wrong. A simple, old fashioned "Click Here To Download" link would have sufficed, and I could've stopped typing two sentences ago. Provided you could spot the link among the bombardment of crap "recommendations" around every edge of the page, that is.

Does it work better in Windows, with IE and Amazon's download manager software? Probably. I wouldn't know.

Tags:

MCKC on Linux

  • Nov. 28th, 2007 at 1:46 AM
oscar
For fun, I decided to play with MCKC tonight. Luckily, NESASM (part of MagicKit) is already available for Linux, and MCKC 0.25 comes with C source code which compiles with no difficulty, saving me from the chore of running the software within Windows. Changing #define LANGUAGE from 0 to 1 in mckc.h and recompiling, I began picking apart the examples in the tutorial by Nullsleep, noted previously. Quickly tripping over and fixing a tiny bug (patch below, submitted to author), everything works as expected.

(in file.c, mckc 0.25)
113c113
<       ptr = malloc( size );
---
>       ptr = malloc( size + 1);

In order to simplify my workflow, I put the sequence of commands to compile/assemble/play the mckc song into a shell script, go.sh:
#!/bin/sh

rm -f make_nsf.nes
rm -f effect.h
rm -f songdata.h
./mckc songdata.mml >/tmp/mckc-out  # useless return code

if [[ -f songdata.h ]] 
then
 ./nesasm  -raw make_nsf.txt >>/tmp/mckc-out 
fi

# neither mckc nor nesmasm appear to indicate failure
# in their exit status. If we give xmms the name of a
# nonexistant file, it will pop open its file dialog,
# which is not helpful. To avoid this, check that the
# output file was created, playing it if so, or show
# the error output if not.

if [[ -a make_nsf.nes ]]
then
 xmms make_nsf.nes
else
 play /usr/share/sounds/gnobots2/splat.wav vol 0.3  >/dev/null 2>&1 &
 xmessage -file /tmp/mckc-out
fi

I wanted to trigger this from emacs by a single key press, so I defined the following function which saves the MML buffer and runs the compile/play script. I seldom use elisp and had to dig around in apropos the find the functions I needed, but this seems to do the trick:
(defun play-mck-songdata ()
  (interactive)
  (save-some-buffers
    (list (find-buffer-visiting
     "/home/hefner/nerdly/mck/songdata.mml")))
  (call-process-shell-command 
  "cd /home/hefner/nerdly/mck/ && /home/hefner/nerdly/mck/go.sh"))

Binding that to F12, I can edit and hear the results with a single keystroke (versus the six and a half keystrokes it would take to save the file, switch to a terminal, recall/repeat the compile and play command, and switch back, but whatever, this way is more fun). Neat.

NES Chiptuning

  • Nov. 27th, 2007 at 1:55 AM
oscar

MML, the "Music Macro Language". Widely used by Japanese VGM composers targeting classic sound chips, or so I've read. Specifying polyphonic music textually is a tricky business, doubly so when various parameters (pitch, amplitude, duty cycle, etc.) must be animated continuously to coax interesting timbres from simple hardware.

MML embodies one successful approach to the problem. The MCKC compiler, in conjunction with the MCK sound driver and an appropriate assembler toolchain, allows compilation of music specified via MML into a playable NSF file. Despite the name, there doesn't appear to be a general purpose macro facility. Rather, it provides a number of built-in 'macros' for automating parameters, performing arpeggios, etc.

I haven't taken MCKC for a spin yet, but it looks very capable. Certainly an improvement over composing music in assembly language.

MML/MCKC Links:

Tags: