Jan 27, 2007 10:33amOhh, Shiny!

I have always had a strong interest in creating computer graphics. There are a couple of approaches to image generation. One approach is to create software that puts artist tools at the disposal of user, and relies on the artistic talents of the user to create a picture. The other approach applies mathematical modeling to how light propagates through a scene and the software crunches numbers until you get a picture out the other side of the processing pipeline.

The second approach, known as Raytracing is what Hollywood uses to create the photo-realistic special effects in movies. Raytracing involves creating mathematical models using simple geometric objects (spheres, planes, polynomial surfaces, triangles, etc) and building them up (like Lego bricks) to form a scene. You describe the materials all these primitive objects are made from, and how they reflect/absorb light, along with describing where all the lights in the scene are located. The software crunches light rays and voila you have a picture.

I was bored. I went back to a book that I bought in 1993 - “Photorealism and Raytracing in C” by Stephen B. Coy, Mark Finlay, Christopher D. Watkins. I pulled the mathematical formulae from there, whipped up some Java code. I would term this “version 0″ of the software. It supports:

  • Ambient, diffuse and specular lighting models
  • Coloured lighting
  • Two primitives: spheres and planes
  • Basic procedural textures

Procedural textures are interesting: instead of the various materials that the primitives are made from being a flat base colour, you rely on some code to tell you what their colour should be at any given position. In the first example the procedural texture generated a checker-board pattern on the infinite plane, and in the second example a very basic implementation of Perlin noise was used to create the smoky effect. Not bad for a “version 0″ piece of software!

There’s a lot left to do before the software is even in a state I would like for someone else to see or get their hands on. I am torn: the mathematical description of a sphere can be generalized and used to describe a cylinder and from there, a cone. More general still to the far more abstract “quadratic surface”; one reasonably simple change and I can support a whole class of new primitives! What the software doesn’t do yet is reflection or refraction - all the primitives are shiny plastic right now - what I want to do is model light bouncing around (metallic objects) and passing through (glassy objects).

Still, I am very happy. My physics class taught me that if you mix red and green lighting, and a surface reflects both, then you will see yellow. In the final screenshot you can clearly see the shiny silver ball now reflects both the colours, with a band of yellow at the top. So, upward and onward toward the goal of “version 0.1″ where more primitives are supported. Then I’ll get to “version 0.2″ where reflection and refraction are modeled. Watch this space!

Jan 18, 2007 11:13amJayne Cobb, Hero of Canton

Jayne. The man they call Jayne…

He robbed from the rich
and he gave to the poor.
Stood up to the man
and gave him what for.
Our love for him now
ain’t hard to explain.
The hero of Canton
the man they call Jayne.

Our Jayne saw the mudders’ backs breakin’.
He saw the mudders’lament.
And he saw the Magistrate takin’
every dollar and leavin’ five cents.
So he said “You can’t do that to my people.”
He said “You can’t crush them under your heel.”
So Jayne strapped on his hat
and in 5 seconds flat
stole everythin’ Boss Higgins had to steal.

He robbed from the rich
and he gave to the poor.
Stood up to the man
and gave him what for.
Our love for him now
ain’t hard to explain.
The hero of Canton
the man they call Jayne.

Now here is what separates heroes
from common folk like you and I.
The man they call Jayne
he turned ’round his plane
and let that money hit sky.

He dropped it onto our houses
he dropped it into our yards.
The man they called Jayne
he stole away our pain
and headed out for the stars!

Here we go!

He robbed from the rich
and he gave to the poor.
Stood up to the man
and gave him what for.
Our love for him now
ain’t hard to explain.
The hero of Canton
the man they call Jayne.

Jan 18, 2007 10:06amCat Haiku

Merinda sent a link that I simply had to share: Cat Haiku. Hidden among the many other poems were a few absolute gems:

You never feed me.
Perhaps I’ll sleep on your face.
That will sure show you.

and

Wanna go outside.
Oh, poop! Help! I got outside!
Let me back inside!

oh, and not to mention:

You must scratch me there!
Yes, above my tail!
Behold, elevator butt.

Just the thing to brighten up your morning!

Jan 15, 2007 10:37pmThose dreaded chipmunks!

Since moving over to Wordpress for my main blog I’ve had the opportunity to look around and install (and in fact to write) a number of plugin modules for the site. There are hundreds of these installable utilities out there and for the most part they go in an silently just work the way they were intended to. Occasionally something really strange will happen.

I was looking for a nice simple way to allow visitors to listen to episodes of my podcast novel “The Matrix :: Repercussions” directly on the webpage without having to download the track to their computer first. I was saved (so to speak) by a neat little audio player Wordpress plugin published by 1 pixel out. Written in Macromedia flash, this plugin did exactly what it was advertised as doing, no more and no less - exactly how I like software to be. I whipped up a quick podcast promo:

Partial screenshot of the Propaganda podcasting software

and proceeded to try to listen to it with the audio player (give it a go…) [audio:http://nano.caffeinatedbliss.com/media/promo-chipmunk.mp3]

The website for the audio player was kind enough to mention the playback speed issue that turns people into chipmunks:

The Macromedia Flash player has a problem playing files that are encoded at a rate that is not a multiple of 11.025 kHz. This effect is sometimes called the “chipmunk” effect: the file is played at double speed. To avoid this, encode MP3’s at 11.025 kHz 22.050 kHz or 44.100 kHz.

Much as I love composing my podcast in Propaganda, I was unable to control the MP3 encoding to the level that they require; all it would export were more chipmunks!

I tried exporting from Propaganda as WAV and then doing the MP3 encoding using the free (and otherwise excellent) Audacity sound editing software:

Partial screenshot of the Audacity sound editing software

And this clearly shows that the WAV file was encoded at an acceptable 44100Hz and therefore should be acceptable to the Flash audio player. BZZzzzzt Wrong. More chipmunks. I was at a loss, then I tried opening the MP3 file itself in Audacity and poking around. Both the one produced by Propaganda and the one created by Audacity looked the same:

Partial screenshot of the Audacity sound editing software

If you’ve read this blog entry up to this point, you’re probably pretty eager to see the solution. It’s not pretty!

Chipmunks be gone!

Audacity relies on a piece of software called “lame” to do the actual MP3 encoding process. This software is a separate download from Audacity. It runs quite happily on its own from the command-line and accepts a number of configuration options. It was with great pleasure that I read in the documentation for lame that I could specify a re-sampling rate for the audio, allowing me to use one of the Macromedia Flash supported values. I opted for 22050Hz:

> lame.exe –resample 22.05 -b 64

The resulting MP3 sounded so much better! Give it a go:
[audio:http://nano.caffeinatedbliss.com/media/promo.mp3]

So now I have a 3 step / application podcasting pipeline:

  1. Record raw audio in Audacity and edit the content
  2. Compose / mix the podcast in Propaganda and export the episode as a WAV file
  3. On the command-line encode the final MP3 using lame

The strange thing is this: when I started out it looked like all I would need was Propaganda, as an all-in-one podcast production application. Little did I know!