Archive for the ‘Experimental’ Category

A Magic Trick

Sunday, July 25th, 2010

This was news to me. It is well known that any periodic waveform can be represented by an infinite sum of harmonic sine waves. What about making a sine wave from an infinite sum of harmonic square waves?

Blasphemy

Blasphemy

Each step in the animation doubles the number of square wave “harmonics” included to approach a pure sine wave. Ignore the numbers in the lower left hand corner despite the attention this sentence draws to them.

I take no credit for the math. I just wrote a GNU octave script to generate the plots based on an equation from http://www.dspdimension.com/

One Bit Sine Wave

Saturday, December 12th, 2009

Like Kicking a Slinky

Like Kicking a Slinky

Several weeks ago, I ported a 2nd order delta sigma D/A converter block diagram from “Principles of Digital Audio” into some Verilog for an FPGA.

The output is a 1-bit logic signal that, when smoothed, matches the input. The human ear does this smoothing naturally, so that slinky-looking wave will actually sound just like a sine wave. Notice that the 1-bit output looks more like an actual sound wave in air: variations in pressure following amplitude.

Delta sigma generates a stream of pulses that have a density corresponding to input amplitude. There is a lot of noise in addition to the input signal, but as long as it’s supersonic it does not audibly matter. I did learn, however, that it can really screw with a microphone preamp. Saying “2nd order” refers to the feedback system the converter uses. Higher orders push more converter noise past the range of hearing.

I ran a digital sine wave generator into my D/A and tied the FPGA pins straight into my soundcard. It was a just a quick sanity check.

Click Here to listen , but be aware it’s just a 1k sine wave

The converter I built was for a 16-bit input, and that recording ended up with a noise floor on par with 14-bit performance. The distortion is pretty high, but that could be clock jitter, a lack of proper filtering, or even the sine wave generator itself. I was just happy that it was making intelligible sound in the very first test on actual hardware.

2A03 Horizons

Thursday, August 27th, 2009

I made an Octave script to simulate and graph all the 2A03 sweep unit settings as they change pitch over time. It is based entirely on my understanding of some documentation I found online… no measurements have actually been done. Each staircase represents one iterated combination of bit shifting and clock dividing. Something about the various quantizations weaving in and out of each other is strangely hypnotic.

Sweeeeeeeep

Sweeeeeeeep

Droppin Logs

Droppin' Logs

Open them in a new window for the full glory.

Variations on a Theme: Bit Crushing

Saturday, January 24th, 2009

Disclaimer: For any sticklers out there, there are some discrepancies between this article and exactly how the NES handles audio. There are also some details neglected (sample rates, resulting bit depths). This is intended as a basic overview.

Original Clip

Crushing 1

Crushing 2

Crushing 3

Crushing 4

Crushing 5

The sound of simple bit crushing exploded in popularity several years ago when “lo-fi” became all the rage. It’s almost always done the same way: a control changes the “step” size of a blocky mess to vary the amount of quantization distortion. The fewer bits used, the bigger, steppier, and noisier the result gets.

Modern digital audio signals are almost always PCM data. Each chunk of data is essentially a sound pressure level at an exact point in time.

..but that’s only one way to store and represent audio in the digital realm. What about an entirely different method?

The Nintendo NES designers didn’t care much about audio fidelity, but did want some type of digital audio playback. You’ve probably played a Nintendo game at some point that warned you, through a wall of half-intelligible fuzz, to “skate or die die die die*” or “double dibl.” It took special audio encoding to sound so terrible.

Instead of encoding the volume of each point in time, many NES games stored a sequence of volume differences. It’s a handy format known as Differential PCM. If you have audio data that looks like, in PCM form:

1, 2, 4, 6, 3, 2

in DPCM form it becomes

+1, +1, +2, +2, -3,-1

To get the original data back you must add each term in the DPCM. As a breakdown:

n[0] = 1

n[1] = n[0] + 1 = 2

n[2] = n[1] + 2 = 4

n[3] = n[2] + 2 = 6…

We get our original data back. The advantage here is that instead of caring about the largest value (6), the largest *difference* (3) is what matters. Most audio signals have relatively small differences compared to their highest and lowest values, so a high compression ratio is possible. Instead of needing a whole byte per sample, you could likely get away with a nibble. Of course, the Nintendo didn’t have that many bits to waste! It used 1-bit DPCM. That same PCM stream of numbers, converted to 1-bit DPCM and back, goes like this:

DPCM: +1, +1, +1, +1, -1, -1

PCM: 1, 2, 3, 4, 3, 2

That’s not what we started with! This creates a distortion different from traditional bit-crushing. It has the effect of increasing noise and filtering the signal at the same time. Essentially the 1-bit DPCM format “chases” the incoming audio. High frequencies end up distorted into triangle waves.

Hopefully we’ve all seen a sine wave at some point. Here is a low frequency sine wave that’s been run through 1-bit DPCM and reconstructed:

Tasty

The Lowest Distortion Case

The wave is slow enough that the 1-bit +/- signal can track it pretty well. Notice the flat regions of the sine wave switch back and forth between two values very quickly:

Flat Part Close Up

Flat Part Close Up

Each new value can only be the previous value plus one or the previous value minus one. There is no such thing as a constant value. Isn’t 1-bit great?

What happens when the sine wave is faster and gets harder to “chase”? The original wave is shown in red, and the 1-bit de/reconstruction is shown in blue.

Triangles!

Triangles!

Graphs are pretty hard to hear, so I included some audio demos of a drum loop. Each file uses 1-bit DPCM, but in each case the size of the steps decreases.

*After listening some more, the Skate or Die 2 intro vocal sounds too clear to be using DPCM. It was possible to use actual 7-bit PCM data on the NES, but was somewhat rare because of the overhead required both to play it back smoothly and also store it. For the highest quality recorded audio I’ve heard in an NES game, check out Big Bird’s Hide and Speak.

Noise Envelopes

Sunday, January 11th, 2009

Audio Clip One

That clip is from some of today’s drum envelope testing. Each percussive hit has an ASR envelope with variable attack and release. I vary the attack and release throughout the clip and change the waveform.

The mystery project is a MIDI Pokey synth. There are many ways it can be done, but I’m going for as much real-time playability as possible. I want something anyone can plug a MIDI keyboard into and instantly be awash in a sea of Atari. The hard part is keeping it cheap at the same time. I have my own methods, but I’ll save the full feature set for later.

Chugging Away

Sunday, January 4th, 2009

Audio Clip 1

It’s just another clip from the mystery project. This time with portamento and adjustable vibrato depth.

Side Effects

Thursday, January 1st, 2009

Audio File 1

What does it mean???

What does it mean???

I’m still waiting on some parts to get back on track with the Pokey synth module, so I’ve been tweaking the mystery project more. The audio clip above is just a 4-note sequence. Each note generates its own pseudo-random rhythmic pattern.

Those Wonderful Toys

Wednesday, December 24th, 2008

Here are a couple short clips from playing around today. They’re from a top secret mystery project being played live. No effects have been added.

Clip One

Clip Two

YM2413 Beginnings

Sunday, December 21st, 2008

Sound Clip One

Sound Clip Two

Sound Clip Three

Yamaha’s YM2413 is a neat little FM chip used in the MSX sound expansion board. It was also in some very cheap keyboards back in the day. Thanks to its widespread consumption, enough went into circulation that they are still pretty easy to find. Another benefit is simplicity. It has only a single custom voice, lending itself well to a monophonic synth module without wasting much horsepower.

Friday I had the chip “running” as far as taking data and giving sound. It is not behaving according to the data sheet at all, though, so sadly my process is flawed somewhere. To make sure the chip was at least taking data and doing something, I made a simple loop to write every possible combination of values to the registers. The sound clips up top ensued. They are mostly noise, so watch your speakers!

A Vague Update in Picture Form

Wednesday, August 20th, 2008

The last two weeks have been quiet, but not without progress. Sadly, most of the progress is relatively uninteresting for the sake of blogging. It has been a fortnight of bug fixing, PCB footprint making, vector graphics learning, part sourcing, simulating, and etc. Instead of talking about all the gruesome minor details, here are several pictures from that span of time that may or may not mean anything.

But'ns
An Ancient Army Prepares for Battle
Snakes
Medusa
Wiring
Vectorizing
Hammer
A Gentle Hammer