Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
printz

Any .WAV to PC SPEAKER converter?

Recommended Posts

Is there any program which converts wave files into PC speaker sounds for vanilla Doom? Would be fun...

Share this post


Link to post

The PC speaker format has never been properly understood, so no. You'll find that there are no utilities for manipulating/generating Doom PC speaker sound effects.

Share this post


Link to post

How were the ones in FreeDoom made (assuming there are some in there - I haven't actually checked)?

Share this post


Link to post

First of all, what kind of "conversion" are you talking about? The PC speaker is able to either play back simple tones with minimal CPU usage and programming effort, or be made to play back ".WAV" sound (PCM) via the use of complex programming and signal theory techniques, check PC Speaker entry on Wikipedia.

The "PC speaker effects" present in doom aren't PCM playback, because that would consume much more CPU time than a sound card, due to the lack of a DMA channel and the need of precise output control, in order to get acceptable output (however it could be done, playing "normal" sound effects through the PC honker).

By "converting to PC speaker" I assume you meant something that takes a "normal" PCM sound sample and converts it to a series of squeaks and beeps that somewhat resemble it...with a LOT of immagination.

Such a tool would require far more effort to write than the results would justify (in practice, a complex signal analysis in order to produce a very, very rough approximation of the original sample in terms of beeps and squeaks, not even comparable with a 4-bit PCM recording).

Very probably, the original PC Speaker effects for Doom were hand-coded sound effects encoded as frequency+duration commands, which with a little guesswork and tweaking could be make to at least sound different than the other (e.g. gunfire should sound like a "crash" sound and be short, a death scream should sound somehow longer and contain melodic/cascading frequencies etc. etc.) but no magical WAV-to-BEEP converters.

Share this post


Link to post
fraggle said:

The PC speaker format has never been properly understood, so no. You'll find that there are no utilities for manipulating/generating Doom PC speaker sound effects.

Seemed quite easy for me. After a header, the rest of the bytes meant the amount of frequency to be played at that moment. A sinusoid shaped string of bytes results in a siren-like alarm. I once made a shotgun-like sound (fire/reload) but it was shorter than intended, but proportional to the rest of the sounds. Can't know what's that hard.

Basically, a program like this would scan WAV's frequency per nth of second and store a similar number into the DP* lump. Sounds cake, but I still have to take a search/look.

Share this post


Link to post

It probably is just a duration+frequency combined information.

Printz wrote:
Can't know what's that hard.
...
Basically, a program like this would scan WAV's frequency per nth of second and store a similar number into the DP* lump. Sounds cake, but I still have to take a search/look.


You got the idea right, but it's not "easy": you're entering the domain of frequency analysis. While "frequency sampling per nth of a second" is indeed practically used, it involves "scanning" for ANY possible frequency, even if you want to single out just one. Natural sounds can be very complex and contain up to thousands of different frequencies per second, and even something complex like e.g. one second of music can be "assembled" by adding up thousands of sinusoidal waves at varying frequencies, phases and amplitudes, which if taken individually sound like bland, continuous single pitches, but when added up correctly result in quite a complex and different sound, which doesn't sound at all like it was the sum of continuous sine waves! (BTW, that's how a part of the MP3 compression scheme works, more or less)

However, even "singling out" the single most powerful of these requires:

a) Performing a complete e.g. Fourier analysis of a signal for every second
b) Filtering out all but the stronger frequencies for that second.

Even if you manage to do that, the result will be capturing only the single most powerful "pitch" of a sound or a melody (e.g. applying this to you humming or whistling a tune, would result in a monophonic, fundamental frequency (sinusoidal) melody resembling what you were humming).

However for more complex sounds it would probably result in a single, flat frequency with no apparent connection to the original sound, since it's the addition of many different simultaneous frequencies that makes a gunshot or an instrument sound as they should.

The PC speaker however, can only play square waves with a single amplitude and variable duration, so even the captured sinusoidal frequency would be transformed into a square wave, thus introducing further distortion. You can simulate sine waves with complex programming tricks, but at that point, it will be better to play PCM samples directly with the speaker!

