I looked into the sound capabilities of Tamagotchi items. Unfortunately, while the hardware seems able to play a wide range of notes at different volumes, this functionality is not available through the figure.
As I mentioned in my previous post, figure ‘items’ are implemented using byte code with six byte instructions. One particular instruction, starting with 0xFEFF controls sound.
The first two bytes of the instruction are always the same, and are likely used to identify it, while the last three bytes are always zero (I checked all the figure dumps I have so far to check this). This leaves one byte to identify the sound. I tried changing this value, and found that it cause the Tamagotchi to play different complete sounds. For example, one value caused the Tamagotchi to beep once, while another code caused it to play “Yankee Doodle” in it’s entirety. Values 0-0×30(ish) played sounds that the Tamagotchi normally plays while running, such as the reset noise and the call noise. Values 0×30-0×52 played a wealth of public-domain music, ranging from “Fur-Elise” to “La Cucaracha” to “The Turkey in the Straw”. After that, codes 0×53-0x5f played a C-major scale. These are all the notes that are available for custom sound.
This is problematic in two ways. First, there are no sharps or flats, so a Tamagotchi figure can only play music that is playable on a major scale. This means that Tamagotchis are unable to dance to many popular tunes, including “Gangnam Style” and “The Macarena”. This isn’t a hardware limitation, as these notes are used in some of the complete songs the figure can play, but the functionality hasn’t been built into the figure.
The other difficulty is timing. The sound instruction does not contain any timing information. Instead, sound timing relies on the delays in image instructions. A sound instruction will not play until the delay in the pre-ceding image instruction is complete, and it will play until the next sound instruction is encountered (there may be several image delays in the mean time). If the sound is not yet complete, it will be interrupted, and not finish playing. There is no other way to change the timing of the sound.
This also means that there is no way to ‘hold’ notes. I tried doing this by repeating notes with a very short delay, but there was no delay that would make the notes play cleanly without “buzzing” due to short breaks in the note. The sound is still reasonable, though. To decrease the delay, and get even better (but not perfect sound), I had the Tamagotchi load a one pixel image during delays, which reduced the inherent delay due to image loading, and the larger image was still visible, except in the one pixel.
This allowed me to create a music video starring my Tamagotchi, albeit one with limited notes and sound quality. A helpful member of pmdev suggested I do “Mad World”, as it can be played with only the notes available.
This song perfectly sums up the angst of being unable to dance “Gangnam Style”. All the more motivation to get code execution!