MP3 Player Software

If you’re quickly looking for the latest .hex file to program into the AVR, here it is:

floppydisk

Just click on the icon to download the.hex file. Or rightclick then select “Save Target As…” or similar. This file was updated 4 December 2004. This version adds bass and treble control support.

The full MP3 player source code is also available. This code is built using the GNU tools, specifically the winavr toolset freely downloadable from avrfreaks. If you’re working in Windows you’ll need the WinAVR compiler installed and working to be able to recompile this source. I strongly recommend using the 20040404 version, downloadable here. To recompile the source code, just type “make” (without the quotes).

The file below is a .zip file. It contains some text files with useful information, along with the source files. There seems to be some interest from other people wishing to do some software development for the player themselves. I’d certainly be supportive of that. The source is heavily commented. If the need arises I can look at putting the code up on a CVS server. For now though it’s just a simple zip file. This file was updated 4 December 2004.

floppydisk

If you’re looking for a mass-storage class driver for Windows 98, or for the serial eeprom file, look at my USB 2.0 page.

Software Features

The MP3 player software has a number of features: random mode, repeat mode, subdirectory support, output level control, etc. The operation of the player is described in more detail below. A lot of time has been spent on two things:

  • making the existing software stable, and
  • making the existing software work quickly with large numbers of files.

To this end there are precious few known bugs in the player. I run it for hours and hours on end.

Making it run well with lots of songs was a challenge given the limited memory on board the player. Two tricks have proven to be a great help. One is a FAT look-ahead function, which greatly speeds accesses to the FAT32 File Allocation Table. This look-ahead function handles both fragmented and unfragmented files. The second is a fast-find table. This table is built each time the files on the disk are changed (not at each powerup; only when things change or when the current directory is changed) and is stored in eeprom. It works in conjunction with the regular FAT32 directory structure to dramatically speed up locating arbitary files (eg the 754th file) in the current directory.

Random

Random mode appears random but is not truely random. I initially implemented a true random mode, but this meant that sometimes a song would be repeated while others wouldn’t be played. After a while it annoyed me. The current random mode is better described as a “randomized shuffle”. Although it never behaves the same way twice, it guarantees that all songs will be played before any are repeated, yet the song order usually appears completely random. (It does use two random seeds.) This mode works quite well and I’m very happy with it. Random defaults to off.

Repeat

This defines what happens when the player is not in random mode and it plays the last song in the directory. If repeat is off the player will stop. If repeat is on the player will wrap around to the beginning of the directory again. Repeat defaults to on.

Stop

The “stop” button works as follows. A single press will stop playing of the current track, but the track number will be remembered. Pressing “play” at this point will result in re-playing of the same track that had just been stopped. This is very useful for temporarily stopping playing, then resuming from the same song you left off.

Pressing “stop” twice (ie pressing it twice in a row) will result in the track number being reset to the beginning. If you press “play” after this (provided random mode is off) the first song in the current directory will play. This is useful for going back to the beginning of a directory for example.

Menus

There is a menu stucture in place. To enter the menus, press the “menu/select” button. This will stop the playing of the current song (necessary because the menu items alter hardware settings or access the disk). Use the up and down arrows to scroll through the menus, and press the “menu/select” button to select a menu item. To exit the menus, select the “exit menus” menu item.

Change Output Level

This is a menu function which allows you to alter the output (volume) level of the player. It’s useful because the audio output level of the MP3 player, by default, may be too high for the input of some stereo systems. You’ll know if you have this problem because the audio will sound very distorted, due to the stereo clipping. This menu function allows you to decrease the audio level, all the way down to zero if desired. The output level value is stored in eeprom so it is remembered across power-downs. It may have to be re-entered if the player is reprogrammed (software updated), as some programming utilities erase the eeprom contents.

Change Current Directory

As its name suggests, this menu function allows the use to change the current directory (the directory that MP3 files are played from). The directory is stored in eeprom so it’s remembered across power-downs. If the USB port is used the player defaults back to the root directory, because its possible that the current directory was deleted or in some way altered during the USB changes (file changes, create new dirs, delete dirs, etc can all be done via the USB port).

The name of the current directory is displayed towards the top of the LCD. Below that the subdirectories can be scrolled through with the Up & Down buttons. Every directory contains a “select this directory” item; press the Select button to choose the current directory and return to normal player operation. Alternatively scroll up and down through the displayed subdirectories and press Select to change down (or up) into a new directory. There is no limit on the number of directories that can be navigated through.

Number of Songs In Current Directory

This menu function displays the name of the current directory and the number of MP3 files contained in it.

Learn IR Remote Control

