How to get working sound in LOVE
Posted: Sun Sep 05, 2010 7:50 pm
As most of us know the current sound engine that is provided with LOVE is very broken, working only intermittently or at times not at all. I recently found a solution that involves tying in an outside sound engine and figured I could share the basics with the LOVE community.
We will be using the proteaAudio engine to accomplish this task. First visit http://www.viremo.de/proteaAudio/index.html and download the binary package that comes with both Linux and Windows binaries (this tutorial focuses on the Windows distribution). Within this archive you will need to transfer proAudioRT.dll and lua51.dll to your main LOVE directory, this is all we will need. Unfortunately with using this engine, you will have to keep your game files in a folder in the LOVE directory if you don't already. My game is called Terus, so I keep my game files in C:\Love\Terus, for example.
Next we will need to have your game include the proteaAudio module in your code, so at the top of your love.load() function include this line:
Next we will need to initialize the audio device within the module, so we do as follows:
Values of 16, 44100, and 1024 should work fine for any modern card, so your function would look like: proAudio.create(16,44100,1024)
Now we can begin to load sound files for the module to use:
soundname is the variable you will use to store the sound's handle and soundpath is the file path to the sound in string format. For example one of my shooting sounds is: laser = proAudio.sampleFromFile('Terus/sounds/laser.ogg')
Don't forget that proteaAudio sees the LOVE directory as root, so you need to reference your game folder in your path as I have done. To play a sound we use the following:
Even though we already gave the sound sample a handle (soundname), playing the sound requires assigning it a handle as well (sound) in order to use functions like stopping the sound or changing it's volume.
To stop a sound that is playing we use the following:
That's it! Well, the basics at least. The Lua API documentation can be found at http://www.viremo.de/proteaAudio/proteaaudiolua.html and details how to use more advanced options such as volume adjustment, sound panning, etc... and is fairly simple and straight forward.
In conclusion, I hope this tutorial helps some of our fellow LOVE developers apply a working sound engine, at least until the current one is repaired and usable.
Happy Coding!
We will be using the proteaAudio engine to accomplish this task. First visit http://www.viremo.de/proteaAudio/index.html and download the binary package that comes with both Linux and Windows binaries (this tutorial focuses on the Windows distribution). Within this archive you will need to transfer proAudioRT.dll and lua51.dll to your main LOVE directory, this is all we will need. Unfortunately with using this engine, you will have to keep your game files in a folder in the LOVE directory if you don't already. My game is called Terus, so I keep my game files in C:\Love\Terus, for example.
Next we will need to have your game include the proteaAudio module in your code, so at the top of your love.load() function include this line:
Code: Select all
require("proAudioRt")
Code: Select all
proAudio.create(tracks,frequency,chunksize)
Now we can begin to load sound files for the module to use:
Code: Select all
soundname = proAudio.sampleFromFile('soundpath')
Don't forget that proteaAudio sees the LOVE directory as root, so you need to reference your game folder in your path as I have done. To play a sound we use the following:
Code: Select all
sound = proAudio.soundLoop(soundname) -- For looping sounds such as music
-- OR
sound = proAudio.soundPlay(soundname) -- For single sound effects
To stop a sound that is playing we use the following:
Code: Select all
proAudio.soundStop(sound) -- To stop a specific sound
-- OR
proAudio.soundStop() -- To stop all running sounds
In conclusion, I hope this tutorial helps some of our fellow LOVE developers apply a working sound engine, at least until the current one is repaired and usable.
Happy Coding!