Legacy GM GM8: Dealing with Same Sound Overlap Distortion and Volume Hike

Some games of mine are still in Game Maker version 8. When 2 or more of the same sound effect overlap in time the sound becomes distorted and much louder in volume. To deal with this when I'm about to play the same sound effect I stop that sound effect if it's already playing before restarting it all in the same frame. This usually works but some of the time it doesn't and the sound plays too loud presumably because it didn't stop the previously playing sound effect in time even though the code order should mean that it does. Is there any solution to this short of using another sound system than the native one?
 

kburkhart84

Firehammer Games
Some games of mine are still in Game Maker version 8. When 2 or more of the same sound effect overlap in time the sound becomes distorted and much louder in volume. To deal with this when I'm about to play the same sound effect I stop that sound effect if it's already playing before restarting it all in the same frame. This usually works but some of the time it doesn't and the sound plays too loud presumably because it didn't stop the previously playing sound effect in time even though the code order should mean that it does. Is there any solution to this short of using another sound system than the native one?
The solution is to go the other direction. Instead of stopping the sound and playing it right away, just don't play the second one at all. The audio system runs in another thread and so despite code ordering things don't always work as planned. So the best solution(and the way I do it in Firehammer Audio) is to simply not play the sound until the other one is done(or the defined time has passed).
 
The solution is to go the other direction. Instead of stopping the sound and playing it right away, just don't play the second one at all. The audio system runs in another thread and so despite code ordering things don't always work as planned. So the best solution(and the way I do it in Firehammer Audio) is to simply not play the sound until the other one is done(or the defined time has passed).
For an existing game that is mostly done, reworking enemy patterns, and when sounds play, isn't a very good option. Also if you want enemies to rapidly fire a projectile that makes a sound on creation, and want to fire it at different intervals that would mean a very very short sounds, but even if you did that if you had multiple enemies firing that projectile and they came onscreen at different times you'd have the same propblem no matter how short the sound. In GM 5 (an earlier version) the sound didn't have the problems I've mentioned, not sure why GM 8 introduced those (maybe 6 or 7 did, but I never used them). Would using a dll such as supersound.dll for sound solve the volume doubling, and distortion problem?
 
Last edited:

kburkhart84

Firehammer Games
For an existing game that is mostly done, reworking enemy patterns, and when sounds play, isn't a very good option. Also if you want enemies to rapidly fire a projectile that makes a sound on creation, and want to fire it at different intervals that would mean a very very short sound, but even if you did that if you had multiple enemies firing that projectile and they came onscreen at different times you'd have the same propblem no matter how short the sound. In GM 5 (an earlier version) the sound didn't have the problems I've mentioned, not sure why GM8 introduced those (maybe 6 or 7 did, but I never used them). Would using a dll such as supersound.dll for sound solve the volume doubling, and distortion problem?
I'm not sure about older versions since my first GM version was GM7....but I would have to guess that older versions likely did have that same problem, unless they didn't let sounds repeat automatically, which would be bad as you couldn't have more than one instance of a sound going at any given time. Honestly though, this problem probably should have been thought out from the beginning, as it is a common thing to have to deal with even with newer versions of Gamemaker(and you are are multiple generations behind on GM8). I even made it a feature of Firehammer Audio to allow for automatic limits on how fast sounds could be repeatedly played in a nice automatic fashion since it is a common problem to have to overcome.

I don't think switching to a dll would fix the issue either, because the issue is with playing too many sounds of the same waves at once...a DLL can't get around that. You need to change the code to avoid playing the sound if it is already playing(or at the least only allow some small amount of repetitions).
 
I'm not sure about older versions since my first GM version was GM7....but I would have to guess that older versions likely did have that same problem, unless they didn't let sounds repeat automatically, which would be bad as you couldn't have more than one instance of a sound going at any given time. Honestly though, this problem probably should have been thought out from the beginning, as it is a common thing to have to deal with even with newer versions of Gamemaker(and you are are multiple generations behind on GM8). I even made it a feature of Firehammer Audio to allow for automatic limits on how fast sounds could be repeatedly played in a nice automatic fashion since it is a common problem to have to overcome.

