dosbox-staging icon indicating copy to clipboard operation
dosbox-staging copied to clipboard

Sound Blaster Pro 1 and 2 PCM audio is reversed

Open James-F2 opened this issue 1 year ago • 16 comments

dosbox-staging version 0.81.0-alpha-1676-gfed6c628d Windows 10

A clear and concise description of what the bug is.

Sound Blaster Pro 1 and 2 PCM audio is reversed in DOSBox (Staging).

My post on VOGONS: https://www.vogons.org/viewtopic.php?p=536104#p536104

James-F2 avatar Sep 16 '23 09:09 James-F2

To add to the output filter register bug: https://github.com/dosbox-staging/dosbox-staging/issues/2869

This makes the SBPro emulation quite buggy and not recommended (by me) to use.... yet. For now use SB16, it has correct stereo and filter.

James-F2 avatar Sep 16 '23 09:09 James-F2

Thanks for the report and the super informative linked thread @James-F2 👍🏻 I'll get to the bottom of it at some point. Well, if it's just a matter of simply swapping the channels on SB Pro 1/2 then it's easy, but I'll read the whole thread anyway first.

In the meantime, not sure if you're aware but can simply reverse the left and right channels with the MIXER SB REVERSE command.

johnnovak avatar Sep 16 '23 12:09 johnnovak

In the meantime, not sure if you're aware but can simply reverse the left and right channels with the MIXER SB REVERSE command.

That will also reverse the CD audio and Mixer L/R channel which are correct. The reversal is only for the interleaved stereo PCM stream, it happens in most games but not all. Fixing this will require an in-depth research of the SBPro card, unfortunately this will not be a quick fix.

James-F2 avatar Sep 16 '23 12:09 James-F2

In the meantime, not sure if you're aware but can simply reverse the left and right channels with the MIXER SB REVERSE command.

That will also reverse the CD audio and Mixer L/R channel which are correct. The reversal is only for the interleaved stereo PCM stream, it happens in most games but not all. Fixing this will require an in-depth research of the SBPro card, unfortunately this will not be a quick fix.

Cool I'll read the whole thing, but CDAUDIO has its own channel. The SB channel is only for PCM audio and nothing else.

johnnovak avatar Sep 16 '23 12:09 johnnovak

Cool I'll read the whole thing, but CDAUDIO has its own channel. The SB channel is only for PCM audio and nothing else.

Got it, I'll try that.

Another temporary solution to have a good SBPro2 experience with correct stereo: sbtype = sb16 sb_filter = sbpro2 opl_filter = sbpro2

Yes, it's cheating. 😝

James-F2 avatar Sep 16 '23 12:09 James-F2

Found a super informative post on the last page of the linked thread which seems to be the definitive answer on the issue. Sample C code for a very comprehensive testing tool is also included.

johnnovak avatar Sep 17 '23 03:09 johnnovak

Yep. I think he talks about what's going on internally in the DSP, but from the perspective of the actual games and what's coming out of the speakers, the real SBPro is not reversed because the game developers compensated for that, whether DOSBox does not. In any case, the linked thread has plenty of info and tools to correct the emulation but I am not a programmer and have no idea how hard it would be.

James-F2 avatar Sep 17 '23 03:09 James-F2

@James-F2 yeah, the observable behaviour is crystal clear and you've documented that extremely well, thanks a lot for that!

I've read the whole thing again, plus found another comment that rules out some theories: https://www.vogons.org/viewtopic.php?p=536908#p536908

This is actually in line with the earlier comment I referenced, and the solution appears to be:

  • The PCM output of the SB Pro is reversed from an implementation perspective (this is important)
  • The very first 1 byte DMA transfer after a DSP reset should be ignored
  • Following odd sized DMA transfers should "carry over"
  • CD Audio and the SB Mixer should not be reversed
  • This should give the observable "non-reversed" behaviour documented by @James-F2

Also, as the commenter noted, PCem v17 has a perfect implementation of the SB Pro 1/2 stereo handling.

johnnovak avatar Sep 19 '23 22:09 johnnovak

Extremely useful summary, @johnnovak!

kcgen avatar Sep 20 '23 01:09 kcgen

Yep, great summary.

Wolfenstein 3D disables the filter even if it's forced in dosbox config file (sb_filter_always_on = true), even with SB16. I think it's related to "first 1 byte DMA transfer after a DSP reset should be ignored", but I'm not sure.

I do see "SB16: DSP was reset" when I start Wolfenstein 3D.

James-F2 avatar Sep 21 '23 16:09 James-F2

Yep, great summary.

Wolfenstein 3D disables the filter even if it's forced in dosbox config file (sb_filter_always_on = true), even with SB16. I think it's related to "first 1 byte DMA transfer after a DSP reset should be ignored", but I'm not sure.

I do see "SB16: DSP was reset" when I start Wolfenstein 3D.

I think this in line with your previous observation about the filter behaviour: the DSP reset should probably not alter the filter state, and it seems we have the programmatic filter setting flipped on top of that. To be investigated as well.

johnnovak avatar Sep 21 '23 21:09 johnnovak

Since people are looking reverse, reverse stereo, reversed stereo or stereo in our issue tracker I'm linking a simple workaround here:

https://github.com/dosbox-staging/dosbox-staging/wiki/Sound-issues#reversed-stereo

Grounded0 avatar Jan 05 '24 08:01 Grounded0

@johnnovak

You're stipulating that we now got both stereo and filter behaviour correct for Sound Blaster Pro series here:

  • #3815

Can this ticket be closed now or am I missing something?

Grounded0 avatar Jul 12 '24 03:07 Grounded0

You're stipulating that we now got both stereo and filter behaviour correct for Sound Blaster Pro series here:

To clarify, when I said stereo behaviour, I meant the bit that toggles between stereo and mono operation. That is handled correctly.

This ticket is about the occasional reversal of the left and right channels when the stereo bit is enabled — different issue, and still outstanding.

johnnovak avatar Jul 12 '24 04:07 johnnovak