Tag Archives: sound

Submediant in Stereo and the Sounds of Sputnik

My major contribution to Submediant this week was adding Stereo Sound.

Not all that terribly impressive, but it does sound cool.

Here is a tribute to Sputnik,

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.

As usual, here’s the notation for this audio file:

@SONGTITLE:Echoes of Sputnik
@ALBUMNAME:Let Them Eat Test
@ARTIST:Little Robots
@YEAR:2011
@GENRE:other

@bpm:120
@timesignature:4/4
@volume:2000

&center class:musical_sine balance:45
E6:1/2 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8
E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8
 _:1/2 _:1/8  _:1/8 _:1/8  _:1/8 _:1/8 _:1/8  _:1/8  _:1/8 _:1/8
E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8

&left class:musical_sine balance:75 volume:500
 _:1/2 _:1/8  _:1/8 _:1/8  _:1/8
E6:1/2 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8
 _:1/8 _:1/8  _:1/8  _:1/8 _:1/8
E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8
E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8

&right class:musical_sine balance:15 volume:500
 _:1/2 _:1/8  _:1/8 _:1/8  _:1/8 _:1/8 _:1/8  _:1/8
E6:1/2 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8
_:1/8  _:1/8
E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8
E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8 E6:1/8 _:1/8

Breaking out Instruments

I did a bit more work on Submediant. The goal for this set of changes was to allow the score files to define what kind of instrument to use.  Before, we could add multiple instruments but they all used the same basic sine wave generator…

Not only did I want to give the ability of specifying an instrument to the score file, though, I wanted to make creating new types of instruments easily… so I introduced a class hierarchy.  Essentially, all instrument objects have a common ancestor, the Instrument.  I defined MusicalInstrument as any instrument that knows/understands musical notation.  Finally, I defined two children of MusicalInstrument, MusicalSineInstrument which plays a sine wave and MusicalSquareInstrument which plays a square wave.  I then found a simple score to transcribe into Submediant…  Here is what it sounds like:

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.

According to the description, it’s a Welsh Lullaby arranged for a recorder duet.

In case you’re curious… here’s the Submediant score file:

@SONGTITLE:All Through The Night
@ALBUMNAME:Let Them Eat Test
@ARTIST:Little Robots
@YEAR:2011
@GENRE:other

@bpm:120
@timesignature:4/4
@volume:2000

&recorder_1 class:musical_sine volume:1000
_:1/2 G5:1/4. F#5:1/8
E5:1/4 G5:1/4 A5:1/4. G5:1/8
F#5:1/4 D5:1/4 E5:1/2

&recorder_2 class:musical_square volume:300
_:1/2 D5:1/2
C5:1/2 E5:1/2
D5:1/2 C5:1/4 D5:1/4

&recorder_1
F#5:1/4. G5:1/8 G5:1/2
C5:1/4 B4:1/4 C5:1/4 D5:1/4
E5:1/4 F#5:1/4 C5:1/4 B5:1/4

&recorder_2
E5:1/4 D5:1/8:tie C5:1/8:untie B4:1/2
_:whole
_:whole

&recorder_1
C5:1/4. B4:1/8 A4:1/4. G4:1/8
B4:1/4 A4:1/4 G4:1/4 F#4:1/4
G4:1/4. F#4:1/8 E4:1/4. G4:1/8
A4:1/4. G4:1/8 E4:1/4 D4:1/4

&recorder_2
G4:1/2 F#4:1/2
E4:1/2 D4:1/2
_:whole
_:whole

&recorder_1
E4:1/2 F#4:1/2. G4:1/8
G4:1/2. _:1/4
_:1/2 G5:1/2. F#5:1/8
E5:1/4 G5:1/4 A5:1/4. G5:1/8

&recorder_2
C4:1/2 D4:1/2
G4:1/2 _:1/2
_:1/2 D5:1/2
C5:1/2 E5:1/2