Don't forget that iD software had a reputation for cool PC speaker sound in its older games (e.g. Commander Keen), and those were carefully crafted sequences of beeps and bloops, and so are doom's sounds. E.g. to make a gunshot, you need some "trashing noise" at first (easily made by playing random frequencies closely) then a series of quick, decreasing pitches (in order to simulate a "bang" exclamation). Similarly, you can imitate the main pitches of a scream or even a sentence by quickly playing the appropriate pitches in succession. A Fourier analysis thing would perhaps be helpful and/or more accurate, but considering the poor results you'd obtain anyway, not worth the effort. Hand-crafting frequencies by guesswork, by "ear" and trial and error is the most common method for synthesized sound effects, including PC speaker ones.

This USED to be an art in the old PC gaming days, but it fell in disuse since sound cards became commonplace, and it's very unusual that a 1993 game (Doom) offered support for the PC speaker at all.

Share this post


Link to post

The timing and frequencies of the PC speaker lumps (DPxxxx) is well known, I've posted the frequency formula on Doomworld at least once (FreeDoom forum).

A while ago I wrote a program to convert sound files to PC speaker lumps. Pretty straight-forward: use DCT to convert the waveform to frequency domain, then pick the strongest peak for each time period.

I even tried dithering, since each time period is very short (7ms) but the human ear (AFAIK) requires at least 20ms to register a sound, hence I alternated between 3 different "peak streams". Not sure whether that improved the sound or made it worse :-). Can't find the source now, I probably let it slide.

EDIT: the DPxxxx lumps in FreeDoom are empty ones.

Share this post


Link to post
Ajapted said:

A while ago I wrote a program to convert sound files to PC speaker lumps. Pretty straight-forward: use DCT to convert the waveform to frequency domain, then pick the strongest peak for each time period.


Bingo! Exactly what I said. I would like however to try and hear if the result is indeed worth all that trouble, in the best of cases you preserve the pitch/melody of something, and noise/blasts would probably render as random frequencies.

The funny thing is, that if you sample with a high enough frequency/small enough interval, in the end you will end up reproducing the PWM/PCM playback method, as well as using a LOT of data.

Anyway, the overall effect of the whole WAV->BEEP conversion would be comparable to applying an extreme distortion filter/vocoder to an audio file: sure, you will obtain something that hopefully sounds interesting and is somewhat correlated with the original audio file, but not a "perfect conversion" or even an "equivalent representation".

I mean, I wouldn't put my hand on fire that this (convenient, since it's automated) method would always produce better results than a hand-crafted sound effect.

Share this post


Link to post
Maes said:

This USED to be an art in the old PC gaming days, but it fell in disuse since sound cards became commonplace, and it's very unusual that a 1993 game (Doom) offered support for the PC speaker at all.

An awful lot of computers back then lacked a sound card. Even for new computers sold at the time (and into 1994), a sound card was often an optional extra, or something people tended to buy separately once they had decided they needed one.

Share this post


Link to post

I remember standing in awe (lol) with five software engineers as my flatmate installed a soundcard into his pc. Doom still only ran in a tiny window (386 pc) but pc speaker never sounded the same again, sadly he didn't own the card and we only got thirty minutes with it. Sound cards and CD-ROM drives were luxury items.

Share this post


Link to post
Grazza said:

An awful lot of computers back then lacked a sound card. Even for new computers sold at the time (and into 1994), a sound card was often an optional extra, or something people tended to buy separately once they had decided they needed one.


Agreed that it was an extra. If you didn't have one, you just didn't get ANY sound out of any game made after 1993 or 1994. Apogee titles (and notably Doom) were among the last titles to offer some kind of support for the PC speaker, and after 1995-1996, when the Miles sound library and midi music was commonplace, the PC speaker was practically unused, either for SFX or MIDI music.

Share this post


Link to post
Ajapted said:

The timing and frequencies of the PC speaker lumps (DPxxxx) is well known, I've posted the frequency formula on Doomworld at least once (FreeDoom forum).

A while ago I wrote a program to convert sound files to PC speaker lumps. Pretty straight-forward: use DCT to convert the waveform to frequency domain, then pick the strongest peak for each time period.

