Structured Audio C Major Scale

I’m continuing to experiment with MP4-SA.  This time around I have a bit more refined infrastructure built.  The major trouble that I had with my previous audio file, It needed to be refined from the raw .wav generated by sfront.

My end goal was to have a process by which I could write instruments and score files and in a single command produce a properly ID3 annotated mp3 file that I could then use to play via the WordPress Audio Player.

Using macports, I was able to quickly install Blade’s MP3 Encoder, and id3tool.

Once all of these packages were installed, I wrote a simple template bash script that takes all of these disparate pieces and forms voltron.

The result is the following, very modest, audio file rendering a simple C Major scale…

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Yeah it’s still rough… I’m not entirely sure what the popping sounds are after each note.  It probably has to do with the signal being cut off abruptly… That’s something I’ll have to work out in the instrument file itself…

Ok. Well, what does a C Scale look like in MP4-SA?

0.00  @INSTRUMENT@ 0.40 261.626 0.8
0.50  @INSTRUMENT@ 0.40 293.665 0.8
1.00  @INSTRUMENT@ 0.40 329.628 0.8
1.50  @INSTRUMENT@ 0.40 349.228 0.8
2.00  @INSTRUMENT@ 0.40 391.995 0.8
2.50  @INSTRUMENT@ 0.40 440.000 0.8
3.00  @INSTRUMENT@ 0.40 493.883 0.8
3.50  @INSTRUMENT@ 0.40 523.251 0.8
4.50 end

The strange @INSTRUMENT@ markup is part of my tool chaining.  Prior to running the sfront program on this file, my shell script replaces all occurrences of @INSTRUMENT@ with the actual instrument being played… in this case it was a sine wave.  The first number after the instrument turns out to be duration of tone.  In my last post I had mistaken this field to be stop time.  The 2nd value is frequency.  This has also changed from my first attempt… instead of a fairly arbitrary decimal value, this is an actual measure of frequency in Hertz.  Finally we have amplitude which pretty much changed the same…

To facilitate the changes in what the parameters mean, I also changed the basic sine instrument that I wrote.  Here is the new, improved sine

instr sine(f, a) {
   asig x, y, init, arate;
   if (init == 0) {
      init = 1;
      x = 0.0;
      arate= f * 3.14159 * 2 / 32000;
   }
   x = x + arate;
   y = sin(x);
   output(y * a);
}

You can see here, that I’m actually using a for real sine function now. The arate variable computes the x value of sine based on the sample rate of the composition, in this case 32000.  In reality, this should be a global variable of some kind but I could not seem to get that to work.

One thing I will probably do in the future is change the frequency numbers of each note to be aliases, much like the @INSTRUMENT@.  This will make it easier to score more complex songs.  I should also do that for note duration.