Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paratrooper game missing helicopter/airplane sound #1492

Closed
rderooy opened this issue Apr 27, 2020 · 8 comments
Closed

Paratrooper game missing helicopter/airplane sound #1492

rderooy opened this issue Apr 27, 2020 · 8 comments

Comments

@rderooy
Copy link
Contributor

rderooy commented Apr 27, 2020

Is your feature request related to a problem? Please describe.
Paratrooper, a early PC game published in 1982.
https://www.mobygames.com/game/pc-booter/paratrooper

This game when run on an actual IBM PC as shown here:
https://www.youtube.com/watch?v=krb4ave2_Mg

Produces helicopter and airplane sound, but not when played in any emulator.

This was reported on Vogons, and user ripsaw80 had a look at it, and had this to say:
"For the helicopter sound, the game alternates between square wave counter values of 1 and 2, which are not audible frequencies, but just the re-programming of the timer counter value apparently causes a subtle noise. I suppose it could be considered an undesirable artifact, like the "snow" effect seen on old CGA hardware, but the game is making use of it and DOSBox does not emulate it."
https://www.vogons.org/viewtopic.php?t=73347

Describe the solution you'd like
Not sure if emulating this makes sense. If it is to be emulated, perhaps it should be behind an option to prevent unwanted effects on later games.

@sikthehedgehog
Copy link

I wouldn't call it inaudible, basically the game is relying on the speaker making "clicks" whenever it switches position (you know when a sample is cut off away from the middle and there's a pop? exactly the same effect).

Now, that's something that should work as-is (assuming PC speaker is properly emulated rather than only when the timer is used)… but this method was also sometimes abused for PWM to play sound with more than 1-bit resolution. Is there any code specifically to handle that case? Because I could see that interfering and failing to account for mere clicks.

Also again, not emulating PC speaker when timer is not in use also would do it, but I suppose DOSBox-X does better than that… right?

@joncampbell123
Copy link
Owner

joncampbell123 commented Apr 27, 2020

It should be emulated, the question is how to implement it, and writing code in DOSLIB to do to the PIT what Paratrooper is doing.

Now as far as I know, writing the mode byte of a timer causes it to stop and reset to a known state depending on the mode. So if it is changing between mode 1 and 2, it is relying on the PIT reverting to initial states of each mode and then running. I don't think the design of the 8254 allows switching modes while counting, without resetting the state.

I will add debug code to DOSBox-X right now to see what it is writing.

@joncampbell123
Copy link
Owner

joncampbell123 commented Apr 27, 2020

Paratrooper writes the mode byte only ONCE at startup.

1096783 ERROR PIT:port 43 B6

After that, all sound effects are just 16-bit (two 8-bit) writes to port 42h to change the counter.

However what is probably preventing this from working is that DOSBox-X inherits DOSBox SVN's performance optimization of enforcing a minimum counter value (one that is well above audible range) so that very small values do not bog down PC speaker emulation.

I see Paratrooper's helicopter noises are made by alternately writing counter=1 and counter=2.

10876253 ERROR PIT:port 42 write:1 state:3
10876255 ERROR PIT:port 42 write:0 state:0
10891577 ERROR PIT:port 42 write:2 state:3
10891579 ERROR PIT:port 42 write:0 state:0
10906868 ERROR PIT:port 42 write:1 state:3
10906870 ERROR PIT:port 42 write:0 state:0
10922240 ERROR PIT:port 42 write:2 state:3
10922242 ERROR PIT:port 42 write:0 state:0
10937750 ERROR PIT:port 42 write:1 state:3
10937752 ERROR PIT:port 42 write:0 state:0
10953148 ERROR PIT:port 42 write:2 state:3
10953150 ERROR PIT:port 42 write:0 state:0
10968537 ERROR PIT:port 42 write:1 state:3
10968539 ERROR PIT:port 42 write:0 state:0
10984021 ERROR PIT:port 42 write:2 state:3
10984023 ERROR PIT:port 42 write:0 state:0
10999379 ERROR PIT:port 42 write:1 state:3
10999381 ERROR PIT:port 42 write:0 state:0

So while either frequency is too high to hear, switching between them should make an audible click. DOSBox-X enforces a minimum count based on the PC speaker sample rate setting in dosbox.conf which these values are limited to, so, no noise.

No mode byte writes (to 43h) after startup were noted.

@joncampbell123
Copy link
Owner

joncampbell123 commented Apr 28, 2020

Hey wait a minute... doesn't mode 3 of the 8254 count down by 2 in order to do each half of the square wave?

So... wouldn't count=1 cause a square wave with one cycle counting from 65536?

Notice in the video you linked, the helicopter sounds are not just pops, they're intermittent low frequency square waves.

Paratrooper keeps the counter at count==2 when silence is intended, alternates between count=1 and count=2 when helicopters are on screen.

@joncampbell123
Copy link
Owner

joncampbell123 commented Apr 28, 2020

According to this, Paratrooper should make noise because N=1, (N - 1) / 2 = 0 (and therefore 65536) and (N + 1) / 2 = 1.
Firefox_Screenshot_2020-04-28T00-28-56 184Z

@joncampbell123
Copy link
Owner

joncampbell123 commented Apr 28, 2020

Pulling out the trusty old 486 laptop... PIT timer 2, mode 3, count=1 does indeed generate a low frequency square wave, instead of a 1MHz ultrasonic frequency that mode 2 would cause. That's what Paratrooper is relying on here.

joncampbell123 added a commit that referenced this issue Apr 28, 2020
@joncampbell123
Copy link
Owner

If you can compile from source, try Paratrooper with the latest build. The PC speaker emulation sounds at least very close to the video now.

@rderooy
Copy link
Contributor Author

rderooy commented Apr 28, 2020

I compiled the latest source, and indeed I now get sound. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants