mamedev / mame

MAME
https://www.mamedev.org/
Other
7.95k stars 1.98k forks source link

Portaudio outputs sound to the wrong speakers when using 44100 sample rate on games that use real stereo output #11007

Open ghost opened 1 year ago

ghost commented 1 year ago

MAME version

0.252 (mame0252) - 0.254

System information

Windows 10 Home, 64-bit, version 22H2, USA, US English Installed RAM 8.00 GB AMD A6-5200 APU with Radeon(TM) HD Graphics 2.00 GHz

and another machine Windows 10 Home, 64-bit, version 22H2, USA, US English Installed RAM 4.00 GB Intel(R) Pentium(R) CPU B950 @ 2.10GHz

INI configuration details

mame -cc

Emulated system/software

anything that uses true stereo output

Incorrect behaviour

When using a samplerate of 44100 in conjunction with portaudio and windows wasapi, the game plays sound out of the wrong channels i.e. with Air Rescue/Outrunners/Stadium Cross style setups, sounds for player 1 come from monitor B side (right) and player 2 comes from monitor A side (left).

Player 1 is monitor A Player 2 is monitor B

Expected behaviour

Sound should come from the correct channels.

Steps to reproduce

  1. Run any game that uses stereo sound output (i.e. ssf2) with this command: mame -samplerate 44100 -audio_latency 2 -sound portaudio -pa_api "Windows WASAPI" ssf2
  2. Enter service mode (f2)
  3. Locate the Sound Test or similarly named option and find something to play that is long enough to test like BGM
  4. Press TAB, then select SLIDER CONTROLS
  5. Highlight the Speaker sliders and turn one off and leave the other on, then reverse the order, the wrong side has audio playing.

Additional details

Also, if I set audio_latency to a value of 1, the sound will change sides when changing from windowed to fullscreen and back. Odd behavior this, why would it do that when changing screens? Seems kind of like the current problem with vector hlsl doing different things in different screen modes.

Edited title according to new findings. Sorry for all the edits. This one really had me running around trying to nail it. Turns out it affects everything stereo and not just the Sega 32 dual monitor games. Check the posts below for notes and different experiments tried.

ghost commented 1 year ago

This sounds to me more like a port audio issue, or something on your system (audio driver?) swapping the channels in specific cases?

I'd be surprised if this was a MAME issue, although MAME's audio handling needs an overhaul to support >2 output speakers and proper positioning etc. anyway.

ghost commented 1 year ago

Doubt it is the system, on 2 completely different machines this happens (noted in post). It caught my attention while playing through the television, and initially I thought it was something bad with the HDMI cable or TV and so here we are. No other game I have does this that I am aware of. I can't think of any off the top of my head that have a setup like Outrunners does with left channel for player 1 and player 2 is the right channel.

Should also mention it may help to have earphones on when checking this whenever that happens. I'm just here to report the issues I am aware of, it does not matter to me if they ever get fixed, but at the very least it will help out anyone in the future that may encounter an issue and find absolutely nothing through searching the internet.

rb6502 commented 1 year ago

Do -sound dsound or -sound xaudio2 also have the channels "reversed"?

b0x-Cub3d commented 1 year ago

Another question to ask is this present with the other System Multi 32 games? The way how the games are setup is that one speaker is for each player, so the stereo setup is actually dual-mono iirc.

ghost commented 1 year ago

Do -sound dsound or -sound xaudio2 also have the channels "reversed"?

No, dsound and xaudio2 are fine, just portaudio with 44100 rate is the problem with wasapi.

I'm on mame 0.253 official stable and now the sound comes out of the wrong channels the whole time unless I hold the insert key to fast forward, then it does this odd thing where the wrong side plays slow, then the correct channel starts playing for a couple seconds but at fast forward speed (around 225% for me), then goes back n forth, wrong channel normal speed, correct channel fast speed, and the speed in the upper right corner being shown with f11 isn't dropping or anything when the switch happens.

