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

Surround sound bad audio #194

Closed
synthc opened this issue Jan 6, 2021 · 35 comments
Closed

Surround sound bad audio #194

synthc opened this issue Jan 6, 2021 · 35 comments
Labels
bug Something isn't working

Comments

@synthc
Copy link

synthc commented Jan 6, 2021

I just did a fresh install of Augustus using my Ceasar III CD for the game files. The game runs just fine except that the audio level is WAY too high - deafening on the lowest volume level in Windows and clipping horribly.

Opening the mixer in Windows, I can see that the audio level is indeed maxed out (it doesn't pass a certain point regardless of where the volume slider is for the game). Changing my speaker settings to stereo fixes the problem.

Augustus 2.0.1
Using C3 from CD-ROM with the patch (also tried without the patch).
Windows 10 Pro 64-bit
Sound Blaster Audigy 5/Rx

@synthc synthc added the bug Something isn't working label Jan 6, 2021
@webfischi
Copy link

Interesting, I don't have an issue with my surround set-up: Sound Blaster Z with Logitech 5.1 surround system. Do you use analog or digital output?

@synthc
Copy link
Author

synthc commented Jan 6, 2021

On further testing, it only happens when it's set to 7.1. It seems to be fine with 5.1. I'm using analog output, though that shouldn't matter.

@crudelios
Copy link
Collaborator

If I have to guess I'd say SDL doesn't support 8 channel audio, only 6, but I'm not entirely sure that has anything to do with the issue.

Still, @synthc, please try Julius. It uses the newest version of SDL, so maybe that bug is already fixed there. In that case it would simply be a matter of updating SDL for Augustus too.

@synthc
Copy link
Author

synthc commented Jan 9, 2021

@crudelios It's exactly the same in Julius.

@webfischi
Copy link

Doesn't look "fixed" for me https://bugzilla.libsdl.org/show_bug.cgi?id=248 just "assigned"

@crudelios
Copy link
Collaborator

Still, from that report Windows should be supported.

@bvschaik do you have any clue? I think it's SDL related.

@bvschaik
Copy link

I have no clue. In Julius/Augustus we don't do anything special with the audio: we just tell SDL_mixer either "play this sound", or "play this sound panned x% right and y% left". After that it's up to SDL_mixer to do the panning and play it on the right set of speakers with the right volume.

@crudelios
Copy link
Collaborator

I thought as much... Either this is an SDL bug or something wrong/strange with @synthc's configuration...

I'm not sure if there is anyone else using 7.1 audio to confirm.

@synthc
Copy link
Author

synthc commented Jan 23, 2021

Two other things I should mention:

  1. Audio level is extremely high with both 7.1 and 5.1 - I imagine this is just the result of the audio engine duplicating channels.
  2. Clipping is very bad in 7.1 and occurs on the title screen music; however clipping does also occur in 5.1, but is far less noticeable - in the 0 to 1000 pop music, there is some clipping in the left channel during the intro when the horns come in.

I listened to the source audio files of both tracks and levels are normal and there is no clipping. I should note that I'm a sound engineer and I use studio monitors; so both my ears and my speakers are very sensitive to clipping. That said, the clipping in the 7.1 title music is very bad and should be easily noticeable using normal speakers. The 5.1 clipping is much more subtle and may be hard to hear without good speakers/headphones.

@crudelios
Copy link
Collaborator

Just to make sure, are you using the latest SDL2 library? I mean, when you tried Julius, did you also replace the SDL2.dll file?

@webfischi
Copy link

webfischi commented Jan 23, 2021

1. Audio level is extremely high with both 7.1 and 5.1 - I imagine this is just the result of the audio engine duplicating channels.

That would explain why I have to turn the volume down, when I start the game. Playing the raw file in VLC really sounds different. In game ROME1 sounds really heavy, with the big drum at much higher peak. You should do a video showing the clipping in software.

@synthc
Copy link
Author

synthc commented Jan 24, 2021

Just to make sure, are you using the latest SDL2 library? I mean, when you tried Julius, did you also replace the SDL2.dll file?

No, I didn't replace any files, just installed and ran it.

@crudelios
Copy link
Collaborator

I went to have a look at SDL's source code. It seems SDL converts the stereo audio to a pseudo 5.1 sound, and then from 5.1 to 7.1. They even mention in the source code their conversion can cause clipping.

I think ideally the conversion should keep only the stereo channels and mute the others, but I'm not sure it's possible to do such a thing from our side right now.

Can you please record the audio so I have a sample to add a bug report to SDL?

@synthc
Copy link
Author

synthc commented Jan 24, 2021

That's what I'd expect - a two stage upmix. Though I'm surprised there's no limiter to prevent clipping. Does SDL have any preferences at all? Like a limiter, or some way to adjust the gain? Just turning down the gain a bit would solve the problem entirely for surround sound.

Keeping only stereo and muting the others would be possibly worse than just running the game in pure stereo (because upmixing happens and can change the original stereo signal going to the front speakers). The upmixed audio actually sounds quite nice aside from the clipping.

I tried recording the audio, but my sound card only outputs stereo for internal recording, and the game doesn't clip in stereo. I could try recording the speakers themselves with a microphone, but I don't really have a proper mic for that on hand.

@crudelios
Copy link
Collaborator

@synthc the only way that SDL provides to adjust gain is already used when setting the volume in the game preferences.

I'd suggest you go to Options -> Sound settings then reduce the volume to about 50% and check if clipping stops. I don't know how else to fix it.

@synthc
Copy link
Author

synthc commented Jan 24, 2021

Oh, I didn't realize there was a separate in-game sound menu. I tried adjusting that, but it makes no difference with regard to the clipping. It's a problem with the internal mixer level, I'm sure.

@crudelios
Copy link
Collaborator

I'll need to file an issue in the SDL bugtracker, I just haven't gotten around to doing it.

@crudelios
Copy link
Collaborator

Since this is not an Augustus but an SDL issue, I did what I could, which was properly reference it on SDL's issue tracker.

As such, I'm closing this issue and hoping it gets fixed on SDL 2.0.16.

@1bsyl
Copy link

1bsyl commented Apr 27, 2021

Hey,
Could you check with that commits:
See libsdl-org/SDL#4104

@crudelios
Copy link
Collaborator

@1bsyl Thanks for working on the issue.

I'll create an Win32 SDL build from the latest github commit and post it here for testing.

@crudelios
Copy link
Collaborator

@synthc @webfischi Please try this custom build with the proposed fix by @1bsyl and check if it's solved:

http://public.josecadete.net/C3/augustus-new-sdl.zip

@webfischi
Copy link

My feeling says, it sounds different, when I compare 3.0.1 and this build. My DB meter confirms that, 3.0.1 avg is 60 DB and this build shows avg 55 DB, this was non scientific because the measure conditions weren't 100% ideal. I would still wait for @synthc's results, because he uses a 7.1 surround system, which should make the differences more prominent.

@synthc
Copy link
Author

synthc commented May 24, 2021

I just tested and levels are considerably lower, clipping is fixed, and it sounds better in general (tested on the title music and 0-1000 pop music which was the worst).

I am, however, noticing a new problem with the 0-1000 pop music, which is rapid popping/clicking noises from all channels. It is particularly prominent when woodwinds or brass are playing (quite bothersome). Occasionally there will be a pop and a brief pause in one of the instruments as well. This sounds like buffer underruns to my ears (though there are other things that could cause this) - maybe the audio buffer size needs to be increased? I tested on version 2.0.1 and this issue is not present. The problem is also present when running the game in stereo.

@1bsyl
Copy link

1bsyl commented May 25, 2021

@webfischi
you use use 5.1 ?
maybe the formula should be changed. because the central channel is subtracted twice, which could be the reason why sound is globally lower. Can you retry, patching SDL with:

in file src/audio/SDL_audio.c:

SDL_ConvertStereoTo51 (line 258)

change:
       dst[0] = 0.5f * (lf + (lf - ce));  /* FL */
       dst[1] = 0.5f * (rf + (rf - ce));  /* FR */
to:       
       dst[0] = 0.571f * (lf + (lf - 0.5f * ce));  /* FL */
       dst[1] = 0.571f * (rf + (rf - 0.5f * ce));  /* FR */

SDL_ConvertQuadTo51 (line 288)

same, change:
       dst[0] = 0.5f * (lf + (lf - ce));  /* FL */
       dst[1] = 0.5f * (rf + (rf - ce));  /* FR */
to:       
       dst[0] = 0.571f * (lf + (lf - 0.5f * ce));  /* FL */
       dst[1] = 0.571f * (rf + (rf - 0.5f ce));  /* FR */

@synthc
you're using 7.1 ? If so I should double-check this also.

about the underruns: are you on linux ?
if so, you can try changing the SDL audio back-end.
set the environment variable SDL_AUDIODRIVER
to something various, like: also, pulseaudio, pipewire, jack, etc.
not sure, about windows backend available ...

(cc @icculus )

@crudelios
Copy link
Collaborator

@1bsyl I think both @webfischi and @synthc are using Windows as both reported their findings when I provided the new dll. I'll patch in your suggested changes and provide a new download link.

I believe the buffer underflow is caused by sdl as we haven't changed the audio code lately. Also, for reference, our version 2.0.1 shipped with sdl 2.0.12.

@1bsyl
Copy link

1bsyl commented May 25, 2021

ok, so for Windows, there seems to be also various audio backends to try (with same env variable SDL_AUDIODRIVER):

wasapi
directsound
winmm

@1bsyl
Copy link

1bsyl commented May 25, 2021

windows default is wasapi ... if this appeared to be solved when using directsound,

maybe, I would worth double checking those commits ...
libsdl-org/SDL@723d014
libsdl-org/SDL@4c2be47
libsdl-org/SDL@b98b5ad

@synthc
Copy link
Author

synthc commented May 25, 2021

There are no underruns with directsound - sounds great now. I also tried forcing wasapi via the environment variable just to double check and there were indeed underruns.

@1bsyl
Copy link

1bsyl commented May 25, 2021

So, wasapi audio back-end regression seems confirmed.
Try reverting the previous commits one by one, to spot the one involved.

@crudelios
Copy link
Collaborator

@1bsyl @synthc @webfischi:

Here's a new SDL build: http://public.josecadete.net/C3/augustus-new-sdl.zip

This one has the above mentioned patch.

@synthc
Copy link
Author

synthc commented May 30, 2021

@crudelios
Not sure what you changed, but that build still has underruns with wasapi.

@crudelios
Copy link
Collaborator

The above build should somewhat louder than the previous one I made available on 5.1/7.1 without clipping.

@1bsyl
Copy link

1bsyl commented May 31, 2021

@crudelios the change is only on 5.1 (stereo to 5.1 and quad to 5.1). Haven't modified 7.1 yet

@Enrada
Copy link

Enrada commented Jun 12, 2021

Thank you crudelios.
I placed this issue in the wrong lcation, so I closed this issue and opened a new issue in correct location:

#436

@1bsyl
Copy link

1bsyl commented Jun 25, 2021

@webfischi
what about the last version ? is the 5.1 modification gives a better DB average ?

icculus added a commit to libsdl-org/SDL that referenced this issue Jul 29, 2021
This is experimental and might be tweaked further.

Reference #4104.

Also reference:

Keriew/augustus#194 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants