Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / How to work around extreme slowdown caused by a large number of sounds loaded at once?

Author
Message
Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 10th Feb 2012 05:11
I'm just starting to add sound to my game and have come across an issue. The "POSITION LISTENER" command brings my game down from 60 fps to 25 when I have a large number of sounds loaded at once (currently around 15 clips, all about half a second long or so). It was my hope to have 3d sound in my game, but it seems as though I was wrong to assume that you could have all the sounds loaded at once.

What's the most reasonable way to handle sound in the game? I load the image media all at once at the beginning of the program, which was my plan for sounds. Do I really need load and delete sounds every single time I need one to play?

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 10th Feb 2012 11:51
I don't know if this works or not, but if it was objects I would move the objects a long way off screen like 1000. Try it, and see if moving the sounds speeds up the program. Then when you need them you bring them back.

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 10th Feb 2012 13:03
Hmm, now that doesn't seem right; you should be able to have more than 15 3d sounds loaded and positioned. If you are able to post some code up, let us have a look.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Feb 2012 13:17 Edited at: 10th Feb 2012 13:18
Do you need the position listener commands? I usually just adjust the volume according to the distance between the sound's and the player's positions (or some other reference point). Works fine for me (unless you need stereo effects).

Certainly 15 clips shouldn't be a problem.

Edit Why would you use load/delete sound? That's bound to be inefficient. Why not play/stop sound?
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 10th Feb 2012 21:31
I've generally discarded the 3D Sound commands. Instead I've been using this: http://forum.thegamecreators.com/?m=forum_view&t=73816&b=5. It's a little old and might have a few bugs if I remember correctly, but it's generally been pretty reliable.

Also, as a side note, if you have duplicates of the same sound then perhaps CLONE SOUND would be more effective? I haven't tested this though.


Guns, cinematics, stealth, items and more!
Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 13th Feb 2012 02:10 Edited at: 15th Feb 2012 17:16
Thanks for the replies everyone; sorry for the delayed response, went out of town this weekend.

I wanted to clarify that the game runs slow even if I don't play any sounds. Just the fact that they're loaded causes an insane amount of lag. Like you all, I'm convinced this shouldn't be happening since it more or less makes the 3d sound commands useless. I don't think it would be much help to post my code since all I'm doing is loading the sounds and running the "POSITION LISTENER" command once every step. I do have a function which clones sounds to ensure that I can play more than one copy of a sound at once, but it has no impact on the game's performance.


Green Gandalf:
Quote: "Do you need the position listener commands? I usually just adjust the volume according to the distance between the sound's and the player's positions (or some other reference point). Works fine for me (unless you need stereo effects).

Certainly 15 clips shouldn't be a problem.

Edit Why would you use load/delete sound? That's bound to be inefficient. Why not play/stop sound?"


I definitely could adjust the volume of sounds, but the reason for using the 3d commands was to the speakers change volume based on where the sound is located in relation to the player.


Sixty Squares:
Quote: "I've generally discarded the 3D Sound commands. Instead I've been using this: http://forum.thegamecreators.com/?m=forum_view&t=73816&b=5. It's a little old and might have a few bugs if I remember correctly, but it's generally been pretty reliable.

Also, as a side note, if you have duplicates of the same sound then perhaps CLONE SOUND would be more effective? I haven't tested this though."


Thanks for the link. I'll look into it if there's no immediate solution. Right now each sound is the same (just for testing purposes), but they'll all be unique eventually.


EDIT: I... have no idea what happened. I leave over the weekend, not changing any code, and it's working perfectly fine when I come back (or at least it seems that way). Quite a bizarre bug.

Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 18th Feb 2012 04:00 Edited at: 18th Feb 2012 04:09
Quote: "Alaror said:
EDIT: I... have no idea what happened. I leave over the weekend, not changing any code, and it's working perfectly fine when I come back (or at least it seems that way). Quite a bizarre bug."


You probably turned off your computer. Your computer may have been on for a very long time, causing the timer() to progress to a negative number counting backwards. There is a bug in DBPRO that causes this. Sometimes this causes problems.
Signed Integer, first binary bit becomes a 1 causing the number to appear negative.


Also:
I try to prevent a large number of sounds from being loaded. I will use a system that keeps track of the 20-30 most used sounds, and keeps them loaded. When a sound needs to be loaded it is played or loaded over the least used sound or a free slot. So all over the program the Sound Handler is called with the sound file wanted instead of directly managing the sound. This idea can be expanded to include groups, priorities, etc.

If you can't beat the lag issue, you can keep it under control.

Login to post a reply

Server time is: 2026-07-09 17:43:12
Your offset time is: 2026-07-09 17:43:12