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 Discussion / Audio DLL for DBC

Author
Message
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Jan 2010 11:07
Here is an audio dll and a DBC library to use with it. This came about because a question was asked about how to figure out the current byte position in a sound that was playing using DBC commands. It turns out that even though the PLAY SOUND command allows for a byte position as a parameter, it doesn't seem to work.

You can check out the thread here:
Getting Audio Position

Anyway, I didn't plan on making a DLL. I had originally just planned to make DLL calls to the winmm.dll . It turns out that sounds loaded and playing with the winmm.dll will remain in memory and cause DB.exe to never end as a process unless the sounds are properly closed before exiting DB. I don't know about you, but I'm in the habit of hitting F12 whenever an error occurs or I want to test something new. I couldn't always remember to use the CLI to close the sounds loaded from calls to winmm.dll. So, I created a DLL that will close itself out and cleanup when DB exits.

I'm posting it here because it's specifically for DBC, and I haven't tested every scenario possible with it; I'll leave that to you. This is being released without any guarantees and you use it at your own risk.

I haven't run into any problems and the calls (internally) are right out of the winmm. There are two main files:

DBCaudio.dba
jkkaudio.dll

DBCaudio.dba contains functions written in DBC code. This is the library that you should #INCLUDE with your source - or copy and paste the functions into your source. The descriptions of how they work are contained in the file. The calling convention is pretty clear (I think) and pretty consistent. It's similar to the built in SOUND commands. For instance:

LOAD SOUND filename,snum
load_sound(dll,filename,snum,flag)

PLAY SOUND snum
play_sound(dll,snum,frompos,topos)

value=SOUND EXIST(snum)
value=sound_exist(dll,snum)

I've limited the number of sounds to 1024. I don't know if that is the limit of simultaneous sounds or not - I just picked that number based on the max in DBC. I've run 6 sounds simultaneously without a hiccup.

You should be able to play most audio formats including midi all with the same function calls. A lot depends on how the drivers are set up on individual computers so the library may or may not work for some or all file types.

I haven't had time to put together a jaw dropping demo that show cases all of the functions. I did, however, include an entry from the DBC challenges with 3 different audio file types added in: midi for background music, mp3s for walking sound effects, and a wav for some whining. It's just to show all three file types work and there is a little bit of panning and volume calculation used.

If you have any questions, feel free to ask. The files are attached.

Enjoy your day.

Attachments

Login to view attachments
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 25th Jan 2010 20:08
Latch... You are a genius! I can use this to sync my game with the music, right? WOOOOHH!!

I do have one question not to do anything specifically with this DLL. Have you heard anything about the "BASS.DLL"? Apparently it was a dll used by people on this forum to control the spin or scale of objects according to the volume of different instruments in the music, therefor allowing you to sync the game with the music and create nice effects like on windows media player. It could return values to measure the volume of the music, get the position of the music, and to control different objects to different instruments. It was not used by many, and as these people left the forum, the knowledge of how to use it was lost.

Considering your knowledge over DBC, I would expect you might know something about it... I may also be wrong.

Anyway, thanks a lot for this, I'll test it as soon as I can!

TheComet


Make the paths of your enemies easier with WaypointPro!
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 26th Jan 2010 00:23
Quote: " Have you heard anything about the "BASS.DLL"? Apparently it was a dll used by people on this forum to control the spin or scale of objects according to the volume of different instruments in the music"

Bass isn't specific to the forums or users, it's a dll that's been around for a while. Check out:

Bass

I had read up on it and I was going to try it out once a couple of years ago but for some reason, I never did. Maybe the license was different then...

Quote: "Latch... You are a genius! I can use this to sync my game with the music, right? WOOOOHH!!"

Thanks! Well, you can use it to start and stop wherever you want within the sound file, but there isn't any instantaneous volume reading (like a peak meter) to help in triggering events. There's an overall volume reading for the specific sound, but no byte reading. I was actually going to try and add that but it wasn't as easy as I thought it would be. I may add it later if the mood strikes me.

Enjoy your day.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 26th Jan 2010 18:21
Great work Latch!
I don't use sound very much but I might play around with this.

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright

Login to post a reply

Server time is: 2024-04-23 13:51:13
Your offset time is: 2024-04-23 13:51:13