I even tried dithering, since each time period is very short (7ms) but the human ear (AFAIK) requires at least 20ms to register a sound, hence I alternated between 3 different "peak streams". Not sure whether that improved the sound or made it worse :-). Can't find the source now, I probably let it slide.

EDIT: the DPxxxx lumps in FreeDoom are empty ones.

Yeah, I remember you decoded the general format. I'd like to know what the exact algorithm is for mapping of values -> frequencies is though. I've thought in the past that it could probably be done using a modified version of DOSBox changed to print the frequencies of data sent to the PC speaker. Alternatively, maybe entryway with his disassembling skills can work it out :-)

Share this post


Link to post

Here is what I said earlier:

FWIW, I figured it out by trial and error.
Each byte in the DP lump lasts 1/140 second.
Zero byte is silence, otherwise frequency is approximately 2 ^ (7.463 + value * 0.0408) Hz.

The PC speaker uses 1193182 Hz as the base frequency, and a 16-bit divider. Minimum frequency is therefore 1193182/65535 or 18.2 Hz, the old DOS timer interrupt frequency.

I've just been playing with that divider formula, but can't make anything elegant fit with my original formula. The closest I found was:

f(x) = 1193182/((127-x)<<4)

Share this post


Link to post

Yay! Relearning the lost art of PC-beeps in 2007 ? Take THAT, Creative Labs :-D

Seriously however, without wanting to sound patronizing to any of the programmers/sound engineers here, the PC Speaker has well known limitations, and using a single square wave to "approximate" the pitch of a PCM sound sample sounds like something else.

I'm sure that if the PC speaker could -at least- consume as much CPU time as a typical sound card of the era, the Gods at iD would have opted for a full PCM-output (yeah, that means 4 PCM channels mixed into the tiny PC honker). Since that didn't happen, they just provided it with a series of beeps that, some of them at least, sound a bit like the pitch of e.g. the death screams or the plasma gun's/BFG crescendo.

As I said, it was also unusual for a 1993 game to include ANY kind of PC-speaker support (but id being id, they had to do something :-) ).

What I'm trying to say: no matter how hard you try, it's always going to sound like the PC speaker always did (there's a reason why sound cards eventually became popular!).

However, just in case you're interested, you can try "Pinball Fantasies" by Digital Illusions: it provided the same exact MOD music and digital effects through ANY of the supported soundcards, including DAC emulation on AdLib, PC Speaker and support for parallel port DACs.

Perhaps someone want to make a special Doom port with full PCM output through the PC-speaker? :-p

Share this post


Link to post
Maes said:

Yay! Relearning the lost art of PC-beeps in 2007 ? Take THAT, Creative Labs :-D

LOL :-)

Actually I may have figured out what's going on. The beep values could be mapped to MIDI note numbers, using this formula:

note(x) = 52 + x/2
Where 52 is note E-4. Comparing this with my original formula and it very very close.

This idea comes from the fact that 0.0408 is around 1/24 where note frequencies differ by a factor of 2^(1/12).

Maes said:

What I'm trying to say: no matter how hard you try, it's always going to sound like the PC speaker always did (there's a reason why sound cards eventually became popular!).

Definitely. I've also played around outputting PCM sound to the PC speaker, aside from requiring full CPU utilisation (writes to the IO port are so slow, plus you need to disable all interrupts as well to get something decent sounding), the worst part is that the PC speaker itself in most systems is just too tiny / low-powered to hear it, especially over the fan noise.

What I was interested in was speech synthesis for blind users in a situation where they have no sound card and the PC speaker was the only option. But the PC speaker is just too quiet to make that viable.

Share this post


Link to post

This may be a bit offtopic, but what sort of format are many of the Wolfenstein sounds in, such as item pickups? And is there any way to convert those into something where I could record those to .wav?

Share this post


Link to post
EarthQuake said:

This may be a bit offtopic, but what sort of format are many of the Wolfenstein sounds in, such as item pickups? And is there any way to convert those into something where I could record those to .wav?


From the SOUND of them, and the fact that they didn't interfere with digitized SFX (voices, gunshots etc.) they were probably direct AdLib command sequences or simple MIDI notes (didn't notice if you still heard something similar with just a General Midi capable card).

