Magical Music Machine

Music is a fascinating blend of art and math. The creation of a song is absolutely an artistic, creative act — but one which generally follows quite a few explicit and implied rules. The music that we enjoy has patterns — if you play the major scale CDEFGAB and then stop, Western ears “want” to hear that final tonic C. We generally find major and minor triads to be harmonious, and generally find other combinations of tones to be dissonant.

A while ago, I came across a fascinating YouTube video on Shostakovich’s Fugue in A Major. Rather, it starts out in A and then goes on a harmonious tour of the Circle of Fifths, modulating only into keys that can be reached by a direct harmonious transition. C major, for example, could modulate into A minor, since C and E form part of the A minor triad. It’s beautiful, and seems to be able to just dance around the Circle of Fifths at will without creating any dissonances. It sounds like the sort of music gemstones would listen to.

That fugue (and video), along with having recently discovered FreeBasic’s MIDI capabilities gave me the idea to try writing a program to play random notes, choosing only from those which made musical sense. First, I had to find out what that meant — and an easy first answer turned out to be “those notes that form major or minor triads.”

From there, I made an Excel spreadsheet to figure out which transitions were possible. Neglecting octave duplicates, it turns out that for each pairing of two notes (that have to start out as either a minor third, major third, or fifth apart for this to work), exactly two new notes are possible — one major and one minor — since any two notes that are a minor third, major third, or fifth apart are musically ambiguous and can form one unique major and one unique minor chord. C and G, for instance, could form C major or C minor. C and E could make C major or A minor.

Seeding the system with C and E, I turned it loose and recorded the output with Audacity. The result is an aimless random walk around the piano keyboard, with few limitations — except that it never plays any dissonant notes. It’s a monkey at a piano keyboard, but either a minimally musically-inclined monkey or a charmed keyboard, enchanted to never play a sour note. (There’s also provision to bring the melody up or down an octave if it gets too low or too high — the farther from Middle C it gets, the more likely it is to be shifted.)

[Stochastic Sugar]

The next step was to add some variation. Tempo was easiest to change, so I added some code to vary the tempo between two limits. (In retrospect, the high limit may be a little too frenetic.)

[Chromatic Wanderings]

With the tempo variations, this sounds a bit more human, but still lacks any real sense of where it’s going. At this point, I started wondering what would happen if it were to show bias in which transition it chose. For each possible new note, it can pick major or minor — so I decided to try biasing it one way or the other.

First, I tried making it 95% likely to take the major branch and 5% likely to take the minor one. Even though I knew this would result in a lot of major-key scales, it was still fascinating to see what a change in the music’s mood could be made, just from tweaking a few numbers.

At some point (maybe here), I also added a 1/8 probability of simply repeating the second-to-last note played, allowing for the possibility for the melody to pause between keys and perhaps return to an original key before committing to a new one.

[Synthetic Optimism]

Biasing for major turned out well, so of course the natural thing to do next was to bias for minor. This didn’t result (at least to my ears) in a melancholy sound, but instead a more introspective one.

[Infinite Introspection]

Next, I wanted to try producing music which switched from major to minor. So instead of choosing the major or minor transition based on constant probabilities, I set it to choose major with 95% probability, but to switch this to 95% minor a small fraction of the time. This results in a piece which commits to major or minor scales, but periodically has mood changes. The music now understands both major and minor, and goes through phases of each.

[Major and Minor]

There’s still a lot to explore here — even with these rules, the melodies that result are still closer to the random, unscripted sound of windchimes than they are to Vivaldi or Mozart. Adding some dynamical systems to influence the mood would probably add quite a bit of interest. Teaching it about motifs, themes, counterpoint, and all the rest … will be trickier. For now, there’s enough musical knowledge baked into the rules that the sounds produced at least sound “syntactically” correct, though — and every so often, it stumbles across beautiful-sounding motifs and chord progressions.

Its output is plausible enough at this point that if it were playing quietly in the background of a posh store, most customers would think it’s fancy classical music (even if the music majors would be shaking their heads at the lack of any real musical plan.) It’s acceptable-to-decent meditation music as it is, and could provide some interesting raw materials for the creation of handcrafted music.

And if you want a constant stream of happy, overcaffeinated, upbeat Musak, basically guaranteed to create endless original-if-soulless major triads 24/7 with no repeats, now there’s an app for that.

[The Fountain Of Happy]

(All songs CC-BY-NC-SA 2020 M. Eric Carr / Northlight Cyberacoustics.)

Posted in BASIC, Coding, Math, Music | Leave a comment

Black Garlic

