# Rainbow Loom update

Very small amount of activity from Gakken today.

First, the Otona no Kagaku site announced that the new Rainbow Loom expansion kit has hit the shelves.

Second, Gakken has finally decided to add the new mini-Theremin kit to their Sound Gadget product line. Now there’s actually more than one product to the “line-up”.

# Riemann prose, part 2

The Greeks were really good at solving problems using pictures. These were geometric problems, and involved determining the relationships between the sides and angles of a triangle, dividing angles in half, and squaring the circle. One result of this process was the realization that you could have fractions.

A fraction represents some unit object that is evenly subdivided. Dividing something doesn’t change the fundamental fact that the subunits still all add up to the unit object. That is, if you have a cake (mmm, cake, gurgle) and you cut it into 4 pieces of equal size, you have 4 pieces that, if pushed back together again, are still the same size as the original cake.

Divide the cake in half, you get 2 halves (2/2).
Divide it in thirds, 3 thirds (3/3).
Divide it in fourths, 4 fourths (4/4).

In all cases, an integer divided by itself equals 1.

If you take only one subunit (1/2, 1/3, 1/4), you get the building block step size for recreating that cake.

It’s easy to see why people want to believe that this is where you stop with the rational numbers.

Interestingly, if you look closer at these fractions, they are telling you to divide 1 by the integer below it. It’s right there, in the number – “divide me! Do it! Do it! Do it!”

Unfortunately, the results aren’t always very clean, and this brings up the issue of decimal values, which has an unclear history. The wiki entry implies that fractional decimals were used as part of the decimal system in India, but that it was marked by putting a line over the units digit of the number. Arab mathematicians eventually used a comma (“,”) as a decimal separator, while the period (“.”) was adopted in France.

So, 1/2 is equal to 0.5.

This fraction is a non-repeating decimal number. People like these, because they’re easy to understand.

1/3 = 0.33333

This is a repeating decimal, and is not beloved quite so much because, if you look at it really, really closely, IT NEVER ENDS! But still, it can be represented as a fraction with integers in the numerator and denominator, so it’s still rational.

The numbers that really drove, and can still drive, people crazy are the ones that can’t be formed as fractions. Such as 1.20001213 + random non-repeating digits. There are a lot of these numbers, which is very irrational.

(To be continued.)

# Bokaro P ni Naritai, vol. 5

(Images used for review purposes only.)

I want to be a Vocaloid Producer, vol. 5, 1,500 yen, plus tax.
The magazine is falling into pretty much of a routine now, with the bulk being a repeat of the videos on the DVD. The new material consists of the 4-panel manga showing Rana learning something new at the “school” (getting the synth flute), a short conversation between Rana and the robo-panda on music theory (this time, reading sheet music and the concept of octaves), the write-up on one of the Vocaloid producers (this time, Chouchou) with examples of his previous works, and a page or two on other Vocaloid products.

The DVD has the regular tutorial videos (6-10 minutes each) on Singer-Song Writer, Vocaloid, and Miku Miku Dance, plus more voice samples of Rana speaking short phrases with different inflections, and a demo music video from the featured producer (Heart Break). Heart Break is a hard rock piece that comes close to sounding like death metal, and the graphics are just still images that spin around a lot. The pictures of Rana portray her as an older teenager, and are a bit disturbing as to how hard-edged she’s become. The music’s good, though.

The DVD does have extra model files, one for a small theater stage, and then a microphone and the electronic flute synth (pictured above).

(Rana gives up on the piano and gets the flute synth as a present instead. Plus, Robo-panda teaches Rana about octaves.)

I have to be honest, I’ve been busy for the last 2 weeks (new video games) and haven’t had time to watch either tutorial for MMD or Vocaloid all the way through. MMD takes the walking march cycle created in the last volume, and places Rana on the theater stage. Most of the tutorial is on how to get Rana to hold the microphone correctly and have it track her hand movements.

For Vocaloid, the demo walks you through the use of the Dynamics setting to make Rana’s voice sound even more realistic. Like some of the other controls, Dyn can be displayed as a magnitude level throughout the entire song. You use the mouse to drag control points to increase or decrease Dyn either linearly, or with curves. The final demo sounds very human-like.

