Category Archives: Uncategorized

Introduction to Music Production, Assignment 4

This is Richard Lee from San Francisco welcoming you to my 4th assignment for Coursera and Berklee College of Music’s class, Introduction to Music Production.

I’ll be talking about Dynamic Processors and their parameters.  Specifically threshold, ratio, attack and release.

As the name suggests, Dynamic Processors affect the Dynamic Range of sound passing through it.  What does that mean, exactly?

Dynamic Range has two distinct contexts.  On one hand, it refers to the contrast between the softest sound that can be perceived by humans to the threshold of pain.  This seems like it’d be straightforward to measure, but not only does the range vary from person to person, it also varies environmental factors such as air pressure.

Thankfully, we’re mostly concerned with the other notion of Dynamic Range.  This Dynamic Range isn’t loudness, but the range of signal amplitudes that can accurately passed from input to output through a piece of audio equipment.

Some of the original uses for Dynamic Processors were to simply limit the amplitude of the signals beyond a certain threshold.  We call this kind of processor a Limit.  It was put in place to protect delicate equipment from sudden jolts or surges caused by connecting or dropping components.

You can generalize a Limit to not just cut a signal off at a threshold but instead restrict its growth to something less aggressive, you get a Compressor.  To say that another way, a Limit is a Compressor with a very large ratio.  In the context of Compressors, the Ratio represents the amplitude of the input in relation to the output.

To make a compressor even more useful, we’ll introduce two new parameters, attack, which has time units (typically milliseconds) gives us a delay between the signal crossing the threshold and the ratio actually being applied to the input to get the output.  The opposite of attack is release, which defines the delay between a signal falling below the threshold and the processor halting its influence.

The main purpose of a compressor in modern music is to reduce the dynamic range of a piece so that it’s possible to increase the gain, which makes the piece sound louder without distortion.

A sort of inverse to a Compressor is a Gate.  Where the Compressor activates when a signal’s amplitude is above a certain threshold, a Gate aggressively attenuates any signal BELOW the threshold.  This helps remove noise from a piece of music as the noise would fall below the amplitude threshold of the instruments or vocals being played over it.

I’m cutting this assignment a little short.  I didn’t have time to create images to help visualize what I was trying to get across in my text.  Hopefully I’ll be able to find some time to put some polish on the next assignment!  Thanks for reading!

 

Booting my Raspberry Pi

Yeah I spent the $35 to get myself a Raspberry Pi. Here it is!

Admittedly, It’s taken me a bit longer than I’d have expected to get it to boot.  First, I bought the wrong USB power cable.  I thought that the connector was a “Mini-USB” but really it was a “Micro-USB”. You’d think that with the volume of electronics I own, I’d know the difference between the two… but you’d be wrong.

My next folly was with the operating system.  First I tried the Arch Linux build, but for some reason, it didn’t copy to my SD card properly. My instinct was that the Amazon Basics SD Card wasn’t compatible for some reason or another, but that was a false trail.  I instead copied the recommended Raspbian “Wheezy” image… and viola! I have it booting!

Here’s a screen shot part way through the boot.  The Composite Video output doesn’t seem to line up very well with my old Dell monitor.

The boot process is pretty swift and the distribution automatically DHCPs a network address and starts sshd, so it’s possible to ssh in as soon as it finishes coming up.

Once inside, I poked around a little bit. Here’s the CPU info

pi@raspberrypi ~ $ cat /proc/cpuinfo
Processor	: ARMv6-compatible processor rev 7 (v6l)
BogoMIPS	: 697.95
Features	: swp half thumb fastmult vfp edsp java tls 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xb76
CPU revision	: 7

Hardware	: BCM2708
Revision	: 0002
Serial		: 0000000048e7f498

I distinctly remember commenting that a “100mhz computer with 128 megs of ram will always make a good linux box.” Here’s a linux box that has way way more as far as capabilities… for $35. Maybe we’ve reached the future.

Getting back to basics – blender rtfm

A while back, I picked up the book Introducing Character Animation with Blender from blender3d.org.  I primarily bought it to support the blender foundation because I love using the software so much… but I finally got around to cracking it open.

Most of my blender knowledge comes from watching youtube videos.  This approach is good because it provided me with a lot of practical modeling skills, but it doesn’t delve much into the intention of the features built into blender.  I think that actually going through and reading the manual will be useful for me at this point.

I think I’ll combine this getting back to basics with the actual character design of “The Weirdo” for my video game project… kill two birds with one stone so to speak.

 

Modeling Die Rolls

Modeling out die rolls seems pretty straight forward.  Let’s say that you wanted to figure out the distribution of sums. The brute force method for doing this looks like the following chunk of perl code:

