Backyard Wildlife

There was a chipmunk outside the window today, so I decided to start a new an album of animals in my backyard.  Not too much there yet… there’s a photo of some birds and another of the black squirrel I took back in January.  Last week, there was a rabbit sitting on the walkway.

And then there was this little fella today:

ACRIS – A Hardware-Based Audio Visualization Project

I’ve always found audio visualization to be pretty interesting — it combines the complex (hah, pun) mathematics of signal processing with the entertainment of watching cool effects. Many audio players have interesting audio visualizers built-in; others are available as addons. MilkDrop seems to be quite popular.

Funky patterns on a screen changing to music is cool, but for a while, I’ve wanted to create a more entertaining experience. Essentially, my idea has been to create a set of wall lamps powered by arrays of multicolored LEDs. A microprocessor would adjust the color and intensity of the lamps based on audio input.

From a high-level standpoint, this kind of system is not too complicated. A low-latency audio processor takes audio signals as an input, performs some frequency analysis on them, and generates PWM signals. These PWM signals are fed into LED arrays making up the wall lamps. As always, though, the devil’s in the details.

System Design

The final design will use an FPGA with some simple support hardware to do the audio processing. Overkill? Probably… A fast microcontroller is usually good enough for these kinds of things. But, I wanted to make this a hardware project. The FPGA I plan to use is a Spartan 3, available cheaply on this eval board.

To elaborate a bit, I’ll feed an audio signal into a high-frequency opamp, which will buffer the audio signal and send it to an 8-bit ADC, whose output is fed into the FPGA. The FPGA will take an FFT of the data and then, based on the color mixing algorithm I choose, will operate on the frequency data. Finally, after deciding the final desired color, the FPGA outputs PWM signals to the wall lamps, those internal circuitry amplifies and uses those signals to light up the desired color. I’m hoping for a total latency on the order of tens or hundreds of microseconds.

I’d like to put up three or four lamps. One will be on the left side of my room and another will be on the right. These two lamps will be controlled solely by their respective stereo components. The other lamps will be above my desk and will be controlled based on a combination of left and right audio data.

I was originally hoping to make the wall lamps interact wirelessly, but I don’t think that’ll be possible given the price of wireless modules. Also, there is a latency problem as well as a security issue involved with wireless.

Anyways, I’ve had a few ideas for the color mixing algorithm. One was to separate the frequency graph into three large chunks (e.g. “low” frequency, “medium,” and “high”) and then define some sort of color scale for each chunk. Next, for each chunk, the center of mass is determined and is used to locate a color on the chunk’s color scale. The relative intensities are compared and then a final color is mixed. This algorithm is actually very easy to implement. A friend of mine suggested another interesting algorithm (harder to implement, but definitely worth a try): split the frequency graph output from the FFT into octaves and then define the same color scale for each octave. Colors are mixed in proportion to their intensity. This guarantees that all equivalent pitches (across octaves) have the same color. You could also improve the algorithm a bit to make the lower octaves biased toward one color and the higher octaves biased toward another. There will be three multiplexers
to determine the FPGA input. The first will allow switching between 2 or 3 analog audio channels. The second can bypass the ADC and send digital data directly into the FPGA. The third will bypass the FPGA directly and allow some device (e.g. a microcontroller) to send in PWM signals to the LED arrays.

Finally, as a finishing touch to bring out the bass, I’d like to add blue backlighting to the wall lamps that lights up only to low frequency responses.

As for the LEDs to use, an array of Cree MC-Es would be spectacular, but pricey. Another option would be to use a bunch of cheaper chips from DealExtreme.

Current Status

Right now, I’ve ordered and AVR and supporting hardware in order to use this project I discovered as a starting point. Instead of outputting a graph to an LCD, though, I am going to begin testing simple color mixing algorithms with whatever LEDs I can find. Using a microcontroller will allow me to quickly test algorithms, although the latency may be noticeable. In the future, I’ll switch the function of that AVR so that it can take input from other sources and control the lighting system.

As I begin building stuff, I’ll start posting my notes and diagrams.

Installing Linux on the MSI X-Slim X340

MSI’s X-Slim laptops are slowly gaining popularity because they are affordable, lightweight, and very mobile.  I purchased an X340 from TigerDirect recently because I couldn’t pass up the great price   Mostly, I purchased this laptop for the excellent battery life — the laptop uses a high-density lithium polymer battery and has a ton of power-saving features that shut off peripherals when you don’t want them.  It’s an excellent 13″ laptop with plenty of power for my mobile computing needs (SSH and Firefox).