My main interest this time was with SSW because it shows how to place notes on the sheet music. The demo song has a section that was left blank, and the video shows you the process of selecting the type of note to use from the note window, apply the notes to the score, and select, copy, paste, and adjust them. One of the projects I was working on last week is an animation of complex numbers, and I want to create some background music for it. I tried making a song from scratch in SSW, but I couldn’t figure out how to change octaves. I want a base guitar at the very bottom end of the instrument, and the default octave is way, way too high (sounds like a regular acoustic guitar, or almost a piano). I need to rewatch the SSW tutorial, and maybe the one from vol. 6, and then I’ll try again. I can say right now, though, that when I sit down to write music, I get really depressed fast, and want to give up immediately. Composition is not a natural activity for me.

Overall, though, this series is still really good, and I recommend it to anyone wanting to make their own music videos by themselves, if they don’t have to pay the import markup.

# Otona no Kagaku Newsletter #162

The latest newsletter showed up in email right after I posted that there wasn’t much new to write about. There still isn’t, but at least I have a newsletter telling me that, now.

The editors start out reminding the readers about the Rainbow Loom kit that came out in August, and then announce 3 events coming up in the next few days.

1) New Rainbow Loom Kit Releases
Due to the popularity of the first kit, a new Master Kit will be coming out on Dec. 5th, for 2,592 yen. Aimed at ages 6 and up, it will have a 52-page, A4-size, guide booklet, plus 10 colors of elastic bands and accessory parts.

The Cute Accessories kit comes out on Nov. 25, with an 84-page booklet and some more elastic bands, at 830 yen.
The Adult Cute Set hits the shelves on Dec. 16. 100-page, B5 booklet, more elastic bands and supporting parts, for 1000 yen.

2) Tokyo Maker Faire
There’s a new Maker Faire being held at Tokyo Big Site on Nov. 23rd and 24th (Sunday and Monday). Gakken will have demos and classes with several of their latest kits, including the Mini Theremin, the Electric Steel Drum and the Pocket Miku. Tickets are 1000 yen for adults, 500 yen for those 18 and under in advance. 1500 and 700 at the door. Hours are 12 PM – 7 PM on Sunday. 10-6 on Monday.

3) Otona No Kagaku email magazine members-only invitation
Kansai University has a program called MOOC, offering special chemistry classes through their online Gacco site. There will be 4 one-day courses on Nov. 29th (2 in the morning, 2 in the afternoon) on biotechnology. The courses will include online lectures and hands-on experiments. Gakken is offering a random drawing and 5 people will be selected to attend the classes. Open to email magazine subscribers only.
Course 1) Japan’s food culture: Experiencing fermentation (10 AM-1 PM)
Course 2) Boasting of Japan’s accomplishments: Make your own capacitor (10 AM-1 PM)
Course 3) Cutting edge medical science: Make a polymer for personal appearance (2-4 PM)
Course 4) Metals used in hybrid cars and airplanes: The strengths of inorganics (2-4 PM)

(I’m really not sure what course 3 is about. I think it’s on plastic surgery, using polymers to enhance skin tone.)

# Riemann prose, part 1

I’ve written about my obsession with prime numbers before, and I’ve created a few art projects that are based on, or influenced by, prime numbers. Now, one of the greatest unsolved problems in math is the Riemann Hypothesis, first proposed by German mathematician Bernhard Riemann in 1859, and it is believed to be intimately entwined with prime numbers. RH was one of David Hilbert’s listed 23 unsolved problems in 1900, and is currently one of the six unsolved problems from the Clay Mathematics Institute’s 10 Millennium list (\$1 million prize if you can solve just one). I’m running out of things to write about for the Gakken kits, backgammon, and programming the NSX-39 Pocket Miku, and I’ve never been able to get my head around RH. So, I’m going to waste some time and energy trying to explain it to myself. If you’re not interested, come back in a few months and see if the next Otona no Kagaku kit has hit the shelves yet.

The Riemann Hypothesis involves what’s called the Riemann Zeta function:

This is a function of the complex variable “s” that, according to the wiki entry, “analytically continues the sum of the infinite series, which converges when the real part of s is greater than 1”. (This is important, and I’ll get to that later.) Riemann’s Hypothesis says that the infinite sum will add up to zero only when the real part of s = 1/2.

What’s important to keep in mind here is that “converging” and “equals zero” are two different, but related, things. I’m interested in the zeros (and more specifically, the “non-trivial” zeros).

So, what does this all mean?

Let’s go all the way back and start from the very beginning.

If you bake a cake, you have one cake. Bake a second, identical cake, you have two cakes. Keep doing this and you’ll have a bunch of cakes that you can count: “1 cake, 2 cakes, 3 cakes, mwuhahaha! 3 cakes!”

These are the counting numbers, also referred to as “natural numbers”. They are positive whole integers, starting from 1, and incrementing by 1 in each step.

The older civilizations, including the Egyptians, Babylonians, and Mesopotamians, used pictorial counting systems, meaning that they had pictures of the numbers that weren’t actual numbers in and of themselves. “Zero” as a concept was an accounting placeholder, such as leaving a space between digits, rather than being a value along the x-axis. It wasn’t until the 9th century, in India, that “zero” was used systematically as a number. And it was the Indian mathematician and astronomer, Aryabhata, that defined in 498 AD, how the modern decimal system would work, “from place to place each is ten times the preceding,” where “ten” is “one followed by a zero”. With natural numbers, we can now easily add, subtract and multiply values on paper without having to deal with pictorial equivalents, or using counting sticks or an abacus.

(Natural numbers)

Currently, some mathematicians argue over whether the natural numbers start at “0” or “1”. Regardless, they’re positive integers.

Negative numbers took a long time to catch on, and were considered “false numbers”. Diophantus, in the 200’s AD, wrote that the equation “4x + 20 = 0” (x = -5) was absurd.

Historically, negative numbers show up in China in texts from the Han Dynasty (200 BC-220 AD), and a manuscript in India between 400 and 700 AD contained calculations with negative numbers, using “+” as a negative sign. European mathematicians didn’t really accept negative numbers until the 17th century (Fibonacci, in 1202, did allow that negative numbers could be used in financial problems when interpreted as debits). It wasn’t until Leibniz used negative numbers in infinitesimal calculus that they finally became a part of the lexicon.

(Negative and positive real integers)

(To be continued.)

# Catching up

One of the things I like about writing long, multi-part blog series is that it gives me something to post 2-3 times a week while waiting for the next kit to come out from Gakken. Unfortunately, doing this usually requires having something to write about, and that doesn’t always happen. Granted, my writing about something doesn’t mean that anyone wants to read it, but still, it’s better than having the blog go dead for 3-4 months at a time, I guess. Maybe. Or, maybe not.

Right now, I’ve got two topics that I’m going to continue for a little while – the Vocaloid Producer bi-weekly magazine DVD series, and a new rambler on how I’ve failed to plot the Riemann Zeta function in Excel. (If you know how to do this, please let me know so I can go write about something else.) I’ll start Zeta either Friday or next Monday.

In the meantime, there has been a very small amount of activity from Gakken.

First, on Facebook, was an announcement for an Oct. 25th in-store demonstration of the new Mini Theremin kit. The location was in Shibuya, and from what I can tell from the write-up, the demo featured theremin group The Putins.

Second is the addition of a new print interview with Aooni Yamane, for the Karada no Himitsu (Secrets of the Human Body) manga. Yamane is the manga artist on Meitantei Kageman, Dekochin and Oyaji Banzai. Of course, the interview is in Japanese.

# Final (?) notes on programming the NSX-39

The Pocket Miku has turned into much more of a learning experience than I’d expected it to be. The regular MIDI sections are pretty much the same as for the other instruments I have, such as the Korg Kaosillator and the A-300 MIDI controller keyboard, as well as the software synth packaged with Java. One of the big hurdles was in trying to read incoming messages from the Miku and aligning them with data requests made by Java to obtain the contents of the lyrics and command slots.  Then there was that whole thing with SysEx messages. Since I don’t use a sequencer app on my PC (yet), system exclusive messages aren’t something that I’d encountered before. As mentioned in an earlier post, SysEx is used to access hardware properties that you can’t normally get to via regular MIDI messages, although it’s possible for the manufacturer to make them available as ChangeControl options (if so, CC is faster than SysEx). This means that SysEx messages are device specific, and songs that you write that use SysEx for one instrument won’t sound the same if you run them on something else.

