Page 1 of 6

TEsound - simple, easy sound/music manager

Posted: Sun Jan 09, 2011 2:44 am
by Taehl
Tired of not being able to overlap sounds in Love? Or maybe you just can't figure out the love.audio module? Ensayia and I wrote this module to make sound and music easy.

Mini-tutorial!

Q) What do I have to do to use it?
1) Put TEsound.lua in your game's folder.
2) At the top of main.lua, add require"TEsound".
3) In love.update(), add TEsound.cleanup(). That's it! TEsound will automatically manage sound channels (sounds can overlap) and memory.

Q) How do I just play a sound?
A) All you need to do is TEsound.play(filepath), where filepath is a string like "sounds/boom.ogg".

Q) I have three different jump sounds, how can I play one at random?
A) TEsound.play(list), where list is a table like {"jump1.ogg", "jump2.ogg", "jump3.ogg"}

Q) Can I make it constantly play randomized music?
A) Sure! TEsound.playLooping(list). When one song ends, a new one from the list will automatically start playing.

Q) Now how do I stop the music? / What are sound tags?
A) The best way is to use TEsound's "tagging" feature. Simply put, TEsound lets you add one or more tags to each sound that's playing, and you can call various functions on all sounds with a given tag. So you could do this:
TEsound.playLooping("song1.ogg", "music")
TEsound.stop("music")
Sounds can have multiple tags if you desire (use a list: TEsound.play(sound, {"something", "whatever", "lol"}), and multiple sounds can share tags (if you call something like TEsound.pitch("sfx", .5), all sounds with the "sfx" tag will immediately be low-pitched). Tags can also be unique, in case you want to work with a specific sound.

Q) What if I want to change the volume/pitch of all sounds?
A) That's what the special "all" tag is for. You don't need to give the tag to sounds, it's automatically applied to them. So if you wanted to cut the volume of everything in half, you just need to TEsound.tagVolume("all",.5).

Q) I want to let the player choose different volume levels for sound effects, music, and voice-acting. Can TEsound handle it?
A) Yep! You can set a volume multiplier for any tag with TEsound.tagVolume(tag, volume). Tag-volume changes take immediate effect (even on sounds that are already playing!). So you could use TEsound.tagVolume("voice", .75), and any sound with the "voice" tag would play at .75 volume. This is multiplied by the sound's own volume and what the "all" tag is set to - if you TEsound.play("splat.ogg", "sfx", .5), and you've set the "sfx" and "all" tags to .6 and 1 volume, then the sound would play at .3 volume.

Q) How do I pronounce the name of your module? "Tee ee sound"?
A) That works, but I, personally, say "teh sound" ;)

Q) Anything else I should know?
A) Each function has several more optional parameters - I've just covered the basics here. Check out the documentation for a full list of functions and their parameters.

Ready for sound and music to finally be easy to use? Download the module, and check out the wiki page for more documentation.

EDIT) Updated it slightly - I streamlined it by merging playRandom into play, and playRandomLooping into playLooping (just pass them a list instead of a single filepath). Updated documentation accordingly.
EDIT2) Updated it slightly again - make pitch work identically to volume, and added special "all" tag functionality. Updated documentation accordingly.

Re: TEsound - simple, easy sound/music manager

Posted: Sun Jan 09, 2011 9:47 am
by nevon
This seems rather useful. So far I've gotten by with a fairly rudimentary sound manager, but this definitely seems more versatile. What license is it being released under?

Re: TEsound - simple, easy sound/music manager

Posted: Sun Jan 09, 2011 2:54 pm
by Lap
Another win for procrastination! I kept putting off making something to manage the looping music and sound effects....glad I did.

Re: TEsound - simple, easy sound/music manager

Posted: Sun Jan 09, 2011 3:20 pm
by Taehl
License? Feh, I don't know. Guess it'll be zlib, like Love itself. But if your game ends up making a lot of money, maybe you could please consider sending a little bit of it my way? ;)

EDIT) Clarified wording.

Re: TEsound - simple, easy sound/music manager

Posted: Sun Jan 09, 2011 3:31 pm
by nevon
Liberal licensing makes my heart smile. :nyu:

Re: TEsound - simple, easy sound/music manager

Posted: Sun Jan 09, 2011 3:45 pm
by Taehl
I'm glad. So, I guess with that out of the way, this thread can be used for bug reports (hah, unlikely!), feature requests / suggestions for improvement, questions about usage, and so forth. Or, hey, if everything just works (hopefully the case), I won't say no to praise. :P

Re: TEsound - simple, easy sound/music manager

Posted: Sun Jan 09, 2011 4:34 pm
by Robin
Taehl wrote:License? Feh, I don't know. Guess it'll be zlib, like Love itself.
Excellent choice.
Taehl wrote:Maybe with the added condition that if you use it for a game that ends up making a lot of money, I ask you to consider sending a little bit of it my way. ;)
Please don't do that. Put it somewhere apart from the license, it could confuse people to no end.

Re: TEsound - simple, easy sound/music manager

Posted: Sun Jan 09, 2011 4:44 pm
by Taehl
Fine, fine. It was mostly a joke.

Re: TEsound - simple, easy sound/music manager

Posted: Tue Jan 11, 2011 7:37 pm
by Taehl
Small update: I've made pitch-changing work exactly like volume-changing, hence two new functions: TEsound.tagPitch and TEsound.findPitch. I've also added a special "all" tag which automatically works on all sounds (they don't need to be assigned the tag) in ADDITION to their own volume/pitch and tag volume/pitch (if any). In other words, the volume/pitch a sound plays at is (sound's level * set tag * "all" tag). So basically, changing the "all" tag is a master volume/pitch control (using TEsound.tagVolume("all",.5) will halve the volume of all sounds, for example).

Re: TEsound - simple, easy sound/music manager

Posted: Thu Jan 13, 2011 3:32 pm
by TechnoCat
Could you add this to the wiki please? http://love2d.org/wiki/Category:Libraries?action=purge