sub dist {
    my ($count, $sides) = @_;
    my $state = [];
    for (my $i = 0; $i < $count; $i++) {
        $state->[$i] = 1;
    }

    my $max = $count * $sides;
    my $result = [];
    while(1) {
       my $sum = 0;
       for (my $i = 0; $i < $count; $i++) {
          $sum += $state->[$i];
       }

       $result->[$sum]++;
       last if $sum >= $max;
       $state->[0]++;
       for (my $i = 0; $i < $count; $i++) { 
           last if $state->[$i] [$i] = 1;
           $state->[$i+1]++;
       }
   }
   return $result;
}

This seems to work well for distributions of same sided dice. What if I wanted to combine multiple types of dice? Say, 4x six sided dice and 8 4-sided dice… well, the brute force method starts to get pretty expensive.

I was reading this lecture on normal distributions for sums and came to the solution to my problem.  Instead of iterating over all sums for all dice, I could probably just add the normal curves for the die rolls.

How do you compute a normal distribution? It’s called a Gausian… check the Wikipedia page!  The code for a gausian given two params, mu and sigma look like so:

sub gausian {
    my ($x, $mu, $sigma) = @_;

    my $exp = - 1/2 * (($x - $mu) / $sigma) ** 2;
    return 1/($sigma * sqrt(2 * $pi)) * exp($exp);
}

Now I just need to figure out how to scale mu and sigma (mean, std deviation) to number of dice and the sides per die.  The lecture above seems to model 6 sided dice well with a mean of 3.5 x number of dice and 1.7 * sqrt(num of dice) but I need to expand that out to other side counts for this to work.

Coursera Classes

I’ve been increasingly impressed by the quality of the online classes on Coursera.

At present, I’m taking two classes, Machine Learning and Human-Computer Interaction.

The Machine Learning class is provided by Stanford University and is taught by Andrew Ng.  The class is challenging but very gratifying.  The class uses Octive/Matlab for its assignments.  The biggest challenge for me so far has been the conversion of mathematical formulas into efficient “vectorized” Octave code.  I’ve always taken for granted that matrix operations did specific tasks… like rotate a shape or change the contrast in an image.  I’ve never really had to face the task of how they do it.  I enjoy that the class takes you from zero knowledge of machine learning to a Neural Network that recognizes handwriting in just the first 5 weeks.  Extremely gratifying.  As part of my learning process I’ll be coding some of the stuff that I learned from the class in Java and later C++.  These things will probably be useful as I work on the pi-like stock market predictor from my previous post… Hopefully I won’t end up drilling a hole in my head.

the Human-Computer interaction class only just started … so I have only gotten through the introduction videos, but I can already tell that the class will affect and inform a lot of the design decisions that I make in the future. The class is also provided by Sanford University and is taught by Scott Klemmer.   The class itself seems to be about formalizing the process of making good user interfaces.  By formalizing, I don’t mean some kind of rigorous proof that X is the best design, I just mean putting enough process around design that will make it approachable to people who have no design intuition (like myself).  I have to wonder if maybe I can use this as an excuse to explore some of Buckmeister Fuller‘s design and engineering principals…. I recently saw an exhibit at SFMOMA entitled “The Utopian Impulse: Buckminster Fuller and the Bay Area“.  Extremely inspiring.

Another Pi Image is Born

I recently saw the movie Pi for the first time.  A number of friends and family recommended the movie to me when it first came out.  Me specifically.  As in, this movie would somehow resonate with me on some fundamental way.   It just seemed, though, that the harder I was pushed to see the film, the less likely I felt like actually watching it.

Fast forward about 10 years to a week ago.  I was trolling Netflix streaming for something to watch and decided… “Oh, what the hell.”  I hit play.

I can understand why so many people thought that I’d like this movie.  I think though, that it hits a little too close to home in some aspects but is somewhat dumb in others.  I don’t really want to get into a technical review of the movie because I’m sure that it wasn’t intended to be scrutinized in that way.  I did enjoy it as a story though.

Every computer scientist I know has thought about how to predict the stock market.  I’m not sure that each and every one creates some explicit mantra as does the guy in the movie, but, you know… we don’t all live in a black and white film.

When I’m done with the Machine Learning class over on Coursera, I do plan on trying to make a short-term sale predictor AI.  I’m hoping that I won’t inadvertently learn a true name of God and end up drilling a hole in my head.  I guess we’ll see.

Instead of just stealing someone else’s colorful pi image, I thought I’d be fun to make one.  The image used in this blog post was based on the Wikipedia SVG of the Greek Letter.  I imported it into the GIMP and exported it as text (Yeah, you can do that!).  After cleaning it up a little, I wrote a program that would populate the actual pi digits into the exported image.

#!/usr/bin/perl
use strict;

open(my $pifd, "pi-image.txt") or die "couldn't open pi image";
open(my $numfd, "pi-digits.txt") or die "couldn't open pi digits";
my $ch;
while(1) {
    read($pifd, $ch, 1) or last;
    if ($ch eq "\n") {
        print "\n";
        next;
    }
    if ($ch ne ' ') {
        read($numfd, $ch, 1) or last;
    }
    print "$ch";
}
close($pifd);
close($numfd);

