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

CD Audio in Wingstar (1996) #3742

Closed
3 tasks done
Python-Exoproject opened this issue Jun 6, 2024 · 19 comments
Closed
3 tasks done

CD Audio in Wingstar (1996) #3742

Python-Exoproject opened this issue Jun 6, 2024 · 19 comments
Labels
audio Audio related issues or enhancements game compatibility Issues related to a specific game not a bug Staging did nothing wrong!

Comments

@Python-Exoproject
Copy link
Collaborator

Are you using the latest Dosbox-Staging Version?

  • I have checked releases and am using the latest release.

Different version than latest?

No response

What Operating System are you using?

Windows 11

If Other OS, please describe

No response

Relevant hardware info

No response

Have you checked that no other similar issue already exists?

  • I have searched and not found similar issues.

A clear and concise description of what the bug is.

Run the game (I used eXoDOS version) and on 0.74 you hear CD Audio during gameplay. Use X\ECE\Staging there is no CD Audio

Steps to reproduce the behaviour.

Explain how to reproduce

  1. Run the game and compare CD Audio music in gameplay between Staging and 0.74

Download URL of affected game or software

No response

Your configuration

Used defaults with cycles=50000, game folder mounted as C and cd cue file mounted as D

Provide a Log

No response

Code of Conduct & Contributing Guidelines

  • Yes, I agree.
@Python-Exoproject Python-Exoproject added the bug Something isn't working label Jun 6, 2024
@weirddan455 weirddan455 self-assigned this Jun 6, 2024
@weirddan455 weirddan455 added audio Audio related issues or enhancements regression We broke something 😊 labels Jun 6, 2024
@interloper98
Copy link
Collaborator

Looks like the game is using the SB16's mixer to turn down the CD audio volume.

A couple solutions I tested:

  • Keep using SB16, but use sbmixer = off
  • Switch to sbpro2 (then you can leave sbmixer as-is)
  • Switch to GUS

Here's Staging lastest CI build w/ sbpro2:

Wingstar-sbpro2.mp4

@weirddan455
Copy link
Collaborator

Looks like the game is using the SB16's mixer to turn down the CD audio volume.

Nice find. I was trying to do a bisect but it broke many years ago, probably in a DOSBox SVN commit. It was using autotools build system back then and, while I was able to compile 0.74 from source, a lot of the intermediate commits won't build so I'm not able to do a proper bisect.

@weirddan455
Copy link
Collaborator

weirddan455 commented Jun 6, 2024

OK, pretty sure it's just this commit. Found by looking at git blame after @interloper98 narrowed down what the problem was. It's a commit from 2010 that's implementing Soundblaster CD audio mixer support that never made its way into DOSBox 0.74_3 so that version only works because setting CD volume this way wasn't implemented.

d7597b8

Unclear if this is actually a DOSBox bug or a game bug. The game is writing into the Soundblaster port telling us to set CD audio volume to 0 and we're doing what it asked 🤷‍♂️

Maybe there's an emulation inaccuracy somewhere but if there is I can't find it at the moment.

@weirddan455 weirddan455 removed their assignment Jun 6, 2024
@interloper98
Copy link
Collaborator

Glad it wasn't a real regression, @weirddan455! Thanks for confirming on the code side.

@interloper98
Copy link
Collaborator

Other games use the sb16's CT mixer to very precisely control music vs. voice volume; such as turning down the music during speech sequences.

So I suspect it's just a game bug (maybe the devs only had an sbpro or GUS).

@interloper98
Copy link
Collaborator

Unclear if this is actually a DOSBox bug or a game bug. The game is writing into the Soundblaster port telling us to set CD audio volume to 0 and we're doing what it asked 🤷‍♂️

Maybe there's an emulation inaccuracy somewhere but if there is I can't find it at the moment.

@weirddan455 , here's a recording of Warcraft 2 using the SB16's mixer to control the CDROM's volume. From what I can hear, the range of volumes sounds perfect to me:

Warcraft2-SB16-Mixer-CDROM-Music.mp4

This test is at least one check toward DOSBox being correct. I can't recall other games with this CD-music volume control feature - but sure there are more.

@weirddan455
Copy link
Collaborator

@interloper98 I tested Warcraft II with some log statements added to the code. It's actually using MSCDEX to control CD audio volume, not the Soundblaster's mixer. You can set sbmixer=false and that volume slider still works. Even the digital volume slider doesn't seem to use the mixer.

Quake is another game that has a CD audio slider but it also uses MSCDEX and doesn't appear to touch the Soundblaster mixer at all.

Finding a game that actually uses Soundblaster mixer would be a data point but the problem with Wingstar could be something more subtle like we're reporting a wrong value somewhere else and that's making it mute CD audio. Or it could just be a buggy game. You'd probably have to test on a real SB16 to know for sure.

@johnnovak
Copy link
Member

johnnovak commented Jun 6, 2024

You'd probably have to test on a real SB16 to know for sure.

I can test it on my AWE32 which is basically an SB16 plus "extras". Also on my ESS which emulates the SB Pro.

Better than nothing, I guess.

