Jump to content


Photo

SG Audio DLL


  • Please log in to reply
134 replies to this topic

#1 snake5

snake5

    GMC Member

  • GMC Member
  • 71 posts

Posted 20 April 2011 - 01:37 AM

Posted Image

This is a sound system DLL that makes controlling your sounds a simple task.
It is based on OpenAL so it should have no problems running on different versions of Windows or even Mac, if the opportunity to port it presents itself.

Why I think you should use my DLL (Pros):
  • A very simple interface
  • 3D sound support
  • Simplified volume control (through group flags and fading)
  • OGG streaming support
  • No crazy DLL dependencies (except OpenAL, of course)
  • Fresh code - I'm able to add requested features
  • Documentation is in script files - you don't have to look too far to know how it works
  • Plays sound as every other player (AFAIK, GM did something odd to the sound files)
The only reasons why you wouldn't need it (Cons / preference mismatch):
  • You like working with ugly interfaces (let's face it, this DLL might be one of the best things you've found this week B) )
  • You hate WAV/OGG file formats (only these are and will be supported in this audio DLL)
  • You cannot afford to put that 1 MB OpenAL redistributable or the OpenAL DLL files in your game's archive

SDK Download (only DLLs and the GML scripts file): http://www.box.net/shared/3tzyqjjp9c
Test kit (GM8 .gmk file, DLLs and one sample track in .ogg): http://www.box.net/shared/0jynnxfjte
Compiled test kit (executable, DLLs and the sample track): http://www.box.net/shared/74rti52x9z


Simplicity
If you need to play music...
e_music = sga_TrackPlay( -1, "music/fight.ogg", 1, 0 );
If you need to play a sound effect...
On object creation:
e_fx = sga_CreateFX( "sounds/shot.wav", 0 );
On deletion/room end:
sga_DestroyEmitter( e_fx );
And when you need to trigger the effect:
sga_PlayFX( e_fx );
There are, of course, some tiny details that make this audio DLL good for other kinds of sound effect/music control but this a very simple usage example that almost everyone probably has seen sometime.

The Design
  • This is an emitter-based system. Which means that sound files don't get loaded into memory twice and all the emitters can (but shouldn't, due to speed limits of every normal game) play something at the same time.
  • To create an emitter, use the appropriate script (sga_CreateEmitter) or one of the simplification functions (sga_Create3DFX, sga_CreateFX), or sga_TrackPlay.
  • All emitters should be destroyed (sga_DestroyEmitter) to prevent memory leaks while the game is running but if they aren't, the DLL frees all the data automatically.
  • sga_Init and sga_Free must be called on game start and end, respectively.
  • Volume is controlled by group bit flags - each group represents a bit, bits are ORed together to influence the final volume of the emitter.
  • Every "flag" argument of any script is the bitwise list of groups that influence the emitter. 0 - no groups, 1 - group 1, 2 - group 2, 4 - group 3, 5(1+4) - groups 1 and 3 etc.
  • In sga_SetGroupVol and sga_GetGroupVol, group 0 is the master group - it controls the volume of all emitters, bit flag groups start with 1 and end with 32. Therefore this group ID is not equal to x in 1 << x (it is to 1 << (x-1) though).
  • sga_TrackPlay is very good for background music / voice acting as it recreates the emitter when necessary.

Licensing
Use it any way you want (commercially or non-commercially), but with some tiny exceptions: it is not allowed is to misrepresent the author of the library and it's not allowed to sell it.
Credit is appreciated but not required.

Version history
1.06 (29/01/2013)- fixed one ogg effect playback bug. Thanks to Gorkiller for reporting it and testing.
1.05 (13/01/2013)- rebuilt the streaming system. Thanks to Ancient Alien and EanFox for help with testing.
1.04 (30/04/2011)- fixed a bug with small OGG files not being played due to their size being smaller or equal to the stream buffer size constant. Thanks for hunting down that one, Bleed!
1.03 - sga_SetPlayOffset/sga_GetPlayOffset/sga_SetPitch/sga_SetPanning and some safety checks to avoid crashing on wrong emitter IDs were added.
1.02 - fixed a bug in sga_SetCamDir where it would hang the game. (to developers of Game Maker: PLEASE FIX EXCEPTION HANDLING!!!)
1.01 - fixed some licensing issues (removed ALUT and thus got rid of its ugly LGPL license), added a new WAV loader that precisely describes what's wrong with the file if an error occurs, I also put the OpenAL DLLs in every archive since they're so small (~550kB uncompressed, ~250kB compressed).
1.00 - initial release.

