Entries : Category [ Hacks ]
Computer and electronics tricks and fooling around
[Miscellaneous]  [Computers and Technology]  [Travel]  [Education]  [Hacks]  [Robotics]  [Science]  [Programming and Software]  [iPhone]  [Digital TV and Video]  [Intellectual Property & Copyright]  [Personal] 

23 June

I am going to the Robotics Science and Systems Conference and want to load my Garmin GPS with a map of Europe. The open source gpsbabel program seems suitable, but the macports install (port install gpsbabel) fails with an error as follows:

configure.in:39: error: AC_SUBST: `' is not a valid shell variable name

The solution for me was to visit the source directory on my machine:

cd /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_textproc_gpsbabel/work/gpsbabel-1.3.5

and edit the file config.in
to delete the lines mentioning the (obsolete) AC_EXEEXT. Then it installed fine.

Once a suitable map has been created, the Garmin 60CSX, like other Garmin USB devices, can be directly mounted on the desktop as a mass storage device. This requires you to go into the System setup menu, in the interface section, and click on "Mass Storage Device".

It's also possible to export a set of points of interest from Google Earth as a .kml file, and then use gpsbabel to convert this to a .gpx file (which can presumably be uploaded directly using gpsbabel).

By Gregory Dudek at | Leave a comment |    
22 October

How to create an Icecast Broadcasting Station on OS X

This post discusses how to distribute music to a collection on locations around a single house, but it works equally well for distributing music across the internet since it involves creating an internet-based streaming "radio station" using icecast, as well as Airtunes.

iTunes being streamed in from icecast

Last weekend my wife Krys threw a party for me. Like any party you have yourself, it was a bit frustrating since there is so much greeting and running around to do that I didn't get much chance to spend much quality time with anybody, and everybody there was somebody I would have liked to sit and talk to.


I had hoped to get people dancing (and failed), but as an aside I arranged to broadcast music around the house to several locations on 2 floors. To do this, I used iTunes (on a Mac) to produce a playlist. The problem then, was how to distribute a synchronized playlist to at least 3 locations within the house. As an aside, I wanted to use icecast (i.e. shoutcast) so I could do other stuff as well like (later on) broadcast outside the house. The Shoutcast protocol can be used to broadcast to Macs, Windows, Linux, FreeBSD and Solaris (and more). Shoutcast is freeware while the compatible Icecast (or Icecast2) is true GPL (and I believe it was released before Shoutcast became free).

Option 1: Use Airport Express: The easiest way to do this is to use airport express wireless "bricks". You can broadcast to these easily from iTunes, and it it just works. My problem was that I didn't have enough Airport Express bricks; some locations had to be actual computers, but iTunes does not support broadcasting to another computer.

Airtunes Setup within iTunes

Option 2: Use Airfoil: There is a software package called Airfoil. This allows you to capture the audio output (from any program) and broadcast it to an Airport Express unit, or to a mac or Windows computer running their free Airfoil Speakers application. It's very nice and only costs $25. Being a bit of a hard-core hacker, I was interested in an icecast solution I could roll myself, for several reasons including the fact it would allow me to subsequently broadcast content over the internet, for example to my office.

Option 3: Roll my own Icecast2 server: this is obviously what I chose to do. It turned out to be a lot harder to figure out than I expected and had I been less reluctant to admit defeat and more practical, I would simply have purchased Airfoil. On the other hand, it's pretty easy once figured out and I needed some hacking-based stress relief. Read on for the recipe.

How to create an Icecast Broadcasting Station on OS X

Internet streaming radio is normally based on Shoutcast or the compatible GPL software called Icecast. Icecast software runs on Apple's OS X as well as Linux an it's what I used. This method can also be using with Airtunes (normal iTunes bradcast to Airport Express) at the same time.

Requirements: OS X, Apple Developer tools, http://www.macports.org/. If you use my precompiled binaries (below) you might get away with all these tools if you are lucky.

To feed content into Icecast, you need one of several programs depending on the format(s) you plan to use (such as MP3 or Ogg Vorbis) I selected Darkice and the MP3 format since I had prior experience with darkice, and like the universality of mp3, and because darkice runs on Linux and OS X, and is pretty solid.

Darkice pulls in data from either a fixed file, or from an input device (like a microphone). I was using iTunes so I needed to re-route the output from iTunes to create a vartual input device for darkice to listen to. To do this,
I used a pair of tools I discovered. This learning process sucked time, but was quite useful for other projects. To do this I used Soundflower and Jack. Soundflower grabs and input (or output) and Jack allows the output from Soundflower to to connected as a virtual input to ay other program.
Soundflower V 1.3.1 is available via macupdate.com/ or thirdcog.eu. Jack is available at http://jackaudio.org/ and can be downloaded directly from Sourceforge.

A diagram illustrating all this is shown here.

Setup of components used for broadcasting

Note that darkice and icecast2 have slightly complex-looking XML setup files, but nothing exotic needs to be done in the setup. Example setup files provided
here should work fine for you, and they're called icecast.xml and darkice.cfg.

To configure and control Soundflower, which is a kernel module, you should use the application program (app) called Soundflowerbed. The program Jackpilot that comes with Jack can be used to control it, but all you actually need to do with it is start Jack. WARNING: I also tried to install Jack using macports as a command-like tool, but the resulting code was incompatible with darkice and had to be completely removed to get things working!

To install darkice and icecast2 you can use macports (i.e. port install darkice and port install icecast2). If you don't know about macports, you should. If you can't figure that out, then this approach isn't for you anyhow, and you should buy Nicecast and/or Airfoil.

How to make it go:

In the normal Sound control panel, set the output to be Soundflower (2ch). With soundflowerbed, you can optionally route the 2ch audio to the hardware output device (speakers) as well, to help you hear what's happening.

Run Jackpilot and start Jack.

Run icecast using:

icecast -c icecast.xml &

Run darkice from the terminal using:

darkice -c darkice.cfg &

Play music with iTunes.

Listen to it from another computer using iTunes by using the Menu item Advanced>>Open Audio stream
and enter something like with the number should be replaced by the IP address or name of the computer doing the broadcast.

Extra notes

Instead of Soundflower it seems like you can use ESD, the Enlightnment Sound Daemon (which is commonplace on Linux). These posts provide an alternate solutions based on esd.

  • Rolf Haynberg provides an approach that is much simpler since it doesn't doesn't use the (standard) shoutcast protocol, and is thus is much more limited in my opinion, but if you only want to broadcast to one or two Macs, this is a easier solution.

  • Related content on using esd is also available at this page on macosxhints.com

  • Darkice config files are explained here.

    Pre-Compiled versions of darkice and icecast for OS X Leopard are available here is you want to try skipping their installation (they were compiled for OSX 10.5.5 and may not work if your computer is configured differently from mine.)

    Soundflower is also available at cycling74.com and they appear to be the original developers, but only provide an older version.

    The full scoop on Icecast, from installation to history can be found in the on-line book by Kerry Cox.

    In you get into Internet radio, a list of stations can be found at dir.xiph.org (in addition to those built into iTunes).

    Audio Hijack can also be used to capture audio on OS X.

    [ Followup, Feb 2010: for Snow Leopard, you may want to install Jack version 0.83 or better.

    Be careful with a combination of multiple jack installations.. The dmg from the Jack web site installs jack in one place (/usr/local) while the macports version installs it someplace else (/opt/local). If both are installed you can end up with strange problems, like a version of darkice that has a problem opening jack and doesn't work. ]

    Another blogger has provided a very clear page on this process with some additional details http://blog.joshdzielak.com/blog/2012/11/21/live-stream-audio-from-osx-mountain-lion-with-icecast-and-darkice/

    By Gregory Dudek at | Read (3) or Leave a comment |    
    27 October

    Apple Time Machine is an attractive backup system for OS X, but I had a hard time fixing it after it recently stopped working for me after I accidentally unplugged my firewire backup disk during a backup operation. For subsequent backup attempts, I got the error message that the backup had failed because a "time machine error -- Unable to complete backup" had occurred. Not so helpful. (This is sometimes manifested as a message in the Console like Backup failed with error: 11.)

    By running the Console application, I was able to look at the error messages from backupd. In my case, there were some files that could not be inspected leading to messages like this:

    10/27/08 10:00:42 PM /System/Library/Frameworks/.../mdworker[13920] tar importer countered an error (512) scanning "/X/1/Scr/private.tar"

    but there were not serious. Eventually a crash occurred though, as follows:

    10/27/08 10:04:24 PM ReportCrash[14175] Formulating crash report for process backupd[14129]
    10/27/08 10:04:25 PM com.apple.launchd[1] (com.apple.backupd[14129]) Exited abnormally: Segmentation fault

    but there was no explanation as to why.

    Well, I figured it might be attempting to continue the previous malfunctioning (somehow corrupted) backups. This was supported by the presence of a (hidden) directory
    of the form


    found by typing "ls -ld thatfile" from the terminal.

    I figured the solution was to dispose of the directory called 2008-10-27-075904.inProgress by either removing it (and its contents) or moving it elsewhere.

    Unfortunately, the files in that directory use extended attributes and cannot be readily deleted. You can turn off these attributes (with xattr), but it needs to be done file-by-file and it's cryptic.

    The solution is to use the command fsaclctl which disables extended attributes (and access control lists) for an entire volume at a time.

    Thus, I used

    cd /Volumes/MyBook/Backups.backupdb/
    sudo fsaclctl -p /Volumes/MyBook/ -d
    mv 2008-10-27-075904.inProgress ../hideme
    sudo fsaclctl -p /Volumes/MyBook/ -e

    After that, Time Machine backups worked again!

    By Gregory Dudek at | Read (2) or Leave a comment |    
    30 January

    Getting c++ to use a custom python framework

    This post addresses how to get the OpenCV vision package with Python bindings to compile on OS X, such that you can use a version of Python other than the one that is supplied with the original operating system installation. It's very hacky and not for casual reading, but my help some person questing for help.

    Dudek faces detected
    Detected faces, using opencv, Viola-Jones algorithm (boosting)

    Detecting a sleeply dudek with opencv
    Face and eyes detected

    The problem is that OpenCV insists on being linked with the standard default installation of Python on OS X. On the other hand, many (most?) techie people using Python will have installed an alternative newer release (for instance via "fink" or "macports").

    When you compile OpenCV and try to use it with your custom-installed Python (e.g. version 2.5.2 instead of the stock 2.5.1), you get an error as follows:

    % python
    >>> import opencv
    Fatal Python error: Interpreter not initialized (version mismatch?)

    Using the standard Python is a workaround, but for me it wasn't acceptable. Unfortunately, since I had no prior experience with cmake or opencv, this was problematic. Here's how to fix it. Despite many only-semi-correct discussions of this on the net, it's fairly easy to fix, once you realize the source of the problem.

    On OS X (or, in fact, the core operating system kernel, Darwin), many packages are installed using Frameworks. They group together libraries and headers. The C compiler on Darwin has been extended to take a -framework PATH flag, and by default this causes the linker to look in the system directories, but not user-installed directories. You need to provide an extra -F DIRECTORY flag to specific the location of your user-installed frameworks (e.g. "-F /opt/local/Library/Frameworks/").

    I never quite figureed out the "right" place to insert the flag before starting a build, but after a failed build you can just insert it into
    The right place is probably interfaces/swig/python/CMakeLists.txt
    using something like

    set(CMAKE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -F/opt/local/Library/Frameworks")

    but once I got it working I didn't want to waste more time on a really clean fix (instead, I wasted time writing it up here).

    When you run make, in order to assure it's working you can set the system frameworks to be temporarily inaccessible to verify the right places are being searched. Do this with the chmod command. Afterwards, you can put things back the way they were (mode 755).
    I suggest you test your patch as follows:

    sudo chmod 000 /System/Library/Frameworks/Python.framework/
    cmake .....
    sudo make install
    sudo chmod 755 /System/Library/Frameworks/Python.framework/

    As an aside, I was also confronted by the error:

    opencv/src/highgui/cvcap_ffmpeg.cpp:70:28: error: ffmpeg/swscale.h: No such file or directory

    this can be fixed by the hack:

    cp -r /opt/local/include/libswscale/* /opt/local/include/ffmpeg

    By Gregory Dudek at | Read (1) or Leave a comment |    
    12 March

    A fix to EXIF.py to make it find the data more consistently

    The Python EXIF.py module is for extracting tags from an image. If the image has been edited with Apple's iPhoto 08 (or probably iPhoto 09 or other software) though, EXIF.py may be unable to find the EXIF tags and you might get a message like "No EXIF information found." Some people have suggested that iPhoto is stripping the EXIF data. In fact, the issue is that EXIF.py does not like it if there is other information before the EXIF segment in the file (specifically something called an APP2 segment). In short, EXIF.py only handles a subset of possible JPEG file formats. This was a particular problem for me since I use EXIF.py on my Zope web site (this one) with the Photo product to display information.

    I found the problem and fixed it and also updated the Photo product as well. The modified version of EXIF.py that is able to parse these files can be found at the following link [EXIF.py]. I've also posted the fix to the maintainers, but don't know how soon they might accept it.

    The basis of the problem relates to the flexibility of the JPEG/EXIF file format. A JPEG file is composed of several segments including the image, a thumbnail, and parts called APP1 and APP2. The standard EXIF.py module expected APP1 to be the first segment in the file, and didn't work if APP2 came before APP1, but this is how iPhoto creates JPEG files. The new version I have posted is smarter about interpreting the segments (although the actual code is rather ugly).

    Download link:
    link [EXIF.py].

    Usage: python EXIF.py pic.jpg

    Or, it can be used inside a python program:

    import EXIF
    print EXIF.process_file(f)

    I have also included a substantially updated version of the wonderful Zope Photo product that was originally created by Rob Bickers (rbickers) and then updated and improved by Søren Roug [ zope.org link].

    This version merges changes from the 1.3.2 and 1.2.4 branches, includes this updated EXIF.py, and has some code changes (such as a method called "exifdata" that takes an EXIF field name for display, no field at all, or a special meta-fields such as "Date"). It also includes patches that allow Zope images to be re-created as Photo objects.

    You can see the product used here at dudek.org/Recruiting2009 to produce the EXIF summary at the top of the picture (click that for more details). I am calling this version 31 and it's a compressed tar file [ photo31.tgz ]. It is also used to produce the images shown here.

    Picture with EXIF dataPicture with EXIF data

    {'Image ExifOffset': (0x8769) Long=360 @ 138, 'EXIF CustomRendered': (0xA401) Short=Normal @ 694, 'EXIF MeteringMode': (0x9207) Short=Pattern @ 502, 'EXIF DateTimeOriginal': (0x9003) ASCII=2009:03:11 20:20:29 @ 754, 'MakerNote FirmwareVersion': (0x0007) ASCII=Firmware Version 1.0.7 @ 1490, 'EXIF ExifImageWidth': (0xA002) Short=5616 @ 622, 'EXIF SubSecTimeOriginal': (0x9291) ASCII=74 @ 574, 'Image XResolution': (0x011A) Ratio=72 @ 196, 'Image YResolution': (0x011B) Ratio=72 @ 204, 'EXIF ShutterSpeedValue': (0x9201) Signed Ratio=21/8 @ 794, 'EXIF ISOSpeedRatings': (0x8827) Short=3200 @ 406, 'EXIF ExposureTime': (0x829A) Ratio=1/6 @ 738, 'MakerNote ImageType': (0x0006) ASCII=Canon EOS 5D Mark II @ 1458, 'MakerNote Tag 0x00AA': (0x00AA) Short=[12L, 1124L, 1024L, 1024L, 715L, 1L] @ 5300, 'Image YCbCrPositioning': (0x0213) Short=Co-sited @ 114, 'Thumbnail XResolution': (0x011A) Ratio=72 @ 10532, 'EXIF ExposureProgram': (0x8822) Short=Program Normal @ 394, 'Image GPSInfo': (0x8825) Long=8660 @ 150, 'Image Copyright': (0x8298) ASCII=Copyright: Gregory Dudek @ 296,

    Picture with EXIF data

    Please let me know if you have any difficulties with or (or not).

    By Gregory Dudek at | Read (8) or Leave a comment |    
    Rate item 154: Rating: 7.7/10 (3 votes cast)
    05 May

    I recently installed and used a miniature Sanav MK-7 GPS logger from SparkFun. This device is really small: a little smaller than one AA battery. I wanted to use it with Apple's OS X Leopard operating system: here's how.

    GPS logger
    GPS logger

    The MK-7 is built around the MTK datalogger chipset and the Transystem EB-230 GPS engine, and includes Flash memory for storing GPS logs. It is connected to a computer with a USB-like cable to either charge the embedded battery, or to upload a data log. Like several other embedded devices there days, the Sanav actually uses a TTL-level serial (RS232) protocol, and needs a GPS-to-serial converter. This is embedded in the cable so that although the whole the cable looks like USB-to-mini-USB, it's actually got a chip inside it that converts USB signals to RS232, put uses a mini-USB connector on the logger to achieve the RS232 and power connection.

    The means that to communicate with the device, you need to have the correct USB drivers. The cable I got with my device uses the Prolific Technology Inc. PL-2303 USB-to-serial bridge chip (0x067b), and the drivers for just about any operating system including OSX can be found here:

    Once the driver is installed, connecting to the serial port lets you see the live data logging (use a baud rate of 115200):

    screen /dev/tty.usbserial 115200

    My MK-7 seems to run a firmwre suite called M-core_2.02.

    To extract logs, one option is to use the Java-based software package BT747 available from: http://bt747.free.fr. Be sure to load the version that includes "RxTx" libraries. You can also find it at the Sourceforge link http://bt747.wiki.sourceforge.net/mac_installation

    By Gregory Dudek at | Read (2) or Leave a comment |    
    Prev  1   2   3   [4]   5   6   7   Next