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.

Code Snippets / [DBP] - Sound functions

Author
Message
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Apr 2011 10:53
I've had this idea for awhile after I played with GLB. If you've ever noticed what happens when you play a sound that's already playing you'll know that it cuts off playback and starts it back over. Let's say you want to play a cute little sound whenever your character picks up a coin or something. When the pick up several coins at once, the sound effect doesn't sound very clean. What this code will do is allow you to specify how many instances of a sound can be played at once. So rather than it being cut-off, you could hear the same sound played again, overlapping what's currently already playing.




The Internet: Where men are men, women are men, and children are federal agents
Talairina
18
Years of Service
User Offline
Joined: 9th Jan 2006
Location: United Kingdom
Posted: 8th Apr 2011 11:06
Nice one Phaelax, work's plain and simple =)
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 10th Apr 2011 19:07
To save on memory usage it would be handy if you could instance a sound like you can with objects. It would also save on the time used for the memory copy too.

Warning! May contain Nuts!
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Apr 2011 20:53
Well the clone sound basically does just that. The clones all share the same wave data.

The Internet: Where men are men, women are men, and children are federal agents
Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 11th Apr 2011 13:22
Quote: "To save on memory usage it would be handy if you could instance a sound like you can with objects. It would also save on the time used for the memory copy too."


Besides saving memory, does it save CPU usage?

WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 11th Apr 2011 20:40
As far as I know from the days of the SID chip, all playing sounds are handled by the sound chip so once wave data is sent then the sound device takes over so there's minimal/no use of cpu anyway. MP3's are different because they need decompressing.

Warning! May contain Nuts!
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Apr 2011 02:29
It would technically use more clock cycles I believe since it does potentially play multiples sounds at a time, but I highly doubt you'd notice any increase.

As far as offloading the sound playback to the sound card, I'm not 100% sure on that. I'm not that familiar on how DirectSound works internally.

The Internet: Where men are men, women are men, and children are federal agents
Jambo B
14
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 13th Apr 2011 20:23
clone music would be a useful command. I get music to loop accurately by loading it into two objects, then switching between the two using Matrix Plugin's hitimer(). The downside to this is that you have to load the music twice!

That is, unless anyone else can suggest a better way of looping music. the loop music command is unreliable, I've found, and there's a noticeable 'audible artifact' when loop music, er, loops.

Jambo
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 14th Apr 2011 02:24
It'll be a low level IRQ that handles the wave data to the sound device. So really the only overhead is the setting up of sounds, or extracting from an mp3. You're right saying hardly notice any difference, even if over 200 sounds are playing at the same time. That never happens often though. Even in a game like UT I don't think there's more than possibly 10-15 sounds all at once.

This is definitely one for me to remember though.

Warning! May contain Nuts!
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Apr 2011 12:40
Quote: "the loop music command is unreliable, I've found, and there's a noticeable 'audible artifact' when loop music, er, loops."


I've noticed that too. One way around it is convert your music to way and load it as a sound. That actually loops a lot better.

The Internet: Where men are men, women are men, and children are federal agents

Login to post a reply

Server time is: 2024-03-29 00:42:24
Your offset time is: 2024-03-29 00:42:24