A bigger sample
A modification of the "fps6" sample that includes some sound effects and some graphical effects that fit the sounds.
You can get it here: http://www.box.net/shared/ng2tspnsmr

If you have any questions, feel free to ask either here or in Twitter. P.S. Due to lack of time, I haven't been using the account for quite some time so you will find more luck with contacting me via the PM system in here.
If you're interested in what I do, check out this website. :)

Edited by snake5, 29 January 2013 - 07:35 PM.

  • 8

#2 Aragon

Aragon

    GMC Member

  • GMC Member
  • 142 posts

Posted 20 April 2011 - 07:58 AM

I think I gonna use it, because of the license
  • 0

#3 snake5

snake5

    GMC Member

  • GMC Member
  • 71 posts

Posted 20 April 2011 - 07:40 PM

I have made a more complex sample (based on FPS tutorial's 6th source file) with music and 3D sound effects.
It should hopefully show how easy it is to use my DLL.

http://www.box.net/shared/ng2tspnsmr
  • 0

#4 dantehavenaar

dantehavenaar

    GMC Member

  • New Member
  • 14 posts

Posted 23 April 2011 - 05:35 PM

I don't know what I'm doing wrong.
When I start the game the following error occured:
ERROR in
action number 1
of Other Event: Game Start
for object obj_menu_controler:

Error defining an external function.

If you will download it:
Game

It's Dutch but I think you don't have problems with it because there is nothing to read. :rolleyes:
  • 0

#5 snake5

snake5

    GMC Member

  • GMC Member
  • 71 posts

Posted 23 April 2011 - 06:12 PM

There's no SGAudio.dll in the folder where I found the other DLLs.
  • 0

#6 dantehavenaar

dantehavenaar

    GMC Member

  • New Member
  • 14 posts

Posted 23 April 2011 - 06:32 PM

Stupid me :wub:
  • 0

#7 DFortun81

DFortun81

    The Fortunate One

  • GMC Member
  • 899 posts
  • Version:GM:Studio

Posted 23 April 2011 - 09:03 PM

There seems to be a bit of a hiccup when booting the DLL up, not by much of course, but it's noticeable.

Edit: Although, if I may, I'd like to see a function where you could load a song and declare on its destruction that a separate song be looped instead. A lot of good games of our time have used a system like this where the introduction of the song would play and after it was completed, it would loop the "LOOP" section of the song - which was a completely different file and trimmed to loop seamlessly. Make this functionality and I'll use this DLL.

Edited by DFortun81, 23 April 2011 - 09:09 PM.

  • 0

#8 snake5

snake5

    GMC Member

  • GMC Member
  • 71 posts

Posted 23 April 2011 - 09:49 PM

There seems to be a bit of a hiccup when booting the DLL up, not by much of course, but it's noticeable.

Probably something that OpenAL/the underlying API does on its own. My initialization code is quite small.

Edit: Although, if I may, I'd like to see a function where you could load a song and declare on its destruction that a separate song be looped instead. A lot of good games of our time have used a system like this where the introduction of the song would play and after it was completed, it would loop the "LOOP" section of the song - which was a completely different file and trimmed to loop seamlessly. Make this functionality and I'll use this DLL.

Hmm, this might be a bit hard to do. But I'll try to figure something out.
  • 0

#9 Jake Armstrong

Jake Armstrong

    GMC Member

  • GMC Member
  • 483 posts
  • Version:GM8.1

Posted 24 April 2011 - 05:01 AM

Things I'd like to see (assuming you can't do them already...):
Being able to change the names of the two OpenAL dlls!
Setting sound position (so many seconds in, etc.)!
Setting sound frequency?
Being able to set pan without setting up a sound position?
  • 0

#10 snake5

snake5

    GMC Member

  • GMC Member
  • 71 posts

Posted 24 April 2011 - 12:31 PM

I added sga_GetPlayOffset/sga_SetPlayOffset/sga_SetPitch...
and sga_SetPanning (should definitely work for mono sounds).
But for other things - they are very hard to do, impossible without hacking and it's hard to see the practical purpose. So could you explain why there's a need for such features like panning and changing names of those DLLs?
  • 0