Installing Linux on just about any hardware nowadays is easy.  Things have changed a lot since I first started with kernel 2.4 — I remember spending countless hours trying to configure my hardware to work properly.  But now, you rarely need to get under the hood to get your hardware running flawlessly, no matter the distribution that you run.  The thing is, I like getting under the hood and fortunately, this laptop has given me a chance to do a little bit of that.

MSI is just enough of an off-brand name that some of the hardware they use is only partially supported by Linux.  The laptop is built on an Intel platform, so all the most important devices work perfectly well out of the box, but a few things: ACPI, the touchpad, and the keyboard, need a little tweaking to work effectively.

This is a short guide with scripts, configs, etc. attached that aims to get as much of the hardware on the X340 working as possible.  I’ll start by describing the really broken stuff and then later provide suggestions for improving battery performance, etc.  I’m writing from the Arch Linux point of view (BSD-style init vs. SysV-style, etc.), but everything should apply to all distributions, possibly with some minor changes.

Brightness

Immediately after installing Linux, you’ll probably notice that the brightness keys don’t work.  I think what’s happening is that when your computer boots up, ACPI hands over brightness control to the operating system.  Some laptops (e.g. Dell) still have hardware support for changing brightness, so no matter what OS you’re running, you can always press the brightness up/down keys to adjust your screen.  The X340 doesn’t seem to support that, so we’ll have to create a script to adjust the brightness from within the operating system.

You can get and set the current brightness setting in /sys/class/backlight/acpi_video0/brightness.  So, I wrote a quick script that sets the brightness in different ways:

http://jwcxz.com/other/msi/brightness.sh

I stuck this script in /etc/brightness/brightness.sh.  Supported functions: bup (increase brightness level by 1), bdn (decrease it), blo (set to minimum brightness), bhi (maximum brightness), bset # (set to some value #), badj # (increase or decrease by #), bget (return the current brightness).  You could source this file as root and run the functions, or you can just give them as arguments to the script.

I’ll get to configuring the brightness keys to work with this script in a minute, but if you would also like to be able to use the functions as a regular user, you can modify sudo to let you issue brightness commands without a password by doing sudo visudo and adding the following line:

yourusername ALL = NOPASSWD: /etc/brightness/brightness.sh

Then, you can define some aliases in your profile:

alias bup="sudo /etc/brightness/brightness.sh bup"
alias bdn="sudo /etc/brightness/brightness.sh bdn"
alias blo="sudo /etc/brightness/brightness.sh blo"
alias bhi="sudo /etc/brightness/brightness.sh bhi"
alias bset="sudo /etc/brightness/brightness.sh bset"
alias badj="sudo /etc/brightness/brightness.sh badj"
alias bget="sudo /etc/brightness/brightness.sh bget"

Keyboard

The keyboard is a bit trickier — there are several things to do.  First, we need to get HAL to recognize the extra keys on the keyboard.  For example, if you press the brightness up key (Fn-Up) and then do dmesg | tail, you’ll see an error message telling you that the scancode hasn’t been mapped to a keycode.

Working off of the keymap entries for other MSI computers, I built an almost-fully-working keymap for the X340.  It might work for other X-Slim laptops too, especially for the X320, X350, and X360.  You can grab that here:

http://jwcxz.com/other/msi/10-keymap-msi.fdi

Stick that in /etc/hal/fdi/information/10-keymap-msi.fdi and restart HAL.  I was able to get all of the special keys working with a few caveats:

  1. The keys labeled with [hw] have a hardware action.  For example, the bluetooth key actually turns the bluetooth module on and off.  So, if you choose to bind something to that key, make sure that you are willing to toggle bluetooth on and off.  A good thing to bind to these keys are status indicators so that when you toggle bluetooth on, an icon or something lights up.
  2. The same thing applies to WLAN.  It toggles the RFKILL bit in hardware.
  3. Fn-F2 (video mode switch) and Fn-F11 (some other WiFi button — maybe for bringing up the connection window?) seem to be “missing” — when I press either one of them, I don’t get an error about a missing keycode, but I don’t get a keycode either.  After I look into this issue, I plan to submit a patch to HAL in order to get this keymap included.
  4. Fn-F5 (economy mode) currently maps to keycode 126, which is plusminus.  I need to remap that scancode to “battery” when I find it.

The next thing to do is to install some software to handle system-wide key bindings.  I like actkbd (AUR package) because it operates as a system service and therefore works even when you aren’t using X.  My /etc/actkbd.conf file is here:

http://jwcxz.com/other/msi/actkbd.conf

Finally, you may want to define some user-level keybindings.  For example, I switch escape with caps-lock and I also define the \| key (which is really less than/greater than when you press the key) that’s right next to the Alt key to be Super_R because I use the Windows key a lot and I think it’s more comfortable next to the space bar.  The xmodmap configuration file I use is as follows.