I don't think switching to a dll would fix the issue either, because the issue is with playing too many sounds of the same waves at once...a DLL can't get around that. You need to change the code to avoid playing the sound if it is already playing(or at the least only allow some small amount of repetitions).
I know in GM 5 the sound form for each sound let you set the number of buffers allowing that many of that sound to play over themselves. It seems like even 2 of the same sounds playing over each other in GM 8 cause distortion and volume doubling which wasn't the case in GM 5. A dll might solve it if the different versions can behave different this way. I know GM 8's old but it's not feasible to upgrade some projects to GMS1, or worse to GMS2.
 

kburkhart84

Firehammer Games
I'm guessing that GM5 had a thing where it would limit the amount of times a sound was playing at once(based on you mentioning a buffer setting). At some point they got rid of that, which actually makes certain sense because sometimes it isn't really an issue if it is controlled and done right, based on the sound itself. Some sounds can be repeated more than others without distortion.

A dll might solve it if the different versions can behave different this way.
If the DLL does any sort of automatic thing where it won't play the sound multiple times at once, then it could work. Otherwise you are going to have the same problem. Sound is sound and overlapping too much of it causes distortion no matter where it comes from.

I know GM 8's old but it's not feasible to upgrade some projects to GMS1, or worse to GMS2.
I'm guessing you have either been at this project for several years now, or you started it when GM8 was already really old. Either way, upgrading to GMS1 or 2 wouldn't fix the problem for the same reason I mention above. It's why I added the sound repetition limiter feature when I wrote Firehammer Audio(for GMS2).

You mention a DLL...I'd hazard a guess that by the time you converted the project to use it, you could have easily just made the changes needed to make sounds not repeat so much. By chance, are you playing sounds when bullets are created? If so, you should certainly do them in the shooting code instead, especially if shooting creates multiple bullets. That would be the big problem right there if that's the case. instead you would want the shooting code to play a single sound, no matter how many bullets it actually shoots.
 
I'm guessing that GM5 had a thing where it would limit the amount of times a sound was playing at once(based on you mentioning a buffer setting). At some point they got rid of that, which actually makes certain sense because sometimes it isn't really an issue if it is controlled and done right, based on the sound itself. Some sounds can be repeated more than others without distortion.

If the DLL does any sort of automatic thing where it won't play the sound multiple times at once, then it could work. Otherwise you are going to have the same problem. Sound is sound and overlapping too much of it causes distortion no matter where it comes from.
After investigating I found the dll correctly interrupts a sound loaded to the same variable when it is played again. I can load the same sound twice and play them over eachother as well. I guess if I want some sounds to overlap I'd put them in an array which would load the sound for each entry and then increment which in the array to play of that sound. The majority of sounds wouldn't need to do that though.
 

kburkhart84

Firehammer Games
After investigating I found the dll correctly interrupts a sound loaded to the same variable when it is played again. I can load the same sound twice and play them over eachother as well. I guess if I want some sounds to overlap I'd put them in an array which would load the sound for each entry and then increment which in the array to play of that sound. The majority of sounds wouldn't need to do that though.
If you do it that way you are wasting memory by loading sounds multiple times....it's up to you though.....I still recommend the way I mentioned earlier.
 
If you do it that way you are wasting memory by loading sounds multiple times....it's up to you though.....I still recommend the way I mentioned earlier.
There might be another way, but that's what I can think of off the top of my head. Have to do a little more investigating on that later to see if the dll allows another way. What's the typical way to play multiple sounds over each other without loading them twice in programming anyway?
 

kburkhart84

Firehammer Games
There might be another way, but that's what I can think of off the top of my head. Have to do a little more investigating on that later to see if the dll allows another way. What's the typical way to play multiple sounds over each other without loading them twice in programming anyway?
When I say loading, I'm referring to the state they are in before actually playing them. In this case, it is the sound being put in the variable(as you say for the DLL), which can only play one at a time, as the DLL interrupts. So if you wanted a second one playing over, you'd have to load a second one into another variable.