#11 Bleed

Bleed

    Chevalier

  • GMC Member
  • 736 posts
  • Version:GM:Studio

Posted 24 April 2011 - 12:56 PM

This has potential and i was looking to replace my old sound dll, but unfortunately i can't seem to make it work, nor do i have the time to look for answers or fixes, since it claimed it was simple to use, if only it had a help file of sorts explaining what each call does in depth (eg, sga_CreateFX(filename,flag).....what flag???). Not all of us are sound gurus.
Proper respect for the clearly hard work you've put into this project, but it'll be appreciated if you'd made a help file for this.


  • 0

#12 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1916 posts
  • Version:GM:Studio

Posted 24 April 2011 - 01:22 PM

I'm not using your dll at this time, as I have coded my own using irrKlang. But, I have a few suggestions to make it better, which would allow features to be added nicely.

I see you just added the get/set "offset" functions. If that is referring to the play position(how far into the track) the song is it, then that is a good thing you probably must have.

My recommendation would be to make this an extension. You would stick your OpenAL wrapper into the extension, but the OpenAL dlls would still have to be in the executable directory for it to work. Then, you add more functionality using GM's scripting. For example, I have two objects, that are completely created through GM code. I have enabled "loop points" and GM "callbacks" in this manner. For the loop points, when a sound is played with loop points, I create an instance of the loop point object. In the step event, it checks(through the dll call) the sound playing position, and if it past the loop point, it sets the play position back to the beginning loop point. Then, when you want to stop the sound, in the same stopping script for stopping any looping sound, you add a check with each object(loop point object) if my sound pointer is the same, destroy it, and stop the sound(with dll call). This way, the sound stops looping, and the controlling object gets destroyed.

The "callback" one works similar. You supply is with either a GM script you want executed, or you could be versatile and use a string to execute(which could execute a script with different arguments, or whatever code you put in the string). The object you create in its step even simply checks if the sound is done playing, and when it is, executes the specified sting/function. Then of course you destroy that object instance. In this manner, you can fire an event, for example to start looping a different sound, or really whatever the game designer needs.

The other reason I recommend an extension is not only because you can add gml functionality to accessing your dll, but because it is simply easier overall to use. I like using extension for even my simplest dlls because I only have to add the extension, and the functions show up in GM's code completion, including the named arguments you used in the extension creator. You can also integrate help files, and if the dll is not wrapping another dll(like in this case yours is) you don't have to worry about putting the dll in anywhere, because GM loads it up as part of the extension.

If you are interested, I am willing to give you the source to my extension, including the C++ and the gml. The irrKlang API does more things for you than OpenAL does, but I don't think that is going to be an issue. I'd think since you already have OpenAL up and running, you would more likely be interested in how I integrated it with gml calls, adding functionality like I recommended above. If you want it, either post it here, or PM me.
  • 0

#13 snake5

snake5

    GMC Member

  • GMC Member
  • 71 posts

Posted 24 April 2011 - 02:05 PM

This has potential and i was looking to replace my old sound dll, but unfortunately i can't seem to make it work, nor do i have the time to look for answers or fixes, since it claimed it was simple to use, if only it had a help file of sorts explaining what each call does in depth (eg, sga_CreateFX(filename,flag).....what flag???). Not all of us are sound gurus.
Proper respect for the clearly hard work you've put into this project, but it'll be appreciated if you'd made a help file for this.

If you don't want to use per-group volume control, just set the flag to 0. I think I explained this in the first post. If not, I'm going to fix this soon.

kburkhart84:
Thank you for the suggestions.
I will probably some day create an extension for this DLL.
But I don't think it would be useful to use automatically created objects for callbacks here. There are many reasons for this but the most important are - they can easily make everything slower for object-heavy games and they can pollute the debug window's instance list. So if I'm going to implement something like this, I'd rather use pure scripts.
Also thanks for the offer to see your source code but I think I will be able to handle this on my own.
  • 0

#14 Jake Armstrong

Jake Armstrong

    GMC Member

  • GMC Member
  • 483 posts
  • Version:GM8.1

Posted 24 April 2011 - 02:20 PM

I'm going to test with 8.1, this looks like it can do everything I want now. Thanks for making it!