remove Lock = Caps_Lock
keysym Escape = Caps_Lock
keysym Caps_Lock = Escape
add Lock = Caps_Lock

keycode 94 = Super_R

I’ve also turned the menu key into left-click, but I’ll get to that in the next section.

Touchpad

I have to say, the touchpad sucks.  It really sucks.  I thought it wouldn’t be as bad as the reviews said — I assumed it would be possible to fine-tune things and so forth — but I was completely wrong.  First of all, it’s not made by Synaptics, but rather by a company called Sentelic.  The touchpad’s operation is really ugly.  Unlike with the Synaptics touchpads, you cannot move your finger on the sides of the touchpad to scroll; you have to place your finger at the corners and hold it.  That wouldn’t be so bad, but it’s not accurate at all; I can’t scroll for more than a few seconds even when holding my finger perfectly still.  Also, there seems to be no control over the sensitivity of the pad, and there’s definitely no “palm check” feature.  Supposedly, you can adjust the acceleration rate, but I haven’t been able to do that yet in Linux.

What I have been able to do is get rid of tap-to-click.  I didn’t want to get rid of it because I use it a lot–it’s much easier than pressing the mouse button.  But, because the touchpad is big and very sensitive, it’s easy to accidentally start clicking when you’re typing.

To get rid of tap-to-click, issue the following command as root:

echo 'c' > /sys/devices/platform/i8042/serio1/flags

I put this in /etc/rc.local so that it runs every time I start my system up.

I also used xbindkeys and xmacroplay (AUR package) to rebind the menu key to left-click by creating the following ~/.xbindkeysrc:

http://jwcxz.com/other/msi/xbindkeysrc

Other Stuff

The brightness settings, keyboard, and touchpad are the three big things to fix on the X340.  Everything else pretty much works out of the box.  A few minor points:

  • You’ll probably want to install and configure laptop-mode-tools.  This, along with the standard cpufreq and acpi packages can provide really nice battery performance improvements.
  • I recommend taking a look at Arch Linux’s laptop article on their wiki.  There’s lots of useful information there.
  • I had to add video=1366×768 to my kernel parameters list in /boot/grub/menu.lst because sometimes, my system would boot up and stay in 640×480.  I think the actual parameter string should actually be something like video=LVDS-1:1366×768 in case you keep an external monitor attached.
  • /etc/acpi/handler.sh is a good place to add hooks based on various ACPI events.  For example, when I plug the power cord in, I run cpufreq -g performance and when I unplug it, I run cpufreq -g ondemand.  I also have the following code in the lid change state:
    if grep -q closed /proc/acpi/button/lid/LID0/state; then pm-suspend; fi
  • Unfortunately, unlike many other laptops, this one doesn’t trigger an ACPI event when you open the lid and the system is suspended.  So, you have to press the power button to wake the system up.

And that’s about it.  Everything else is just a matter of minor configuration to your preferences.  It’s not like the old days when you had to research all sorts of minor points in the kernel configuration and build your own kernels to support the hardware you needed, but for almost everyone, it’s probably best that those days are behind us.  Still, the opportunity to contribute even a few small improvements or findings to the open-source community is quite a valuable experience.

Up next: I finally start describing the plans for my FPGA-based audio visualization project.  I have them all written down in my notebook; I just need to formalize them a bit and start building.

Drive Upgrade: OCZ Vertex 2 SSD

Last week, I purchased an OCZ Vertex 2 50GB SSD drive ($174.00) and a Samsung 1TB drive ($79.99; I’m using it to keep the backups I take with DAR).  After doing some research, I decided on the Vertex 2 SSD for its impressive speed: reads peak at 285MB/s and writes peak at 275MB/s.  The reviews indicated that the manufacturer’s specifications were accurate, so I decided to give the drive a try.  As usual, NewEgg shipping was ridiculously fast; the drives shipped from New Jersey, so it took all of a day for them to get here.

Image taken from OCZ's WebsiteLike most SSDs on the market, the Vertex 2 is in a 2.5″ form-factor, but comes with a convert to secure it into a 3.5″ bay.  Unfortunately, this converter is not immediately compatible with the Antec 1200 (well, any of the Antec cases that use special screws to secure drives in the bays).  The problem is that the screws for the drive bay have a smaller diameter than the ones that come with Antec’s drive bay.

This is a problem because Antec’s screws are very long.  The drive bay has an outer and an inner wall, with a plastic piece connecting the two; the screws go through both walls and into the hard drive.  Since I could only use the screws that came with the SSD, which were obviously very short, I thought I was out of luck.

It turns out that by popping out the plastic pieces highlighted in red in the image below (the drawing itself is taken from the Antec 1200 mechanical drawings, available on the Antec website), you can access the inner wall of the drive bay directly.