This allows you to train the player to use a remote-control for most functions (such as play, stop, next, power, etc). Follow the on-screen instructions. The “learnt” remote-control codes are stored in EEPROM so they’re remembered across power-downs. Not all remote controls will work, although most seem to. I have tested with six remote-controls; here are the results:

Hitachi works well
JVC works well
Viewsonic works well
Yamaha works well
Sharp works well
GE does not work

 

These are just my results; it’s even possible that different remotes from the same brand could yield different results. If you’re having trouble with a certain remote, just try another one. The basic issue is that there are a variety of frequencies (both IR carrier and modulation frequencies) used by different remotes. Although this player uses a fairly general-purpose receiver, it cannot receive absolutely everything, and hence there are always some remotes that are received poorly, or not at all. From my experience, most remotes work fine.

Change Bass Level, or Change Treble Level

These two menu functions allow you to alter the bass & treble levels of the player. You can increase or decrease both bass and treble. They both default to zero (no change). The levels are stored in eepom so they’re retained across power-downs. They may have to be re-entered if the player is reprogrammed (software updated), as some programming utilities erase the eeprom contents.

Stepping Through the Songs

Software versions 12 Feb 2004 and later support a variety of ways of stepping through the MP3s in the current directory.

The simplest method is of course the “next” and “back” buttons. When random mode is off, these typically step forward to the next MP3 on the disk, or the previous MP3 on the disk, respectively.

In a somewhat similar fashion, the 4 “diamond” pushbuttons can be used. The “up” button jumps forward 10 tracks, whereas the “down” button jumps backwards 10 tracks. For yet larger jumps the “right” button on the diamond jumps forward 100 tracks, and the “left” pushbutton jumps backwards 100 tracks.

Finally, for really large numbers of tracks, there is another way of stepping through them. It is possible, by pressing and holding the “next” button, to change the stepsize of the player (only when random mode is off). Stepsize is the number of tracks that the player moves when the “next” or “back” button is pressed. By default (power-on) stepsize is 1, so that pressing “next” (for example) advances to the next MP3 in the directory. When random is enabled, stepsize is set to a random value so that each time you press “next” the player will move forward a random number of tracks.

Holding down “next” (when random is off) allows you to change the value of stepsize. You’ll see it cycle through these values: 1-10-50-100-500-1000. Stepsize will always be less than the number of tracks in your current directory; hence you may not see all of these numbers appear. Release “next” when the value you want appears on the screen. Having changed stepsize to 500 in this manner for example, pressing “next” will now advance 500 tracks; pressing “back” will jump backwards 500 tracks. Keep in mind that stepsize is also used when playing songs; when the currently playing song ends the MP3 player will advance stepsize tracks to find the next track to play. So, if you change stepsize to move around in your directory of songs, you’ll likely want to change it back to 1 before playing them. Otherwise playing songs might feel similar to having random mode on!

Using the up/down/right/left buttons to move through the tracks in the current directory does not change stepsize. These buttons will work even with random mode switched on. Which makes these buttons much more convenient for quickly hopping around the current directory. The “power-users” have the ability to change stepsize if they wish.

USB 2.0 Access

When the MP3 player is connected to a PC via its USB 2.0 port, this is automatically detected by the player software. It will immediately stop playing any tracks and stop all disk accesses, then hand over control of the harddisk to the USB (mass-storage class) interface. Once the USB cable is disconnected the player will basically perform a reset – it’ll revert to the root directory and restart. This allows it to rediscover the number of MP3 files in the directory and so forth, which will have likely changed as a result of the USB access.

When the USB port is in use the player functions exactly like a USB harddrive. For example the drive will appear in “Windows Explorer” on most Windows machines. Any file can be stored on the harddisk; it’s not limited to only MP3 files. Of course once it’s back in MP3 player mode, after the USB cable is unplugged, it will only actually play the MP3 files. Any other files are simply ignored.

Diagnostics

There are some diagnostics available via the debug port. These are available on 21 May 2004 software versions and later. Use a straight-through DB9-to-DB9 RS232 cable to connect the player to a terminal of some type (eg a PC running HyperTerminal or similar). Baud rate is 19,200. Press any key on the terminal and you should get an intelligent response.

Likely the most useful item is the IDE ports bits test. If your player is powering up OK, but then refusing to play songs from the harddisk, one possibility is a solder blob between IDE pins. This test may help. Unplug the diskdrive (Very important! Don’t run this test with the diskdrive plugged in.) then power up the player and run this test. It’s able to detect quite a few different possible shorts between IDE pins. If you’re in the process of building a player, running this test before plugging your harddisk in for the first time might be an idea, just as a confidence builder and sanity-check.

Bug List

Check the issues.txt file in the source .zip file for the bug list. It’s very short, given my preference for squishing bugs rather than adding features. I’m a big fan of reliable software.