Normally, there is one version of a sound loaded into the IDE, and in a sense it gets duplicated each time it is played(there is more to it then that, including things you stream from the hard drive). It isn't necessarily actually duplicated, though the actual sound buffers would contain duplicated data for the small bytes of sound data that is actually in the buffer. Each sound that is playing has a buffer, but I don't know how many bytes they use these days for those. So technically, the single sound would get bits and pieces of it duplicated in those buffers, even if you only have one of them at a given time.

Like I said, the better way which is used by everybody I know is to simply not play the sounds if they are already playing. For most people, just making sure you can only shoot the bullets some amount per second is enough, as the sounds don't overlap as much. You also want to only play one sound even if the single act of shooting creates multiple bullets, meaning you don't play the sound when you create a bullet, rather on the object that handles the shooting. So a single shot could create 20 bullets, but you only get one sound. Then, if you limit it to only 8 shots per second, and the sound is about an 8th second long, you don't get any overlap at all, without having to do any special handling of it. If you have multiple objects using the same effect though, you might need to do things differently, which is where I suggested having a little extra system that tracks how long it has been since the sound last played and skips that playing of it. All you need is an extra function really, which uses global variables for those sounds that need it. You could use a ds_map with the sound id as keys to store the time played data for example. This is why my audio system has a thing that handles it, but since you are seemingly not going to upgrade it won't work for you as it needs the later GMS2 versions to work.
 
When I say loading, I'm referring to the state they are in before actually playing them. In this case, it is the sound being put in the variable(as you say for the DLL), which can only play one at a time, as the DLL interrupts. So if you wanted a second one playing over, you'd have to load a second one into another variable.

Normally, there is one version of a sound loaded into the IDE, and in a sense it gets duplicated each time it is played(there is more to it then that, including things you stream from the hard drive). It isn't necessarily actually duplicated, though the actual sound buffers would contain duplicated data for the small bytes of sound data that is actually in the buffer. Each sound that is playing has a buffer, but I don't know how many bytes they use these days for those. So technically, the single sound would get bits and pieces of it duplicated in those buffers, even if you only have one of them at a given time.

Like I said, the better way which is used by everybody I know is to simply not play the sounds if they are already playing. For most people, just making sure you can only shoot the bullets some amount per second is enough, as the sounds don't overlap as much. You also want to only play one sound even if the single act of shooting creates multiple bullets, meaning you don't play the sound when you create a bullet, rather on the object that handles the shooting. So a single shot could create 20 bullets, but you only get one sound. Then, if you limit it to only 8 shots per second, and the sound is about an 8th second long, you don't get any overlap at all, without having to do any special handling of it. If you have multiple objects using the same effect though, you might need to do things differently, which is where I suggested having a little extra system that tracks how long it has been since the sound last played and skips that playing of it. All you need is an extra function really, which uses global variables for those sounds that need it. You could use a ds_map with the sound id as keys to store the time played data for example. This is why my audio system has a thing that handles it, but since you are seemingly not going to upgrade it won't work for you as it needs the later GMS2 versions to work.
It's a mostly complete game that I want to fix a few audio problems in. I definitely don't want to go back and change gameplay. It's complex and works so I'm leaving that alone. Better to have a system I can lay exactly where the sound plays occur in code than try to rework where it does in every circumstance.

I'm not sure if the dll will be used for all sound in the game yet, but if I only used the native system in GM 8 that only gives me one volume for both music and sound. The example I figured out the dll from doesn't seem to play the same sound over itself without interruption so loading it twice might not be the only way to do that. Sounds that play over each other are needed mainly for two player cooperative mode, but most sound effects don't need to do that. If I use multi-loading and arrays for those specific sounds they'd only be 2 to 3 entries for sounds that do that.
 

kburkhart84

Firehammer Games
It's a mostly complete game that I want to fix a few audio problems in. I definitely don't want to go back and change gameplay. It's complex and works so I'm leaving that alone. Better to have a system I can lay exactly where the sound plays occur in code than try to rework where it does in every circumstance.