One of the bigger learning opportunities came when I decided to reverse engineer the command slots. The Pocket Miku has 128 command slots, which are blocks of memory that hold instructions to be executed when the associated event is encountered. Examples include playing “Hello” on power-up, initializing a lyrics string when the “A”-“E”-“I”-“O”-“U” buttons are pressed, or doing something customized by the user. You can see the contents of all of the command slots by sending multiple “Command Slot # Requests”.

Let’s start out simply programming a command slot first. The best example is from the Perfect Guide, which is to add a “keypressed beep” to the SHIFT key (which I’ve discussed before).

The SHIFT key is button SW7, and the command slot for SW7 pressed is #17 (0x11), CS_SW7D. So this is the command slot we’re going to write to. To program the NSX-39, we need to use SysEx (0xF0). First, we need the SysEx header for accessing the NSX-39 features:

F0 – Start of SysEx message
43 79 09 11 – Header for programming the NSX-39

After this portion, we specify the instruction to execute. 0x01 will request the version number, 0x0B lets us request specific command slot strings. To SET a command slot, the command is 0x0C (without the “0x” part).

0C – Request command slot # contents
11 – CS_SW7D – slot # for SHIFT pressed

I’ve finally got a handle on the next portion. In MIDI, bit 7 (the most-significant bit of an 8-bit byte) specifies whether the byte is data, or a message status byte. The MIDI instruction for NOTE ON is 0x90 (1001 0000). Putting a NOTE ON instruction in the middle of the SysEx string will result in an error – “Illegal SysEx character. Only F0 and F7 are allowed.” To get around this, we need to convert the instruction from three 8-bit bits to four 7-bit bytes with padded leading 0’s.

Specifically, for our SHIFT key, I want to use NOTE ON to play the open triangle from the percussion instrument set on channel 9 of the general MIDI instrument sound bank, and I’ll randomly pick a velocity of 0x65. Since the triangle is key 81 (0x51) on the keyboard, the MIDI message would be

99 – Note on for channel 9
51 – Open triangle
65 – velocity (volume)

99 51 65

To convert this, turn it into binary:
10011001 01010001 01100101
0000100 1100101 0100010 1100101
00000100 01100101 00100010 01100101
Then convert back to hex:
04 65 22 65

To complete the SysEx string, add 0xF7 as “end of SysEx message”.

The full message would be (in Java, no spaces):
F0 43 79 09 11 0C 11 04 65 22 65 F7

If we’re using sequencer software like Acid Studio or GarageBand, we’d just activate the SysEx box and type this message in as-is. In Java, we need to use a SysEx object kind of as follows:

SysexMessage sysexMessage = new SysexMessage();
sysexMessage.setMessage(byteMsg, byteMsg.length);
nsxRcvr.send(sysexMessage, -1);

Ok, so far so good.
Let’s get the string back. As mentioned above, we need to use SysEx to talk to the NSX-39, and the command we want to send is 0x0B – Request Command Slot.

F0 – Start of SysEx message
43 79 09 11 – NSX-39 header
0B – Request command slot contents
11 – Desired slot # (CS_SW7D = SHIFT pressed)
F7 – End of SysEx message

F0 43 79 01 00 0B 11 F7

This will cause the NSX-39 to come back with:
F0437909111B04652265F7

If we add white space to make it more readable, and divide it into lines with comments:
F0 – Start of SysEx
43 79 09 11 – NSX-39 header
1B – Command Slot contents (note there’s no slot number)
04 65 22 65 – The contents of the returned slot
F7 – End of SysEx

For amusement value, let’s look at another response string returned from the NSX-39:
F0437909111B0A0801000A060000F7

F0 – Start of SysEx
43 79 09 11 – NSX-39 header
1B – Command Slot contents (unknown slot)
0A 08 01 00 – Command 1
0A 06 00 00 – Command 2
F7 – End of SysEx

This anonymous slot executes two commands. From this example we can see that the commands are always 4 bytes each. We’ll have to look at the table on page 23 of the NSX39MIDIGuide.pdf to get the meaning of these commands:

0A 08 01 00 – Activate DOREIMI mode (play “Do Re Mi” on the keyboard)
0A 06 00 00 – Turn off NSX-1 compatibility mode

