How to get working sound in LOVE

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Ensayia
Party member
Posts: 399
Joined: Sat Jun 12, 2010 7:57 pm

How to get working sound in LOVE

Post by Ensayia »

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:

Code: Select all

require("proAudioRt")
Next we will need to initialize the audio device within the module, so we do as follows:

Code: Select all

proAudio.create(tracks,frequency,chunksize)
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:

Code: Select all

soundname = proAudio.sampleFromFile('soundpath')
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:

Code: Select all

sound = proAudio.soundLoop(soundname) -- For looping sounds such as music
-- OR
sound = proAudio.soundPlay(soundname) -- For single sound effects
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:

Code: Select all

proAudio.soundStop(sound) -- To stop a specific sound
-- OR
proAudio.soundStop() -- To stop all running sounds
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! :awesome:
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: How to get working sound in LOVE

Post by nevon »

I feel kind of bad for you now, but the sound in Löve has been fixed very recently. The fix is only out for 0.6.2 in the Ubuntu PPA, but once 0.7.0 is released (which it should be very soon), sound will be working on all platforms.
User avatar
Ensayia
Party member
Posts: 399
Joined: Sat Jun 12, 2010 7:57 pm

Re: How to get working sound in LOVE

Post by Ensayia »

Well, us humble Windows users don't have the advantage of a working love.audio at the moment, which is why I provided this alternative.

Even if love.audio is fixed, proteaAudio still works and is still a usable alternative.

The choice is the developers.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: How to get working sound in LOVE

Post by nevon »

Ensayia wrote:Well, us humble Windows users don't have the advantage of a working love.audio at the moment, which is why I provided this alternative.

Even if love.audio is fixed, proteaAudio still works and is still a usable alternative.

The choice is the developers.
True enough. Choice is always good.
User avatar
bruce779
Prole
Posts: 2
Joined: Wed Sep 15, 2010 10:08 pm

Re: How to get working sound in LOVE

Post by bruce779 »

Hey :) I was wondering if you could spare a sec for some proAudio advice?
I've followed the instructions above for installing it, and there doesn't appear to be any obvioius issues, well, it isn't crashing :P

This is how the code looks:

Code: Select all

    require("proAudioRt")
    proAudio.create()
    sample = proAudio.sampleFromFile("snake/snake_battle.mp3")
    if sample then bgm = proAudio.soundLoop(sample) end
    bgm = proAudio.soundLoop(sample)
    love.audio.play(bgm)
When the game runs though there is no audio coming through.
If I take the if statement off the soundLop the game crashes with an error message:
bad argument #1 to 'soundLoop' (number expected, got nil)

The mp3 is definitely in snake/ and it is a working file.
Any pointing out of idiot errors and noobish mistakes welcomed :awesome:
User avatar
Ensayia
Party member
Posts: 399
Joined: Sat Jun 12, 2010 7:57 pm

Re: How to get working sound in LOVE

Post by Ensayia »

I see a few issues here, I'll provide the correct code and then explain what's happening.

Here is the correct code that should work:

Code: Select all

require("proAudioRt")
proAudio.create(16,44100,1024)
sample = proAudio.sampleFromFile("snake/snake_battle.mp3")
bgm = proAudio.soundLoop(sample)
1. When calling proAudio.create(), the values are absolutely necessary. The ones I have provided should work for most anyone.

2. The line 'if sample then bgm = ...' is not really neccessary either. You've already declared the sample so you know you have one.

3. By assigning proAudio.soundLoop(sample) to bgm, we will use bgm to modify the sound. One example: You would use proAudio.soundStop(bgm) to stop that sound. This code will also cause the sound to be played.

4. When using proAudio, it's not neccessary to call the LOVE sound engine at all. As a matter of fact, you can even disable LOVE's sound module in your config.
User avatar
bruce779
Prole
Posts: 2
Joined: Wed Sep 15, 2010 10:08 pm

Re: How to get working sound in LOVE

Post by bruce779 »

Thanks for the help. I'll update the code when I get into work, might as well get paid for doing what I love ;) , and I'll update on how it goes.
Post Reply

Who is online

Users browsing this forum: No registered users and 55 guests