I’m not a fan of spicy foods. Heinz 57 is, for me, what hot sauce is for most normal people. I never understood the appeal of black pepper, since it tastes like hot coals on my tongue. Similarly, I usually find garlic to be overpowering and painful rather than flavorful to taste, and only really used it in garlic bread as an excuse to consume butter.

Then, shopping in Wegmans one day a couple of years ago, I discovered black garlic. It’s botanically still garlic — but completely different. When garlic cloves are gently heated over the course of several weeks, they undergo a Maillard reaction that breaks down the sharp garlicky enzymes into smoother, subtler sweet and umami flavors. Just like time can turn grape juice into wine, a couple of months of gentle heat can turn cloves of garlic into something magical.

A bulb of black garlic, fresh from the fermenter.
(Two months ago, this was a bulb of fresh, white garlic.)

The recipe is a lot simpler than you might think. Wrap bulbs of fresh garlic (the same kind you’d use to sort out a vampire problem) tightly in plastic wrap and then aluminum foil, place them in a smart pot or crock pot with Keep Warm setting, and leave them alone for six to eight weeks. (I started mine at the end of August and harvested today, November 1st.) You could probably pack the cooker full, if you wanted to do a lot of them. Yield is one bulb per bulb.)

NOTE: DO NOT USE A “COOK” SETTING — EVEN “LOW.”
You want the bulbs to stay in a warm, humid environment — around 85% humidity and 70C.

The rest of the batch in the Smart Pot.
These are done — but you can’t tell without opening them (or smelling them.)

After a couple months in the cooker (pro tip: get one that doesn’t helpfully turn itself off periodically), they’re done. Shut it down, let them cool, and unwrap…

The rest of the cloves. I’ll keep them wrapped in the plastic for now.

Taking one clove apart for science reveals a complete transformation inside — the cloves have been transformed from pungent, acrid fresh garlic into coal-black lumps. Separating them from the garlic skin, I got about 22g of cloves from one bulb.

The bulb was very dry and, while not fragile when whole, disassembled easily.
The cloves of garlic, fermented into black garlic.
I believe they should be sticky and gummy; these were hard and dry.

The black garlic I bought from Wegmans had sticky, gummy cloves — which were messier to extract but tasted great. The ones from this homemade batch were hard and dry — very easy to clean up, but slightly bitter-tasting along with the characteristic sweet umami flavor. It’s nothing a dash of sugar won’t fix, but I may try cooking the next batch for six weeks instead of two months.

I ground some up and mixed it with mayonnaise.
Not bad, but slightly bitter. Two months may be a couple weeks too long.

To make your own:

* Wrap bulbs of fresh garlic in plastic wrap and then aluminum foil;

* Place them in a covered smart pot or crock pot (on Keep Warm) for about six weeks;

* That’s it. Enjoy!

Posted in Food, HOW-TO | Leave a comment

Warranty Not Void If Removed

Occasionally, bureaucracy gets it right. But getting the word out is often another matter.

We’ve all seen devices with those “WARRANTY VOID IF REMOVED” stickers. We may be curious about what’s inside that Xbox or Roomba, but breaking the manufacturer’s seal would void the warranty.

Well, it turns out that, in the U.S. at least, those stickers not only have no legal force — but are themselves illegal. Manufacturers, according to a 2018 ruling by the Federal Trade Commission, shall not make warranty coverage contingent on using branded parts or service. Since one of the specific warnings in the press release refers to “the warranty seal,” it is implied that this extends to manufacturer warnings that opening the cover will void the warranty.

So go ahead — do that DIY repair. (It’s better for the manufacturer than RMA’ing it, and better for the environment than throwing it out.)

Posted in Current Events, Digital Citizenship, Electronics | Leave a comment

Comma Delimited

Some of the most useful tools are the simplest. I would argue that simplicity is often why those tools are the most useful.

The humble .csv file is a good example of this. It may even, other than the question of character encoding, be one of the only things nearly all programmers can agree on. It’s almost up there with “bytes have eight bits.”

.CSV files, named for the traditional file extension dating back to the days of DOS, are just about as simple a data format as there is. CSV stands for Comma Separated Values — and that’s just what these files are. Raw data, split into columns by commas and into rows by CR/LF combinations (okay, this varies by system, too.)

Although .csv files aren’t as flexible or self-documenting as modern formats such as JSON, they are both (generally) human-readable and very simple to programatically create and parse. Practically anything that works with data can export them, so they have become a significant lingua franca of data analysis.

It’s not as flashy as XML, but there’s something to be said for a format that’s easily readable by desktops, microcontrollers, and humans.

Posted in Coding, Tools | Leave a comment