I’ll tell you now that this is slot 0, CS_MIDI_INIT, which activates on power-up, after the NSX-1 initialization completes. That is, whenever I turn on the Pocket Miku, the NSX-1 chip initializes, and then CS_MIDI_INIT is activated. The CS_MIDI_INIT command slot contains “DOREMI Mode On” and “NSX-1 Compatibility Off”. That’s it. (Although, when CS_MIDI_INIT finishes running, it activates command slot CS_MIDI_INIT2, which in turn calls CS_MIDI_INIT3, and you could put more commands in those 2 slots if you wanted.)

If you’ve got the MIDI Guide pdf open, then look at the rest of the commands. Most of them are fully-spelled out and start with 0x08 – 0x0F. The exceptions are DIRECT_MIDI_1 – DIRECT_MIDI_3 and DIRECT_MIDI_OUT_1 – DIRECT_MIDI_OUT_3. The first set sends direct data to the NSX-1 from the NSX-39. The second set is used to treat the NSX-39 as a MIDI controller by sending the data directly to the USB port.

The importance of these exceptions lies in the fact that the data is 7-bit encoded. If we go back to the contents of the CS_SW7D slot, we had obtained:

04 65 22 65

According to the NSX-39 MIDI Guide, this is a DIRECT_MIDI_3 command. To decode it, convert it to binary:
00000100 01100101 00100010 01100101
Take the right-most 7 bits:
1100101
Trim the remaining trailing 0 (and the space) and add those 7 bits back:
00000100 01100101 001000101100101
Remove the 8 right-most bits and call this D2:
D2 = 01100101 = 0x65
This leaves us with:
00000100 01100101 0010001
Take the right-most 6 bits:
0010001
Trim the trailing 0 and space and add those 6 bits back:
00000100 01100101010001
Cut the right-most 8 bits and call them D1:
D1 = 01010001 = 0x51 = 81
This leaves us with:
00000100 011001
Take the right-most 5 bits:
11001
Trim the trailing 0 and space and add those 5 bits back:
0000010011001
Take the right-most 8 bits and call them D0:
D0 = 10011001 = 0x99 = NOTE ON channel 9

Putting D0 D1 D2 in order:
99 51 65 = Note On, channel 9, Open Triangle, Velocity = 101

Granted, we could have predicted this just by looking at the encoded data, but knowing how to decode everything in the return strings means that I can now write encoder-decoders in Java, and have all of the command slots in human-readable form within a matter of a few seconds. This is important when looking at things like the string for CS_SW6U (VIBRATO button released):

CACCO_START, DIRECT_MIDI [CONTROLCHANGE Ch 0 (MODULATION 32)], TIME_WAIT 000013, DIRECT_MIDI [CONTROLCHANGE Ch 0 (MODULATION 28)], TIME_WAIT 000013, DIRECT_MIDI [CONTROLCHANGE Ch 0 (MODULATION 1E)], TIME_WAIT 000013, DIRECT_MIDI [CONTROLCHANGE Ch 0 (MODULATION 14)], TIME_WAIT 000013, DIRECT_MIDI [CONTROLCHANGE Ch 0 (MODULATION 0A)], TIME_WAIT 000013, DIRECT_MIDI [CONTROLCHANGE Ch 0 (MODULATION 05)], TIME_WAIT 000013, DIRECT_MIDI [CONTROLCHANGE Ch 0 (MODULATION 04)], TIME_WAIT 000013, DIRECT_MIDI [CONTROLCHANGE Ch 0 (MODULATION 03)], TIME_WAIT 000013, DIRECT_MIDI [CONTROLCHANGE Ch 0 (MODULATION 02)], TIME_WAIT 000013, DIRECT_MIDI [CONTROLCHANGE Ch 0 (MODULATION 01)], TIME_WAIT 000013, DIRECT_MIDI [CONTROLCHANGE Ch 0 (MODULATION 00)], TIME_TAIL, DIRECT_MIDI [CONTROLCHANGE Ch 0 (MODULATION 00)], CACCO_END_TIME 0F

Try reading that as pure hex code. (As a hint, “cacco” is the Japanese word for “parenthesis” or “bracket”.)

I may be the only person who cares at all about this. I whined some more on the U.S. Yamaha forums, and was told that the NSX-1 chip is only available in the Asian region, not in the U.S., and that I have to try finding the documentation from a server in Asia somewhere. So, this isn’t really on anyone’s radar, if they’re not Japanese. Now that I have my Java applet running, I’ll put everything away to focus on something else (maybe video games).

# Sierpinksi again