Once I had the numerically populated glyph, I pulled it back into the GIMP via screenshot and applied a rainbow gradient! Bam! Yet another Pi image is born!

PGM Class and Octave

About a month and a half ago, I signed up for an on-line class called Probabilistic Graphical Models in an attempt to learn a bit more about some of the math that we use at Topsy Labs.

The strange logo to the right is the Octave logo.  To quote the Octave website…

GNU Octave is a high-level interpreted language, primarily intended for numerical computations. It provides capabilities for the numerical solution of linear and nonlinear problems, and for performing other numerical experiments.

Based on that description, it makes sense that this and Matlab are the two languages recommended for this course.  Yeah. This means that I’ll be learning yet another language… but I’m hoping that octave will allow me to quickly generate cool visualizations for large data sets if not directly, then through gnuplot.

Wrapping N-Body Simulation

Continuing with my previous efforts, I updated my N-Body simulation code to not require the edges of the simulation to be boundaries.  Instead, the edges now wrap.

That might seem like a pretty simple change, but the code involved gets a bit complex…

For example, say you’re calculating the force between particle A and some other particle B and particle B’s force is wrapped around the screen, you need to basically translate B to the other side of A and do your calculation…

If you’re in a corner… say the upper right, you’d have to do this with all particles above and all particles to the right of you, so you’d need to do two sets of transformations.

The process is slow enough with 100,000 points that I need to think about moving from Java, which is what the simulation is currently written in, to something speedier, like C.

Using Background Images in Blender

While I was building the iPhone4 model, I began to realize that my proportions were off.  The Home Button seemed out of place. The front camera and speaker were not quite the right shape.  The buttons and breaks in the seems were a bit off from where they needed to be… the list went on and on.

It turns out that blender has a feature for exactly this problem, background images.  This lets you set an image as the background to your modeling space, thus allowing you to match up your mesh boundaries to features of the image!  Obviously, care has to be chosen when choosing these kinds of images, but assuming you can find fairly orthogonal shots of the front, back, left, right, top and bottom, you can model very precisely from actual photographs.

Ok. How can you set background images?  Go to your view menu and click properties. That should pop up a properties pane.  Near the bottom of the properties pane, you’ll see the widget for background images.  Check the check box and click “Add Image”.  Select which view you’d like this image to show up in (front, left, right, back, etc) and expand the “Not Set” arrow. That should give you a little dialog box that’ll give you a file picker.

You can add an image for every orthogonal view, so when you hit a perspective key on the number pad, the appropriate background image is displayed.

After digging around the web for a while, I finally found a set of images that could help me re-tune my iPhone mesh… here’s the mesh with the “front” background image

N-Body Simulation

A long time ago, I created a simple animation using POV-Ray that simulated a Neptune-like planet that I named Augustus-Voltaire 4.  I used POV-Ray’s built-in programmatic texturing features to create a blue banded atmosphere that had white speckled high atmospheric clouds. You can see the video here… It’s got some pretty bad aliasing features due to compression, but you can get a basic idea of what I was going for…

Ultimately, I wasn’t happy with the result, so now years later, I’ve decided to take a stab at the problem again…  This time, armed with a much faster computer!  But how do you simulate turbulent, banded clouds?

I came up with a couple of different ideas for how to do it… but the only one that seemed to produce anything vaguely interesting was N-Body simulation.  Essentially, you assume that the atmosphere is a fluid and realize that fluids can be approximated with particles.  In the simulation, you throw a few thousand simulated particles which interact with each other in set ways (in my case, they all repel each other in an enclosed space).

I wrote the simulator in Java… and is kind of slow.  Here is my first real attempt… it took about 18 hours to render.  The source is too large to include here in the post.  If you’re interested in seeing it, drop me an email.

In this simulation the Red and Blue components of the color describe its mass.  The redder the particle, the heavier it is.  The Green component of the color is controlled by how fast the particle is going.   I introduced a force pushing through the center.  The intensity tapers off as you get closer to the top and bottom.  That the simulation quickly reached a form of equilibrium…. which is kinda cool, but doesn’t make for very interesting weather patterns.

I noted as I watched this run, was.. the particles tended to segregate themselves based on mass.  The heavier stuff accumulated near the center of rotation and the lighter stuff was pushed out to the edges.

In my second N-Body simulation, I used far fewer particles but made each particle way more massive.  I also changed the shape of the force pushing through the center of the simulation, making it much more narrow.

Once again, you can see that we quickly reach a stable pattern.  This one seems to have much more circulation though.  It seems like bigger particles are the way to go.   I have 2 more avenues to explore as far as particles go…

  • Make the simulatiion have a 3rd generation.  This aught to cause different masses to group in layers. That might be visually interesting.
  • Add more complex ambient forces than the simple down-the-middle force.