&recorder_1
F#5:1/4 D5:1/4 E5:1/2
F#5:1/4. G5:1/8 G5:1/2
C5:1/4 B4:1/4 C5:1/4 D5:1/4
E5:1/4 D5:1/4 C5:1/4 B5:1/4

&recorder_2
D5:1/2 C5:1/4 D5:1/4
E5:1/4 D5:1/8:tie C5:1/8:untie B4:1/2
_:whole
_:whole

&recorder_1
C5:1/4. B4:1/8 A4:1/4. G4:1/8
B4:1/4 A4:1/4 G4:1/4 F#4:1/4
G4:1/4. F#4:1/8 E4:1/4. G4:1/8
A4:1/4. G4:1/8 F#4:1/4 D4:1/4

&recorder_2
G4:1/2 F#4:1/2
E4:1/2 D4:1/2
_:whole
_:whole

&recorder_1
E4:1/2 F#4:1/4. G4:1/8
G4:1/4. _:1/4

&recorder_2
C4:1/2 D4:1/2
G4:1/2 _:1/2

Submediant: Imagine – A work in progress

This past weekend, I worked more on Submediant.  This time through included both an internal refactor as well as a few new features:

  • Instruments have a chord notation
  • Instruments can have individually adjusted volume
  • Notes can now be tied together

To help demonstrate the new features, I’ve called upon one of my inspirations, John Lennon.  This is about a quarter of the song, Imagine rendered with Submediant…

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.

Here is source code for the song…

@SONGTITLE:Imagine
@ALBUMNAME:Let Them Eat Test
@ARTIST:Little Robots
@YEAR:2011
@GENRE:other

@bpm:80
@volume:1000

&righthand volume:1000
D4,E4,G4:1/8:tie C4:1/8 D4,E4,G4:1/8 C4:1/8:untie D4,E4,G4:1/8:tie C4:1/8:untie D4,E4,G4:1/4
D4,F4,A4:1/8:tie C4:1/8 D4,F4,A4:1/8 C4:1/8:untie D4,F4,A4:1/8:tie C4:1/8:untie D4,F4,A4:1/4

&lefthand volume:1000
C2,G3:1/2. C2,B3:1/8:tie C2,C4:1/8:untie
F2,A3:1/2. F2,A3:1/16:tie A#3:1/16 B3:1/16 C4:1/16:untie

&vocals volume:4000
_:whole
_:whole

&righthand
D4,E4,G4:1/8:tie C4:1/8 D4,E4,G4:1/8 C4:1/8:untie D4,E4,G4:1/8:tie C4:1/8:untie D4,E4,G4:1/4
D4,F4,A4:1/8:tie C4:1/8 D4,F4,A4:1/8 C4:1/8:untie D4,F4,A4:1/8:tie C4:1/8:untie D4,F4,A4:1/4
D4,E4,G4:1/8:tie C4:1/8 D4,E4,G4:1/8 C4:1/8:untie D4,E4,G4:1/8:tie C4:1/8:untie D4,E4,G4:1/4

&lefthand
C2,G3:1/2. C2,B3:1/8:tie C2,C4:1/8:untie
F2,A3:1/2. F2,A3:1/16:tie A#3:1/16 B3:1/16 C4:1/16:untie
C2,G3:1/2. C2,B3:1/8:tie C2,C4:1/8:untie

&vocals
# Imagine there's no hea-
G4:1/8 G4:1/8 G4:1/8 G4:1/4 B4:1/8 B4:1/8:tie
# ven--
B4:1/8 A4:1/8 A4:1/4:untie _:half
#     It's easy if you
_:1/8 G4:1/8 G4:1/8 G4:1/8 G4:1/4 B4:1/4

&righthand
D4,F4,A4:1/8:tie C4:1/8 D4,F4,A4:1/8 C4:1/8:untie D4,F4,A4:1/8:tie C4:1/8:untie D4,F4,A4:1/4
D4,E4,G4:1/8:tie C4:1/8 D4,E4,G4:1/8 C4:1/8:untie D4,E4,G4:1/8:tie C4:1/8:untie D4,E4,G4:1/4
D4,F4,A4:1/8:tie C4:1/8 D4,F4,A4:1/8 C4:1/8:untie D4,F4,A4:1/8:tie C4:1/8:untie D4,F4,A4:1/4