I like the Sierpinski-inspired fractals.  They’re (mostly, usually) easy to hand-draw in paint programs like Gimp that have snap-to-grid functions. The classic is the Sierpinski Triangle, in which you take an equilateral triangle and remove the middle quarter, and just keep repeating the process on the remaining portions down infinitely. This gives you something with infinite surface area and zero mass. For some reason, though, Gimp doesn’t have infinite precision on pixel width, so I usually have to stop after a few iterations. On the other hand, because each triangle is a copy of the triangle one-half the length of its side, you can invert the process by printing three triangles and taping them together, then repeating again, to make a huge Sierpinski paper blanket that’s infinitely large (if you have enough paper and your company pays for the ink).

(Sierpinski Triangle)

(Sierpinski Carpet.)

You can do the same thing with a square, which gives you the Sierpinski Carpet, and circles (which I haven’t tried doing by hand). If you have a CAD package and a 3D printer, you can build real three-dimensional versions, too.

(Koch Snowflake, from the wiki page.)

Now, there’s the opposite approach, which is to draw the triangle, and add triangles at the sides, pointed outward, that are 1/3 the length of each side. If you only plot the exterior contour, you get the Koch Snowflake (I haven’t tried drawing this by hand because Gimp’s not really suited for it).

I wanted to know what would happen if I combined the Sierpinski Carpet with the Koch Snowflake, applying the algorithm to all open surfaces. The result isn’t really what I was hoping for, but if I use a coloring scheme that fades to white with each new iteration, it’s kind of interesting.

(Extrusions with seeds of side=8 and 9.)

The next step is to add variations. Instead of changing the length of the side of each extruded layer by 1/3 of the original length, what happens if the sides are prime numbers (not including 2)? A square of length 3 is the smallest possible “dust”, and the recursion process stops there. So, go to a “seed” square of length 5, and the make the first extrusion 3 (you can see the result in the upper-left corner of the below picture). Next, use a seed cube of length 7. The first extrusion will be of length 5, and the second (extruded from all “naked” sides of the 5 cubes) is length 3. Stop. Go to a seed of length 7, and repeat. Very quickly, the extruded sides overlap, and then start curling in towards the center of the seed, making it really hard to keep track of them all by hand by the time you get up to 13. At 19, I decided to not calculate the interior, and just fudged it with shrinking squares with sides of prime number lengths.

(Lower left, going clock-wise: Seeds of 3, 5, 7 and 11. The central object is kind of a 13-19 hybrid.)

It’s something to do when you’re bored.

# Programming the Pocket Miku, Details, Part 6

Most of what I’d done in the last blog entry was to summarize the translations of Polymoog’s MIDI guide, which brings me to page 16 of that guide. Most of what follows concerns manipulating the pointer to the phoneme character strings that Miku “sings” when you touch the stylus to the carbon keyboard. You can issue these commands either as a “command” (0D) or as an instruction string placed in one of the command slots (0C) to be implemented when a particular button action occurs (pressing “A”, or releasing SHIFT + “U”).

F0 43 79 09 11 0C … F7, or
F0 43 79 09 11 0D … F7

These character pointer operations include setting the pointer (MOJI_SET_KASHI = 09 05 00), incrementing the pointer (KASHI_POS_INC = 09 01 00 00), selecting the pointer position (0 to 63: KASHI_POS_SEL = 09 02 00 nn, where nn is 00 to 3F), selecting the lyrics slot (KASHI_SLOT_SEL = 09 03 00 0n, where n is 0 to F), and phoneme character entry (MOJI_SEL = 09 04 00 nn, where nn is 00 to 7F from the character table on page 10 of Polymoog’s MIDI guide). (Japanese translations appear below.)

Page 17 gets into some of the other commands from the command table on page 23, such as NOTEON, NOTEOFF, ADV_PB (pitch bend), VOL_UP, VOL_DOWN, etc. They work as you’d expect them to as regular MIDI messages.

F0 43 79 09 11 0D 0A 02 00 00 F7 – Like pressing the Volume Up key on the front panel.

VOL_SET: Set volume level (0-8)
VOL_UP: Increase volume one level
VOL_DOWN: Decrease volume one level

KEY_UP: With NOTEON or REVOICE,
KEY_DOWN: changes the keyboard up or down one octave.

