[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Release of DMS Drummer: A Percussion Sequencer for the Apple II



winston19842005@yahoo.com wrote:
How did we evolve from only having the ability to make beeps and door-creaking noises to this?

Never thought I'd hear something like this out of an Apple II+/e

It has been a remarkable evolution in capability--and one which is
entirely the result of software evolution, since the hardware that
is used is still the Woz-designed, beep-inspired, speaker toggle.

I got started down this path in the early 1990s, after hearing
Scott Alfter's 3-bit SoftDAC play a gravelly but still quite
intelligible "Insert Disk" message through the speaker.

Others had used the Apple speaker to produce non-beeplike sounds
before--in fact, in 1981, within two months of getting my ][+,
I had written routines to capture 1-bit sound through the cassette
port and play them on the speaker.  (HEX.DUMP.READER is an early
result of these experiments.)  But 1-bit sound is pretty hard on
the ears, with quantization noise as loud as the desired sound.

Scott's SoftDAC, by reproducing sound with 3-bit precision, made
such a noticeable improvement that it really captivated me.  I was
travelling that week, and spent part of a plane ride studying his
disassembled code.

It was quite simple, and based on the idea of using pulse-width
modulation of an 11kHz pulse train to cause the speaker to move,
not to the usual two positions--on and off--but, by virtue of
toggling it faster than it could physically respond, moving it
to 8 different positions, providing 3-bit resolution in reproducing
the 11kHz sound samples.  (This is not strictly true, but it is
a straightforward way of understanding what is going on.)

A word about sampled sound:  an Apple II un-augmented by an ADC
card is not capable of capturing sound to greater than 1-bit
precision (not strictly true, but close enough for our purposes),
so the sampled sounds must be obtained either with an ADC-equipped
Apple II or from some other source.  This story is about *playing*
sampled sound, not capturing it.

Inspired, I set about discovering how far I could push this PWM
technique to greater precision.

Sticking with the "standard" 11kHz sample rate, I had 92 cycles
of the Apple clock per sample to work with.  Within this amount
of time, it is necessary to 1) fetch the next sound sample, 2)
test for the end of the sound, and 3) generate a pulse whose width
is proportional to the value of the sample.  Sounds easy.

It turns out not to be so easy, since generating a speaker (or cassette)
pulse requires toggling the speaker to start the pulse, then toggling
it again (with 1-cycle accuracy) to end it at precisely the right time.

The difficulty arises because often the pulse must end before the
sample has been fetched and decoded.  So it is necessary to "pipeline"
the samples:  while playing the previous sample, the next sample must
be fetched, end-checked, and decoded to be played in the next 92-cycle
interval.

So far, so good.  And, with clever coding techniques, it is possible
to obtain 6-bit precision at an 11kHz pulse rate.  Not bad for a machine
that is only designed to beep!

The problem remaining is that the 11kHz pulse train is *extremely*
loud, and quite annoying even to ears without great high frequency
response.  ;-)

Since my objective was to reproduce good sound on an unmodified
Apple II (and with unmodified ears ;-), I decided to trade one bit
of sample resolution for a 22kHz pulse train.  This effectively
plays each 11kHz sample twice with 5-bit resolution, eliminating
the 11kHz "carrier" and making the speaker output much more pleasing
for all but those blessed with good hearing at 22kHz.

For pretty mundane reasons, I called this software DAC "DAC522", and
it is the basis of all my sound programs:  SOUND.EDITOR, CRATE.SYNTH,
RT.SYNTH, and now DMS Drummer.

Of course, the internal Apple speaker is a sonic disaster, with almost
no low-frequency response, so anyone who wants to hear the sounds with
any fidelity will want to: 1) connect an external speaker, 2) use some
headphones, or 3) connect an external amplifier and speaker.

If an external amplifier (or amplified speaker) is used, then you can
turn down the treble control to filter out any noise above the highest
useful frequency, which is 5kHz.  This is, after all, what used to be
known as "AM radio" fidelity.  ;-)

There were some further refinements along the way which reduced the
"pops" which result from starting and stopping the 22kHz pulse train--
the solution is to never stop it!  A significant modification to DAC522
allowed it to resample on the fly, rather than just playing a sound
as it was recorded.  This allows full wavetable synthesis of musical
instrument voices at any desired pitch.

So, as you can see, the "breakthrough" technology is pulse-width
modulation, which makes digital-to-analog conversion possible on the
Apple II, and various refinements, which make it pleasing to the ear
and useful for musical applications.

On a more personal note, DAC522 and all of its applications are
critically dependent on cycle-accurate timing, and the challenge
that it represents has been a consistent thread running through
several of my projects.  The core "wire-wiggling" routines of
NadaNet make similar use of cycle-accurate programming, and derive
their speed and reliability from those techniques.

I was first awed by these techniques used in Woz' RWTS, and the
strict timing determinacy of the Apple II remains one of its most
endearing characteristics, sadly lacking in most modern systems.

-michael

NadaNet 3.1 for Apple II parallel computing!
Home page:  http://home.comcast.net/~mjmahon/

"The wastebasket is our most important design
tool--and it's seriously underused."