&lefthand
F2,A3:1/2. F2,A3:1/16:tie A#3:1/16 B3:1/16 C4:1/16:untie
C2,G3:1/2. C2,B3:1/8:tie C2,C4:1/8:untie
F2,A3:1/2. F2,A3:1/16:tie A#3:1/16 B3:1/16 C4:1/16:untie

&vocals
# try...
B4:1/8:tie A4:1/8 A4:1/2:untie _:1/4
#     No hell below-
_:1/4 G4:1/8 G4:1/8:tie G4:1/4:untie B4:1/8 B4:1/8:tie
# us--
B4:1/8:untie A4:1/8 A4:1/4 _:half

You can see that chords are simply notes that specify multiple frequencies… for example, C4,E4:1/4 is a quarter note that rings as both middle C and the E a step above it. You can also see the notation for tied notes:  C4:1/8:tie C4:1/8 C4:1/8:untie are three 8th notes tied together. Whether a note is tied or not tells the instrument rendering the sound how to handle the attack/decay aspects of the sound generated…

You can see that each of the instruments in the source sets a custom volume.  One thing that I want to work on in the future is allowing the volume of an instrument to change.  Even though you can set the volume on any of the lefthand designators, only the last one is applied to the whole song.

There are a few aspects of the code that bother me… it needs more refactoring… but I’ve gotten it to the point where I need it.  I can now use Submediant as a framework to give Little Robots the ability to speak.

Submediant, the voice of robots

This past weekend, I spent some time honing the script from last blog post into a framework that could be used to give voice to my Little Robots.  Okay, so what’s changed since I published that awesome .wav generating perl script? Well, first let’s listen to something rendered by the new script…

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.

You can hear that the sound is far more refined.  I took the time to add some basic attack and decay to the sine waveform.  Even though it’s one of the most audible changes… it’s probably one of the least significant.   One major change from the previous script is the movement of all data to external data files…

Here is the data file that generated the MP3 that you just listened to:

@SONGTITLE:Minuet in G
@ALBUMNAME:Let Them Eat Test
@ARTIST:Little Robots
@YEAR:2011
@GENRE:other

&righthand
D4,1/4 G3,1/8 A3,1/8 B3,1/8 C4,1/8
D4,1/4 G3,1/4 G3,1/4
E4,1/4 C4,1/8 D4,1/8 E4,1/8 F#4,1/8
G4,1/4 G3,1/4 G3,1/4

&lefthand
B2,1/2 A2,1/4
B2,1/2.
C3,1/2.
B2,1/2.

&righthand
C4,1/4 D4,1/8 C4,1/8 B3,1/8 A3,1/8
B3,1/4 C4,1/8 B3,1/8 A3,1/8 G3,1/8
F#3,1/4 G3,1/8 A3,1/8 B3,1/8 G3,1/8
A3,1/2.

&lefthand
A2,1/2.
G2,1/2.
D3,1/4 B2,1/4 G2,1/4
F#2,1/4 D2,1/4 F#2,1/4

&righthand
D4,1/4 G3,1/8 A3,1/8 B3,1/8 C4,1/8
D4,1/4 G3,1/4 G3,1/4
E4,1/4 C4,1/8 D4,1/8 E4,1/8 F#4,1/8
G4,1/4 G3,1/4 G3,1/4

&lefthand
B2,1/2 A2,1/4
B2,1/2.
C3,1/2.
B2,1/2.

&righthand
C4,1/4 D4,1/8 C4,1/8 B3,1/8 A3,1/8
B3,1/4 C4,1/8 B3,1/8 A3,1/8 G3,1/8
A3,1/4 B3,1/8 A3,1/8 G3,1/8 F#3,1/8
G3,1/2.