Definitively however, they were synthesized for AdLib/Soundblaster (OPL2). Considering how id was so careful about sound, it's plausible they are some low-level FM chip commands (and it seems strange how they didn't use the same solution for SFX over AdLib in Doom, but perhaps the sound system was too different to allow a mixed music/SFX use).

About "converting", the layman's way would be recording the output of the game directly and isolating them, else it involves ripping codes, and emulating the OPL2 chip.

Share this post


Link to post

I'm more interested in BEEP sounds, not fantasy-like sampled PC Speaker sounds which seem indeed to eat power. As an example of sampled PC sounds, is it the one from Supaplex, when you set internal sounds to "samples"? Glad I've triggered your enthusiasm. My idea is to make internal Doom sounds that are differentiated. By default, much stuff shares sound. Regular monsters see and die the same. Bosses see and die the same. Some monsters from Doom 2, as far as I heard, only do a tiny short low pitched beep when they should burst. And PC sound could be the only one one can hear under Win XP and unchocolated 'nilla Doom. Unfortunately, as you might see, I'm not well informed on the work of sounds.

Share this post


Link to post

So you want more varied beep sounds? I guess they could have done it back then if they wanted to (and, by 1993 standards, iD put far more effort than necessary in PC speaker effects, plus as I said like 2-3 times now, they had the experience from Commander Keen games, about creating "rich" PC speaker beep-only effects).

What next, a "Doom oldsk00l" port with dramatically enhanced PC Speaker sound (either PCM + MOD/chiptune, or "oldskool" quickly arpeggiating music and sound effects) and TEXTMODE video output? :-D

Share this post


Link to post
printz said:

Yeah. Varied and similar to the digitized. But still beep.


Then you should be happy with the sounds as they are now. True, they could have used a bit more variety but IMO they didn't even bother making a different PC Speaker sound for pistol and shotgun: they sound exactly the same, and in vanilla they are probably hardcoded in the proprietary and non-GPLed sound system (BTW, are there as many PC Speaker lumps as there are DSxxxxxx lumps?).

No idea if they made any new sounds for Doom 2. Interestingly, Heretic, that uses the Doom engine, doesn't have support for the PC speaker at all.

Share this post


Link to post
Maes said:

No idea if they made any new sounds for Doom 2.

They did. They sound like short taps. Especially Baphomet. His sight sound is merely a tap. Most sounds are different to their Doom I similar.

Share this post


Link to post
Ajapted said:

Actually I may have figured out what's going on. The beep values could be mapped to MIDI note numbers, using this formula:

note(x) = 52 + x/2
Where 52 is note E-4. Comparing this with my original formula and it very very close.

This idea comes from the fact that 0.0408 is around 1/24 where note frequencies differ by a factor of 2^(1/12).

Some thoughts I just had: I think it's unlikely that DMX supported PC speaker effects, which means that Id probably wrote the code themselves. If this is the case, it's more than likely that they reused whatever sound effect format/code they used in previous games. This would let them reuse the same tools they used to generate them. Perhaps it would be worthwhile looking at the Wolf3d source?

Share this post


Link to post

fraggle wrote about SMMU:
If you have a fit and die after playing my port, it's not my fault.

Best disclaimer ever.

I believe the VGA hardware can program a text mode of 160x50. By reprogramming the character cells to be a 2x4 block of pixels, you get a crude 320x200 video mode. Imagine DOOM on that :-)

fraggle said:

Some thoughts I just had: I think it's unlikely that DMX supported PC speaker effects, which means that Id probably wrote the code themselves. If this is the case, it's more than likely that they reused whatever sound effect format/code they used in previous games. This would let them reuse the same tools they used to generate them.

Yeah, I believe the music connection is very strong. The MUS music format is based on 140Hz timing, which is where the 35Hz video refresh rate comes from (divide by 4). Their DOS interrupt would simply program the PC beeper each time. It's possible this was a feature of DMX (meant for music playback).

