Feeds:
Posts
Comments

Archive for the ‘Music’ Category

JC and I have added mtalk to our sf2a — solfege to audio — distribution. Once installed, you can do this:

% mtalk 'Please get me a quart of milk at \
   the store.  Thanks.' -p -t tempo:144

The option -p means “play the audio file immediately,” and -t temp:144 sets the temp. Here is what the result sounds like:


Please get me a quart of milk at the store. Thanks.

This little programming project (we have to get our fun somehow:-) was inspired by James Gleick’s book, The Information. See previous post

HH.

Read Full Post »

Many changes. (1) New name –sf2a (2) source code is at github. (3) At github click on download button if you wish to download. (4) Installation on mac: untar or unzip downoaded file, cd to the resulting folder, run sudo sh setup.sh -install YOUR_USER_NAME; (5) after install, run sf2a 'do re mi' A file out.wav should be created. This is the audio file. (6) There is a musical dictation program, dict that creates audio files and a web page for dictation exercises based on the data in a text file. Use the file dictation.txt in the install folder for an example. Just run dict -m in that folder, then open the web page index.html. (7) For a draft manual, see this web page.

All this works on a mac. Adapting it to Linux is easy. Just change the values of $INSTALL_DIR and $BIN_DIR in setup.sh. I don’t know enough about PC’s to advise on this — one ought to be able to modify the file setup.sh

Read Full Post »

Sonatina

The above is a visual representation of the opening measures of Muzio Clementi’s sonatina, Op 26, No1 as rendered by sf2sound — a kind of command line synthesizer that takes a stream of solfa symbols as input. This is homework for an eventual ear-training program. In any case, here is the audio file:

theme

One of the challenges has been in shaping the waveforms of the individual notes so that they fit together without making annoying pops. A simple exponential decay did not work, although that is good for making the sound more or less percussive. What I discovered is that (at a minimum), one has to shape the attack and release of the note. For the moment I have done this by shaping the wave form with a simple quadratic function.

I’ve been experimenting with various settings and algorithms in order to get a better or more interesting sound. The sound file you hear is slightly more complex than the other ones I have posted. In previous version the sound was either (1) an exponentially damped sine wave, or (2) the former with some kind of shaping of the amplitude profile as mentioned above. In the current version, higher harmonics are mixed with the fundamental tone. Here is the code snippet of quad2samp where the mixing occurs:

// Form the sine wave and add harmonics to it
samp = sin(W*phase);
samp += -0.4*sin(2*W*phase);
samp += +0.2*sin(3*W*phase);
samp += -0.1*sin(4*W*phase);

I’ve observed an odd but likely well-known phenomenon (or is it an illusion?). When the sound consists of a shaped sine wave, i.e. no (deliberate) harmonic mixture, I find it painful to listen to it, even at relatively low volumes. Painful in the most elementary sense of the word, not because the poor artistry of sf2sound! When I mix in higher harmonics in some degree, the (physical) pain diminishes. I suspect this because the acoustic energy in the first instance is concentrated near a single frequency, so a small number of hair cells in the inner ear are overstimulated. When the same energy is spread among the various harmonics, albeit in unequal proportions, it is also spread over more hair cells, so that individual cells are not overstimulated. Perhaps someone who really knows what is going on can comment.

I’ll close with one more image — a close-up shot that shows how the wave forms from two adjacent notes join smoothly. The jaggedness of the sound wave reflects the addition of higher harmonics to the sine wave representing the fundamental tone.

HH

Sonatina: close-up

Read Full Post »

We combine C and Python programming to transform a sequence of solfege syllables, e.g., do re mi re do, into a sound file.

1 | 2 | 3 | 4 | 5 | Source Code

In our last post we used tfork and a few unix commands to construct a sound file for an A major chord, A C# E A’. The idea was (1) to make text files representing the sounds of the individual notes using tfork, (2) glue the text files end-to-end using cat, (3) convert the resulting big text file into a .wav file using text2sf.

This works fine for short “melodies,” but it soon gets tedious — and out of hand. A better way is to write a short program that does all this for you, given a text string of solfa syllables like “do re mi re do”. This is what we do in the Python program solfa2sf. Below is the sound produced by


./solfa2sf -w foo 0.3 0.1 do re mi re do

SOUND OF FOO

SOURCE CODE for solfa2sf

In running solfa2sf, the arguments are as follows: (1) an option: -d for “dry run”, i.e., no output, -v for an output file with verbose messages, -w for wet, the opposite of dry: produces the output .wav file with few messages; (2) the file name; foo results in an output file foo.wav, (3) the note duration in seconds, (4) the decay time, (*) the solfa syllables.

If you use a small decay time, the sound is percussive, like a marimba, or even a drum. If you use a large one, it is more like an organ. Try delay times of 0.01, 0.1, and 1.0 to see what the effect is.

Python is very good with strings, lists, and dictionaries, which is what we need to parse and handle an input string like “do re mi re do’. C is the best tool for fast computation. So we use them together! As you can see from the source code, we call on the C program tfork using the Python command os.system. Like a carpenter, we use saw, chisel, hammer, etc. as needed for the task at hand.

HH

Read Full Post »

When I was recovering from a serious coding binge back in Iceland, long walks along the seashore and playing the piano were the two things that saved me. Since then, I’ve tried to lead a more balanced life: no coding after sundown, a mix of activities — reading, walking, seeing friends, hanging out at the neighborhood bar, cooking, playing music. The point is to do several things, not just one — one terrible thing that swallows up both the day and the night, demanding your full attention for five, ten, fifteen, twenty hours at a stretch until you finally lie exhausted, shipwrecked in the dawn, clinging to the foot of the bed as if it were a lifeboat, the mess of dishes and books piled high, crowding the sacred space before the altar of the computer.

I’ve tried to keep this healthy routine, part of which is to meet with friends every Thursday to play music. We are so-so amateur musicians, but we have a lot of fun, and also a new “activity:” each of us brings an original composition to play, either individually, or as a group. Well, at the beginning we were pretty bad, but we have learned a lot, and we have had a lot of good times. One of the house rules is that after a piece is played, we all have to improvise on it. This way we all share in the embarrassment, the good musical moments, as well as the beer! I promise to post something of my own soon, since the last person to do so has to buy food and drink for the whole group. I am, however, taking the liberty of linking to a piece by one of the other players:

short piece for solo cello

There is more … this is just the first line of the piece:-)

HH

Read Full Post »