Feeds:
Posts
Comments

Posts Tagged ‘sine wave’

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 the power of tfork and text2sf with the magic of unix to construct a sound file for an A major chord.

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

A Chord

In Audio Programming 1, we compiled the tfork.c program in chapter 1 of the Audio Programming Book, Richard Boulanger and Victor Lazzarini, editors. This program , together with text2sf, gave us the tools needed to algorithmically construct simple sounds, namely an exponentially decaying sine wave. We used these tools to fabricate a file that represents the sound of a tuning fork.

Simple as these two tools are, they gives us the means to construct more complicated sounds without any additional C programming (fun though that is!). We will use the magic of unix. To begin, a short shell script:


# Language: unix/sh
# File: sound.sh
# Example: sh sound.sh 440 a --- writes text representation of
# a 0.2 second 220 Herz sound to a file a.txt

./tfork $2.txt 0.2 $1 44100 0.2

Using sound.sh, we make four sounds, each 0.2 seconds in duration, with frequencies of 220, 275, 330, and 440 Hertz. These correspond to the notes A, C#, E, and A’ = A one octave higher. The frequency ratios are C#/A = 5/4, E/A = 3/2, and A’/A = 2. Thus we are using Pythagorean tuning, in which pitch ratios in the scale are rational numbers with small numerator and denominator.

Let us now execute the following commands:


% sh sound.sh 220 a
% sh sound.sh 275 c#
% sh sound.sh 330 e
% sh sounds.sh 440 a2

The result is the creation of text files a.txt, c#.txt, etc., which represent the given sounds. Next, we concatenate these files, putting a.txt first, c#.txt next, etc:


% cat a.txt c#.txt e.txt a2.txt >chord.txt

Then, we convert chord.txt into a .wav file:


% text2sf chord.txt chord.wav 44100 1 1.0

To conclude, we play the file:


play chord.wav

Here is the sound:

A MAJOR CHORD

Clearly there is more to do, among which are  (1) Clean up this sound: it needs to fade cleanly into silence; (2) Develop a mini language for transforming a sequence of pitch names into a sound file; (3) make more complex sounds.

HH

Read Full Post »