Perhaps the same note range was used in their earlier games with PC speaker music?

EDIT:

fraggle said:

Perhaps it would be worthwhile looking at the Wolf3d source?

I've just browsed around ID_SD.C and ID_SD_A.ASM, and didn't see any code for playing music on the PC speaker, but I did find some code (if I understood correctly) for playing digitized sounds on the PC speaker, using a 7000Hz interrupt! Was this feature actually present in the game?, as I don't remember it.

Share this post


Link to post
fraggle said:


Textmode can actually display clearer stuff and with more color dithering effects than most people would think, if you use careful character manipulation and background/foreground colors, check out 8088 Corruption.

However, encoding digital video into this "richer" text format must take a lot of CPU time, as it involves dithering, shape/corner analysis etc. Playing it back on the other hand, is trivial.

Anyway, not really worth it to reverse engineer the "beeper" format of doom: I remember experiencing with GWBASIC and QBASIC like in 1992-1994 and trying to make simple programs with an "interesting" sound output through the PC Speaker. These included "spaceship", "Bass drum", and even outright PCM sound output, including a program that read the input from the SB Mic in and tried to play it back real time on the PC Speaker...and a "speech synthesis" program using simplistic vowel and consonant sample files. Anyway, all stuff that had been done before and more successfully by more hardcore ASM and C/C++ programmers and demogroups :-)

Share this post


Link to post
Ajapted said:

format is based on 140Hz timing, which is where the 35Hz video refresh rate comes from (divide by 4). Their DOS interrupt would simply program the PC beeper each time. It's possible this was a feature of DMX (meant for music playback).

I have experimental evidence for the musical connection :-)

http://www.soulsphere.org/random/speaker_values.csv

I made a modified version of DOSBox that prints out the countdown values sent to the timer chip (PCSPEAKER_SetCounter in src/hardware/pcspeaker.cpp), then used it to run Doom. I ran Doom with a PWAD containing a replacement DPPISTOL lump, with a rising scale that goes through all values from 1..95.

In the CSV file above, the first column is the counter value; the second is the actual frequency this corresponds to (freq = 1193180 / counter). Now compare the frequencies in the second column with the frequencies on this page at the bottom. The Doom values seem to be a superset of the frequencies in the western music scale; there seem to be 24 notes per octave, where as western music has 12 notes per octave. ie. The Doom values have an extra note halfway between each semitone.

Some of the frequencies seem to be off by a couple of hz, I don't know why.

Share this post


Link to post

Neat little proggy, fraggle. It reminded me of my days of random experimentation with the PC speaker and port 0x61 :-)

Seriously, since there is a sort of renewed interest in the sound capabilities (or lack thereof) of the IBM Sound System (TM), why not complete the task and produce a polyphonic MIDI driver for the PC speaker to use for crude music output (and perhaps use it to polyplex sound effects, with the usual oldskool tricks, to the extent they're windows-friendly).

The techniques for giving the illusion of playing multiple notes via arpeggio are well-known, a complete driver for source ports would be t3h p4wn..just imagine listening to E1M1 or E1M8 music via the PC speaker...awesome.

Share this post


Link to post
fraggle said:

Andrew, I've drafted a PC speaker file format description to document the PC speaker format. If you could have a look over I'd be grateful.

Looks great, well done.

One minor thing I suggest is to give the notes in the frequency table their octave number, i.e. F-3, F#3, G-3 etc...

The small frequency errors are just an accuracy thing, for example:

1193182.0 / 2349.32 = 507.8839, round down then:
1193182 / 507 = 2353.416

Hence you could replace the statement "this is possibly some kind of rounding error" with something like: "this is simply a limitation of the 8253 chip".

I've also written a small program to play PC sound effects (source code). I don't notice any difference between the output from this and Vanilla Doom.

Cool.

Linux has an ioctl() for playing beeps on the PC speaker (maybe KDMKTONE), I think you use it on /dev/tty, but I'm not sure if that works in X-windows or not. From your code I guess the Beep() function also delays, whereas the Linux ioctl() doesn't delay.

Share this post


Link to post
Guest
This topic is now closed to further replies.
×