I am currently using the Song (for music tracks) and SoundEffect classes in my game. The music track is always playing in the background. I noticed that when a sound effect is playing, the music track gets quieter, and the more sound effects I play at the same time, the quieter the music track gets. After the sound effects are finished playing, the music track gets back to its “normal” loudness. I tried searching for an answer online, but I couldn’t find one for this specific problem. Is this normal? As far as I know, other game’s music tracks aren’t affected by sound effects.
Which platform is this for? Generally SoundEffects are played directly whereas Songs are more connected with the platform’s media player systems.
I know back on Xbox 360 the volume of Songs could be controlled by the OS (for example playing guide media would mute the game music but not the sound effects).
In your case my guess is this is a platform setting outside of MonoGame which the underlying media player is using.
Thanks for your input! But the platform is Windows. I don’t think that’s the problem.
Is it a DesktopGL project/platform?
When you play soundeffects are you setting their volume to <1?
Create a DesktopDX project and port your game.
The DirectX implementation is generally in a better shape.
It is a DesktopGL project/platform. I never changed the volume of any SoundEffects/Songs/MediaPlayer, and I would assume that their volume would be 1 by default. I will try porting my game to DX and see if that fixes the issue, but ultimately I want the game to target all desktop platforms. Thanks for the suggestion !
Yeah, it might make a difference if it is WindowsDX or DesktopGL which is what I was wondering with the MonoGame platform.
WindowsDX SoundEffect = XAudio2
WindowsDX Song = Microsoft Media Foundation
DesktopGL SoundEffect = OpenAL
DesktopGL Song = OpenAL
I was expecting it might have something to do with Microsoft Media Foundation but that won’t be the case if it is already a DesktopGL project.
I think it’s possible to downgrade the nuget and test the previous version 3.8.0.
I did a quick test and checked the Platformer sample with my own fork.
Additionally I tested the official GL 3.8.0 with the same sample.
I didn’t hear any difference in the background music. However the sfx there are short.
It could be another detail, like SoundEffect.Play vs SoundEffectInstance.Play.
Testing 3.8.1 was not possible because it was a net framework project and 3.8.1 is net6-only.
If you hear no difference, it might be my computer then… But this shouldn’t be the case because other MonoGame games do not have this issue on my computer.
I tested both SoundEffect.Play and SoundEffectInstance.Play, they both cause the background music to get quiet. It is very noticeable when 4+ sound effects play at the same time. The sound effects I used are short as well (less than 0.2 seconds). It is a 16-bit 44100Hz Stereo wav file.
Also, my project used MonoGame GL188.8.131.521. I just spent a few hours upgrading it to MG3.8.1, but the issue persists.
I did some research on this problem beyond MG, and I found that a few people had the same issue with engines like Unity Sound effects cause the music to become quiet? and Godot Why do my sound effects make my music quieter? - Godot Engine - Q&A. I have limited knowledge of audio in computer science, but my educated guess is that the underlying audio mixer causes this problem. I will also try and reinstall my audio drivers, but I doubt that it causes the problem.
Does the issue only occur when using a combination of Song and SoundEffects? Maybe try playing the music as a SoundEffect instead to prove if that’s the case as a test.
Also for testing purposes if you set both SoundEffects and MediaPlayer volumes to a lower value (e.g. 0.5 instead of 1.0) does the issue persist?
Thanks for the suggestions ! I tried using SoundEffects for the music, but the issue persists. I also tried lowering the volume of both SFX and music. The problem is less apparent but is still there.
Additionally, I re-exported the audio files and made sure they have the same sample rate. The SFXs have bit-depths of 16, and the music has a bit-depth of 24. Again, the issue persists.
Ok. I was thinking it might have been some external sound output limiter if all the sounds combined were clipping, but if lowering the volumes didn’t work it probably isn’t that.
If you wanted to upload a cut down sample project which replicates the issue I can give that a try on my PC. Not sure what else to suggest.
what is your audio device? is it a Realtek one? the one that usually comes with most motherboards?
If that is the case, your Realtek audio driver comes with added enhancement features. It allows you to tweak the bass boost, headphone virtualization, and loudness equalization options. However, these enhancements can cause your system volume to change with no user input.
So you have to disable all such enhancements and that may help resolve volume-related issues on your system.
Check this article
Thanks for all your help so far ! Here’s a minimal testing program I made. (Press Enter to play 6 sound effects at the same time. I made the “music” play the same note so that you can hear it more clearly).
I tried this program on another computer but I could still hear the volume change, which means it’s probably not just my computer.
Hi there! Thanks for helping! Yes, I was using a Realtek device. However, I also tried using headphones but I could still hear the volume difference.
I tried all the tips in the article (including reinstalling drivers) but the music still gets quiet.
Thanks for that. Interestingly I’m getting the same issue with your project. Using audacity I’m getting the following approximate reductions in amplitude when pressing enter:
DesktopGL: 60% reduction
WindowsDX: 25% reduction
Also like you said it occurs regardless of whether the music is played as a Song or SoundEffect.
I think I just haven’t noticed this before as the audio levels in my games seem to be much lower than your project. Also as I limit the number of simultaneous sound effect instances and generally reduce volume based on 3D distance I think this too means I just haven’t been clipping my audio before.
Without the auto volume reduction kicking in though (still not sure what is causing this) there would most likely be distortion instead.
I have a feeling it may just be a case of reducing the overall volume, particularly of sound effects with multiple instances and maybe reducing the volume of new instances based on the number of sound effects already being played.
Thanks for your suggestions ! I will try to limit the overall volume of SFX and music. In my game, I did have a system that limited the number of each SoundEffectInstance playing simultaneously (I limited the game to play a maximum of 4 sound effects per SoundEffect file) but I still noticed the problem, which is why I created this thread.
Interestingly, MonoGame games like Stardew Valley don’t have this problem at all (at least I never noticed it) even when the SFXs are much louder than the music.
As you said, I really should tune down the overall volume of the audio files because that does make the problem less apparent. However, I think players with headphones would still notice this, but I can probably work with it for now. Since you said DX only has a 25% reduction, should I port the game to DX? Also, should I submit an issue on GitHub?
I’m not sure what is causing the auto volume reduction so I don’t know if it is worth switching to WindowsDX for that. If it is driver related those percentages could be entirely different on different systems.
Just to illustrate the distortion issue though below is a picture of the song and six sound effects after being mixed into a single audio track within Audacity (so not using MonoGame at all).
Without the auto reduction present the audio would clip the maximum levels and distortion would occur. So even if this auto reduction was something that can be fixed within MonoGame the fix would allow distortion to occur instead at the volume levels used within your test program.
I’ll have a look again next week but I couldn’t find anything related to an auto volume reduction feature within XAudio2 or OpenAL when I briefly looked at them yesterday. So personally I’m not sure if this is an issue for GitHub or not yet.