VOGONS


First post, by NY00123

User metadata
Rank Member
Rank
Member

Hey all,

Before writing about its purpose, I'd just tell that a minor (experimental) patch to DOSBox v0.74 is attached. I've chosen v0.74, as the SVN changes often, while it also doesn't seem to differ where the patch is to be applied.

Now to explain the patch's purpose: Some of you have possibly spotted some differences between sounds outputted via DOSBox' emulated PC Speaker and the same ones outputted via a real speaker. This is especially noticeable in games like Commander Keen 1-3 and Dangerous Dave, at least for some of the sound effects.

Here's a way to illustrate the cause (even if not fully accurate). Suppose that some game outputs a few successive square waves (beeps) of exactly the same frequency. Then:
- On a real speaker, when a new wave begins, it really begins from scratch, "forgetting" any earlier wave.
- In DOSBox, the waves are "merged" into a single long(er) successive square wave of the same frequency.

So, this patch is an attempt to solve this.
It's confirmed to *not* break the ability to output proper digitized sound via the speaker, at least in Ken's Labyrinth.

KNOWN ISSUES:
- Some who try the patch may feel that the sound quality is lower, or that the sound is less "smooth". In fact, this is closer to the way it works with an actual speaker, and I consider it to be more "authentic" 😉.
- Maybe it's just me, but I have a feeling that a few unexpected high-volume noises are outputted in Dangerous Dave, at least upon obtaining a trophy, a gun or a jetpack. You still get something more true to the original, though.

AN IDEA (possibly low priority):
- Let the user choose between the current DOSBox way of emulating and the patched way. May be used for backwards compatibility with a few things originally developed and tested within DOSBox (i.e. games or MODs).

Note that I haven't posted this on the "Patches" sub-forum, as this is experimental, and there may be a better (code-wise) way of improving the emulation's accuracy.

Have fun!

Attachments

Reply 1 of 47, by NY00123

User metadata
Rank Member
Rank
Member

Hmm, looks like I can't edit the post. Alright lets add a new short one 😀

Basically, I'm attaching two recordings of sound effects from Commander Keen 1 for comparison: One recorded on the unmodified DOSBox v0.74, and the other one on the patched DOSBox. So, a few should now have a ready comparison, possibly clarifying what I've originally referred to. It shouldn't be a surprise if the patched form sounds much more similar to a real thing than the non-patched.

Attachments

  • Filename
    keen1_dosbox074.ogg
    File size
    124.74 KiB
    Downloads
    527 downloads
    File comment
    Recording from CK1 with vanilla DOSBox v0.74
    File license
    Fair use/fair dealing exception
  • Filename
    keen1_dosbox074_pcspkrpatched.ogg
    File size
    133.52 KiB
    Downloads
    556 downloads
    File comment
    Recording from CK1 with patched DOSBox
    File license
    Fair use/fair dealing exception

Reply 2 of 47, by robertmo

User metadata
Rank l33t++
Rank
l33t++

edit button is in the top right corner of every post, although it is better to add new post as otherwise it won't be noticed. I don't think many people (if any) open every thread to check if one of posters edit something. That is simply not possible.

Btw is there any way to highlight edited threads? Are there any forums on Internet with such a feature?

Reply 5 of 47, by VileR

User metadata
Rank l33t
Rank
l33t

VERY NICE! This seems to fix many things, a lot of them way more basic than Keen's sfx. Tried some games that use the PC speaker for simple one-note music, and all of them sound better w/ this patch - i.e., successive notes of the same pitch can be distinguished.

Heck, if you just open GWBASIC and type "BEEP:BEEP:BEEP", you can actually hear three distinct beeps now 😁

However, here's the bad news.... I tried testing a few more games/programs that tweak the PC speaker, and found one thing that seems to break so far - the fanfare in Digger (when you complete a level) sounds choppy and misses notes.
If you'd like a recording, feel free to ask, though I've only compared MB6 vs. my own SVN build (to which I applied your patch), so I might be in the wrong here.

