Monday, January 18, 2016

MP3 headphones (2) / The scientific method

As I've been wearing the mp3 headphones (and listening to the music stored within) every time that I take the dog for a walk (that's two or three times a day during the week, four times a day on Fridays and Saturdays), I've had a lot of time to think about the order in which the songs are played. I want to treat this in a scientific manner, so first I will give a non-rigorous version of the scientific method:
  1. One makes observations 
  2. One makes hypotheses based on those observations to explain them
  3. One test those hypotheses to see whether they support all observations
  4. A hypothesis cannot be proved to be true, but it can be proved to be false. One accurate observation which contradicts a hypothesis means that the hypothesis has been falsified.
  5. A good theory (or hypothesis) should predict future observations
So what are my observations? These are at two levels: directory (artist) and song. The artists played in order were Richard Thompson, Robin Frederick, Sandy Denny, Tales of us (Goldfrapp), The Band, The Blue Nile, The Swell Season. Hmmm: seems like they're in alphabetical order. Question: why was Richard Thompson the first artist to be played, and not No'am Newman, considering that the latter comes before the former in alphabetical order? Thus at the moment, one can hypothesize that the directories are played in alphabetical order, but I'm expecting that this hypothesis will be falsified.

The songs in each directory are also played in alphabetical order of their titles. True, the directories of Sandy Denny and The Swell Season played the songs in the order in which I intended, but when I examined the directories, I saw that the song names had been prefixed with a number which indicates the order. This observation strengthens the hypothesis is that the songs are played in alphabetical order.

On Saturday afternoon, I remembered that an old mp3 player of mine (prior to the Sansa clip+) used to drive me mad as the songs were played in the order of their being copied to the player! Could the same thing be happening here? Could it be that the songs are currently in alphabetical order because they were copied in alphabetical order? Cue this web page, which states that "Many modern MP3 players are based on USB flash drives (i.e. Creative's MuVo range of MP3 players). These devices don't allow you to sort the MP3 files in the order you want to listen to them. Instead they play the MP3 files in the order they find them; usually the order you copied them to the flash drive. Unfortunately if you select a bunch of files in Windows' Explorer and copy them to your MP3 player, they don't always copy in alphabetical order (even if you have told Explorer to display the files alphabetically). And of course you may want to add new MP3 files at a later date, which will result in them being added to the end of the directory."

Several people have created a solution: a utility program which sorts the FAT32 directory without the need to recopy the files (the FAT is like a phone book which records where every file is located on the disk/memory. The entries are made in the order of writing to the medium). I tried DriveSort which achieves its aim pretty well. Before updating the directory, however, it is necessary to edit each song's file name to include its play number; this number is included in the ID3V2 tag but DriveSort ignores this.

Going back to the scientific method for a moment: point 3 says that hypotheses can (and should) be tested. Here is the experiment: 

  • Take a directory whose songs are currently being played in alphabetical order (e.g. The Band)
  • Rename the songs in the required order
  • Play the songs 
  • Using DriveSort, update the directory
  • Play the songs again
Stage 3 will check whether the alphabetical hypothesis still holds - if the songs are played in their new order, then the hypothesis has not been falsified. I suspect that they will still be played in their original order, an order which does not match the new order. Stage 5 will check whether the new hypothesis is true: that the songs are played in the order of their copying, or more technically, in the order of their appearance in the FAT32 directory.

I confess that I haven't performed this experiment yet because I got sidetracked with an earlier problem. All the songs have their order number contained in their ID3V2 tag; I would like an automatic method of transferring this tag to the song's file name so that DriveSort can do its job. Whilst obviously I could do this manually, it is a pain in the finger; being a programmer, my natural inclination is to write a program to do the renaming for me. 
So I started looking for libraries which enable a Delphi program to read the tag; the first solution which I found did not work at all. The second seemed to work; this came with a test program with a visual interface which allowed me to examine an existing mp3 file, to read its tag and to update it. This program didn't read pre-existing tags, but it did write tags which it could read back; also WinAmp could recognise these tags.

I took the dog for a walk, during which time I realised that this program was of no use to me as it doesn't read the pre-existing tags and so could not update the file names. I had wasted at least half an hour playing with it. I resolved to find another library which could read pre-existing tags.

And find I did. This library also came with a test program which allowed me to view the tags contained within a file; it passed this test with flying colours. By now it was getting late so I decided to leave the subject for another day. Despite this decision, some of my dreams were about mp3 tags (this is why I can't program for too long in the evening).

I am aware that in the time that I have devoted to finding a programmatic solution to the file name problem I could have renamed all of the files. But I like a programmatic solution which supposedly will save me time in the future. Actually, in this case, that's not necessarily true: in the future, I might decide to edit the file name directly instead of the tag, though this means that the order will be wrong should I decide to return to the Sansa.

I see that I did not address the issue of why Richard Thompson was the first artist to be played. My supposition is that this was the first directory to be copied then the other directories were copied in alphabetical order by Windows. This supposition is strengthened by the fact that the computer sees the Sansa as two separate disks: its built-in memory and an external memory card. If I remember correctly, first I copied the directories on the memory card (where Richard Thompson et al. are to be found) then the other directories. I should be able to solve this by running DriveSort at the directory level.

No comments: