Saturday, July 12, 2014

Pushing the Limits : PC Sound Chip Digitized Sound

The PC Speaker was the most limited of all sound devices for the PC.  Unlike later dedicated sound chips, the timer-driven PC speaker had no programmable capability to change the volume.  The typical PC Speaker outputs a square wave.  A square wave is suitable for representing a musical note, but not digitized audio.  A square wave is notable because the voltage level spends the same amount of time high as it does low.  If the voltage period varies (it spends more time high than low, or vice versa), it is no longer a square wave.  Additionally, if the frequency changes faster than the speaker can cope, you can get intermediate positions in the speaker cone between full expansion and full contraction. The end result is something approximating 6-bit digitized sound.  The quality of the resulting audio varied considerably on the size of the speaker cone (IBM PC=big, Tandy = bigger, PCjr. and some PS/2s = tweeters (bad)).  Some good samples of the digitized PC Speaker can be found on my friend Trixter's page : http://www.oldskool.org/sound/pc

The first practical, widely supported digital audio devices in PC games were the Tandy digital sound chip, known as the PSSJ (parallel, serial, sound and joystick), and the Sound Blaster's DSP (Digital Signal Processor) chip.  Both had access to a hardware interrupt (7 for Tandy, 7 by default for Sound Blaster) and a DMA channel (1 for both) to feed a DAC without requiring much processing time.  There was also a parallel port sound device called the Covox Speech Thing, which required the CPU to feed data bytes to the a resistor network attached to the parallel port.  The result was a crude 8-bit DAC

Between the PC speaker and the DMA-driven Earlier music devices were generally programmable sound generators, essentially using variable frequency square waves and frequency modulated sine waves to produce sounds.  None of them had natural DAC functionality.  However, these could be tweaked to simulate the effect of a crude DAC.

The PCjr. and Tandy 3-Voice chip, the TI SN76496 and its clones, was quite a bit more capable than the PC Speaker.  It had three square wave generators as opposed to the single square wave of the PC Speaker.  Additionally, it had a 4-bit volume control for the chip's output.  This volume control, combined with one of the square waves, could be used as a DAC.  The Game Blaster SAA-1099 chips operated very similarly to the Tandy chip (but with six channels per chip instead of three) and thus were also capable of using this method.  The Adlib YM-3812 chip used two operator frequency modulated sine waves to produce sound.  There are eighteen operators in total, and each could be manipulated via multiple registers.  Each operator has a 6-bit volume control, giving 6-bit DAC functionality.  Similar methods could be used to produce digitized sound as with the less-advanced devices.

As a sidenote, these methods were also used for other, non-PC chips.  Programmgers for the Commodore 64 used such methods to allow the MOS 6581 SID chip to produce an approximation of human voice for the classic game "Impossible Mission" and others.  The impressive digitized sound effects of Dungeon Master for the Atari ST were produced solely by the high-clocked AY-3-8910 clone in that machine, the YM-2149.  The Atari TIA (Quadrun) and POKEY chips could also handle digitized sound.  All these chips have 4-bit volume controls like the TI and Phillips chips, so the same methods can be used to get digitized sound out of them.  The NES 2A03 had a 7-bit DAC that could be fed directly by the processor and could also employ a delta modulation technique for digitized sound.

There are several disadvantages to this method.  First, the result will definitely sound "lo-fi" and is often very quiet.  Second, it requires a lot of processor time, because the processor has to send a lot of data directly to the device to make it work faster than it should.  Third, it requires much more space to store a sample than a chiptune, and in the era of 360KB and 720KB floppy disks, the room for digitized sound was limited.

As far as PC games go, outside digitized PC Speaker, the effect was seldom used.  An early use of the effect was in Imagic's Touchdown Football for the PCjr.  It's digitized voice only played back properly on a PCjr., the faster Tandy 1000 would make the voice sound like a chipmunk.  The game was later ported to Tandy 1000, and the voice played back at the correct speed.

Electronic Arts used Tandy digitized sound in several titles.  Among them are Kings of the Beach, 688 Attack Sub and Skate or Die.  My friend Cloudschatze has some comparison videos between the Tandy 3-voice sound and C64 SID sound on his Youtube Channel, see here : https://www.youtube.com/user/Cloudschatze/videos
Interplay used it for the sound effects in the original 16-color version of Battle Chess.  Epyx's Storm Strike uses for voice samples in at least two places.

Capstone's Bill and Ted's Excellent Adventure utilized it for the Adlib, as did Interplay's/Delphine Software's Another World/Out of this World.  Another World also supported the Sound Blaster, and the sampled sound effects sound far superior with the Sound Blaster.  GameTek's Super Jeopardy supports Adlib for digitized music and it may also support digitized playback with the Innovation SSI-2001, which also used a MOS 6581 SID chip.

Sir-Tech's Wizardry : Bane of the Cosmic Forge and Wizardry : Crusaders of the Dark Savant supports digitized sound through the Adlib, even if Sound Blaster is selected.  The game also supports digitized PC Speaker sound, and in DOSBox, you must select PC Speaker sound.  Crusaders allows you to select a music device independently of the sound device.  Some games, like Budokan, support digitized PC Speaker for sound effects regardless of sound device selected.  Dragon Wars is one of many games that supports digitized PC Speaker sound even though the Tandy 1000 and other sound cards were available by the time of its PC port's release.

Activision's OmniMusic driver, used in F-14 Tomcat, BattleTech: The Crescent Hawk's Revenge and Joe Montana Football, support digitized playback with Adlib, Tandy and Game Blaster.  BattleTech's PC Speaker digitized sound is more limited, because there is no voice in BattleTech whereas there is voice with every other sound chip.

While DOSBox can support digitized PC Speaker music reasonably well, it utterly fails to render digitized Tandy, Adlib or Game Blaster music.  Usually the result is muted, muffled or virtually inaudible.  This is one area where you still need real hardware to hear the music and sound effects as the creators intended.

14 comments:

  1. Interesting article thanks. The PC speaker has a bad name and perhaps rightfully so, but I quite like it for some games. The opening music for 'Street Rod' is a good example and I can still play it in my mind to this day. id's use of the PC speaker was also quite memorable (in wolf3d, etc).

    I've also come across some games that use RealSound (http://en.wikipedia.org/wiki/RealSound) recently and it's an interesting effect too. That + a PAS16 (which intercepts and plays PC speaker sounds from the ISA bus) is not a bad way to experience what PC speaker has to offer.

    ReplyDelete
  2. i luv when u discuss tandy 1000

    the pc of my early childhood.

    ReplyDelete
  3. The game Zeliard used some PC Speaker magic to play polyphonic music with 3 simultaneous voices.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. just noticed that I can't find any mention of this unique capability of Zeliard on he internet. So here goes:
    Configure the game to use PC Speaker for music.
    While running the game, the F1 key toggles between the following modes:
    - Music On; Single Channel
    - Music Off;
    - Music On; Multiple Channels
    - Music Off;

    ReplyDelete
  6. The first time I was blown away by a PC speaker was when playing Pinball Fantasies for the first time, and also started my love affair with tracker music generally. I'd never heard actual music on the PC speaker before this.

    ReplyDelete
  7. You say there was a way to play samples on the Game Blaster/SAA1099 chips. This is true, and I've seen examples of that on the SAM Coupe.
    But do you know of any PC software that does this?
    I've created a simple Proof-of-Concept myself, which you can find here: https://www.dropbox.com/s/fg6tibvrjp1unni/cmsdigi.zip?dl=0 (base address hardcoded to 220h).
    It works, but it suffers from some nasty aliasing, so I wonder if it can be done better. I'd like to study other examples to see how I can improve on this.

    ReplyDelete
  8. Battletech: The Crescent Hawk's Revenge is the only game I know of that tries to do digitized sound on the Game Blaster, a sample of it can be heard here :

    http://nerdlypleasures.blogspot.com/2014/09/non-pc-speaker-digitized-sound-part-ii.html

    That sample suffers from nasty aliasing too. Maybe the filtering on the Game Blaster isn't up to the task of removing the high-pitched noise. I understand it became heavier by the time of the Sound Blaster 2.0.

    ReplyDelete
  9. Oh right, I just got to your blog post via some googling for CMS/Game Blaster info and digital sound. I didn't see part 2.
    Yea, indeed, that Battletech high-pitched aliasing is pretty much what I was experiencing myself.
    At least I can now study the Battletech code to see what they are doing.

    ReplyDelete
  10. I have studied what Battletech 2 does...
    It was indeed a slightly different approach than mine.
    Simpler and faster, but more noisy.

    What I did is this:
    Play the lowest possible note (around 28 Hz), and reset the frequency generator at every sample. Use amplitude to control the actual 'DAC' output value.

    What Battletech 2 does is this:
    Play the highest possible note (around 7.8 kHz), and just leave it running. Only use amplitude to play the samples.

    That explains why you hear the 7.8 kHz whine in Battletech 2. In fact, I'm somewhat surprised it even works that well.

    Anyway, I figured I'd experiment a bit with the code, based on what I saw in Battletech 2. I found that if I combine the two approaches (use highest frequency, and reset freq generator at every sample), then it actually sounds pretty clean, as long as your sampling rate is high enough (apparently twice the 7.8 kHz or beyond will do the trick).
    If I just used a ~16 kHz sample rate with either of the two techniques, the noise was still there.
    But combined, you get this: https://www.dropbox.com/s/fg6tibvrjp1unni/cmsdigi.zip?dl=0

    Pretty nifty :)

    ReplyDelete
  11. Your playback program appears to be speed sensitive. It seems that an AT/286 @ 8MHz speed is ideal for the proper speed, can you confirm that?

    Is there any reason why the SAA-1099s are noisier at the DAC functionality than the earlier TI SN 76496 or AY-3-8910 or even a YM-3812?

    ReplyDelete
  12. It shouldn't be speed-sensitive, as long as your CPU is fast enough.
    I didn't create a new sample though, so the sample is only 8 kHz, and runs at twice the speed at 16 kHz (you can replace the sample.raw file with any 16-bit signed raw file).
    A 286 at 8 MHz may be too slow to keep up with the 16 kHz timer, so it may actually play it closer to the 8 kHz the sample was originally made for. But that probably re-introduces the aliasing as well. I've only tested it on a 20 MHz 286, and that sounded quite good.

    The SN76496, AY-2-8910 and YM-3812 can all be persuaded to play a '0 Hz' waveform. Basically you get the output 'stuck' at a certain level. Then you can manipulate that level by adjusting only the volume. Technically that is a 'proper' DAC, limited only by the resolution that the volume control gives you, and the speed at which you can change that volume (your sampling rate).

    The SAA1099 cannot play a '0 Hz' waveform, or at least, I haven't found a way to do it yet.
    So you are merely trying to approach a '0 Hz' waveform in some way, but it's not entirely level, so you will get some noise/aliasing.

    ReplyDelete
  13. Is this how Windmill Software's "Digger" did its multichannel sound?

    ReplyDelete