[ WEB ] - [ BLOG ] - [ TUBE ] - [ CODE ]

Reply 6 of 47, by NY00123

User metadata
Rank Member
Rank
Member

Thanks to anyone who has tried this or even just listened to the previously attached samples!

robertmo wrote:

edit button is in the top right corner of every post, although it is better to add new post as otherwise it won't be noticed.

Interestingly, while looking for it, I've got to the text on the bottom-right, telling what I can and cannot do. I've been so sure it tells I cannot do so many things, editing posts being one of them...but now I see that I can...oh well...Ah, and thanks for telling about the edit button, of course!

bloodbat wrote:

Great patch Happy
Here it is for SVN.

This is good for the many with SVN or so 😀

VileRancour wrote:

However, here's the bad news.... I tried testing a few more games/programs that tweak the PC speaker, and found one thing that seems to break so far - the fanfare in Digger (when you complete a level) sounds choppy and misses notes.

Yeah, I've just that that Digger clone from 2001 and could spot it. One good reason to really consider the patch "experimental" then.
As for possible causes:
- There's a specific case I haven't taken care of. To compare, originally, the patch had no the check for mode 3, resulting in the digitized sounds within Ken's Labyrnith not working as expected (of course talking about sounds outputted to the PC speaker).
- There are two "problematic" sound effects in Dangerous Dave (obtaining a trophy and obtaining a gun/jetpack). These may now sound much similar to the originals, but there are still a few bits of a little high volume heard, or so I believe. I have a very basic guess for the cause but I'm unsure.

Well, if it is incorporated, it could be wiser to have two modes then: Original (i.e. for Digger or "backwards compatibility" with a few things) and patched (usually more true to the real thing).

Reply 7 of 47, by leileilol

User metadata
Rank l33t++
Rank
l33t++

Another game to test this with is Hard Drivin' II. The engine makes a powerful motor "buzzing" noise, but in standard Dosbox it's pitched and doesn't have its "buzz".

apsosig.png
long live PCem

Reply 8 of 47, by bloodbat

User metadata
Rank Oldbie
Rank
Oldbie

Based on what NY00123 said and for ease of testing, here's a quick patch (for SVN) that allows you to turn off or on the experimental patch. The code could probably be improved, but...hey...I'm sleepless right now, so I had to do something. 😜

In your .conf file.

[speaker]
pcspeaker=exp

The possible values are true, exp and false.
True gives "vanilla" DosBox emulation, exp provides experimental patch and false behaves just as you'd expect.

It can be changed on the fly without quitting or restarting DosBox (with config).

It includes NY00123's patch.

Attachments

Reply 9 of 47, by VileR

User metadata
Rank l33t
Rank
l33t

some thoughts about fixing Digger w/ this patch... I have a hunch that an extra conditional check or two would fix it:

