MENU
Home
Introduction
Construction
Behaviour
Sound Sampling
MIDI handling
Limitations
Sound Toolkit
|
MIDI
WOBU the robot had two major objectives; the first was to find people, and the second was to entertain them. We decided to achieve this by making the robot play a tune (using the IC tone command) and dance with his motors. Thus, its behaviour on finding what it had recognised as a person would be followed by a little sing and dance, and then the robot would go and look for someone else to entertain.
The singing presented us with some initial problems; as we knew little about the advanced features of IC, songs would consist of a long series of tone instructions. The tone instruction looks as follows:
tone(1000.0, 1.5);
The 1000.0 is the frequency in hertz, and the 1.5 is the duration in seconds.
While some people may know the exact notes of their favourite tunes, it is somewhat unlikely that they can name their frequencies, or their precise durations. Nevertheless, I decided to program the Macarena into Wobu as best I could as a test exercise. The process took around two hours of trial and error, sitting in front of the computer and the robot as it squealed off-key notes of irregular lengths and people stared at me. Much humming and playing of various tones was required, and I ended up with something that sounded a bit like the Macarena (an insultingly simple tune on its own), but not that much.
This, then, was clearly not the way to proceed.
There was one computer music standard that had been around for a long time that could help, however. The MIDI standard has existed since the Eighties and the Amiga, and unlike formats such as .WAV and .MP3 it stores note information, rather than sound waveforms. This means that it is not only small in file size, but also conversion from MIDI to other standards can be relatively straightforward.
It was in this direction that we turned. It was, in theory, possible to convert the note information stored in a MIDI file to tones by extracting the note information and interpreting it correctly. While researching this on the Internet, I came across a conversion chart for MIDI notes to frequency - detailed below. This was invaluable, as it allowed us to see a direct comparison between the tones and real musical notes.
MIDI Note Number to Frequency Conversion Chart
MIDI MIDI MIDI
Note Frequency Note Frequency Note Frequency
C 0 8.1757989156 12 16.3515978313 24 32.7031956626
Db 1 8.6619572180 13 17.3239144361 25 34.6478288721
D 2 9.1770239974 14 18.3540479948 26 36.7080959897
Eb 3 9.7227182413 15 19.4454364826 27 38.8908729653
E 4 10.3008611535 16 20.6017223071 28 41.2034446141
F 5 10.9133822323 17 21.8267644646 29 43.6535289291
Gb 6 11.5623257097 18 23.1246514195 30 46.2493028390
G 7 12.2498573744 19 24.4997147489 31 48.9994294977
Ab 8 12.9782717994 20 25.9565435987 32 51.9130871975
A 9 13.7500000000 21 27.5000000000 33 55.0000000000
Bb 10 14.5676175474 22 29.1352350949 34 58.2704701898
B 11 15.4338531643 23 30.8677063285 35 61.7354126570
C 36 65.4063913251 48 130.8127826503 60 261.6255653006
Db 37 69.2956577442 49 138.5913154884 61 277.1826309769
D 38 73.4161919794 50 146.8323839587 62 293.6647679174
Eb 39 77.7817459305 51 155.5634918610 63 311.1269837221
E 40 82.4068892282 52 164.8137784564 64 329.6275569129
F 41 87.3070578583 53 174.6141157165 65 349.2282314330
Gb 42 92.4986056779 54 184.9972113558 66 369.9944227116
G 43 97.9988589954 55 195.9977179909 67 391.9954359817
Ab 44 103.8261743950 56 207.6523487900 68 415.3046975799
A 45 110.0000000000 57 220.0000000000 69 440.0000000000
Bb 46 116.5409403795 58 233.0818807590 70 466.1637615181
B 47 123.4708253140 59 246.9416506281 71 493.8833012561
C 72 523.2511306012 84 1046.5022612024 96 2093.0045224048
Db 73 554.3652619537 85 1108.7305239075 97 2217.4610478150
D 74 587.3295358348 86 1174.6590716696 98 2349.3181433393
Eb 75 622.2539674442 87 1244.5079348883 99 2489.0158697766
E 76 659.2551138257 88 1318.5102276515 100 2637.0204553030
F 77 698.4564628660 89 1396.9129257320 101 2793.8258514640
Gb 78 739.9888454233 90 1479.9776908465 102 2959.9553816931
G 79 783.9908719635 91 1567.9817439270 103 3135.9634878540
Ab 80 830.6093951599 92 1661.2187903198 104 3322.4375806396
A 81 880.0000000000 93 1760.0000000000 105 3520.0000000000
Bb 82 932.3275230362 94 1864.6550460724 106 3729.3100921447
B 83 987.7666025122 95 1975.5332050245 107 3951.0664100490
C 108 4186.0090448096 120 8372.0180896192
Db 109 4434.9220956300 121 8869.8441912599
D 110 4698.6362866785 122 9397.2725733570
Eb 111 4978.0317395533 123 9956.0634791066
E 112 5274.0409106059 124 10548.0818212118
F 113 5587.6517029281 125 11175.3034058561
Gb 114 5919.9107633862 126 11839.8215267723
G 115 6271.9269757080 127 12543.8539514160
Ab 116 6644.8751612791
A 117 7040.0000000000
Bb 118 7458.6201842894
B 119 7902.1328200980
NOTES: Middle C is note #60. Frequency is in Hertz.
However, MIDI contains the data for up to 16 channels of sound. The tone command can only play a single note at any one time, and on top of that there were things like drum beats and backing which would have been superfluous. Direct conversion from MIDI to tone turned out to be impossible, therefore, but we found an intermediate step:
The Nokia ring tone standard - the .RTX format.
Many mobile telephones have the function to import custom rings, and ironically there were several pieces of software available on the Internet to convert MIDI to ring tone format - which is single channel, within octave boundaries (4 to 7 on the chart), and can be directly applied to the conversion table to find frequency. It therefore became our goal to write a program to convert from .RTX to tone instructions.
A program called Midi2Tone allowed us to isolate the main channel of a MIDI file, and then save it as an .RTX. This is shown below, along with the note view for picking the required notes from the highlighted channel. The track shown is Staying_Alive.MIDI, which is as follows in .RTX format:
| stay_al : d=4, b=50 : 32c#7, 32c#7, 32c#7, 32c#7, 32c#7, 32b6, 32b6, 16b6, 32a6, 32a6, 32a6, 32a6, 32g#6, 32g#6, 16g#6, 32a6, 32a6, 8a.6, 32g#6, 32a6, 32a6, 8a.6, 32c#7, 32c#7, 32c#7, 32c#7, 32c#7, 32b6, 32b6, 16b6, 32a6, 32a6, 32a6, 32a6, 32g#6, 32g#6, 32g#6, 32g#6, 32a6, 32a6, 8a.6, 32g#6, 32a6, 32a6, 8a.6, 8c#7, 8b6, 8a6, 8g#6, 32g#6, 32a6, 32a6, 8a.6, 32g#6, 32a6, 32a6, 8a.6, 8c#7, 8b6, 8a6, 8g#6, 32g#6, 32a6, 32a6, 4c#.7, 4b.6, 32c#7, 32b6, 4a.6, 4g#6 |
The file contains the name, then the default note duration, and beats per minute and then all of the notes. The notes break down as duration (4 is a quarter note or crotchet, likewise 32 is 1/32 of a full note), note (the note from the scale,) and octave (from the conversion chart, from 4 to 7).