TUNING_STOP: Lets you calibrate the carbon keyboard.
TUNING_START:
TUNING_TOGLE:

NSX1_GOKAN_OFF: Turns NSX-1 compatibility mode on and off.
NSX1_GOKAN_ON:
NSX1_GOKAN_TOGLE:

MODE_DOREMI: Puts keyboard into Do-Rei-Mi mode.
MODE_NORMAL: Miku sings from the lyrics tables.

MIDI_RESET: (Panic) Resets the phoneme chip.

ROM_RESET: (Initialize) Returns the Flash ROM settings to the defaults .

Section 3-6 on page 20 discusses the concept of CACCO, which is the Japanese word for “brackets” or “parentheses”. This mode is used to assign a string of unrelated commands to a specific command slot as if they were within a pair of parentheses. Once CACCO_START is encountered, the NSX-39 will execute the subsequent commands until encountering CACCO_END.

The example is to assign certain commands to the SHIFT button when pressed (CS_SW7D = 11).

0C 02 00 00 – CACCO_START (command list start)
09 02 00 00 – KASHI_POS_SEL(0) (reset lyrics list character pointer to position 0)
0C 03 00 0A – CACCO_END (command list end)
0C 02 00 00 – CACCO_START (command list start)
09 05 00 00 – MOJI_SET_KASHI (set pointer to play current character)
08 01 00 00 – REVOICE (replay the character)
09 01 00 00 – KASHI_POS_INC (point to the next character in the lyrics list)
0C 03 00 05 – CACCO_END (command list end)

From these commands we can see that when you press the SHIFT key, Miku will sing the first character in the currently selected lyrics slot.

The full SysEx message would be (all one line, no comments):

F0 43 79 09 11 // Start of SysEx message (fixed)
0C 11 // Change Command Slot for CS_SW7D
0C 02 00 00 // As given above
09 02 00 00
0C 03 00 0A
0C 02 00 00
09 05 00 00
08 01 00 00
09 01 00 00
0C 03 00 05
F7 // End of SysEx message (fixed)

Section 3-7 (page 21) describes timing. You can specify a wait time (TIME_WAIT = 0D nn nn nn, where nn can be from 00 to 7F). A value of 500 is roughly 1 second. You can cancel wait time with TIME_CANCEL (0C 05 00 00), and specify a TIME_TAIL (0C 04 00 00), which lets the timing buffer clear out. The pattern would look like:

CACCO_START > A > B > TIME_TAIL > C > D > CACCO_END

The example on page 22 is to assign a string to VOL UP + VOL DOWN + “A” (panic reset). (All one line, no comments.)

F0 43 79 09 11 // Start of SysEx message (fixed)
0C 32 // Change the command slot for CS_SW89_1D (Up + Dn + A)
04 65 12 66 // Direct MIDI 3 command mode to play a music note (see below)
0C 02 00 00 // CACCO_START
0D 00 00 C4 // Wait 200 ms
0A 07 00 00 // MIDI_RESET
0C 04 00 00 // TIME_TAIL
0A 07 00 00 // MIDI_RESET resets even with Cancel
0C 03 00 0F // CACCO_END
F7 // End of SysEx message (fixed)

Note: The 04 65 12 66 portion is a repeat of the 7-bit direct MIDI format, which takes “99 49 66” (Note Number 49 from the Drum Kit sound bank ON with a velocity of 0x66) and converts it to “04 65 12 66”.

Everything else is tables. Page 23 shows the command table. Translations:
“kashi” is “song lyric” (used to refer to the current lyrics string).
“Gokan” is “compatibility mode”.
“cacco” is “parentheses”.

Pages 24 to 27 describe the operations of the Command Slots. These are addresses within the Flash ROM pointing to instructions to execute when specific events occur, such as pressing or releasing one of the front panel buttons, power up (kidou), turning audio on/off, or activating the USB port. The slots themselves are listed in the tables on pages 28 to 30. I think most of this is self-explanatory so I’m not going to translate the tables. If there are enough requests for it, though, I’ll reconsider.

# Backgammon, Part 12