I tried recording a wav file of this for you to listen to, but here is the kicker, it plays normally in the wav file, correct speakers are playing for the correct monitor (left speaker is monitor A and right monitor B don't forget!).

Edit: tried the old 0.239 version and even that one does this. Changing audio_latency to 1 instead of 2 makes it switch when changing windowed/fs for a bit too. I give up with this game.

As for trying other sega32.cpp games, name the ones that have this set up, as I have some of the other racers on that but I simply don't recall any of them having this speaker setup at all.

rb6502 commented 1 year ago

The "System 32 Multi" games all have the dual-mono setup. Those games are Hard Dunk, Stadium Cross, Title Fight, and of course OutRunners.

The next version of MAME will include a massively updated version of PortAudio, taking it from 2015 to their latest development on GitHub as of March 31, 2023. There are significant updates to the WASAPI support, so hopefully it will fix this issue.

ghost commented 1 year ago

The "System 32 Multi" games all have the dual-mono setup. Those games are Hard Dunk, Stadium Cross, Title Fight, and of course OutRunners.

The next version of MAME will include a massively updated version of PortAudio, taking it from 2015 to their latest development on GitHub as of March 31, 2023. There are significant updates to the WASAPI support, so hopefully it will fix this issue.

Yeah I saw that the other day in the history. I had a hunch it might fix the problem too, and thanks for mentioning Stadium Cross because that was the one motorcycle game I tend to forget about that I have on here now. I'll look at the others too, they are on the external drive.

ghost commented 1 year ago

Reporting back. Um, Hard Dunk and Title Fight do not use separate speakers for the monitors, so they are real stereo. Unless there is some trick to the service menu I am not aware of with these two.

Stadium Cross on the other hand exhibits the same thing as Outrunners, but you have to press F2 in the sound check on the LEFT/RIGHT speaker option, then press 9 to go to the BGM option to play music which is a bit different to how Outrunners menu is set up. Holding Insert also does the weird alternating fast/slow speed when playing sound.

scross 0000 0001

harddunk 0000

titlef 0000

Tried Air Rescue and it does it too. This one needs F2 and F1 pressed just so you can get the right monitor out of attract mode and silence things 0000 0001

Are there any other games not Sega Multi 32 with the orunners and scross setup? I want to try them all at this point.

Going back to Title Fight I tried messing with the speaker sliders, and disabled the left/right one by one, and they are switched too. It's just not evident when both sides play together. titlefsliders

One last go at it. I tried Super Street Fighter II Turbo and moving the sliders also has the wrong speaker output so it's definitely just portaudio across the board and not just certain games or drivers. ssf2tu

Gonna edit the title and try to clean up the first post a bit and hopefully no one gets too upset about all the edits but this thing really took a turn.

ghost commented 1 year ago

Sorry to report that this issue is still present in 0.254 with the updated portaudio. Holding Insert key is still fast for 2 seconds then slow for 1 second and alternating like before. Seems like it should play at consistent fast speed for the entirety of the key press. It also makes the speakers sometimes switch momentarily when held with audio_latency set on 1 or 2 but doesn't break when set to 0.

Below are the notes on exactly what happens with each setting configuration so far.

These settings produce correct speaker output (right from right/left from left): samplerate 44100 sound portaudio audio_latency 0 pa_api "Windows WASAPI" pa_device none pa_latency 0

These flip the speakers to wrong sides: samplerate 44100 sound portaudio audio_latency 2 pa_api "Windows WASAPI" pa_device none pa_latency 0

These flip the speakers, and flip them back temporarily if you switch from fullscreen to window vice versa: samplerate 44100 sound portaudio audio_latency 1 pa_api "Windows WASAPI" pa_device none pa_latency 0

The pa_latency doesn't seem to affect which side is playing which speaker, only the audio_latency is making it behave badly on 1 or 2. I haven't even tried with higher numbers yet, but then I'm aiming for low latency and speed, and despite what I've read, going from 48000 to 44100 does boost performance some for this hunk of junk, and helps with the cv1k and taito_f3 games (along with changing resolution to 1280x720 in windows from 1600x900).