the end-of-level music tries to produce non-square waves by modulating the speaker cone position (changing the on/off values *really* quickly, so that the physical speaker doesn't have the time to reach fully ON/OFF status, producing intermediate levels). This doesn't happen with Keen's sfx or with simple single-tone music, which this patch does fix well.
So perhaps some of those "last" vars for the previous speaker/PIT status should also be checked, to determine whether or not we really need to set spkr.pit_index = spkr.pit_max. Right now it's done unconditionally and that's what seems to break (silence) certain sections of the music in this case.

unfortunately, I don't know enough about the DOSBox pcspeaker code, what the various "modes" mean or what each status var stands for. Maybe someone who does can tackle this, but hopefully i'm on the right direction with this.

bloodbat: nice - works fine here with your config patch.

[ WEB ] - [ BLOG ] - [ TUBE ] - [ CODE ]

Reply 10 of 47, by NY00123

User metadata
Rank Member
Rank
Member
VileRancour wrote:

the end-of-level music tries to produce non-square waves by modulating the speaker cone position (changing the on/off values *really* quickly, so that the physical speaker doesn't have the time to reach fully ON/OFF status, producing intermediate levels).

This is, in fact, *exactly* my guess for the cause of a few high volume samples in the Dangerous Dave sounds mentioned beforehand. The current patch raises the emulated speaker's cone to the maximum immediately, not gradually; So it shouldn't be a surprise if an unexpected little noise is being heard.

Unfortunately, I have a feeling that correcting that wouldn't be so trivial, and, in fact, might even require a rewrite of most of the speaker code, if not all.
As of now, most of the time, the speaker's volume is really one of the edges: The very maximum or the very minimum. The only case when it isn't, is when so-called "Timer mode 0" is used. This is basically how digitized sound works in games like Ken's Labyrnith. For the usual square waves, mode 2 is used.

For such a rewrite, I suppose, all that the speaker should really know is its input; If 1, the speaker's (emulated) cone will gradually move to the maximum. Otherwise it'll gradually move to the minimum. When it comes to the different timer modes (i.e. square waves), these are to be handled by the timer only.

Therefore, I think that for now, the solution would be in bloodbat's way: Let one toggle the speaker mode. Use the patched mode in games like Commander Keen and the original in ones like Digger.

Reply 11 of 47, by ripa

User metadata
Rank Oldbie
Rank
Oldbie

I made some modifications to PC speaker emulation a while ago (tried to fix popping). If you're interested in incorporating my changes, check out:
Re: Emulate PC Speaker with Soundcard

It would be incredibly helpful if someone had a scope and captured the pre-filtered (e.g. on or off voltage) output from the speaker wires.

Reply 12 of 47, by VileR

User metadata
Rank l33t
Rank
l33t

NY00123: oh yeah - for now the ability to switch between the two modes is perfect. Just trying to think how to help this progress beyond experimental stage, precisely because I'd really like to see it committed into DOSBox (trunk) someday 😀

Anyway,

NY00123 wrote:

As of now, most of the time, the speaker's volume is really one of the edges: The very maximum or the very minimum. The only case when it isn't, is when so-called "Timer mode 0" is used.

are you sure? I just made a recording of the end-of-level Digger music (with the 'original' speaker mode), opened it up in Audacity, and I can clearly see various sample levels in between min and max. Unless we're not talking about the same thing here, in which case I again have to plead ignorance of what the various code bits really do.

curiously though, similar intermediate levels also appear in other bits of 'tweaked' speaker audio (i.e. in Styx), which do sound fine with your patch. So I don't know if a total rewrite woud be needed, but I'm also not sure anymore why this piece of music seems to break, but not others.
Perhaps it's still reasonable to somehow check for the previous "speaker" position and then do the reset it to pit_max only if it wasn't at an intermediate level. Really don't know though.

[ WEB ] - [ BLOG ] - [ TUBE ] - [ CODE ]

Reply 13 of 47, by NY00123

User metadata
Rank Member
Rank
Member
ripa wrote:

I made some modifications to PC speaker emulation a while ago (tried to fix popping). If you're interested in incorporating my changes, check out:
Re: Emulate PC Speaker with Soundcard

Hey, nice to see that you've attempted to solve another speaker-related issue. Truly, it seems to be a bit different than what I've originally aimed to solve (for Keen and the like).

However, I've attempted to use your patch, combined with mine. Interestingly, the digger game doesn't output the "popcorn" theme music anymore 😮. The level completion fanfare still plays, and it is maformed as it is just with my patch (and not the two combined).
BTW, I've used a sample rate 48000Hz for this test (along with a few other ones), to accommodate to a few values you've got from somewhere.

VileRancour wrote:
are you sure? I just made a recording of the end-of-level Digger music (with the 'original' speaker mode), opened it up in Audac […]
Show full quote
NY00123 wrote:

As of now, most of the time, the speaker's volume is really one of the edges: The very maximum or the very minimum. The only case when it isn't, is when so-called "Timer mode 0" is used.

are you sure? I just made a recording of the end-of-level Digger music (with the 'original' speaker mode), opened it up in Audacity, and I can clearly see various sample levels in between min and max. Unless we're not talking about the same thing here, in which case I again have to plead ignorance of what the various code bits really do.

curiously though, similar intermediate levels also appear in other bits of 'tweaked' speaker audio (i.e. in Styx), which do sound fine with your patch. So I don't know if a total rewrite woud be needed, but I'm also not sure anymore why this piece of music seems to break, but not others.
Perhaps it's still reasonable to somehow check for the previous "speaker" position and then do the reset it to pit_max only if it wasn't at an intermediate level. Really don't know though

Hmm... well, logging calls to some function like PCSPEAKER_SetCounter, it seems like timer mode 3 (square waves) is the only one being used, at least when it comes to speaker output. So, while some games with digitized sound may take advantage of mode 0 for that, this isn't the case here.
I've also recorded the Digger fanfare on vanilla DOSBox v0.74. The recorded contents appear to be made of many short spikes, with (relatively) long periods of silences in-between.

So I have a few guesses regarding this:
- Maybe Digger does commonly turn off the sound in a few places (i.e. disconnect the speaker from the timer), if not all. It could explain why, in a few occasions, the volume level goes up from negative to 0 and then down again.
- As vanilla DOSBox doesn't restart tones the way it's done in the patch, it may, actually, be more similar to the real thing, with the speaker cone taking a short while to move.

Reply 14 of 47, by ripsaw8080

User metadata
Rank DOSBox Author
Rank
DOSBox Author

A tweak to the modification seems to keep the effect on Keen while not harming Digger:

     case 3:        /* Square wave generator */
if (cntr<spkr.min_tr) {
/* skip frequencies that can't be represented */
spkr.pit_last=0;
spkr.pit_mode=0;
return;
}
+ if (spkr.mode==SPKR_PIT_ON) spkr.pit_index=spkr.pit_max;
spkr.pit_new_max=(1000.0f/PIT_TICK_RATE)*cntr;
spkr.pit_new_half=spkr.pit_new_max/2;
break;

Reply 18 of 47, by NY00123

User metadata
Rank Member
Rank
Member

Oh wow, a simple "relocation" of the original patch seems to solve not just the digger fanfare issue, but also the volume issues with these DDave sound effects! Good find Ripsaw!
So, the problematic sound effects in Dangerous Dave are now being heard even more like the originals! And, there are some clearly doubts regarding my guess about "short square waves" and the like...

Oh well, possibly a bit late, I've decided to attach a few more sound samples for comparison; This time from Dangerous Dave, and taking advantage of the new patch. You may clearly hear how you practically get whole different sound effects! (And after patching, actually recognized as the originals.)

Ah, and yes, the Keen 1 sounds are still correct now.
Thanks Ripsaw!

Attachments

  • Filename
    dave_gotsomething_dosbox_newpatch.ogg
    File size
    9.09 KiB
    Downloads
    427 downloads
    File comment
    DDave "got gun/jetpack" sound with the new patch
    File license
    Fair use/fair dealing exception
  • Filename
    dave_gotsomething_dosbox_vanilla.ogg
    File size
    9.58 KiB
    Downloads
    405 downloads
    File comment
    DDave "got gun/jetpack" sound, vanilla DOSBox
    File license
    Fair use/fair dealing exception
  • Filename
    dave_gottrophy_dosbox_newpatch.ogg
    File size
    22.45 KiB
    Downloads
    420 downloads
    File comment
    DDave "got trophy" sound with the new patch
    File license
    Fair use/fair dealing exception
  • Filename
    dave_gottrophy_dosbox_vanilla.ogg
    File size
    23.19 KiB
    Downloads
    423 downloads
    File comment
    DDave "got trophy" sound, vanilla DOSBox
    File license
    Fair use/fair dealing exception

Reply 19 of 47, by ripsaw8080

User metadata
Rank DOSBox Author
Rank
DOSBox Author

There's a bit more than a simple relocation; the added spkr.mode condition is what helps Digger.

Some other early games by id Software like Dangerous Dave in The Haunted Mansion, Rescue Rover, and Shadow Knights sound more like what I remember. Not too surprising because the sound code was probably reused amongst their games.