Figure 5 - Midi2Tone with Staying_Alive.midi loaded

Figure 6 - the Note view, showing channel 4

Figure 7 - the zoomed note view, with the chorus highlighted
We then wrote a program, RTX2Tone (which is available for others to use from the Sound Toolkit page) which read in .RTX files and converted them to .TON files - a long IC file with both the tone instructions for the notes and also the "dancing" instructions.
Staying_Alive.RTX is converted by our program, RTX2Tone, to the following tone instructions:
/* Start of Tone conversion... created from file "STAY_AL.RTX" */
fd(1);bk(0);
tone(554.0, 0.203125);
tone(554.0, 0.203125);
tone(554.0, 0.203125);
tone(554.0, 0.203125);
tone(554.0, 0.203125);
fd(0); bk(1);
tone(493.0, 0.203125);
tone(493.0, 0.203125);
tone(493.0, 0.40625);
tone(440.0, 0.203125);
. . .
tone(415.0, 0.203125);
tone(440.0, 0.203125);
tone(440.0, 0.203125);
tone(554.0, 2.4375);
fd(0); bk(1);
tone(493.0, 2.4375);
fd(1); bk(0);
tone(554.0, 0.203125);
tone(493.0, 0.203125);
tone(440.0, 2.4375);
fd(0); bk(1);
tone(415.0, 1.625);
fd(1); bk(0);
ao();
/* End of Tone conversion... */
The fd(1); bk(0); refers to the motors - this controlled the "dancing". The ao(); at the end switches off the motors at the end of the dance. The motor commands were inserted at regular intervals according to tempo and note length, meaning that by and large the robot followed the beat. Obviously, there were many more tone commands than those listed - some 96 in total. These were then inserted into the code at the appropriate point, and lo and behold Wobu sang.
|
|