How to use p2s

The p2s program provides a simple graphical way of opening an image and turning into sound. It allows lots of control over the way that the picture will be interpreted. It creates a midi file which can be played by media players such as Windows Media Player, or on any midi sequencer. Midi files basically 'play' your computer's own built-in sound chip, so the quality of the sound is totally dependent on your computer.

You can download p2s from this site and use this page to get started with it. If you are interested in how it works, skip to the end of this page. The following screen shots show some of the features in the first version (but I keep adding more so it might change!).

Below is a screenshot of the p2s application, showing how to open a picture:

browse for a picture file

You can select images of most common types: .jpg, .gif, .png etc.Tip: view the files as thumbnails to make it easier to select them....

file selection

The picture will show up in the top left hand panel of p2s. 

You can also select a folder where the sound (midi) files will be placed. By default, they will be created in the folder from which you run p2s.

Next, open the control dialog, to control how the picture is turned into sound...

opening the control panel

First divide up the picture into a number of columns and rows, remembering that the total number of notes generated will be the number of columns multiplied by the number of rows. The last note can be extended to make a nice ending! If the image is large (say, bigger than 1024x768) you can speed up the note generation by ticking the 'Fast Mode' box (this results in a slight loss of resolution but it will hardly affect the resulting tune).

divide up the picture

Next, set the speed in "beats per minute". For example, 60bpm would play one note per second (...a rather slow tune).

set bpm

Now select the 'note mapping'. This setting has a huge influence over the final music. You can define a set of notes for each color (i.e. one set for red, one for blue, and one for green). For example you might define the set of notes for RED to be: C4 D4 E4 F4 G4 A4 B4 C5 D5 E5 F5 G5 A5 B5. This represents two octaves starting at middle-C (C4). With this mapping, C4 will be played when there is a very LOW level of red (or none at all). The very strongest red will play B5. Intermediate levels will play all the notes between.

note mapping

The current version of p2s already has some note mappings built in, and you can select them from a drop-down menu. When you select one, p2s reports the mapping. E.g here is what it reports when you select the 'blues1' mapping:

Selected tones:
Red   -> C5 Eb5 E5 F5 Gb5 G5 Bb5 C6 D6 Eb6 E6 G6
Green -> C4 Eb4 F4 Gb4 G4 Bb4 C5 Eb5 E5
Blue  -> C3 E3 G3 A3 Bb3

Note that "B flat" is written "Bb". F sharp is written Fs. You can write your own note mappings in a text file called UserNoteMapping.txt which must be placed in the same folder as p2s, and must be formatted exactly as below (download an example from the download page). After you change the UserNoteMapping.txt file, re-start the control panel and the new mappings should be available on the menu underneath the built-in ones.

# Extend the list of note mappings like the examples below.
# A4 is 440Hz
# C4 is middle C
# Bb = B flat
# Fs = F sharp (a.k.a Gb)
# The order is: red, green, blue
C3 E3 G3 Bb3 C4 E4 G4 Bb4 C5 E5 G5 Bb5 C6 E6
C3 E3 G3 Bb3 C4 E4 G4 Bb4 C5 E5 G5 Bb5 C6 E6
C3 E3 G3 Bb3 C4 E4 G4 Bb4 C5 E5 G5 Bb5 C6 E6
C3 Eb3 Gb3 A3 C4 Eb4 Gb4 A4 C5 Eb5 Gb5 A5 C6 Eb6 Gb6 A6
C3 Eb3 Gb3 A3 C4 Eb4 Gb4 A4 C5 Eb5 Gb5 A5 C6 Eb6 Gb6 A6
C3 Eb3 Gb3 A3 C4 Eb4 Gb4 A4 C5 Eb5 Gb5 A5 C6 Eb6 Gb6 A6

Next, select which instruments play each color. The quality of the resulting sound depend entirely on the quality of your computer's sound chip. Most do a passable impression of a piano, but some of the other instruments will be unrecognisable on average-priced computers!

midi instruments for each note

You can generate tunes in stereo! Use the sliders to set up the degree of stereo separation. For example, you can make red play in the left ear, green in the middle, and blue in the right ear.

stereo panning

Now press the green run button! This does two things: - Finds the average color in each block and makes a new 'averaged' picture. - Maps each of these blocks to notes and creates a midi file containing your new tune As it runs, it reports what it is doing in a 'log window'. You can see the averaged image at any time by pressing "Show averaged image"....

averaged image after tune generation

Now you can play the tune! By default p2s names the tune according to some of the main settings, e.g. the file blue_flower.jpg, divided into 4 by 3 squares and played with the 'blues1' scale, is called blue_flower.jpg-4x3-blues1.mid. But you can type a different name in the 'output filename' box if you want. There are two ways you can play this tune. Either 1) use windows explorer to navigate to the folder where you place the midi files (by default this is the directory where you keep p2s) or 2) press the "Play with media player" button on p2s.

By default, "Play with media player" will try to use Windows Media Player in the folder C:/Program Files/Windows Media Player. That might work if you run windows XP like I do, but if not you can customise is from the 'play' menu

There are infinitely many ways of customising the sound that a single picture generates, and (of course) infinitely many pictures that you can use with any given settings. Some results are more satisfying than others. Have a look at the examples page for some ideas!

The p2s software - tech details

p2s is written in Tcl. There is no good reason for this - I just like it! It is a very accessible scripting language for those of us who are not software professionals, and it is freely available from

The original version was a command-line script that read a bitmap image file, and actually created a .wav file with sinewaves for the three tones. This took just two evenings to write, and when I heard the first haunting noises come out of it, I was hooked! However, generating .wav files was VERY slow and the resulting files were large. Command-line scripts are fine for us geeks, but it needed a GUI if it was to be shared more widely. And it needed to handle all the common graphics formats, not just bitmaps.

GUI: Tk (an extension of Tcl) was the obvious choice for the GUI. It is not terribly clever, but it is adequate and easy to write.

Image: Another extension of Tcl, called Img, is then used to handle all the different graphics formats. p2s now reads .jpg, .bmp, .png and .gif formats, and could do others.

Sound: MIDI was the obvious choice for the sound files. It makes files which are a tiny fraction of the size of .wav files, and offers a huge variety of sounds. A future version of p2s should include a midi sequencer, but for now it just generates files which you can play with a media player. The MIDI file format was ripped off from various examples, and some helpful websites like this one. The General MIDI insrument mapping has been coded into the p2s menus, and this should be correct for most (all?) sound cards. i.e. when you select piano, it should sound like a piano!

The p2s code still contains the .wav file generation, but it cannot be enabled from the GUI. It can be re-enabled if you have a fast enough computer and want to play with it.

OS support: p2s has only been tested on windows XP (and I saw it run on Vista once). Tcl is not widely installed on home PCs, so freewrap is used to effectively create a single executable for use on windows computers. Unfortunately the freewraped version is huge because it basically contains a fully compiled version of Tcl, plus any libraries, plus the p2s script itself.

For Linux users, they probably already have Tcl installed or would not mind installing it. Theoretcally I think MAC users could do the same. But it is not tested on either platform yet.

Graphics: all graphics (such as icon creation) was done using the Gimp - an open source image manipulation program.

Free software: this project was made possible by open source software freely available on the internet. And p2s, in turn, is open source (under GPL, which means developers have to share any modifications they make if they release variants of p2s). I am not a software professional, so the coding style does not stand close scrutiny!