&lefthand
A2,1/2.
G2,1/2.
C2,1/4 D2,1/4 D2,1/4
G2,1/4 D2,1/4 G0,1/4

You can see, both the notes and metadata about the song are found all in one place, completely apart from the code.  At the very top of the file are attributes which are denoted with an ‘@’.  Notes are comma separated tuples where the first field is the note itself and the 2nd field is its duration.   Notes are divided into sections attributed to instruments (set off by an &).  Multiple sections for a single instrument simply append notes.

In this particular example, we have two instruments, one called lefthand and the other called righthand.  They simulate the left and right hands when playing the very simplified version of Minuet in G from the Easiest Book of Piano Favorites.

Both the notes and the durations are defined in a file.  The notes get mapped to frequencies and the durations get mapped to fractions of beats.  In my notation, 1/2 means half note, 1/4 means quarter note, etc… and if it ends in a period, that’s a dotted note.

Like all great projects, this one needed a name… and so I scoured Wikipedia‘s audio/sound entries for the first cool sounding term that I had no real understanding of… and that became the name of the project… Submediant. Even after trying to read the wiki page… I still have no idea what a Submediant is… but I’m sticking to it.

Exit Structured Audio, Enter Home Grown

In a previous blog post, I had explored using MPEG4 Structured Audio to produce the sounds that my robots will make in future animation.  A few weeks later, I find that the learning curve for the tools is a bit too steep for my liking… so I decided to start from scratch… and write my own.

Yeah, I understand that people of far greater sound knowledge and experience put a LOT of effort into Structured Audio, but that doesn’t help me now.  Maybe this tool that I’m building (which doesn’t quite have a name yet) will iterate toward the stuff I’m giving up… but I’m sure I’ll learn quite a bit about audio programming along the way.

As it turns out, most of the tool chain that I had previously built still works! I’m just replacing sfront with something that I’ve written… and if you’re curious what a program looks like which generates .wav files? here it is!

#!/usr/bin/perl

use strict;

my $filename = shift @ARGV;
die "You must specify an output file." unless $filename;

my %aliases = (
   C4 => 261.626,
   D4 => 293.665,
   E4 => 329.628,
   F4 => 349.228,
   G4 => 391.995,
   A4 => 440.000,
   B4 => 493.883,
   C5 => 523.251
);

my @song = qw(B4 A4 G4 A4 B4 B4 B4 A4 A4 A4 B4
              D4 D4 B4 A4 G4 A4 B4 B4 B4 B4 A4 A4 B4 A4 G4);
my $duration = (scalar @song) * 0.5 + 0.5;
my $volume = 8000;

my @notes;
push @notes, $aliases{$_} for @song;

my $channels = 1;
my $samplerate = 44100;
my $bitspersample = 16;
my $byterate = $channels * $samplerate * $bitspersample / 8;
my $blockalign = $channels * $bitspersample / 8;
my $samples = $samplerate * $duration;
my $dataChunkSize = $samples * $bitspersample / 8;
my $chunkSize = 36 + $dataChunkSize;

my @values;
for (my $i = 0; $i < $samples; $i++) {
   my $note = int($i / $samplerate * 2);
   my $freq = $notes[$note];
   my $x = $i * $freq / $samplerate * 3.14159 * 2;
   push @values, int($volume * sin($x));
}

open(FILE, "> $filename") || die "could not open $filename";
print FILE pack('NVN', 0x52494646, $chunkSize, 0x57415645);
print FILE pack('NVvvVVvv', 0x666d7420, 16, 1, $channels, $samplerate,
     $byterate, $blockalign, $bitspersample);
print FILE pack('NV', 0x64617461, $dataChunkSize);
for my $sample (@values) {
    print FILE pack('v', $sample);
}

close(FILE);

Yup. That’s the whole thing.  No libraries. No weird complexity.

I decided to write the thing in perl for the practice.  I use an awful lot of perl at work, so as this project grows, it’ll force me to learn the proper perl patterns.

If you’re curious what that program produces? Here’s the converted MP3:

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.