As for the .dll name changing, it's obviously not essential, but I like to be able to call it Sound.dll or something just so less tech savy people playing my game aren't all like "What is an OpenAL?".
  • 0

#15 snake5

snake5

    GMC Member

  • GMC Member
  • 71 posts

Posted 24 April 2011 - 02:31 PM

As for the .dll name changing, it's obviously not essential, but I like to be able to call it Sound.dll or something just so less tech savy people playing my game aren't all like "What is an OpenAL?".

Ah. In that case, you could just put those DLLs in a "SoundLibraries" directory or something like that and change the DLL path in sga_Init. That should answer their question. :)
  • 0

#16 Jake Armstrong

Jake Armstrong

    GMC Member

  • GMC Member
  • 483 posts
  • Version:GM8.1

Posted 24 April 2011 - 02:41 PM

Thanks! And it definitely works with 8.1 :P
  • 0

#17 Bleed

Bleed

    Chevalier

  • GMC Member
  • 736 posts
  • Version:GM:Studio

Posted 24 April 2011 - 02:43 PM

Still wont play, i have a .ogg mono sound file at 44100 hz. The file seem to load properly with no errors, but just cant hear anything playing.
  • 0

#18 snake5

snake5

    GMC Member

  • GMC Member
  • 71 posts

Posted 24 April 2011 - 02:53 PM

Still wont play, i have a .ogg mono sound file at 44100 hz. The file seem to load properly with no errors, but just cant hear anything playing.