I'm not sure if the dll will be used for all sound in the game yet, but if I only used the native system in GM 8 that only gives me one volume for both music and sound. The example I figured out the dll from doesn't seem to play the same sound over itself without interruption so loading it twice might not be the only way to do that. Sounds that play over each other are needed mainly for two player cooperative mode, but most sound effects don't need to do that. If I use multi-loading and arrays for those specific sounds they'd only be 2 to 3 entries for sounds that do that.
Alright then, good luck and hopefully you can figure out a solution that works for you.
 
Alright then, good luck and hopefully you can figure out a solution that works for you.
I've downloaded and will have a look at your Firehammer Audio system when I'm doing something in GMS2 again. Right now I'm pretty annoyed at GMS2 because 2.3.4 quits as soon as the launch menu is about to appear. I could revert to 2.3.3, but like I said I'm pretty annoyed with GMS2 for the time being. I've file a bug report and hope they address this. Your sound method would probably work best if I were starting from scratch, and didn't want 2 volumes.
 

kburkhart84

Firehammer Games
I've downloaded and will have a look at your Firehammer Audio system when I'm doing something in GMS2 again. Right now I'm pretty annoyed at GMS2 because 2.3.4 quits as soon as the launch menu is about to appear. I could revert to 2.3.3, but like I said I'm pretty annoyed with GMS2 for the time being. I've file a bug report and hope they address this. Your sound method would probably work best if I were starting from scratch, and didn't want 2 volumes.
If you do start a project in GMS2 and want to use my system, feel free to let me know in the GMC topic, or join the Discord and I can help you implement the system if you need it.
 
If you do start a project in GMS2 and want to use my system, feel free to let me know in the GMC topic, or join the Discord and I can help you implement the system if you need it.
A few questions:

What are the usage rights? Is it free for commercial use?

GMC Topic

Do you mean to post another topic the same exact way I have here to let you know?

Discord

I never joined a discord as far as I know. What and where is it?
 

kburkhart84

Firehammer Games
What are the usage rights? Is it free for commercial use?
I originally had put it for sale, but I decided to make it free. So it is free, completely free, as in use it however you want, including commercially. If you hit it big, maybe remember me. I didn't put any requirements once I made it free.

Do you mean to post another topic the same exact way I have here to let you know?
There is actually a topic here on the GMC dedicated to the asset. You would want to respond to that topic, not create a new one, since it would be specifically for support on the code and not a more general thing.

I never joined a discord as far as I know. What and where is it?
Discord is a free chat/voice service. People create servers, and others join them in order to chat in text or speak in voice channels. It is an alternative to forums. It is often used for communication in video games(like team based games), but is also often used for any other types of communities as well. Mine is specifically about my assets, and eventually my games once I get something finished. If you downloaded the audio system, the docs come with a link to the Discord. I can also send you an invite directly if you want one, but you have to set up a Discord account first. Note that it can be used online in a browser, but generally the experience is better if you download the app and use it natively.
 
I originally had put it for sale, but I decided to make it free. So it is free, completely free, as in use it however you want, including commercially. If you hit it big, maybe remember me. I didn't put any requirements once I made it free.

There is actually a topic here on the GMC dedicated to the asset. You would want to respond to that topic, not create a new one, since it would be specifically for support on the code and not a more general thing.

Discord is a free chat/voice service. People create servers, and others join them in order to chat in text or speak in voice channels. It is an alternative to forums. It is often used for communication in video games(like team based games), but is also often used for any other types of communities as well. Mine is specifically about my assets, and eventually my games once I get something finished. If you downloaded the audio system, the docs come with a link to the Discord. I can also send you an invite directly if you want one, but you have to set up a Discord account first. Note that it can be used online in a browser, but generally the experience is better if you download the app and use it natively.
I'll keep these answers about GMC and Discord in mind.

"Mine is specifically about my assets, and eventually my games once I get something finished."

Ah yes I can relate to that!

If it turns out that I end up using your audio system in a game I'll definitely credit you.
 
Top