You could also test in PCem and X.

@johnnovak
Copy link
Member

List of DOS games that use CD Audio in some form (by kcgen):

https://www.vogons.org/viewtopic.php?p=673031#p673031

@weirddan455
Copy link
Collaborator

Worth noting if I change the in-game setup to use any of the other Sound Blaster settings, CD audio plays fine (it doesn't even attempt to write to the port to mute it) but the sound effects don't play, even I change sbtype in DOSBox config to match. Only Sound Blaster 16 works.

image0001

Setting sbmixer = off is a good work-around though. I was looking into this thinking it was a CD audio bug, which I had gotten fairly familiar with working on but it's looking more like a potential Sound Blaster bug which I'm not as familiar with.

@interloper98
Copy link
Collaborator

It's actually using MSCDEX to control CD audio volume

@weirddan455 -- great find! I guess we still need to find a game that tweaks the CD volume via SB mixer.

@johnnovak ; damn... That's a huge stack of CD audio games to dig through 😌. I've played some of them; will try to remember if any offered volume control.

@Python-Exoproject
Copy link
Collaborator Author

Thanks @interloper98 Ive used sbmixer=false which worked, so as far as eXoDOS is concerned this is resolved as we have a solution.

@interloper98
Copy link
Collaborator

interloper98 commented Jun 7, 2024

@weirddan455 , seeing as Warcraft II and Quake both used MSCDEX, I wanted to find you a couple more that positively use the SB16's mixer to control the CD volume.

Here are four confirmed (tested by disabling the sbmixer), with Staging-specific confs that you can drop in and run if you extract these games from eXoDOS zips.

(With these custom confs, I'm just launching from the console)

Chasm - The Rift (1997)
# No setup needed; game auto-detects SB16 on startup.
# Adjust CD audio in Options -> CD Volume.
# The initial 80% CD music volume is pretty quiet, but
# still audible if you turn up the volume.

[dosbox]
memsize = 63

[cpu]
core = dynamic
cpu_cycles_protected = 120000
cpu_throttle = true

[midi]
mpu401 = off
mididevice = none

[sblaster]
sbtype = sb16
sbmixer = on

[autoexec]
mount c .
imgmount d cd\CHASMPR.cue -t cdrom
c:
cd chasm
chasm
ChasmThe-SB-Mixing-CD-Audio.mp4
Operation Body Count (1994)
# Skip the intro scenes and start a new game.
# (You need to start a game to get the CD music underway).
# Press ESC to go back to the main menu, then up arrow and select 'Audio Mix'
# Arrow down to 'CD Music' and hold right-arrow max out its volume.
# Do the same for the 'Master volume', at which point you'll hear the CD music.

[cpu]
core = dynamic
cpu_cycles = 15000

[midi]
mpu401 = off
mididevice = none

[sblaster]
sbtype = sb16
sbmixer = on

[autoexec]
mount c .
imgmount d CD\BODYCOUNT.cue -t cdrom
c:
cd BCCD
call BC CDMUSIC
OpBodyC-SB-Mixing-CD-Audio.mp4
Terra Inc (1997)
# At the main menu, click the lavender music
# icon off then on to reset the music.
# Then you can adjust the music volume using
# the lower scale.

[dosbox]
memsize = 63

[cpu]
core = dynamic
cpu_cycles_protected = 30000
cpu_throttle = true

[midi]
mpu401 = off
mididevice = none

[sblaster]
sbtype = sb16
sbmixer = on

[autoexec]
mount c .
imgmount d CD\TerraInc.cue -t cdrom
c:
CD TERRAINC
autotype -w 3 right enter , enter , left enter x
SETSND
TERRAINC
TerraInc1997-SB-Mixing-CD-Audio.mp4
WipEout (1995)
# Game auto-detects SB16.
# CD audio is playing from the start.
# Volume can be adjusted from the main menu.

[dosbox]
memsize = 63
dos_rate = 60
vmem_delay = 600

[cpu]
core = dynamic
cpu_cycles_protected = 120000
cpu_throttle = true

[midi]
mpu401 = off
mididevice = none

[sblaster]
sbtype = sb16
sbmixer = on

[autoexec]
mount c .
imgmount d cd\Wipeout.cue -t cdrom
d:
cd
cls
call wipeout.bat
WipEout-SB-Mixing-CD-Audio.mp4

@Grounded0 Grounded0 added the game compatibility Issues related to a specific game label Jun 17, 2024
@interloper98 interloper98 added not a bug Staging did nothing wrong! and removed bug Something isn't working regression We broke something 😊 labels Jun 26, 2024
@interloper98
Copy link
Collaborator

interloper98 commented Jun 26, 2024

Recommend this be closed as the CDDA audio works however the game is just turning down the CDDA volume using the SB16's mixer IO control.

sbtype=sb16 + sbmixer=false and sbtype=sbpro2 are options to keep CDDA volume at 100%

@weirddan455
Copy link
Collaborator

There's a good change there's still an emulation inaccuracy here. sbmixer = false is a good workaround so it's not game-breaking anymore but that is a convenience setting that doesn't reflect real hardware. On a real SB16, the mixer would always be on (as far as I know) so why is the game muting its own music tracks? Does it do that on real hardware or are we doing something wrong?

@interloper98
Copy link
Collaborator

interloper98 commented Jun 26, 2024

I think the fact that the above 4 games have good cdda volume control via the SB ctmixer across the entire volume range at least has me confident that the emulation side is correct and that this one game is buggy.

My hunch is that developer owned an sbpro and only coded the sb16 compatibility without testing.

Another thought is that the developer had an sb16, but used a direct audio out from the cdda drive instead of feeding audio through the sb16 where it can cut the volume.

Maybe ran the miniplug output to their stereo or headphones:

Screenshot_20240625_224754

(Totally agree that verification on hardware is the best though if we're sure the CDROM's audio is routed through the sb16).

@johnnovak
Copy link
Member

I think the fact that the above 4 games have good cdda volume control via the SB ctmixer across the entire volume range at least has me confident that the emulation side is correct and that this one game is buggy.

My hunch is that developer owned an sbpro and only coded the sb16 compatibility without testing.

Another thought is that the developer had an sb16, but used a direct audio out from the cdda drive instead of feeding audio through the sb16 where it can cut the volume.

Maybe ran the miniplug output to their stereo or headphones:

Screenshot_20240625_224754

(Totally agree that verification on hardware is the best though if we're sure the CDROM's audio is routed through the sb16).

I'm kinda learning towards this explanation, yeah, and conclude that the game is buggy.

Pretty challenging to find working CD-ROM drives with CD audio support these days to test on real hardware 😅

@interloper98
Copy link
Collaborator

interloper98 commented Jun 26, 2024

Added logging around every access of ctmixer's CDA volume value (reads and writes).

When sbtype = sb16, the game reads the CDDA left and right volumes and (regardless of what it gets back) always follows that by writing a zero value to the CDDA left and right volumes:

SB16: Resetting DSP
ctmixer_read at line 2687: IO index 0x36: Read SB16 left CDDA volume value 0xf8
ctmixer_read at line 2701: IO index 0x37: Read SB16 right CDDA volume value 0xf8
ctmixer_write at line 2464: IO index 0x36: Write SB16 CDDA volume left value 0x0
ctmixer_write at line 2478: IO index 0x37: Write SB16 CDDA volume right value 0x0

It does that before the intro screen. It doesn't do any more CDDA IO reads or writes after this.

When sbtype = sbpro2, the games neither reads nor writes CDDA volumes. It only performs a DSP reset and carries on to its intro and then into the game:

SB16: Resetting DSP

I looked through the Sound Blaster programming guide https://pdos.csail.mit.edu/6.828/2018/readings/hardware/SoundBlaster.pdf
and noticed the only things we're missing regarding CDDA audio behavior is ctmixer IO index 0x3c, called "Output mixer switches (SB16)".

This lets the program selectively turn the line, CD, and mic paths on or off so they're included or excluded from the analog mixing path:

bit 4 - Line.L on/off
bit 3 - Line.R on/off
bit 2 - CD.L on/off
bit 1 - CD.R on/off
bit 0 - Mic on/off

Adding logging for this in the ctmixer_write switch:

case 0x3c: // Output mixer switches (SB16)
	if (sb.type == SbType::SB16) {
		LOG_MSG("%s at line %d: IO index 0x3c: Output mixer switches (SB16) value 0x%x",
		        __FUNCTION__,
		        __LINE__,
		        val);
	}
	break;

Rerunning the game with this:

SB16: Resetting DSP
ctmixer_read at line 2687: IO index 0x36: Read SB16 left CDDA volume value 0xf8
ctmixer_read at line 2701: IO index 0x37: Read SB16 right CDDA volume value 0xf8
ctmixer_write at line 2464: IO index 0x36: Write SB16 CDDA volume left value 0x0
ctmixer_write at line 2478: IO index 0x37: Write SB16 CDDA volume right value 0x0
ctmixer_write at line 2507: IO index 0x3c: Output mixer switches (SB16) value 0x0

Lol. So the game not only sets the CD left and right volumes to 0, but it then completely shuts off the CD from the mixing output. So it's a double-whammy!

I have no doubt the game would mute and disable the CD on a real SB16 too looking at these port writes!

Here's the log patch file: log_sblaster_cdda_io.patch.zip

Run git apply /path/to/patch when inside your source root.

@johnnovak
Copy link
Member

johnnovak commented Jun 26, 2024

Nice detective work @interloper98 🕵🏻‍♂️ That's enough evidence to conclude this is a game bug.

Well, to their credit, they made sure the CD Audio output is really muted for good 😎

Unless someone can prove the game doesn't completely mute the CD Audio output on Sound Blaster 16 on real hardware (highly unlikely), we can conclude the emulation is not at fault, so closing.

Please just use sbtype = sbpro2 (which is the best default for DOS games anyway).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audio Audio related issues or enhancements game compatibility Issues related to a specific game not a bug Staging did nothing wrong!
Projects
None yet
Development

No branches or pull requests

5 participants