Sunday, September 9, 2012

Auto-generated Music : Time-Frequency Analysis

New side project!  Time to add it to my list of 20 other side projects.

Goal: Generate some nice instrument samples that don't just sound like A. waves, or B. random noise.

Big-Fish Goal: Use these instrument samples to generate music.

Partially because I'm lazy and can't make my own music.
Partially because it'd be pretty fucking cool.

The first arm of this project lies in something called time-frequency analysis.  Essentially, you're looking at the dominance of sound (time) and the dominance of pitch (frequency) throughout a sample.

The interesting thing is, "good" sounds tend to have something in common.  Look at the following frequencies of a sine wave at 440 Hz:

Sine Wave
 You can see it peaking at 440 Hz first of all (not surprising), but more important is that it slopes downwards in general.  Being a sine wave (and having a parallel frequency graph) makes it not-so-intuitive to see, but here's one of white noise:
It spikes up at random and stays uniform throughout every frequency.  It also sounds like murder to the ears.

Meanwhile, here's one of pink noise, which is a little more tolerable to listen to:
See the difference?  "Good" sounds tend to have dominance in the lower frequencies, and then pan out.

(If you're interested, brown noise does the same.  Didn't post a screenshot but it's very similar to that of pink noise).

Now, the problem I'm having is that frequencies are discrete here.  If I were to, say, average out the frequencies of 20 different sine waves, then I won't converge to a "good" frequency graph.  I'll just get random peaks everywhere.  Sine waves with different frequencies will have their peaks a bit over to the left or right of the others.

Same problem happens in the time (amplitude) domain.  A drum sound, for example, has a small attack phase, where the sound gets very loud, and then a long tail afterwards.  Snare sample:
Someone tell me how to crop images in Ubuntu :(
This goes for pretty much every basic drum.  But say the sample wasn't properly made, and it has a long piece of silence at the beginning that moves everything over a few 0.1 seconds or so.  When you average the sounds out, you'd get something fairly uniform rather than a straight downwards slope.

... I'm not sure how I'd remedy this but averaging out the derivatives between values rather than discrete points might work out?  Who knows.

Will keep you updated.

No comments:

Post a Comment