Original drawing from Antec's websiteNext, you need to use a pair of tweezers to get the SSD mount screws in through the hole highlighted by the orange arrow (they won’t fit through the screw hole in the outer wall of the drive bay).  Once you have positioned the screw at the hole in the inner wall, you’re all set.  This process is a little tricky and can take some time and patience, but it will mount the drive very securely into the bay.

According to my initial testing, this drive absolutely performs up to the specifications listed on the website and the POST that my computer does on startup now is the slowest point in booting.  More importantly, I’m using this drive for everything in / besides /home, so application load times are fantastic.  My 1.2TB RAID 5 array is now entirely devoted to my home partition.  Disk read times were once the major bottleneck in my computer’s operation (as they usually are for any computer), but the addition of this SSD has improved the speed dramatically.

Lastly, I can’t help but make a small plug for Arch Linux.  I chose to reinstall all of my software on my new drive instead of copying it over with DAR.  So, I backed up my home directory, etc directory, and used Arch’s package manager, pacman, to create lists of packages I installed both from the main Arch repositories and from the AUR.  That’s literally all I needed to make a complete backup of my system.

Back from Spain

Just a few days after getting out of school, I was off to Spain to see Madrid, Toledo, Seville, Córdoba, and Barcelona.  I took about 1000 pictures in total, but here are the halfway-decent ones (77 of them).

http://jwcxz.com/photos/es10

MIT Brass Rat!

It’s finally here.  One of the “three recognizable rings in the world” is sitting on my finger.  I didn’t take my camera to Ring Delivery, which was held last night at the Boston Public Library, but I did get a few shots of the ring this morning.  The lighting conditions weren’t great, though; I’ll try to get some better shots some other time.

Edit: here are a few full-resolution (4000×3000) photos using longer exposure times.

More Photos from Mem. Drive

I know… boring and repetitive, but I took another walk along Memorial Drive today and brought my camera again.

Full Set

Next time, I’ll take a different route.  :)

April Screenshots

This month, I’ve switched to the Awesome Window  Manager (configs coming eventually) and rxvt-unicode.  That’s pretty much it.

New Hosting!

I’ve switched to RAM Host.  If you see this message, then DNS information has propagated.  :)

I will leave my existing hosting up for a few days before I replace it with a redirection message (for anyone who still tried to use my old domain to go to my website).  The old hosting will go away in July.  My stay with FodyHost has been pleasurable and I would recommend it to anyone who wants unlimited space and bandwidth in a shared hosting environment for a great price.

There shouldn’t be any loss of mail but if you have sent me something recently and don’t think it went through, feel free to send it to me again.

Staffen SRX Fountain Pen

I was feeling old-fashioned recently, so I decided to buy a fountain pen.  After a little research, I found xFountainPens, a retail site that promises high quality pens and ink for low prices.  For a grand total of $28 for a pen and a bottle of ink, I decided to take a chance.  I purchased a Staffen SRX Galaxie pen and a bottle of black ink.  I ordered it last week and it arrived, so the shipping was fairly quick (and free); it was also packaged well.  For $20, I wasn’t expecting too much; a pack of ballpoint pens costs almost as much nowadays.  What few reviews I could find for this pen were generally positive.

I was extremely impressed.  The ink flow is extremely smooth and even and the pen is a good weight–very comfortable to write with.  I’m a lefty (the curséd breed, I know), so my writing usually involves scratching up pages (because lefties have to push the pen across the paper and not pull it), but I had no trouble writing with it.  The ink is also quite nice: it flows smoothly, dries quickly, and doesn’t bleed.  One of the older reviews that I read mentioned a few weakness with the pen, including a loose cap, but I did not find any.  It was a $28 well-spent.

I decided to keep the pictures at their original 4000×3000 resolution to show off some of the amazing macro capabilities of my camera…

None of my classes this term really require writing…  The assignments are all accomplished via computer, whether they’re labs for my courses in communications and computer architecture, problem sets for my CS theory course, or the research paper for my class in urban history.  Yet, I still take notes by hand for the most part, because I find it’s faster.  And I also have lots of scratch paper in case I need to review my work later.

The other day, I got bored and tried to see what it would be like to write like a righty.  So, I did the obvious thing and started writing backwards (right-to-left with mirrored characters) with my left hand and I picked it up very quickly.  I’m still trying to develop the spatial skills that will allow me to mirror diagrams intuitively, but my right-to-left writing speed is now very nearly as fast as my left-to-right speed.  Yes, I do get this bored sometimes.

Anyways, the tl;dr is that this pen is really fantastic and I’m quite happy with the service from xFountainPens.