The point to starting this series was to talk about making an AI for a backgammon RPG. With the yahoo game, the AI makes some boneheaded mistakes, such as unaccountably leaving blots in White’s home field in the mid-game, occasionally avoiding Red’s blots in order to play it safe for the running game, and to switch to a running game too early. Then again, yahoo game’s “dice” aren’t really random, with double 6’s, and 6-5, 1-3 combinations coming up way too frequently in the first one or two turns of the game for White. This means that White almost always has the advantage at the beginning, and you the player need to stick to a back game. As I said, I can beat the yahoo game 80% of the time, sometimes with a gammon, and a backgammon maybe once every 20 games. (A gammon is when one side wins when the other hasn’t started bearing off; a backgammon is when one side wins and the other side either still has one stone in their back field, or on the bar. A gammon is worth x2, and backgammon is worth x3. A human player will almost NEVER allow themselves to be backgammoned.)

It is possible to hardcode the first 2-3 turns using a table of dice rolls and the standard opening moves. The alternative, though, is to assign weights to certain outcomes, which lets me create NPCs for the game that can have varying tolerances for different kinds of risks.

A safe play is to move a stone to an existing block, making new blocks when possible and only leaving blots at the lowest numbered points (1-5 for White, 20-24 for Red) when unavoidable. Desire to initiate a running game would encourage the AI to move its stones out of its back field as early as possible, while the opposite would cause the AI to move the stones in the middle of the board (those on point 12 for White, 13 for Red) to maximize the number of blocks in the home field. An increased risk tolerance plus high “patience” would result in blots mid-board in the first 2-3 turns, and a possibility of blots being sent to the bar.

A patient game would tolerate being sent to the bar once or twice. A running game would want to check how many pieces would be sent to the bar to end up in its home field to mess up the game (ref. – hitting too many blots = bad). All games would check whether the running game has been initiated and then focus on bearing off the maximum number of stones per turn. They should also check whether one of their stones is on the bar when the opponent has the entire home field blocked (no point in rolling the dice if there’s 0% chance of getting on the board). Finally, a strategic game would distribute an extra one or two stones on blocks to make construction of long walls (4 or 6 blocks in a row) more likely.

Possible algorithm:

Set up board, set doubling cube to 1
Check who starts
(Roll one die each for high)
Starting player assigned as current
While no winner
current player rolls two dice
check if on bar
(if on bar, check if can move to board
if yes, check risks and opportunities and move to open point

if no, change current player
if yes and on board and can keep playing, keep playing)

For all points with player’s stones:
If not running game:
For all dice combinations:
Assign risk factor to each point that stone can land on
Assign opportunity factor to each point that stone can land on (includes bear off)
Identify opponent’s blot within reach of that stone and assign damage factor

If opponent can be sent to bar:
calculate number of opponent stones going into home field
Assign risk value to player’s home field blots
Check difficulty of returning to board if Opponent’s bar stone hits home field blot
Check length of opponent’s wall, if any
Compare calculated risk to NPC’s risk tolerance
Compare calculated opportunity (wall size, extra stones on point, etc.)
Compare blot hit count to NPC’s bloodthirst level
Compare opponent wall length and location to stupidity level
Move stones based on best-match pattern
Check all stone locations for initiation of running game
(If running game, set flag)

If running game:
Calculate maximum stone bear-off for each die combination
Compare bear-off count to NPC stupidity level
Move stones based on best-match pattern
Check for end of game

(If one side has 0 stones left:
assign winner
calculate value of game (score)
set end of game flag
Show Play Again? screen

Calculating risk:
Identify points that will have blots after a given move
For each blot, calculate percentage chance of being hit by ANY opponent stone
Calculate chance of having 3 or more opponent’s stones in your home field.

Calculating damage:
For each blot, get rough count of turns to return to current location if sent to the bar
If any blot goes to the bar, calculate chances of returning to the board
Divide lost turns by chances of returning to the board (check for divide by 0)

Calculating benefits:
Part A:
For all points with stones, identify which ones can hit an opponent’s blots
For hit-blots, get rough count of turns to return to current location
Calculate odds of hit-blot returning to the board
Divide inflicted lost turns by chances of returning to the board (check for divide by 0)

Part B:
Calculate number of points making up a wall, check wall length
Assign weights to new points based on closeness to the tray
Add benefit of making a longer wall closer to the tray
Assign weights to making points in the wall with only 3 stones on them

Part C:
Identify points that block the opponent from making a running escape when rolling 6’s.

There are probably some other niceties to include in the algorithm, but until I start writing the game, they can wait until later.

Fin