Entries Tagged 'ipod' ↓

Markov Decision Processes and the iPod shuffle

I just finished reading Peter Norvig’s article about the “Martin Shuffle“. (By the way, if you are a computer programmer, you need to visit Mr. Norvig’s site. It is chock full of good programming/lisp/algorithm stuff.) The Martin Shuffle is basically a search for a specific song by using the random shuffle feature of an iPod.

Now I know what you are thinking, but its not a crazy thing to do. In a situation where you can’t see the display or access the controls (for example with an iPod Shuffle, or when I have my iPod mini hooked up to my car stereo and I have to control it with the CD changer controls which only allow skipping and turning the shuffle on or off) this “random searching” is actually a pretty good strategy. Basically you randomly skip through songs until you get to the artist you are looking for. Once finding the artist, turn off the shuffle part and search one song at a time until you find the one you are looking for! Pretty straightforward and a fun way, well ok, a way to pass the time while sitting in traffic.

Norvig’s article talks about the math behind this type of search. Specifically he solves how long it would take to find a song (on average). He describes the problem as a Markov Decision Process that can be solved using a value iteration algorithm. Its amazing how something that sounds so complicated is actually pretty straightforward. The code that is used to implement the solution is in python and it is pretty short so it is doubly impressive, at least to me.

Spicing up iTunes playlists

I really like my iPod. I’ve got a 4GB Mini that I keep in the car (hooked up to the stereo) and I listen to that instead of the radio. I have a couple of playlists that account for about 2GB of songs on there. You would think with that many songs all would be good. And most of time it is, but after a while, you will listen to all of those songs and start to hear the same ones over and over and over. Even your most favorite of songs will begin to grate on your nerves.

So how do you prevent this?

For me the secret has been to set up two new play lists. One is dedicated to new songs (i.e. just bought or ripped), and the other is for songs that haven’t been played a while.

With iTunes, you can setup a play list that will select songs based on certain fields. For me, most of my play lists revolve around the “rating” of the song. 1 Star means I don’t like it, 5 Stars means its the best thing I’ve ever heard. As a consequence, I have a lot of songs that fall into the 3 to 4 star range. Randomly choosing songs from this pool is ok, but for some reason I always seem to wind up with the same core groups of songs, and like I said earlier, they are starting to get stale.

It turns out that there is another field that iTunes keeps track of, the “last time played”. This is interesting because now we can build a play list based not only on how much we like the song, but also how long it has been since we have heard it. Combining the two ideas together leads to an interesting new play list. Here’s a picture of how I have mine setup:

playlist.png

With this play list feeding into my iPod when I sync I get a nice selection of “fresh” songs almost every time. Since I have about 800 songs rated between 3 and 5 stars, this gives me a good size pool of songs to pull from. And since the play list is time dependant, what is in the list today will be different than what is in the list 2 weeks from now.

The real beauty of this play list is that as songs are listened to, their “last played” date is set to now, and when I sync up the next time, a new song will take its place. This way, I can keep listening to the songs I like, but don’t have to worry about stale songs because the play list is always being refreshed.

And as I listen to songs on the Mac, this updates the last played dates also, so the net effect is I’m adding a lot of chaotic variability to the play list. Which in turn means that the songs on the play list will tend to be more “random” because there are two sources of input (the iPod and iTunes) that are influencing the results of what gets picked.

iTunes and Metadata

Its been almost a year since I started using iTunes, and in that time I’ve adapted to its way of looking at my music library. It took me a while to get used to its mangling of my music directory (I’m picky like that), but all in all things are pretty good now. I do have a few observations:

  • Metadata and the files
  • I like that when I play a song the album artwork is displayed. I think that’s neat. I was however really surprised to find out that the image of the album cover is stored in the mp3/m4p file, thus increasing its size. That struck me as really odd since if you have an album’s worth of songs, the same picture could be used for each song/file. It seems that over your entire music library that if there was only one copy of the image floating around, you’d have more file space, which is to say you could fit more songs onto your iPod.

    Then I discovered the most interesting thing: The ratings that you assign for a song are not stored in the music file! They are kept in a separate file! I’m pretty sure that the MP3 file standard has a field for the user’s rating, it seems to me that setting the field (which is already there and wouldn’t add anything to size of the file) would be the way to do it, instead of storing that info in a file that if it gets corrupted will effect every rating in the library. Plus if you go an move the music file to another machine, you loose the rating info. I’ve been relying heavily on rating information lately.

  • Playlist fatigue
  • I’ve noticed lately that I’m getting really tired of my playlists, they seem to play the same songs over and over. Investigating further I found the problem is that the size of the playlists (which are mostly based off of the ratings of the song) is not as large as I thought they were. It turns out I have not rated a large portion of my music library. This means that the playlist is pulling selections from a rather limited pool. The smaller this pool, the more frequently you are going to hear a repeat.

    Of course the way to get around this is to create an “unrated” playlist and force yourself to listen through it. As you listen to the songs, rate them. This will help enlarge the pool of possible songs the playlists can play from. Previous studies have shown the randomizer in iTunes does a pretty good job of picking songs randomly, so by increasing the playlist size you’ll find that you don’t have as many “I just heard that song!” moments.

    Please note that the last item about the playlists applies to all music players, not just iTunes. I discovered this problem at work while using the Windows Media player. If you’ve got a small population of things to choose from, then there is a high probability that you are going to hear the same thing often.

    Hooking an iPod up to a Honda Civic Hybrid

    I’ve been meaning to write about this for a while (I guess it never made it to my “To Do” list), a few months ago I installed a USASpec iPod Interface into my Honda Civic Hybrid. It is a neat little device that allows me to hook the iPod into the stock radio in the car, and control the iPod from the radio buttons (specifically, using the 6 disc changer buttons).

    I followed the directions I found on this site and they worked perfectly. In fact, with the pictures that Brad has of the installation he did on his car, this site is better than the instructions I found from Honda on the web. The only thing I did different was to pop the radio (and most of the center cluster) out of the dashboard in order to hook up the CD cable.

    The other bit of advice I would offer is to make sure that you have the cables securely plugged in before you put everything back together. I didn’t double check everything and the first time I fired it up, only the left side speakers were getting a signal. Additionally, instead of using the self-tapping screws that come with the interface module, I used zip ties to secure it to a metal crossbar that is behind the exterior panel that has the cigarette lighter on it.