If you could send me the file, I'd check if there's a bug in the streaming code or if the file is not supported (there are many ogg codecs and I'm not sure if all of them can be read by this DLL).
  • 0

#19 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1916 posts
  • Version:GM:Studio

Posted 24 April 2011 - 03:27 PM


This has potential and i was looking to replace my old sound dll, but unfortunately i can't seem to make it work, nor do i have the time to look for answers or fixes, since it claimed it was simple to use, if only it had a help file of sorts explaining what each call does in depth (eg, sga_CreateFX(filename,flag).....what flag???). Not all of us are sound gurus.
Proper respect for the clearly hard work you've put into this project, but it'll be appreciated if you'd made a help file for this.

If you don't want to use per-group volume control, just set the flag to 0. I think I explained this in the first post. If not, I'm going to fix this soon.

kburkhart84:
Thank you for the suggestions.
I will probably some day create an extension for this DLL.
But I don't think it would be useful to use automatically created objects for callbacks here. There are many reasons for this but the most important are - they can easily make everything slower for object-heavy games and they can pollute the debug window's instance list. So if I'm going to implement something like this, I'd rather use pure scripts.
Also thanks for the offer to see your source code but I think I will be able to handle this on my own.


The things I'm doing I'm not sure if they can be done with scripts alone, unless the developer himself has objects calling those scripts. I've never had a problem with it though, simply because the objects don't get "names" like normal objects do, since you define them through code only. I can see it being an issue with too many objects at once though. The other thing is that you probably in most cases wouldn't have too many sounds needing callbacks, and probably only one sound using the loop points, so I don't think the amount of objects is an issue, even in an object heavy game. But I can see your point of view here. I just don't see an easy way to get automation for the "callbacks" or "loop points" without adding objects.

If you come up with one, let me know, so I can use it.
  • 0

#20 Jaycliff

Jaycliff

    GMC Member

  • New Member
  • 8 posts

Posted 25 April 2011 - 01:33 PM

Hello snake5 thanks for making this openAL dll! I tried it and it works. I have one suggestion though

Currently when you play a sound (a sound fx type) repeatedly, the sound itself gets 'restarted' and not being layered (GM's built-in sound system layers ('chorus') sounds when repeatedly played). In other words, the sound isn't 'multishot'. It would be nice if you add a 'multishot' option for soundfx types (In the old GM 5.3a that option is called 'buffers') I hope you would consider this ^_^

Oh and by the way, your dll works with the old GM 5.3a - great! B-)
  • 0

#21 snake5

snake5

    GMC Member

  • GMC Member
  • 71 posts

Posted 25 April 2011 - 04:26 PM

If you come up with one, let me know, so I can use it.

I have an idea, so I'll probably write it down soon and update the library.

Currently when you play a sound (a sound fx type) repeatedly, the sound itself gets 'restarted' and not being layered (GM's built-in sound system layers ('chorus') sounds when repeatedly played). In other words, the sound isn't 'multishot'. It would be nice if you add a 'multishot' option for soundfx types (In the old GM 5.3a that option is called 'buffers') I hope you would consider this

Since it's possible to implement this feature in scripts with the existing system, I'll probably write them quite soon.
  • 0

#22 grugin

grugin

    GMC Member

  • GMC Member
  • 127 posts

Posted 26 April 2011 - 09:07 AM

Thank you, a great alternative to the supersound dll ! It works really well with gm 8.1 ! Cool, the sound is coming back :)
  • 0

#23 Dom83

Dom83

    GMC Member

  • GMC Member
  • 138 posts

Posted 27 April 2011 - 09:59 PM

Hi, I have this error just running the sg audio test kit : alcOpenDevice failed - default device could not be opened. Do you want to continue without sound ?
I thought your dll was just not compatible with GM8.1 but I read it is. I wonder what is the problem then. My audio card is an E-Mu 0404 (which sure works) and I am running WinXP Pro.
  • 0

#24 snake5

snake5

    GMC Member

  • GMC Member
  • 71 posts

Posted 28 April 2011 - 04:23 AM

Dom83:
That should be only the case when the sound card does not support any kind of audio output. But I'll check my code - perhaps I haven't written it in the right way for this to be true. The other possibility is a bug in OpenAL though so let's hope I've made the mistake. :D

P.S. To those who requested different features, I have to say that I've unfortunately had lots of work to do and I haven't been able to implement many of those features in any way. I didn't forget about them and will try to make at least some of those as soon as finish adding important updates to my engine.

Edited by snake5, 28 April 2011 - 04:27 AM.

  • 0

#25 Bleed

Bleed

    Chevalier

  • GMC Member
  • 736 posts
  • Version:GM:Studio

Posted 29 April 2011 - 06:03 PM

Waiting anxiously on that bug fix mr. snake Posted Image

Edited by Bleed, 29 April 2011 - 06:09 PM.

  • 0

#26 snake5

snake5

    GMC Member

  • GMC Member
  • 71 posts

Posted 30 April 2011 - 01:03 AM

Waiting anxiously on that bug fix mr. snake Posted Image

Fixed it now. Playing, at least. I don't exclude the possibility of having some problems with timing but everything should be +/- OK now.
You can get the DLL in the newest version of the SDK.

To those who want to update their DLLs: don't take them from the test kits/samples. They aren't updated in those archives. The only way to get the newest version is to download the SDK. Shouldn't be much of a problem since SDK is the smallest of all those downloads anyway. :)

Edited by snake5, 30 April 2011 - 01:03 AM.

  • 0

#27 Dom83

Dom83

    GMC Member

  • GMC Member
  • 138 posts

Posted 30 April 2011 - 01:23 AM

Wow you were quick to update it. It works for me now. ;)

edit : Er, in deed SGATest.exe with the updated dll now works, but in GM it still telling me the error message, even for your SGATest.gmk . I copied the updated dll though. How come ?

Edited by Dom83, 30 April 2011 - 02:01 AM.

  • 0

#28 snake5

snake5

    GMC Member

  • GMC Member
  • 71 posts

Posted 30 April 2011 - 04:14 AM

Dom83, do you have all the DLLs together with the .exe / Game Maker source file? This is the only possible difference I can think of at the moment.
  • 0

#29 Dom83

Dom83

    GMC Member

  • GMC Member
  • 138 posts

Posted 30 April 2011 - 07:46 PM

Yes, I even copied the SGATest.gmk in the same folder as SGATest.exe . SGATest.exe works, SGATest.gmk gives me an error message... :mellow: I deleted all the scripts in SGATest.gmk and imported the updated gml, in case you updated it, but the error message keeps displaying.

edit : I noticed something strrange, if I create an exe then this exe works, but the editable still doesn't... :blink:
  • 0

#30 snake5

snake5

    GMC Member

  • GMC Member
  • 71 posts

Posted 01 May 2011 - 06:07 AM

It's probably a GM 8.1 bug then.
Setting the correct path to DLL manually (changing the "nm" variable in sga_Init) before everything else could help with testing.

P.S. Anyone knows where could I report bugs?

Edited by snake5, 01 May 2011 - 06:07 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users